cloudius-systems / osv

OSv, a new operating system for the cloud.
osv.io
Other
4.12k stars 605 forks source link

brk/sbrk: implement program break #1236

Closed wkozaczuk closed 1 year ago

wkozaczuk commented 1 year ago

This patch implements the program break and the related functions brk() and sbrk() and the corresponding syscall. The program counter implementation is necessary to support statically linked executables as well as applications launched by the Linux dynamic linker (aka ld-linux-x86-64.so.2) on OSv.

Please note that both the functions and the syscall are considered legacy API however we need to support it for the reasons stated above. Glibc and some memory allocators like jemalloc use brk for some type of memory allocations.

In essence, the program break implementation is based on mmap(). For details please look into the relevant code comments.

This patch also adds a new unit test to verify if the program break works correctly.

This is one of the very first patches of the series implementing the missing functionality to support statically linked executables as well as applications launched by the Linux dynamic linker.

Fixes #1138

wkozaczuk commented 1 year ago

@nyh What do you think about this PR? Would you have a bit of time to review it?