This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Newlib Hitachi SH-2 _sbrk() and malloc() problems?


Hello, I am developing on embedded hardware with two SH-2 CPUs. One of
the problems that I have ran through is that malloc() locks the
hardware by doing multiple word/long writes to prohibited areas in
memory, for example, where the "BIOS" is located.

I decided to take a look at: src/newlib/libc/sys/sh/syscalls.c and to
my dismay, I find this snip of code:

caddr_t
_sbrk (int incr)
{
 ...
 prev_heap_end = heap_end;
 if (heap_end + incr > stack_ptr)
   {
     _write (1, "Heap and stack collision\n", 25);
     abort ();
   }
 heap_end += incr;
 ...
}

As You can see, the heap_end pointer checks the address value of sp
(r15) and checks if it has collided with stack. Obviously, if _stack
(r15) is defined before _end, there will be a problem. Why exactly is
this so? The hardware that I'm developing on has its stack set to an
address before _end.

The problem mainly is that _write() crashes the system. I do not have
a patch for this since I would first like to understand why _sbrk() is
set up this way.

Thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]