Hello, I’ve been trying, mostly for fun, to build the compiler for the Zig programming language on Haiku R1 Beta 4 (x86_64). I’ve faced issues, but a team member for the language has been looking into it: haiku: get a cross-compiled compiler working by jacobly0 · Pull Request #19406 · ziglang/zig · GitHub
They were able to identify the following issue:
bootstrap isn’t working because single large allocations > 0x3f60e740 bytes fail, even though many allocations of that size succeed.
Through some testing, I’ve found that calls to malloc, realloc, calloc… fail for any value above 1063315264 (or 0x3f60e740) bytes
#include <stdlib.h>
int main() {
void *p = malloc(1063315264);
return p == NULL;
}
~/test> cc -o maxmem maxmem.c
~/test> ./maxmem
~/test> echo $?
0
Succeeds, but
#include <stdlib.h>
int main() {
void *p = malloc(1063315265);
return p == NULL;
}
~/test> cc -o toomuchmem toomuchmem.c
~/test> ./toomuchmem
~/test> echo $?
1
Fails.
However, directly calling mmap for amounts greater than 1063315264 seems to work:
#include <sys/mman.h>
#include <unistd.h>
int main() {
void* p = mmap(NULL, 1349910528, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) return 1;
return munmap(p, 1349910528);
}
~/test> ./testmmap
~/test> echo $?
0
Do you know what could be causing this limitation? Is it intended behavior?
If I can provide any additional information for debugging, don’t hesitate to ask me.