man-pages/man2/arch_prctl.2.html
2021-03-31 01:06:50 +01:00

240 lines
4.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ARCH_PRCTL</TITLE>
</HEAD><BODY>
<H1>ARCH_PRCTL</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
arch_prctl - set architecture-specific thread state
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/asm/prctl.h">asm/prctl.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/sys/prctl.h">sys/prctl.h</A>&gt;</B>
<B>int arch_prctl(int </B><I>code</I><B>, unsigned long </B><I>addr</I><B>);</B>
<B>int arch_prctl(int </B><I>code</I><B>, unsigned long *</B><I>addr</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>arch_prctl</B>()
sets architecture-specific process or thread state.
<I>code</I>
selects a subfunction
and passes argument
<I>addr</I>
to it;
<I>addr</I>
is interpreted as either an
<I>unsigned long</I>
for the &quot;set&quot; operations, or as an
<I>unsigned long&nbsp;*</I>,
for the &quot;get&quot; operations.
<P>
Subfunctions for x86-64 are:
<DL COMPACT>
<DT id="1"><B>ARCH_SET_FS</B>
<DD>
Set the 64-bit base for the
<I>FS</I>
register to
<I>addr</I>.
<DT id="2"><B>ARCH_GET_FS</B>
<DD>
Return the 64-bit base value for the
<I>FS</I>
register of the current thread in the
<I>unsigned long</I>
pointed to by
<I>addr</I>.
<DT id="3"><B>ARCH_SET_GS</B>
<DD>
Set the 64-bit base for the
<I>GS</I>
register to
<I>addr</I>.
<DT id="4"><B>ARCH_GET_GS</B>
<DD>
Return the 64-bit base value for the
<I>GS</I>
register of the current thread in the
<I>unsigned long</I>
pointed to by
<I>addr</I>.
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>arch_prctl</B>()
returns 0; on error, -1 is returned, and
<I>errno</I>
is set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="5"><B>EFAULT</B>
<DD>
<I>addr</I>
points to an unmapped address or is outside the process address space.
<DT id="6"><B>EINVAL</B>
<DD>
<I>code</I>
is not a valid subcommand.
<DT id="7"><B>EPERM</B>
<DD>
<I>addr</I>
is outside the process address space.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>arch_prctl</B>()
is a Linux/x86-64 extension and should not be used in programs intended
to be portable.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
<B>arch_prctl</B>()
is supported only on Linux/x86-64 for 64-bit programs currently.
<P>
The 64-bit base changes when a new 32-bit segment selector is loaded.
<P>
<B>ARCH_SET_GS</B>
is disabled in some kernels.
<P>
Context switches for 64-bit segment bases are rather expensive.
As an optimization, if a 32-bit TLS base address is used,
<B>arch_prctl</B>()
may use a real TLS entry as if
<B><A HREF="/cgi-bin/man/man2html?2+set_thread_area">set_thread_area</A></B>(2)
had been called, instead of manipulating the segment base register directly.
Memory in the first 2&nbsp;GB of address space can be allocated by using
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
with the
<B>MAP_32BIT</B>
flag.
<P>
Because of the aforementioned optimization, using
<B>arch_prctl</B>()
and
<B><A HREF="/cgi-bin/man/man2html?2+set_thread_area">set_thread_area</A></B>(2)
in the same thread is dangerous, as they may overwrite each other's
TLS entries.
<P>
As of version 2.7, glibc provides no prototype for
<B>arch_prctl</B>().
You have to declare it yourself for now.
This may be fixed in future glibc versions.
<P>
<I>FS</I>
may be already used by the threading library.
Programs that use
<B>ARCH_SET_FS</B>
directly are very likely to crash.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+modify_ldt">modify_ldt</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+prctl">prctl</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+set_thread_area">set_thread_area</A></B>(2)
<P>
AMD X86-64 Programmer's manual
<A NAME="lbAJ">&nbsp;</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">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="8"><A HREF="#lbAB">NAME</A><DD>
<DT id="9"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="10"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="11"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="12"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="13"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="14"><A HREF="#lbAH">NOTES</A><DD>
<DT id="15"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="16"><A HREF="#lbAJ">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:32 GMT, March 31, 2021
</BODY>
</HTML>