]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/pkey_alloc.2
sched_setattr.2: Minor tweaks to Claudio Scordino's patch
[thirdparty/man-pages.git] / man2 / pkey_alloc.2
1 .\" Copyright (C) 2016 Intel Corporation
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and author of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PKEY_ALLOC 2 2018-02-02 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 pkey_alloc, pkey_free \- allocate or free a protection key
28 .SH SYNOPSIS
29 .nf
30 .B #include <sys/mman.h>
31 .PP
32 .BI "int pkey_alloc(unsigned int " flags ", unsigned int " access_rights ");"
33 .BI "int pkey_free(int " pkey ");"
34 .fi
35 .SH DESCRIPTION
36 .BR pkey_alloc ()
37 allocates a protection key (pkey) and allows it to be passed to
38 .BR pkey_mprotect (2).
39 .PP
40 The
41 .BR pkey_alloc ()
42 .I flags
43 is reserved for future use and currently must always be specified as 0.
44 .PP
45 The
46 .BR pkey_alloc ()
47 .I access_rights
48 argument may contain zero or more disable operations:
49 .TP
50 .B PKEY_DISABLE_ACCESS
51 Disable all data access to memory covered by the returned protection key.
52 .TP
53 .B PKEY_DISABLE_WRITE
54 Disable write access to memory covered by the returned protection key.
55 .PP
56 .BR pkey_free ()
57 frees a protection key and makes it available for later
58 allocations.
59 After a protection key has been freed, it may no longer be used
60 in any protection-key-related operations.
61 .PP
62 An application should not call
63 .BR pkey_free ()
64 on any protection key which has been assigned to an address
65 range by
66 .BR pkey_mprotect (2)
67 and which is still in use.
68 The behavior in this case is undefined and may result in an error.
69 .SH RETURN VALUE
70 On success,
71 .BR pkey_alloc ()
72 returns a positive protection key value.
73 On success,
74 .BR pkey_free ()
75 returns zero.
76 On error, \-1 is returned, and
77 .I errno
78 is set appropriately.
79 .SH ERRORS
80 .TP
81 .B EINVAL
82 .IR pkey ,
83 .IR flags ,
84 or
85 .I access_rights
86 is invalid.
87 .TP
88 .B ENOSPC
89 .RB ( pkey_alloc ())
90 All protection keys available for the current process have
91 been allocated.
92 The number of keys available is architecture-specific and
93 implementation-specific and may be reduced by kernel-internal use
94 of certain keys.
95 There are currently 15 keys available to user programs on x86.
96 .IP
97 This error will also be returned if the processor or operating system
98 does not support protection keys.
99 Applications should always be prepared to handle this error, since
100 factors outside of the application's control can reduce the number
101 of available pkeys.
102 .SH VERSIONS
103 .BR pkey_alloc ()
104 and
105 .BR pkey_free ()
106 were added to Linux in kernel 4.9;
107 library support was added in glibc 2.27.
108 .SH CONFORMING TO
109 The
110 .BR pkey_alloc ()
111 and
112 .BR pkey_free ()
113 system calls are Linux-specific.
114 .SH NOTES
115 .BR pkey_alloc ()
116 is always safe to call regardless of whether or not the operating system
117 supports protection keys.
118 It can be used in lieu of any other mechanism for detecting pkey support
119 and will simply fail with the error
120 .B ENOSPC
121 if the operating system has no pkey support.
122 .PP
123 The kernel guarantees that the contents of the hardware rights
124 register (PKRU) will be preserved only for allocated protection
125 keys.
126 Any time a key is unallocated (either before the first call
127 returning that key from
128 .BR pkey_alloc ()
129 or after it is freed via
130 .BR pkey_free ()),
131 the kernel may make arbitrary changes to the parts of the
132 rights register affecting access to that key.
133 .SH EXAMPLE
134 See
135 .BR pkeys (7).
136 .SH SEE ALSO
137 .BR pkey_mprotect (2),
138 .BR pkeys (7)