Problem with malloc(3)/sbrk(2)/brk(2)/something
Hi,
This is a follow-up to my footnote about not being able to run the 'config.guess' shell script with ash (and some other stuff) on our userland. Basically I've found a minimal testcase for the problem, which is that it's not possible to malloc() across a page boundary.
Beware that since we don't have a real page fault handler, this program will crash your machine. (Press TOC, and we'll take it from there :-)
If you turn on debugging assertions in the malloc code you'll see that it triggers this assertion:
/* We always land on a page boundary */
assert(((unsigned long)((char*)top(ar_ptr) + top_size) & (pagesz-1)) == 0);
I don't see sbrk() or brk() failing, so I'm not exactly sure why this happens. I suspect they are returning bogus values in this case. If someone knows that would be great although I expect to find the problem soon (I may try to get strace going, since it will be very useful for other similar problems).
#include <stdlib.h>
#include <stdio.h>
int main()
{
/* get the first address */
char *foo = malloc(16);
/* now try to break a page boundary */
char *target = (char *) ((unsigned long) (foo + 4095) & ~4095);
size_t nbytes = target - foo;
foo = malloc(nbytes);
return 0;
}Signature · 2 lines
[email protected], http://www.linuxcare.com/ Linuxcare. Support for the revolution.
Quoted 2 lines · David Huggins-Daines
userland. Basically I've found a minimal testcase for the problem, which is that it's not possible to
malloc()across a page boundary.
Oops, sorry, this did not seem to be the actual problem. It seems that I may have been running a kernel that was not %r8-clean, or something similar, because recompiling malloc.c with -ffixed-r8 made these test cases work :(
However config.guess still doesn't work :( Once I get a working kernel again I suppose I'll look at that.
Signature · 2 lines
[email protected], http://www.linuxcare.com/ Linuxcare. Support for the revolution.
Quoted 2 lines · David Huggins-Daines
However config.guess still doesn't work :( Once I get a working kernel again I suppose I'll look at that.
Okay, fixed. See parisc-linux-cvs and rebuild your kernels :-)
Signature · 1 line
David Huggins-Daines - [email protected]