This was originally discussed in #37 but I realized there is not an explicit issue for it.
The "lazy" decompression, while potentially quite useful (though still not tested much in the real world) only works on Linux, relying on the Linux-specific userfaultfd library.
It seems a Darwin/Mach-ish way to achieve the same is to register a Mach port, a low-level IPC mechanism between the kernel and processes. This allows creating ports that can be registered to be passed a message when an exception occurs in some task (process / thread). A handler thread can then monitor the receiving end of this port. The thread that originated the exception is suspended until the a user-provided callback function is called. I don't fully understand all the details yet, but it seems to be possible, and is in fact how libsigsegv is implemented on macOS, check it out: https://gitweb.git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=blob;f=src/handler-macos.c;h=1929cb366021a05c12447fbc70c7904e86382164;hb=HEADf
I was going to mention as a fallback to that using libsigsegv, though might be worth going directly that route since it already uses the Mach port mechanism anyways; might be able to avoid reinventing too much.
I also wanted to write this issue to copy down a TODO that was in the file.h header in the documentation for asdf_block_decomp_mode_t. It doesn't really belong there since it's discussing a future feature that should be implemented; it's not useful there to the reader.
When lazy is implemented there may likely be multiple implementations
(userfaultfd, sigsegv, etc.). Add options to specify exactly which
implementation to use, where ASDF_DECOMP_MODE_LAZY by itself will
choose the most appropriate choice (generally userfaultfd if available)
This was originally discussed in #37 but I realized there is not an explicit issue for it.
The "lazy" decompression, while potentially quite useful (though still not tested much in the real world) only works on Linux, relying on the Linux-specific userfaultfd library.
It seems a Darwin/Mach-ish way to achieve the same is to register a Mach port, a low-level IPC mechanism between the kernel and processes. This allows creating ports that can be registered to be passed a message when an exception occurs in some task (process / thread). A handler thread can then monitor the receiving end of this port. The thread that originated the exception is suspended until the a user-provided callback function is called. I don't fully understand all the details yet, but it seems to be possible, and is in fact how libsigsegv is implemented on macOS, check it out: https://gitweb.git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=blob;f=src/handler-macos.c;h=1929cb366021a05c12447fbc70c7904e86382164;hb=HEADf
I was going to mention as a fallback to that using libsigsegv, though might be worth going directly that route since it already uses the Mach port mechanism anyways; might be able to avoid reinventing too much.
I also wanted to write this issue to copy down a TODO that was in the
file.hheader in the documentation forasdf_block_decomp_mode_t. It doesn't really belong there since it's discussing a future feature that should be implemented; it's not useful there to the reader.