3 ms·
That's one way to do it, dealing with linkers was really not my thing so I just get the mapped memory list [1] and set it as the start pivot then stack pages on
by 1fishe2fishe 2y ago
That's one way to do it, dealing with linkers was really not my thing so I just get the mapped memory list [1] and set it as the start pivot then stack pages on top of it [2]. Thankfully the brk heap isn't intrusive enough to climb up into the pages I allocated :) (this is actually why Linux' MAP_32BIT mmap starts from 0x40000000 [3], but I didn't like how high it was and made it dynamic)
[1]: https://github.com/1fishe2fishe/EXODUS/blob/90f70386b8ac6bd02f35a54766b29ea82a1fc971/src/exodus/posix/shims.c#L264 https://github.com/1fishe2fishe/EXODUS/blob/90f70386b8ac6bd0...
[2]: https://github.com/1fishe2fishe/EXODUS/blob/90f70386b8ac6bd02f35a54766b29ea82a1fc971/src/exodus/posix/alloc.c#L59 https://github.com/1fishe2fishe/EXODUS/blob/90f70386b8ac6bd0...
[3]: https://github.com/torvalds/linux/blob/8f2c057754b25075aa3da132cd4fd4478cdab854/arch/x86/kernel/sys_x86_64.c#L100 https://github.com/torvalds/linux/blob/8f2c057754b25075aa3da...
- xmlparser 2y ago> Thankfully the brk heap isn't intrusive enough to climb up into the pages I allocated :) That seems about right[1], but the MAP_FIXED_NOREPLACE flag has been a thing since Linux 4.17. What about using that? [1]: https://godbolt.org/z/698dPcvf6 https://godbolt.org/z/698dPcvf6
- 1fishe2fishe 2y agoThanks for the information, I wasn't aware of that! Seems like it's not available on FreeBSD though ;( I want to support as many OS'es as possible, but I'll still add a comment on that for future reference.
- xyproto 2y agoCould it be enabled with a define or other compile-time mechanism for Linux?
- 1fishe2fishe 2y agoYeah, I could just use that flag on Linux and let the kernel do more work but I'm afraid I might have to add more logic for looping for a failed mmap only for linux, and more ifdefs usually mean I'm doing something wrong. I'd rather roll with my current strategy (finding a safe pivot and keep bumping without checking anything)