This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
brk(2) and stack pointer
- From: "Shaun Jackman" <sjackman at gmail dot com>
- To: "ARM Linux" <linux at arm dot linux dot org dot uk>, "uClinux development list" <uClinux-dev at uclinux dot org>
- Cc: newlib at sources dot redhat dot com
- Date: Fri, 28 Apr 2006 09:53:53 -0600
- Subject: brk(2) and stack pointer
- Reply-to: "Shaun Jackman" <sjackman at gmail dot com>
Hello,
I'm implementing ARM Linux support for the newlib libc. When
implementing brk(2), is it reasonable to check that the requested
end_data_segment is below the stack pointer, or should the brk(2)
implementation allow for a stack that's been allocated below the heap
in memory?
Thanks,
Shaun
extern char _end[];
static void *curbrk = _end;
extern void *_brk(void *addr);
int brk(void *addr)
{
void *newbrk;
register void *stack_ptr asm ("sp");
if (addr > stack_ptr) {
errno = ENOMEM;
return -1;
}
if (curbrk == addr)
return 0;
newbrk = _brk(addr);
curbrk = newbrk;
if (newbrk < addr) {
errno = ENOMEM;
return -1;
}
return 0;
}