220 lines
5.2 KiB
HTML
220 lines
5.2 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PKEY_ALLOC</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PKEY_ALLOC</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-08-02<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
pkey_alloc, pkey_free - allocate or free a protection key
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/sys/mman.h">sys/mman.h</A>></B>
|
|
|
|
<B>int pkey_alloc(unsigned int </B><I>flags</I><B>, unsigned int </B><I>access_rights</I><B>);</B>
|
|
<B>int pkey_free(int </B><I>pkey</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>pkey_alloc</B>()
|
|
|
|
allocates a protection key (pkey) and allows it to be passed to
|
|
<B><A HREF="/cgi-bin/man/man2html?2+pkey_mprotect">pkey_mprotect</A></B>(2).
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>pkey_alloc</B>()
|
|
|
|
<I>flags</I>
|
|
|
|
is reserved for future use and currently must always be specified as 0.
|
|
<P>
|
|
|
|
The
|
|
<B>pkey_alloc</B>()
|
|
|
|
<I>access_rights</I>
|
|
|
|
argument may contain zero or more disable operations:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>PKEY_DISABLE_ACCESS</B>
|
|
|
|
<DD>
|
|
Disable all data access to memory covered by the returned protection key.
|
|
<DT id="2"><B>PKEY_DISABLE_WRITE</B>
|
|
|
|
<DD>
|
|
Disable write access to memory covered by the returned protection key.
|
|
</DL>
|
|
<P>
|
|
|
|
<B>pkey_free</B>()
|
|
|
|
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.
|
|
<P>
|
|
|
|
An application should not call
|
|
<B>pkey_free</B>()
|
|
|
|
on any protection key which has been assigned to an address
|
|
range by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+pkey_mprotect">pkey_mprotect</A></B>(2)
|
|
|
|
and which is still in use.
|
|
The behavior in this case is undefined and may result in an error.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>pkey_alloc</B>()
|
|
|
|
returns a positive protection key value.
|
|
On success,
|
|
<B>pkey_free</B>()
|
|
|
|
returns zero.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="3"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>pkey</I>,
|
|
|
|
<I>flags</I>,
|
|
|
|
or
|
|
<I>access_rights</I>
|
|
|
|
is invalid.
|
|
<DT id="4"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
(<B>pkey_alloc</B>())
|
|
|
|
All protection keys available for the current process have
|
|
been allocated.
|
|
The number of keys available is architecture-specific and
|
|
implementation-specific and may be reduced by kernel-internal use
|
|
of certain keys.
|
|
There are currently 15 keys available to user programs on x86.
|
|
<DT id="5"><DD>
|
|
This error will also be returned if the processor or operating system
|
|
does not support protection keys.
|
|
Applications should always be prepared to handle this error, since
|
|
factors outside of the application's control can reduce the number
|
|
of available pkeys.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>pkey_alloc</B>()
|
|
|
|
and
|
|
<B>pkey_free</B>()
|
|
|
|
were added to Linux in kernel 4.9;
|
|
library support was added in glibc 2.27.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The
|
|
<B>pkey_alloc</B>()
|
|
|
|
and
|
|
<B>pkey_free</B>()
|
|
|
|
system calls are Linux-specific.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<B>pkey_alloc</B>()
|
|
|
|
is always safe to call regardless of whether or not the operating system
|
|
supports protection keys.
|
|
It can be used in lieu of any other mechanism for detecting pkey support
|
|
and will simply fail with the error
|
|
<B>ENOSPC</B>
|
|
|
|
if the operating system has no pkey support.
|
|
<P>
|
|
|
|
The kernel guarantees that the contents of the hardware rights
|
|
register (PKRU) will be preserved only for allocated protection
|
|
keys.
|
|
Any time a key is unallocated (either before the first call
|
|
returning that key from
|
|
<B>pkey_alloc</B>()
|
|
|
|
or after it is freed via
|
|
<B>pkey_free</B>()),
|
|
|
|
the kernel may make arbitrary changes to the parts of the
|
|
rights register affecting access to that key.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?7+pkeys">pkeys</A></B>(7).
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+pkey_mprotect">pkey_mprotect</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+pkeys">pkeys</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="13"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="14"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DT id="15"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="16"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|