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