1 .\" Copyright (C) 2016 Intel Corporation
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and author of this work.
25 .TH PKEY_ALLOC 2 2021-03-22 "Linux" "Linux Programmer's Manual"
27 pkey_alloc, pkey_free \- allocate or free a protection key
30 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
31 .B #include <sys/mman.h>
33 .BI "int pkey_alloc(unsigned int " flags ", unsigned int " access_rights ");"
34 .BI "int pkey_free(int " pkey ");"
38 allocates a protection key (pkey) and allows it to be passed to
39 .BR pkey_mprotect (2).
44 is reserved for future use and currently must always be specified as 0.
49 argument may contain zero or more disable operations:
51 .B PKEY_DISABLE_ACCESS
52 Disable all data access to memory covered by the returned protection key.
55 Disable write access to memory covered by the returned protection key.
58 frees a protection key and makes it available for later
60 After a protection key has been freed, it may no longer be used
61 in any protection-key-related operations.
63 An application should not call
65 on any protection key which has been assigned to an address
68 and which is still in use.
69 The behavior in this case is undefined and may result in an error.
73 returns a positive protection key value.
77 On error, \-1 is returned, and
79 is set to indicate the error.
91 All protection keys available for the current process have
93 The number of keys available is architecture-specific and
94 implementation-specific and may be reduced by kernel-internal use
96 There are currently 15 keys available to user programs on x86.
98 This error will also be returned if the processor or operating system
99 does not support protection keys.
100 Applications should always be prepared to handle this error, since
101 factors outside of the application's control can reduce the number
107 were added to Linux in kernel 4.9;
108 library support was added in glibc 2.27.
114 system calls are Linux-specific.
117 is always safe to call regardless of whether or not the operating system
118 supports protection keys.
119 It can be used in lieu of any other mechanism for detecting pkey support
120 and will simply fail with the error
122 if the operating system has no pkey support.
124 The kernel guarantees that the contents of the hardware rights
125 register (PKRU) will be preserved only for allocated protection
127 Any time a key is unallocated (either before the first call
128 returning that key from
130 or after it is freed via
132 the kernel may make arbitrary changes to the parts of the
133 rights register affecting access to that key.
138 .BR pkey_mprotect (2),