Heap allocators are responsible for actively requesting memory from the OS to grow the heap, e.g., with brk
or mmap
. Accessing unallocated memory leads to segfaults.
I could design a different OS-user interface, where users could freely read/write anywhere in their 64bit address space (except for executable-no-write pages that hold .text, and kernel reserved sections), and any reads/writes to unallocated memory would, as now, pagefault/segfault, but the OS would trap these read/writes automatically allocate these pages and resume program execution.
The current state-of-the-art seems to leak abstractions. Virtual addressing seems to promise users that they can live in their own address space and do whatever they need to to take care of business (outside program text/ reserved addresses), but we have this leaky abstraction where users need to ask the OS themselves to allocate pages and set read/write/execute bits.
It's like virtual addressing has managed successfully to isolate processes from each other, but still fails to isolate processes from OS-layer and hardware memory management.
Why is user code (e.g., libc) responsible for managing a program's own size? Since user code can request any non-reserved address space to be mapped, what's the point of the user needing to do this themselves?