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]

Re: sbrk question?


Roman.Pollak@Sun.COM wrote:
Hi,

I try to port newlib to a self made OS and run in to problems.
So far I didn't find the real problem, since it overwrites structures
and crashes when uses stdio functions.
Could it be that the malloc expects to have a continues sbrk return values?

Malloc is expecting sbrk to behave like sbrk is supposed to. It asks for an increment and expects the return address to increase. If it does not increase as expected, it assumes that something else is issuing sbrk calls. Take a look at malloc_extend_top in libc/stdlib/mallocr.c.


If that is not your problem, you may want to look at where the stack and heap are defined. If they are colliding during your application and you aren't catching this, random behavior will occur. I can't comment on your platform as you haven't given any details. Make sure your crt0 is properly clearing the .bss section and initializing the stack pointer (usually top of data area and above _end linker symbol which is used as start of heap).

Or may I alloc memory from a different place (such as kernel and
newlib), without running in to trouble?


You can create your own malloc family set of routines if you want. Routines that use malloc/calloc/realloc don't have any expectation of the memory address return value (other than non-null). Remember that newlib internally uses _r versions of a number of malloc-family routines. These versions take a reentrant structure pointer which is needed to properly set errno.


-- Jeff J.


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