Function wasmtime_runtime::mpk::keys

source ·
pub fn keys(max: usize) -> &'static [ProtectionKey]
Expand description

Allocate up to max protection keys.

This asks the kernel for all available keys up to max in a thread-safe way (we can expect 1-15; 0 is kernel-reserved). This avoids interference when multiple threads try to allocate keys at the same time (e.g., during testing). It also ensures that a single copy of the keys is reserved for the lifetime of the process. Because of this, max is only a hint to allocation: it only is effective on the first invocation of this function.

TODO: this is not the best-possible design. This creates global state that would prevent any other code in the process from using protection keys; the KEYS are never deallocated from the system with pkey_dealloc.