[Vm-dev] Robust FFI with Memory Protection Keys

Ben Coman btc at openinworld.com
Sat Aug 4 15:40:46 UTC 2018

A problem with FFI is that if a callout segfaults, all of memory
including that of the Image is suspect, and execution of the Image terminates.

Occasionally I hunt around hoping to find technology to mitigate that problem.
Maybe this time in I found something... Memory Protection Keys [1]
Perhaps these could ensure Image memory safe when an FFI callout segfaults.

IIUC the main problem with protecting Image memory on every FFI callout
is the time it would take update the flags on every page of Image memory.
Would being able to change the protection of a massive number of pages
with one syscall make it feasible to wrap them around FFI callouts?

This may be useful at least where the FFI use is more about reuse of
existing functionality than about performance.
Or at least useful while someone is learning/experimenting with FFI for
the first time or while becoming familiar with some external library.
Further info at [2] & [3].

cheers -ben

[1] https://lwn.net/Articles/643797/
[2] http://man7.org/linux/man-pages/man7/pkeys.7.html
[3] https://lwn.net/Articles/689395/

More information about the Vm-dev mailing list