Problem with malloc (WinARM, GCC 4.0.2)

OP #1171225
Rate this post
• ▲ useful
▼ not useful
I can't build the program with memory allocation functions thats work
correctly.

I definded _sbrk() and _sbrk_functions, but malloc returns zero-pointer,
or getting stick in after second call of _sbrk_r().

CPU - LPC2214
i tried to compile syscalls.c in pure arm mode and in thumb-interwork,
but result is same

----------------syscalls.c cut------------------------------------

 extern char _end;

 caddr_t _sbrk(int incr)
{
     HalDebugInfo("sbrk\n");
     static unsigned char *heap_end =0;
     unsigned char *prev_heap_end=0;

     if( heap_end == 0 ) heap_end = (caddr_t)&_end;

     prev_heap_end = heap_end;
     heap_end += incr;
     return(caddr_t) prev_heap_end;
 }

void *_sbrk_r(struct _reent* reent, ptrdiff_t incr)
{
  return _sbrk(incr);
}
-----------------------------------------------------------------
Whats version of libc should i use ?

..\arm-elf\lib\interwork\libc.a           // the program get stack in
after
                                          // second _sbrk_r call

..\arm-elf\lib\thumb\interwork\libc.a     // malloc always return zero
pointer


..\arm-elf\lib\be\interwork
..\arm-elf\lib\be\nofmult


Does anybody has a working code for memory functions ?
Guest #1171226
Rate this post
• ▲ useful
▼ not useful
Vyachwslav Krutov wrote:

> [...]
> Does anybody has a working code for memory functions ?

There is working code for sbrk in the newlib-lpc, source comes with
WinARM  in utils/newlib_lpc_src/. In other examples sbrk is implemented
in the file syscalls.c (basicly code from newlib-lpc or the
newlib-default-code or from Keil-Examples - it my differ a little bit).
Also check if end is provided correctly in the linker-script.

Martin Thomas

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.