Re:Userfaultfd – Create a file descriptor for handling page ...
by kragen on Thursday February 10, 2022 @12:03PM
(#30289129)
I think specifically for 0x4000 you can't map anything there with a default Linux kernel configuration. The minimum address where you can map things now is 0x10000. This broke my StoneKnifeForth and Max Bernstein fixed it: https://github.com/tekknolagi/stoneknifecpp/commit/905105b44...
Re:Userfaultfd – Create a file descriptor for handling page ...
by tekknolagi on Thursday February 10, 2022 @12:45PM
(#30289828)
Technically Tom fixed it :) He's the Linux whisperer. I just submitted the patch
Re:Userfaultfd – Create a file descriptor for handling page ...
by kragen on Thursday February 10, 2022 @01:10PM
(#30290197)
Oops! Thanks Tom Hebb!
Re:Userfaultfd – Create a file descriptor for handling page ...
by kentonv on Thursday February 10, 2022 @12:19PM
(#30289414)
Whoops, indeed. Guess you'll have to modify the code that made the jump. Ugh.
Re:Userfaultfd – Create a file descriptor for handling page ...
by mattgreenrocks on Friday February 11, 2022 @07:54AM
(#30300860)
Thank you for in-depth answer! It was partially motivated by seeing if userfaultfd could work around mmap_min_addr (it can’t) and partially to see if it is possible to use it to use it for things like emulation.
To map memory at a specific address, you use mmap() with the MAP_FIXED flag. This lets you tell the kernel: "Please put these pages at this virtual address, replacing what's already there."
Note that userfaultfd is not the only way to detect and handle faults. You can also register a signal handler for SIGSEGV. The signal handler function receives information from the kernel specifying what address caused the fault. If, in the signal handler, you use mmap() to map memory at that address, and then return, the program will continue as if nothing happened.
userfaultfd allows you to do the same but from a different thread or process. The SIGSEGV signal handler would actually run inside the thread that faulted, but with userfaultfd the faulting thread pauses and some other thread or process receives the notification.