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]

brk(2) and stack pointer


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;
}

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