-
-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement brk syscall to support statically linked executables #1138
Comments
I don't the In any case, I suggest that before implementing |
Indeed, there is no I guess you are right about the tests. Do you know how exactly the |
Unfortunately, my only experience with the brk/sbrk system calls is from 30 years ago, when I read their manpages on a Unix machine ;-) But I understand the ideas fairly well: The "brk" is the "break address" between the memory used by the application for malloc(), and the memory it doesn't use. Or actually - the addresses above the break can be used for mmap() so modern malloc() implementations uses mmap - not the break - for large allocations. I think that you are right about the first call to brk - you don't know where is the lowest address you can use so you ask brk to give you the current break. If that result is A, you can now sbrk(1000000) and get 1 million bytes between A and A+1000000 that you can use for your allocations. If later you need another million bytes, you call sbrk(1000000) and now can use between A+1000000 and A+2000000. Note that this is "sbrk" but the system call "brk" is not incremental - you need to say brk(A+2000000) to make that the break - and allow you to write between the original break A to A+2000000. You can experiment by writing your own statically-linked programs that use brk/sbrk directly and run them on Linux and OSv and see how the result behaves. You can also run on Linux "strace" on any program (e.g., "strace /bin/ls") and see all the system calls it calls - including brk. |
I think I understand how the Imagine an app calls So given the latest memory mapping:
and the
So maybe we can pick some arbitrarily large area out of the above like Another concern is that the Finally, instead of |
I think maybe we can do the following in the first brk/sbrk call (you raised some of the same ideas in your own comment):
You're right that even 2MB pages take up space in the page table, but since we already have such a "linear map" for malloc(), I don't think it will be too much. |
The very naive implementation using
mmap()
might look like this:To make it possible to de-allocate memory we would need to do something more interesting than that and truly track the
addr
argument that normally increases and decreases.The text was updated successfully, but these errors were encountered: