pkey_alloc, pkey_free - allocate or free a protection key
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <sys/mman.h>
int pkey_alloc(unsigned int flags, unsigned int access_rights);
int pkey_free(int pkey);
pkey_alloc() allocates a protection key (pkey) and allows it to be passed to pkey_mprotect(2).
The pkey_alloc() flags
is reserved for
future use and currently must always be specified as 0.
The pkey_alloc() access_rights
argument may
contain zero or more disable operations:
Disable all data access to memory covered by the returned protection key.
Disable write access to memory covered by the returned protection key.
pkey_free() frees a protection key and makes it available for later allocations. After a protection key has been freed, it may no longer be used in any protection-key-related operations.
An application should not call pkey_free() on any protection key which has been assigned to an address range by pkey_mprotect(2) and which is still in use. The behavior in this case is undefined and may result in an error.
On success, pkey_alloc() returns a positive
protection key value. On success, pkey_free() returns
zero. On error, -1 is returned, and errno
is set to indicate
the error.
See pkeys(7).
pkey_mprotect(2), pkeys(7)