I'm trying to learn more about memory management (mmap, brk, sbrk) genuinely confused as to how:
char *ptr = sbrk(0);
char *ptr2 = ptr + 100000;
*ptr2 = 8;
printf("%d\n", *ptr2);
Doesn't trigger a segmentation fault? I'm compiling this with clang on OS X Mojave.
The man page for sbrk() says that says that it's deprecated, but it also says that sbrk() should reliably return the program break. If that's true, and the pagesize is 4096 bytes, then shouldn't setting a value for an address 100000 spaces beyond the program break trigger a segfault? If it doesn't reliably return the program break (which it can't, if you can set values for addresses beyond it right?) then how do you reliably find the program break on Mac OS?
The exact same code produced a segfault on Ubuntu 18.10.
Thanks!