]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/prctl.2
prctl.2: ffix
[thirdparty/man-pages.git] / man2 / prctl.2
CommitLineData
fea681da 1.\" Copyright (C) 1998 Andries Brouwer (aeb@cwi.nl)
73d3ac53 2.\" and Copyright (C) 2002, 2006, 2008, 2012, 2013 Michael Kerrisk <mtk.manpages@gmail.com>
af5f9508 3.\" and Copyright Guillem Jover <guillem@hadrons.org>
3cd5e983 4.\" and Copyright (C) 2014 Dave Hansen / Intel
fea681da 5.\"
93015253 6.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
7.\" Permission is granted to make and distribute verbatim copies of this
8.\" manual provided the copyright notice and this permission notice are
9.\" preserved on all copies.
10.\"
11.\" Permission is granted to copy and distribute modified versions of this
12.\" manual under the conditions for verbatim copying, provided that the
13.\" entire resulting derived work is distributed under the terms of a
14.\" permission notice identical to this one.
c13182ef 15.\"
fea681da
MK
16.\" Since the Linux kernel and libraries are constantly changing, this
17.\" manual page may be incorrect or out-of-date. The author(s) assume no
18.\" responsibility for errors or omissions, or for damages resulting from
19.\" the use of the information contained herein. The author(s) may not
20.\" have taken the same level of care in the production of this manual,
21.\" which is licensed free of charge, as they might when working
22.\" professionally.
c13182ef 23.\"
fea681da
MK
24.\" Formatted or processed versions of this manual, if unaccompanied by
25.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 26.\" %%%LICENSE_END
fea681da
MK
27.\"
28.\" Modified Thu Nov 11 04:19:42 MET 1999, aeb: added PR_GET_PDEATHSIG
29.\" Modified 27 Jun 02, Michael Kerrisk
c13182ef 30.\" Added PR_SET_DUMPABLE, PR_GET_DUMPABLE,
fea681da 31.\" PR_SET_KEEPCAPS, PR_GET_KEEPCAPS
e87fdd92
MK
32.\" Modified 2006-08-30 Guillem Jover <guillem@hadrons.org>
33.\" Updated Linux versions where the options where introduced.
34.\" Added PR_SET_TIMING, PR_GET_TIMING, PR_SET_NAME, PR_GET_NAME,
35.\" PR_SET_UNALIGN, PR_GET_UNALIGN, PR_SET_FPEMU, PR_GET_FPEMU,
36.\" PR_SET_FPEXC, PR_GET_FPEXC
8ab8b43f
MK
37.\" 2008-04-29 Serge Hallyn, Document PR_CAPBSET_READ and PR_CAPBSET_DROP
38.\" 2008-06-13 Erik Bosman, <ejbosman@cs.vu.nl>
39.\" Document PR_GET_TSC and PR_SET_TSC.
40.\" 2008-06-15 mtk, Document PR_SET_SECCOMP, PR_GET_SECCOMP
bc02b3ea 41.\" 2009-10-03 Andi Kleen, document PR_MCE_KILL
06afe673 42.\" 2012-04 Cyrill Gorcunov, Document PR_SET_MM
bc02b3ea
MK
43.\" 2012-04-25 Michael Kerrisk, Document PR_TASK_PERF_EVENTS_DISABLE and
44.\" PR_TASK_PERF_EVENTS_ENABLE
34447828 45.\" 2012-09-20 Kees Cook, update PR_SET_SECCOMP for mode 2
f83fe154 46.\" 2012-09-20 Kees Cook, document PR_SET_NO_NEW_PRIVS, PR_GET_NO_NEW_PRIVS
934487a0
MK
47.\" 2012-10-25 Michael Kerrisk, Document PR_SET_TIMERSLACK and
48.\" PR_GET_TIMERSLACK
491b2e75 49.\" 2013-01-10 Kees Cook, document PR_SET_PTRACER
31cc8387 50.\" 2012-02-04 Michael Kerrisk, document PR_{SET,GET}_CHILD_SUBREAPER
03979794 51.\" 2014-11-10 Dave Hansen, document PR_MPX_{EN,DIS}ABLE_MANAGEMENT
fea681da 52.\"
e14baeeb 53.\"
8538a62b 54.TH PRCTL 2 2018-02-02 "Linux" "Linux Programmer's Manual"
fea681da
MK
55.SH NAME
56prctl \- operations on a process
57.SH SYNOPSIS
521bf584 58.nf
fea681da 59.B #include <sys/prctl.h>
68e4db0a 60.PP
521bf584
MK
61.BI "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 ,
62.BI " unsigned long " arg4 ", unsigned long " arg5 );
63.fi
fea681da 64.SH DESCRIPTION
e511ffb6 65.BR prctl ()
fea681da 66is called with a first argument describing what to do
1a329b56 67(with values defined in \fI<linux/prctl.h>\fP), and further
c4bb193f 68arguments with a significance depending on the first one.
fea681da 69The first argument can be:
03547431
MK
70.\"
71.TP
72.BR PR_CAP_AMBIENT " (since Linux 4.3)"
73.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
1a52f4f6
MK
74Reads or changes the ambient capability set of the calling thread,
75according to the value of
03547431
MK
76.IR arg2 ,
77which must be one of the following:
78.RS
79.\"
80.TP
81.B PR_CAP_AMBIENT_RAISE
82The capability specified in
83.I arg3
84is added to the ambient set.
85The specified capability must already be present in
86both the permitted and the inheritable sets of the process.
87This operation is not permitted if the
88.B SECBIT_NO_CAP_AMBIENT_RAISE
89securebit is set.
90.TP
91.B PR_CAP_AMBIENT_LOWER
92The capability specified in
93.I arg3
94is removed from the ambient set.
95.TP
96.B PR_CAP_AMBIENT_IS_SET
97The
bf7bc8b8 98.BR prctl ()
03547431
MK
99call returns 1 if the capability in
100.I arg3
101is in the ambient set and 0 if it is not.
102.TP
103.BR PR_CAP_AMBIENT_CLEAR_ALL
104All capabilities will be removed from the ambient set.
105This operation requires setting
106.I arg3
107to zero.
108.RE
269e3b97
MK
109.IP
110In all of the above operations,
111.I arg4
112and
113.I arg5
114must be specified as 0.
cf086650
MK
115.IP
116Higher-level interfaces layered on top of the above operations are
117provided in the
118.BR libcap (3)
119library in the form of
120.BR cap_get_ambient (3),
121.BR cap_set_ambient (3),
122and
123.BR cap_reset_ambient (3).
fea681da 124.TP
2e781e20 125.BR PR_CAPBSET_READ " (since Linux 2.6.25)"
8ab8b43f
MK
126Return (as the function result) 1 if the capability specified in
127.I arg2
128is in the calling thread's capability bounding set,
129or 0 if it is not.
130(The capability constants are defined in
131.IR <linux/capability.h> .)
132The capability bounding set dictates
133whether the process can receive the capability through a
2914a14d 134file's permitted capability set on a subsequent call to
8ab8b43f 135.BR execve (2).
efeece04 136.IP
8ab8b43f
MK
137If the capability specified in
138.I arg2
139is not valid, then the call fails with the error
140.BR EINVAL .
d9a0d1d7
MK
141.IP
142A higher-level interface layered on top of this operation is provided in the
143.BR libcap (3)
144library in the form of
145.BR cap_get_bound (3).
8ab8b43f
MK
146.TP
147.BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
148If the calling thread has the
149.B CAP_SETPCAP
af53fcb5 150capability within its user namespace, then drop the capability specified by
8ab8b43f
MK
151.I arg2
152from the calling thread's capability bounding set.
153Any children of the calling thread will inherit the newly
154reduced bounding set.
efeece04 155.IP
8ab8b43f
MK
156The call fails with the error:
157.B EPERM
2914a14d 158if the calling thread does not have the
8ab8b43f
MK
159.BR CAP_SETPCAP ;
160.BR EINVAL
161if
162.I arg2
163does not represent a valid capability; or
164.BR EINVAL
165if file capabilities are not enabled in the kernel,
166in which case bounding sets are not supported.
d9a0d1d7
MK
167.IP
168A higher-level interface layered on top of this operation is provided in the
169.BR libcap (3)
170library in the form of
171.BR cap_drop_bound (3).
73d3ac53
MK
172.TP
173.BR PR_SET_CHILD_SUBREAPER " (since Linux 3.4)"
174.\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b
175If
176.I arg2
177is nonzero,
178set the "child subreaper" attribute of the calling process;
179if
180.I arg2
181is zero, unset the attribute.
efeece04 182.IP
fbc63931 183A subreaper fulfills the role of
73d3ac53
MK
184.BR init (1)
185for its descendant processes.
fbc63931
MK
186When a process becomes orphaned
187(i.e., its immediate parent terminates)
188then that process will be reparented to
189the nearest still living ancestor subreaper.
190Subsequently, calls to
191.BR getppid ()
192in the orphaned process will now return the PID of the subreaper process,
193and when the orphan terminates, it is the subreaper process that
73d3ac53
MK
194will receive a
195.BR SIGCHLD
1a8e1c2f 196signal and will be able to
73d3ac53
MK
197.BR wait (2)
198on the process to discover its termination status.
efeece04 199.IP
d59a7572
MK
200The setting of this bit is not inherited by children created by
201.BR fork (2)
202and
203.BR clone (2).
204The setting is preserved across
205.BR execve (2).
efeece04 206.IP
94e460d4
MK
207Establishing a subreaper process is useful in session management frameworks
208where a hierarchical group of processes is managed by a subreaper process
209that needs to be informed when one of the processes\(emfor example,
210a double-forked daemon\(emterminates
211(perhaps so that it can restart that process).
212Some
213.BR init (1)
214frameworks (e.g.,
215.BR systemd (1))
216employ a subreaper process for similar reasons.
73d3ac53
MK
217.TP
218.BR PR_GET_CHILD_SUBREAPER " (since Linux 3.4)"
219Return the "child subreaper" setting of the caller,
220in the location pointed to by
221.IR "(int\ *) arg2" .
8ab8b43f 222.TP
88989295 223.BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
2d7fc98d
MK
224Set the state of the "dumpable" flag,
225which determines whether core dumps are produced for the calling process
226upon delivery of a signal whose default behavior is to produce a core dump.
efeece04 227.IP
88989295 228In kernels up to and including 2.6.12,
8ab8b43f 229.I arg2
8aad30d7
MK
230must be either 0
231.RB ( SUID_DUMP_DISABLE ,
232process is not dumpable) or 1
233.RB ( SUID_DUMP_USER ,
234process is dumpable).
0de51ed1
MK
235Between kernels 2.6.13 and 2.6.17,
236.\" commit abf75a5033d4da7b8a7e92321d74021d1fcfb502
237the value 2 was also permitted,
88989295
MK
238which caused any binary which normally would not be dumped
239to be dumped readable by root only;
240for security reasons, this feature has been removed.
241.\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
242.\" Subject: Fix prctl privilege escalation (CVE-2006-2451)
243.\" From: Marcel Holtmann <marcel () holtmann ! org>
244.\" Date: 2006-07-12 11:12:00
245(See also the description of
2d7fc98d 246.I /proc/sys/fs/\:suid_dumpable
88989295
MK
247in
248.BR proc (5).)
efeece04 249.IP
2d7fc98d
MK
250Normally, this flag is set to 1.
251However, it is reset to the current value contained in the file
252.IR /proc/sys/fs/\:suid_dumpable
253(which by default has the value 0),
a644bc48 254in the following circumstances:
2d7fc98d
MK
255.\" See kernel/cred.c::commit_creds() (Linux 3.18 sources)
256.RS
41f90bb7 257.IP * 3
a644bc48 258The process's effective user or group ID is changed.
2d7fc98d 259.IP *
a644bc48 260The process's filesystem user or group ID is changed (see
2d7fc98d
MK
261.BR credentials (7)).
262.IP *
a644bc48 263The process executes
2d7fc98d 264.RB ( execve (2))
41f90bb7
MK
265a set-user-ID or set-group-ID program, resulting in a change
266of either the effective user ID or the effective group ID.
27ce08bf
KF
267.IP *
268The process executes
269.RB ( execve (2))
270a program that has file capabilities (see
271.BR capabilities (7)),
41f90bb7 272.\" See kernel/cred.c::commit_creds()
27ce08bf 273but only if the permitted capabilities
41f90bb7 274gained exceed those already permitted for the process.
5d28ea3e 275.\" Also certain namespace operations;
2d7fc98d
MK
276.RE
277.IP
cadcf1b1 278Processes that are not dumpable can not be attached via
6fdbc779 279.BR ptrace (2)
982d8cf7
MK
280.BR PTRACE_ATTACH ;
281see
282.BR ptrace (2)
283for further details.
efeece04 284.IP
161946a2
MK
285If a process is not dumpable,
286the ownership of files in the process's
287.IR /proc/[pid]
288directory is affected as described in
289.BR proc (5).
64536a1b 290.TP
88989295
MK
291.BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
292Return (as the function result) the current state of the calling
293process's dumpable flag.
294.\" Since Linux 2.6.13, the dumpable flag can have the value 2,
295.\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
c7094399 296.\" flags has a nonzero value. This was fixed in 2.6.14.
64536a1b 297.TP
8ab8b43f 298.BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
c13182ef 299Set the endian-ness of the calling process to the value given
64536a1b 300in \fIarg2\fP, which should be one of the following:
8ab8b43f 301.\" Respectively 0, 1, 2
64536a1b
MK
302.BR PR_ENDIAN_BIG ,
303.BR PR_ENDIAN_LITTLE ,
304or
0daa9e92 305.B PR_ENDIAN_PPC_LITTLE
64536a1b 306(PowerPC pseudo little endian).
e87fdd92 307.TP
8ab8b43f
MK
308.BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
309Return the endian-ness of the calling process,
310in the location pointed to by
311.IR "(int\ *) arg2" .
64a53a67
ES
312.TP
313.BR PR_SET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305
MK
314.\" commit 9791554b45a2acc28247f66a5fd5bbc212a6b8c8
315On the MIPS architecture,
316user-space code can be built using an ABI which permits linking
317with code that has more restrictive floating-point (FP) requirements.
318For example, user-space code may be built to target the O32 FPXX ABI
b3073df8 319and linked with code built for either one of the more restrictive
89507305 320FP32 or FP64 ABIs.
b3073df8 321When more restrictive code is linked in,
89507305
MK
322the overall requirement for the process is to use the more
323restrictive floating-point mode.
efeece04 324.IP
07d6076e 325Because the kernel has no means of knowing in advance
89507305 326which mode the process should be executed in,
07d6076e
MK
327and because these restrictions can
328change over the lifetime of the process, the
329.B PR_SET_FP_MODE
330operation is provided to allow control of the floating-point mode
331from user space.
efeece04 332.IP
64a53a67
ES
333.\" https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
334The
335.I (unsigned int) arg2
89507305 336argument is a bit mask describing the floating-point mode used:
64a53a67
ES
337.RS
338.TP
fb90e0c7 339.BR PR_FP_MODE_FR
64a53a67
ES
340When this bit is
341.I unset
342(so called
343.BR FR=0 " or " FR0
41a926bf
MK
344mode), the 32 floating-point registers are 32 bits wide,
345and 64-bit registers are represented as a pair of registers
b3073df8 346(even- and odd- numbered,
89507305
MK
347with the even-numbered register containing the lower 32 bits,
348and the odd-numbered register containing the higher 32 bits).
efeece04 349.IP
64a53a67
ES
350When this bit is
351.I set
07d6076e 352(on supported hardware),
41a926bf 353the 32 floating-point registers are 64 bits wide (so called
64a53a67 354.BR FR=1 " or " FR1
89507305 355mode).
b3073df8 356Note that modern MIPS implementations (MIPS R6 and newer) support
64a53a67
ES
357.B FR=1
358mode only.
efeece04
MK
359.IP
360.IP
89507305 361Applications that use the O32 FP32 ABI can operate only when this bit is
64a53a67
ES
362.I unset
363.RB ( FR=0 ;
364or they can be used with FRE enabled, see below).
89507305
MK
365Applications that use the O32 FP64 ABI
366(and the O32 FP64A ABI, which exists to
367provide the ability to operate with existing FP32 code; see below)
368can operate only when this bit is
64a53a67
ES
369.I set
370.RB ( FR=1 ).
ffb0dafc 371Applications that use the O32 FPXX ABI can operate with either
07d6076e
MK
372.BR FR=0
373or
374.BR FR=1 .
64a53a67 375.TP
fb90e0c7 376.BR PR_FP_MODE_FRE
07d6076e 377Enable emulation of 32-bit floating-point mode.
b3073df8 378When this mode is enabled,
07d6076e
MK
379it emulates 32-bit floating-point operations
380by raising a reserved-instruction exception
b3073df8 381on every instruction that uses 32-bit formats and
89507305
MK
382the kernel then handles the instruction in software.
383(The problem lies in the discrepancy of handling odd-numbered registers
384which are the high 32 bits of 64-bit registers with even numbers in
64a53a67 385.B FR=0
89507305 386mode and the lower 32-bit parts of odd-numbered 64-bit registers in
64a53a67 387.B FR=1
89507305
MK
388mode.)
389Enabling this bit is necessary when code with the O32 FP32 ABI should operate
390with code with compatible the O32 FPXX or O32 FP64A ABIs (which require
64a53a67 391.B FR=1
b3073df8
MK
392FPU mode) or when it is executed on newer hardware (MIPS R6 onwards)
393which lacks
64a53a67 394.B FR=0
89507305 395mode support when a binary with the FP32 ABI is used.
64a53a67 396.IP
89507305
MK
397Note that this mode makes sense only when the FPU is in 64-bit mode
398.RB ( FR=1 ).
64a53a67 399.IP
89507305 400Note that the use of emulation inherently has a significant performance hit
b3073df8 401and should be avoided if possible.
64a53a67
ES
402.RE
403.IP
07d6076e
MK
404In the N32/N64 ABI, 64-bit floating-point mode is always used,
405so FPU emulation is not required and the FPU always operates in
64a53a67
ES
406.B FR=1
407mode.
408.IP
07d6076e
MK
409This option is mainly intended for use by the dynamic linker
410.RB ( ld.so (8)).
64a53a67 411.IP
89507305
MK
412The arguments
413.IR arg3 ,
414.IR arg4 ,
415and
416.IR arg5
64a53a67
ES
417are ignored.
418.TP
419.BR PR_GET_FP_MODE " (since Linux 4.0, only on MIPS)"
89507305 420Get the current floating-point mode (see the description of
64a53a67
ES
421.B PR_SET_FP_MODE
422for details).
efeece04 423.IP
89507305 424On success,
07d6076e 425the call returns a bit mask which represents the current floating-point mode.
efeece04 426.IP
89507305
MK
427The arguments
428.IR arg2 ,
429.IR arg3 ,
430.IR arg4 ,
431and
432.IR arg5
64a53a67 433are ignored.
8ab8b43f 434.TP
8ab8b43f 435.BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
e87fdd92 436Set floating-point emulation control bits to \fIarg2\fP.
7626d2ce
MK
437Pass
438.B PR_FPEMU_NOPRINT
439to silently emulate floating-point operation accesses, or
440.B PR_FPEMU_SIGFPE
441to not emulate floating-point operations and send
8bd58774
MK
442.B SIGFPE
443instead.
e87fdd92 444.TP
8ab8b43f
MK
445.BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
446Return floating-point emulation control bits,
447in the location pointed to by
448.IR "(int\ *) arg2" .
e87fdd92 449.TP
8ab8b43f 450.BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
1c44bd5b
MK
451Set floating-point exception mode to \fIarg2\fP.
452Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
c45bd688
MK
453\fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
454\fBPR_FP_EXC_OVF\fP for floating-point overflow,
455\fBPR_FP_EXC_UND\fP for floating-point underflow,
456\fBPR_FP_EXC_RES\fP for floating-point inexact result,
457\fBPR_FP_EXC_INV\fP for floating-point invalid operation,
e87fdd92 458\fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
b28f6e56 459\fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
e87fdd92
MK
460\fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
461\fBPR_FP_EXC_PRECISE\fP for precise exception mode.
462.TP
8ab8b43f
MK
463.BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
464Return floating-point exception mode,
465in the location pointed to by
466.IR "(int\ *) arg2" .
467.TP
88989295 468.BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
03361448
MK
469Set the state of the calling thread's "keep capabilities" flag.
470The effect if this flag is described in
471.BR capabilities (7).
88989295 472.I arg2
03361448
MK
473must be either 0 (clear the flag)
474or 1 (set the flag).
028cb080 475The "keep capabilities" value will be reset to 0 on subsequent calls to
88989295
MK
476.BR execve (2).
477.TP
478.BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
88ee5c1c 479Return (as the function result) the current state of the calling thread's
88989295 480"keep capabilities" flag.
03361448
MK
481See
482.BR capabilities (7)
483for a description of this flag.
88989295 484.TP
03547431 485.BR PR_MCE_KILL " (since Linux 2.6.32)"
eb359b3e 486Set the machine check memory corruption kill policy for the calling thread.
03547431
MK
487If
488.I arg2
489is
490.BR PR_MCE_KILL_CLEAR ,
491clear the thread memory corruption kill policy and use the system-wide default.
492(The system-wide default is defined by
493.IR /proc/sys/vm/memory_failure_early_kill ;
494see
495.BR proc (5).)
496If
497.I arg2
498is
499.BR PR_MCE_KILL_SET ,
500use a thread-specific memory corruption kill policy.
501In this case,
502.I arg3
503defines whether the policy is
504.I early kill
505.RB ( PR_MCE_KILL_EARLY ),
506.I late kill
507.RB ( PR_MCE_KILL_LATE ),
508or the system-wide default
509.RB ( PR_MCE_KILL_DEFAULT ).
510Early kill means that the thread receives a
511.B SIGBUS
512signal as soon as hardware memory corruption is detected inside
513its address space.
514In late kill mode, the process is killed only when it accesses a corrupted page.
515See
516.BR sigaction (2)
517for more information on the
518.BR SIGBUS
519signal.
520The policy is inherited by children.
521The remaining unused
522.BR prctl ()
523arguments must be zero for future compatibility.
88989295 524.TP
03547431
MK
525.BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
526Return the current per-process machine check kill policy.
527All unused
528.BR prctl ()
529arguments must be zero.
88989295 530.TP
03547431
MK
531.BR PR_SET_MM " (since Linux 3.3)"
532.\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
533Modify certain kernel memory map descriptor fields
534of the calling process.
535Usually these fields are set by the kernel and dynamic loader (see
536.BR ld.so (8)
537for more information) and a regular application should not use this feature.
538However, there are cases, such as self-modifying programs,
539where a program might find it useful to change its own memory map.
efeece04 540.IP
03547431
MK
541The calling process must have the
542.BR CAP_SYS_RESOURCE
543capability.
544The value in
545.I arg2
546is one of the options below, while
547.I arg3
548provides a new value for the option.
a87d0921
MF
549The
550.I arg4
551and
552.I arg5
553arguments must be zero if unused.
efeece04 554.IP
261c7e1d 555Before Linux 3.10,
d2eeb68f 556.\" commit 52b3694157e3aa6df871e283115652ec6f2d31e0
261c7e1d
MF
557this feature is available only if the kernel is built with the
558.BR CONFIG_CHECKPOINT_RESTORE
559option enabled.
03547431
MK
560.RS
561.TP
562.BR PR_SET_MM_START_CODE
563Set the address above which the program text can run.
564The corresponding memory area must be readable and executable,
997d21e1 565but not writable or shareable (see
03547431 566.BR mprotect (2)
0fcc276f 567and
03547431
MK
568.BR mmap (2)
569for more information).
f83fe154 570.TP
03547431
MK
571.BR PR_SET_MM_END_CODE
572Set the address below which the program text can run.
573The corresponding memory area must be readable and executable,
997d21e1 574but not writable or shareable.
f83fe154 575.TP
03547431
MK
576.BR PR_SET_MM_START_DATA
577Set the address above which initialized and
578uninitialized (bss) data are placed.
579The corresponding memory area must be readable and writable,
997d21e1 580but not executable or shareable.
88989295 581.TP
03547431
MK
582.B PR_SET_MM_END_DATA
583Set the address below which initialized and
584uninitialized (bss) data are placed.
585The corresponding memory area must be readable and writable,
997d21e1 586but not executable or shareable.
88989295 587.TP
03547431
MK
588.BR PR_SET_MM_START_STACK
589Set the start address of the stack.
590The corresponding memory area must be readable and writable.
491b2e75 591.TP
03547431
MK
592.BR PR_SET_MM_START_BRK
593Set the address above which the program heap can be expanded with
594.BR brk (2)
595call.
596The address must be greater than the ending address of
597the current program data segment.
598In addition, the combined size of the resulting heap and
599the size of the data segment can't exceed the
600.BR RLIMIT_DATA
601resource limit (see
602.BR setrlimit (2)).
603.TP
604.BR PR_SET_MM_BRK
605Set the current
606.BR brk (2)
607value.
608The requirements for the address are the same as for the
609.BR PR_SET_MM_START_BRK
610option.
11ac5b51 611.PP
03547431
MK
612The following options are available since Linux 3.5.
613.\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
614.TP
615.BR PR_SET_MM_ARG_START
616Set the address above which the program command line is placed.
617.TP
618.BR PR_SET_MM_ARG_END
619Set the address below which the program command line is placed.
620.TP
621.BR PR_SET_MM_ENV_START
622Set the address above which the program environment is placed.
623.TP
624.BR PR_SET_MM_ENV_END
625Set the address below which the program environment is placed.
626.IP
627The address passed with
628.BR PR_SET_MM_ARG_START ,
629.BR PR_SET_MM_ARG_END ,
630.BR PR_SET_MM_ENV_START ,
631and
632.BR PR_SET_MM_ENV_END
633should belong to a process stack area.
634Thus, the corresponding memory area must be readable, writable, and
635(depending on the kernel configuration) have the
636.BR MAP_GROWSDOWN
637attribute set (see
638.BR mmap (2)).
639.TP
640.BR PR_SET_MM_AUXV
641Set a new auxiliary vector.
642The
643.I arg3
644argument should provide the address of the vector.
645The
646.I arg4
647is the size of the vector.
648.TP
649.BR PR_SET_MM_EXE_FILE
650.\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
651Supersede the
652.IR /proc/pid/exe
653symbolic link with a new one pointing to a new executable file
654identified by the file descriptor provided in
655.I arg3
656argument.
657The file descriptor should be obtained with a regular
658.BR open (2)
659call.
660.IP
661To change the symbolic link, one needs to unmap all existing
662executable memory areas, including those created by the kernel itself
663(for example the kernel usually creates at least one executable
664memory area for the ELF
665.IR \.text
666section).
667.IP
642df17c 668In Linux 4.9 and earlier, the
47bc9cec 669.\" commit 3fb4afd9a504c2386b8435028d43283216bf588e
47bc9cec 670.BR PR_SET_MM_EXE_FILE
642df17c
MK
671operation can be performed only once in a process's lifetime;
672attempting to perform the operation a second time results in the error
673.BR EPERM .
674This restriction was enforced for security reasons that were subsequently
675deemed specious,
676and the restriction was removed in Linux 4.10 because some
677user-space applications needed to perform this operation more than once.
11ac5b51 678.PP
7e3236a5
MF
679The following options are available since Linux 3.18.
680.\" commit f606b77f1a9e362451aca8f81d8f36a3a112139e
681.TP
682.BR PR_SET_MM_MAP
683Provides one-shot access to all the addresses by passing in a
684.I struct prctl_mm_map
685(as defined in \fI<linux/prctl.h>\fP).
686The
687.I arg4
688argument should provide the size of the struct.
efeece04 689.IP
7e3236a5
MF
690This feature is available only if the kernel is built with the
691.BR CONFIG_CHECKPOINT_RESTORE
692option enabled.
693.TP
694.BR PR_SET_MM_MAP_SIZE
695Returns the size of the
696.I struct prctl_mm_map
697the kernel expects.
698This allows user space to find a compatible struct.
699The
700.I arg4
701argument should be a pointer to an unsigned int.
efeece04 702.IP
7e3236a5
MF
703This feature is available only if the kernel is built with the
704.BR CONFIG_CHECKPOINT_RESTORE
705option enabled.
03547431
MK
706.RE
707.TP
708.BR PR_MPX_ENABLE_MANAGEMENT ", " PR_MPX_DISABLE_MANAGEMENT " (since Linux 3.19) "
709.\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c
710.\" See also http://lwn.net/Articles/582712/
711.\" See also https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
712Enable or disable kernel management of Memory Protection eXtensions (MPX)
713bounds tables.
714The
715.IR arg2 ,
716.IR arg3 ,
717.IR arg4 ,
718and
719.IR arg5
720.\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88
721arguments must be zero.
efeece04 722.IP
03547431
MK
723MPX is a hardware-assisted mechanism for performing bounds checking on
724pointers.
725It consists of a set of registers storing bounds information
726and a set of special instruction prefixes that tell the CPU on which
727instructions it should do bounds enforcement.
728There is a limited number of these registers and
729when there are more pointers than registers,
730their contents must be "spilled" into a set of tables.
731These tables are called "bounds tables" and the MPX
732.BR prctl ()
733operations control
734whether the kernel manages their allocation and freeing.
efeece04 735.IP
03547431
MK
736When management is enabled, the kernel will take over allocation
737and freeing of the bounds tables.
738It does this by trapping the #BR exceptions that result
739at first use of missing bounds tables and
740instead of delivering the exception to user space,
741it allocates the table and populates the bounds directory
742with the location of the new table.
743For freeing, the kernel checks to see if bounds tables are
744present for memory which is not allocated, and frees them if so.
efeece04 745.IP
03547431
MK
746Before enabling MPX management using
747.BR PR_MPX_ENABLE_MANAGEMENT ,
748the application must first have allocated a user-space buffer for
749the bounds directory and placed the location of that directory in the
750.I bndcfgu
751register.
efeece04 752.IP
a23d8efa 753These calls fail if the CPU or kernel does not support MPX.
03547431
MK
754Kernel support for MPX is enabled via the
755.BR CONFIG_X86_INTEL_MPX
756configuration option.
757You can check whether the CPU supports MPX by looking for the 'mpx'
758CPUID bit, like with the following command:
efeece04 759.IP
03547431 760 cat /proc/cpuinfo | grep ' mpx '
efeece04 761.IP
03547431
MK
762A thread may not switch in or out of long (64-bit) mode while MPX is
763enabled.
efeece04 764.IP
03547431 765All threads in a process are affected by these calls.
efeece04 766.IP
03547431
MK
767The child of a
768.BR fork (2)
769inherits the state of MPX management.
770During
771.BR execve (2),
772MPX management is reset to a state as if
773.BR PR_MPX_DISABLE_MANAGEMENT
774had been called.
efeece04 775.IP
03547431
MK
776For further information on Intel MPX, see the kernel source file
777.IR Documentation/x86/intel_mpx.txt .
778.TP
779.BR PR_SET_NAME " (since Linux 2.6.9)"
780Set the name of the calling thread,
781using the value in the location pointed to by
782.IR "(char\ *) arg2" .
783The name can be up to 16 bytes long,
784.\" TASK_COMM_LEN in include/linux/sched.h
785including the terminating null byte.
786(If the length of the string, including the terminating null byte,
787exceeds 16 bytes, the string is silently truncated.)
788This is the same attribute that can be set via
789.BR pthread_setname_np (3)
790and retrieved using
791.BR pthread_getname_np (3).
792The attribute is likewise accessible via
793.IR /proc/self/task/[tid]/comm ,
794where
795.I tid
796is the name of the calling thread.
797.TP
798.BR PR_GET_NAME " (since Linux 2.6.11)"
799Return the name of the calling thread,
800in the buffer pointed to by
801.IR "(char\ *) arg2" .
802The buffer should allow space for up to 16 bytes;
803the returned string will be null-terminated.
804.TP
805.BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
40dfb5ba 806Set the calling thread's
03547431
MK
807.I no_new_privs
808bit to the value in
809.IR arg2 .
810With
811.I no_new_privs
812set to 1,
813.BR execve (2)
814promises not to grant privileges to do anything
815that could not have been done without the
816.BR execve (2)
817call (for example,
818rendering the set-user-ID and set-group-ID mode bits,
819and file capabilities non-functional).
820Once set, this bit cannot be unset.
821The setting of this bit is inherited by children created by
822.BR fork (2)
823and
824.BR clone (2),
825and preserved across
826.BR execve (2).
efeece04 827.IP
c70fea6e
MK
828Since Linux 4.10,
829the value of a thread's
830.I no_new_privs
831bit can be viewed via the
832.I NoNewPrivs
833field in the
834.IR /proc/[pid]/status
835file.
efeece04 836.IP
03547431 837For more information, see the kernel source file
a84a5830
ES
838.IR Documentation/userspace\-api/no_new_privs.rst
839.\" commit 40fde647ccb0ae8c11d256d271e24d385eed595b
840(or
841.IR Documentation/prctl/no_new_privs.txt
842before Linux 4.13).
4d850396
MK
843See also
844.BR seccomp (2).
03547431
MK
845.TP
846.BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
847Return (as the function result) the value of the
848.I no_new_privs
40dfb5ba 849bit for the calling thread.
03547431
MK
850A value of 0 indicates the regular
851.BR execve (2)
852behavior.
853A value of 1 indicates
854.BR execve (2)
855will operate in the privilege-restricting mode described above.
856.TP
857.BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
858Set the parent death signal
859of the calling process to \fIarg2\fP (either a signal value
860in the range 1..maxsig, or 0 to clear).
861This is the signal that the calling process will get when its
862parent dies.
c5236575 863.IP
03547431
MK
864This value is cleared for the child of a
865.BR fork (2)
866and (since Linux 2.4.36 / 2.6.23)
867when executing a set-user-ID or set-group-ID binary,
868or a binary that has associated capabilities (see
869.BR capabilities (7)).
870This value is preserved across
871.BR execve (2).
efeece04 872.IP
03547431
MK
873.IR Warning :
874.\" https://bugzilla.kernel.org/show_bug.cgi?id=43300
875the "parent" in this case is considered to be the
876.I thread
877that created this process.
878In other words, the signal will be sent when that thread terminates
879(via, for example,
880.BR pthread_exit (3)),
881rather than after all of the threads in the parent process terminate.
882.TP
883.BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
884Return the current value of the parent process death signal,
885in the location pointed to by
886.IR "(int\ *) arg2" .
887.TP
888.BR PR_SET_PTRACER " (since Linux 3.4)"
889.\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
890.\" commit bf06189e4d14641c0148bea16e9dd24943862215
891This is meaningful only when the Yama LSM is enabled and in mode 1
892("restricted ptrace", visible via
893.IR /proc/sys/kernel/yama/ptrace_scope ).
894When a "ptracer process ID" is passed in \fIarg2\fP,
895the caller is declaring that the ptracer process can
896.BR ptrace (2)
897the calling process as if it were a direct process ancestor.
898Each
899.B PR_SET_PTRACER
900operation replaces the previous "ptracer process ID".
901Employing
902.B PR_SET_PTRACER
903with
904.I arg2
905set to 0 clears the caller's "ptracer process ID".
906If
907.I arg2
908is
909.BR PR_SET_PTRACER_ANY ,
910the ptrace restrictions introduced by Yama are effectively disabled for the
911calling process.
efeece04 912.IP
03547431 913For further information, see the kernel source file
6744a500
ES
914.IR Documentation/admin\-guide/LSM/Yama.rst
915.\" commit 90bb766440f2147486a2acc3e793d7b8348b0c22
916(or
917.IR Documentation/security/Yama.txt
918before Linux 4.13).
03547431
MK
919.TP
920.BR PR_SET_SECCOMP " (since Linux 2.6.23)"
921.\" See http://thread.gmane.org/gmane.linux.kernel/542632
922.\" [PATCH 0 of 2] seccomp updates
923.\" andrea@cpushare.com
924Set the secure computing (seccomp) mode for the calling thread, to limit
925the available system calls.
926The more recent
927.BR seccomp (2)
928system call provides a superset of the functionality of
929.BR PR_SET_SECCOMP .
efeece04 930.IP
03547431
MK
931The seccomp mode is selected via
932.IR arg2 .
933(The seccomp constants are defined in
934.IR <linux/seccomp.h> .)
efeece04 935.IP
34447828 936With
8ab8b43f 937.IR arg2
34447828 938set to
b1248a9d 939.BR SECCOMP_MODE_STRICT ,
8ab8b43f
MK
940the only system calls that the thread is permitted to make are
941.BR read (2),
942.BR write (2),
85fbef74
MK
943.BR _exit (2)
944(but not
945.BR exit_group (2)),
fea681da 946and
8ab8b43f
MK
947.BR sigreturn (2).
948Other system calls result in the delivery of a
949.BR SIGKILL
950signal.
34447828 951Strict secure computing mode is useful for number-crunching applications
8ab8b43f
MK
952that may need to execute untrusted byte code,
953perhaps obtained by reading from a pipe or socket.
33a0ccb2 954This operation is available only
d6ef3d57
MK
955if the kernel is configured with
956.B CONFIG_SECCOMP
957enabled.
efeece04 958.IP
34447828
KC
959With
960.IR arg2
961set to
b1248a9d 962.BR SECCOMP_MODE_FILTER " (since Linux 3.5),"
6239dfb2
MK
963the system calls allowed are defined by a pointer
964to a Berkeley Packet Filter passed in
965.IR arg3 .
966This argument is a pointer to
967.IR "struct sock_fprog" ;
968it can be designed to filter
d6ef3d57 969arbitrary system calls and system call arguments.
33a0ccb2 970This mode is available only if the kernel is configured with
d6ef3d57
MK
971.B CONFIG_SECCOMP_FILTER
972enabled.
efeece04 973.IP
1733db35
MK
974If
975.BR SECCOMP_MODE_FILTER
976filters permit
977.BR fork (2),
990e3887 978then the seccomp mode is inherited by children created by
1733db35
MK
979.BR fork (2);
980if
981.BR execve (2)
fa1d2749 982is permitted, then the seccomp mode is preserved across
1733db35
MK
983.BR execve (2).
984If the filters permit
a26ec136 985.BR prctl ()
1733db35
MK
986calls, then additional filters can be added;
987they are run in order until the first non-allow result is seen.
efeece04 988.IP
6239dfb2 989For further information, see the kernel source file
28d96036
ES
990.IR Documentation/userspace\-api/seccomp_filter.rst
991.\" commit c061f33f35be0ccc80f4b8e0aea5dfd2ed7e01a3
992(or
993.IR Documentation/prctl/seccomp_filter.txt
994before Linux 4.13).
8ab8b43f
MK
995.TP
996.BR PR_GET_SECCOMP " (since Linux 2.6.23)"
5e91816c
MK
997Return (as the function result)
998the secure computing mode of the calling thread.
34447828
KC
999If the caller is not in secure computing mode, this operation returns 0;
1000if the caller is in strict secure computing mode, then the
8ab8b43f
MK
1001.BR prctl ()
1002call will cause a
1003.B SIGKILL
1004signal to be sent to the process.
d6ef3d57 1005If the caller is in filter mode, and this system call is allowed by the
8eeb062d
MK
1006seccomp filters, it returns 2; otherwise, the process is killed with a
1007.BR SIGKILL
1008signal.
33a0ccb2 1009This operation is available only
d6ef3d57
MK
1010if the kernel is configured with
1011.B CONFIG_SECCOMP
1012enabled.
efeece04 1013.IP
787843e7
MK
1014Since Linux 3.8, the
1015.IR Seccomp
1016field of the
1017.IR /proc/[pid]/status
1018file provides a method of obtaining the same information,
1019without the risk that the process is killed; see
1020.BR proc (5).
88989295
MK
1021.TP
1022.BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
1023Set the "securebits" flags of the calling thread to the value supplied in
03547431
MK
1024.IR arg2 .
1025See
1026.BR capabilities (7).
88989295 1027.TP
03547431
MK
1028.BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
1029Return (as the function result)
1030the "securebits" flags of the calling thread.
1031See
1032.BR capabilities (7).
1033.TP
dd08fcca 1034.BR PR_GET_SPECULATION_CTRL " (since Linux 4.17)"
a01c1cbc
MK
1035Returns the state of the speculation misfeature specified in
1036.IR arg2 .
1037Currently, the only permitted value for this argument is
2feab5d3
MK
1038.BR PR_SPEC_STORE_BYPASS
1039(otherwise the call fails with the error
1040.BR ENODEV ).
1041.IP
1042The return value uses bits 0-3 with the following meaning:
e23acd79
KRW
1043.RS
1044.TP
1045.BR PR_SPEC_PRCTL
2feab5d3 1046Mitigation can be controlled per thread by
e23acd79
KRW
1047.B PR_SET_SPECULATION_CTRL
1048.TP
1049.BR PR_SPEC_ENABLE
1050The speculation feature is enabled, mitigation is disabled.
1051.TP
1052.BR PR_SPEC_DISABLE
1053The speculation feature is disabled, mitigation is enabled
1054.TP
1055.BR PR_SPEC_FORCE_DISABLE
1056Same as
1057.B PR_SPEC_DISABLE
1058but cannot be undone.
1059.RE
1060.IP
2feab5d3 1061If all bits are 0,
e23acd79
KRW
1062then the CPU is not affected by the speculation misfeature.
1063.IP
1064If
1065.B PR_SPEC_PRCTL
2feab5d3 1066is set, then per-thread control of the mitigation is available.
ac3756bc 1067If not set,
e36dfb81 1068.BR prctl ()
e23acd79 1069for the speculation misfeature will fail.
a01c1cbc
MK
1070.IP
1071The
e36dfb81
MK
1072.IR arg3 ,
1073.IR arg4 ,
e23acd79
KRW
1074and
1075.I arg5
a01c1cbc 1076arguments must be specified as 0; otherwise the call fails with the error
e36dfb81 1077.BR EINVAL .
e23acd79 1078.TP
dd08fcca
MK
1079.BR PR_SET_SPECULATION_CTRL " (since Linux 4.17)"
1080.\" commit b617cfc858161140d69cc0b5cc211996b557a1c7
1081.\" commit 356e4bfff2c5489e016fdb925adbf12a1e3950ee
a01c1cbc
MK
1082Sets the state of the speculation misfeature specified in
1083.IR arg2 .
1084Currently, the only permitted value for this argument is
2feab5d3
MK
1085.B PR_SPEC_STORE_BYPASS
1086(otherwise the call fails with the error
1087.BR ENODEV ).
a01c1cbc 1088This setting is a per-thread attribute.
ac3756bc 1089The
e23acd79 1090.IR arg3
a01c1cbc
MK
1091argument is used to hand in the control value,
1092which is one of the following:
e23acd79
KRW
1093.RS
1094.TP
1095.BR PR_SPEC_ENABLE
1096The speculation feature is enabled, mitigation is disabled.
1097.TP
1098.BR PR_SPEC_DISABLE
1099The speculation feature is disabled, mitigation is enabled
1100.TP
1101.BR PR_SPEC_FORCE_DISABLE
1102Same as
1103.B PR_SPEC_DISABLE
ac3756bc
MK
1104but cannot be undone.
1105A subsequent
e23acd79
KRW
1106.B
1107prctl(..., PR_SPEC_ENABLE)
2feab5d3 1108will fail with the error
e36dfb81 1109.BR EPERM .
e23acd79
KRW
1110.RE
1111.IP
1112Any other value in
1113.IR arg3
2feab5d3 1114will result in the call failing with the error
e23acd79 1115.BR ERANGE .
a01c1cbc
MK
1116.IP
1117The
2feab5d3 1118.I arg4
e23acd79
KRW
1119and
1120.I arg5
a01c1cbc 1121arguments must be specified as 0; otherwise the call fails with the error
e36dfb81 1122.BR EINVAL .
e23acd79 1123.IP
a01c1cbc
MK
1124The speculation feature can also be controlled by the
1125.B spec_store_bypass_disable
1126boot parameter.
1127This parameter may enforce a read-only policy which will result in the
1128.BR prctl (2)
1129call failing with the error
e23acd79 1130.BR ENXIO .
a01c1cbc
MK
1131For further details, see the kernel source file
1132.IR Documentation/admin-guide/kernel-parameters.txt .
e23acd79 1133.TP
03547431
MK
1134.BR PR_SET_THP_DISABLE " (since Linux 3.15)"
1135.\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
1136Set the state of the "THP disable" flag for the calling thread.
1137If
1138.I arg2
1139has a nonzero value, the flag is set, otherwise it is cleared.
1140Setting this flag provides a method
1141for disabling transparent huge pages
1142for jobs where the code cannot be modified, and using a malloc hook with
1143.BR madvise (2)
1144is not an option (i.e., statically allocated data).
1145The setting of the "THP disable" flag is inherited by a child created via
1146.BR fork (2)
1147and is preserved across
1148.BR execve (2).
1149.\"
06afe673
MK
1150.TP
1151.BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
1152Disable all performance counters attached to the calling process,
1153regardless of whether the counters were created by
1154this process or another process.
1155Performance counters created by the calling process for other
1156processes are unaffected.
66a9882e 1157For more information on performance counters, see the Linux kernel source file
06afe673
MK
1158.IR tools/perf/design.txt .
1159.IP
03547431
MK
1160Originally called
1161.BR PR_TASK_PERF_COUNTERS_DISABLE ;
1162.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
b0ea1ea3 1163renamed (retaining the same numerical value)
03547431
MK
1164in Linux 2.6.32.
1165.\"
03979794 1166.TP
03547431
MK
1167.BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
1168The converse of
1169.BR PR_TASK_PERF_EVENTS_DISABLE ;
1170enable performance counters attached to the calling process.
1171.IP
1172Originally called
1173.BR PR_TASK_PERF_COUNTERS_ENABLE ;
1174.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
1175renamed
1176.\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
1177in Linux 2.6.32.
1178.\"
1179.TP
1180.BR PR_GET_THP_DISABLE " (since Linux 3.15)"
1181Return (via the function result) the current setting of the "THP disable"
1182flag for the calling thread:
1183either 1, if the flag is set, or 0, if it is not.
1184.TP
1185.BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
1186.\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
1187Retrieve the
1188.I clear_child_tid
1189address set by
1190.BR set_tid_address (2)
1191and the
1192.BR clone (2)
1193.B CLONE_CHILD_CLEARTID
1194flag, in the location pointed to by
1195.IR "(int\ **)\ arg2" .
1196This feature is available only if the kernel is built with the
1197.BR CONFIG_CHECKPOINT_RESTORE
c7f2f9ed
MK
1198option enabled.
1199Note that since the
1200.BR prctl ()
1201system call does not have a compat implementation for
1202the AMD64 x32 and MIPS n32 ABIs,
1203and the kernel writes out a pointer using the kernel's pointer size,
1204this operation expects a user-space buffer of 8 (not 4) bytes on these ABIs.
03547431
MK
1205.TP
1206.BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
1207.\" See https://lwn.net/Articles/369549/
1208.\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
3780f8a5
MK
1209Each thread has two associated timer slack values:
1210a "default" value, and a "current" value.
1211This operation sets the "current" timer slack value for the calling thread.
1212If the nanosecond value supplied in
1213.IR arg2
1214is greater than zero, then the "current" value is set to this value.
03547431
MK
1215If
1216.I arg2
1217is less than or equal to zero,
1218.\" It seems that it's not possible to set the timer slack to zero;
1219.\" The minimum value is 1? Seems a little strange.
3780f8a5
MK
1220the "current" timer slack is reset to the
1221thread's "default" timer slack value.
efeece04 1222.IP
3780f8a5 1223The "current" timer slack is used by the kernel to group timer expirations
03547431
MK
1224for the calling thread that are close to one another;
1225as a consequence, timer expirations for the thread may be
1226up to the specified number of nanoseconds late (but will never expire early).
1227Grouping timer expirations can help reduce system power consumption
1228by minimizing CPU wake-ups.
efeece04 1229.IP
03547431
MK
1230The timer expirations affected by timer slack are those set by
1231.BR select (2),
1232.BR pselect (2),
1233.BR poll (2),
1234.BR ppoll (2),
1235.BR epoll_wait (2),
1236.BR epoll_pwait (2),
1237.BR clock_nanosleep (2),
1238.BR nanosleep (2),
1239and
1240.BR futex (2)
1241(and thus the library functions implemented via futexes, including
1242.\" List obtained by grepping for futex usage in glibc source
1243.BR pthread_cond_timedwait (3),
1244.BR pthread_mutex_timedlock (3),
1245.BR pthread_rwlock_timedrdlock (3),
1246.BR pthread_rwlock_timedwrlock (3),
1247and
1248.BR sem_timedwait (3)).
efeece04 1249.IP
03547431
MK
1250Timer slack is not applied to threads that are scheduled under
1251a real-time scheduling policy (see
1252.BR sched_setscheduler (2)).
efeece04 1253.IP
03547431 1254When a new thread is created,
3780f8a5 1255the two timer slack values are made the same as the "current" value
03547431 1256of the creating thread.
3780f8a5
MK
1257Thereafter, a thread can adjust its "current" timer slack value via
1258.BR PR_SET_TIMERSLACK .
1259The "default" value can't be changed.
03547431
MK
1260The timer slack values of
1261.IR init
1262(PID 1), the ancestor of all processes,
1263are 50,000 nanoseconds (50 microseconds).
1264The timer slack values are preserved across
1265.BR execve (2).
efeece04 1266.IP
c1f78aba
MK
1267Since Linux 4.6, the "current" timer slack value of any process
1268can be examined and changed via the file
1269.IR /proc/[pid]/timerslack_ns .
1270See
1271.BR proc (5).
e81a96ec 1272.TP
03547431
MK
1273.BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
1274Return (as the function result)
3780f8a5 1275the "current" timer slack value of the calling thread.
4bf25b89 1276.TP
d6bec36e
MK
1277.BR PR_SET_TIMING " (since Linux 2.6.0)"
1278.\" Precisely: Linux 2.6.0-test4
03547431
MK
1279Set whether to use (normal, traditional) statistical process timing or
1280accurate timestamp-based process timing, by passing
1281.B PR_TIMING_STATISTICAL
1282.\" 0
1283or
1284.B PR_TIMING_TIMESTAMP
1285.\" 1
1286to \fIarg2\fP.
1287.B PR_TIMING_TIMESTAMP
1288is not currently implemented
1289(attempting to set this mode will yield the error
1290.BR EINVAL ).
1291.\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
1292.\" and looking at the patch history, it appears
1293.\" that it never did anything.
4bf25b89 1294.TP
d6bec36e
MK
1295.BR PR_GET_TIMING " (since Linux 2.6.0)"
1296.\" Precisely: Linux 2.6.0-test4
03547431
MK
1297Return (as the function result) which process timing method is currently
1298in use.
4bf25b89 1299.TP
03547431
MK
1300.BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
1301Set the state of the flag determining whether the timestamp counter
1302can be read by the process.
1303Pass
1304.B PR_TSC_ENABLE
1305to
1306.I arg2
1307to allow it to be read, or
1308.B PR_TSC_SIGSEGV
1309to generate a
1310.B SIGSEGV
1311when the process tries to read the timestamp counter.
4bf25b89 1312.TP
03547431
MK
1313.BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
1314Return the state of the flag determining whether the timestamp counter
1315can be read,
1316in the location pointed to by
1317.IR "(int\ *) arg2" .
1318.TP
1319.B PR_SET_UNALIGN
1320(Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
0e2c6b8c
ES
1321PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22;
1322.\" sh: 94ea5e449ae834af058ef005d16a8ad44fcf13d6
1323.\" tile: 2f9ac29eec71a696cb0dcc5fb82c0f8d4dac28c9
1324sh, since Linux 2.6.34; tile, since Linux 3.12)
03547431
MK
1325Set unaligned access control bits to \fIarg2\fP.
1326Pass
1327\fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
1328or \fBPR_UNALIGN_SIGBUS\fP to generate
1329.B SIGBUS
2da72a43
MK
1330on unaligned user access.
1331Alpha also supports an additional flag with the value
1332of 4 and no corresponding named constant,
1333which instructs kernel to not fix up
0e2c6b8c 1334unaligned accesses (it is analogous to providing the
2da72a43
MK
1335.BR UAC_NOFIX
1336flag in
1337.BR SSI_NVPAIRS
1338operation of the
1339.BR setsysinfo ()
1340system call on Tru64).
03547431
MK
1341.TP
1342.B PR_GET_UNALIGN
1343(see
1344.B PR_SET_UNALIGN
1345for information on versions and architectures)
1346Return unaligned access control bits, in the location pointed to by
0e2c6b8c 1347.IR "(unsigned int\ *) arg2" .
47297adb 1348.SH RETURN VALUE
8ab8b43f
MK
1349On success,
1350.BR PR_GET_DUMPABLE ,
1351.BR PR_GET_KEEPCAPS ,
f83fe154 1352.BR PR_GET_NO_NEW_PRIVS ,
5745985f 1353.BR PR_GET_THP_DISABLE ,
8ab8b43f
MK
1354.BR PR_CAPBSET_READ ,
1355.BR PR_GET_TIMING ,
c42db321 1356.BR PR_GET_TIMERSLACK ,
8ab8b43f 1357.BR PR_GET_SECUREBITS ,
ed31c572 1358.BR PR_MCE_KILL_GET ,
0c3e75cb 1359.BR PR_CAP_AMBIENT + PR_CAP_AMBIENT_IS_SET ,
8ab8b43f
MK
1360and (if it returns)
1361.BR PR_GET_SECCOMP
2fda57bd 1362return the nonnegative values described above.
fea681da
MK
1363All other
1364.I option
1365values return 0 on success.
1366On error, \-1 is returned, and
1367.I errno
1368is set appropriately.
1369.SH ERRORS
1370.TP
0478944d
MK
1371.B EACCES
1372.I option
1373is
4ab9f1db
MK
1374.BR PR_SET_SECCOMP
1375and
1376.I arg2
1377is
1378.BR SECCOMP_MODE_FILTER ,
1379but the process does not have the
1380.BR CAP_SYS_ADMIN
1381capability or has not set the
1382.IR no_new_privs
1383attribute (see the discussion of
1384.BR PR_SET_NO_NEW_PRIVS
1385above).
1386.TP
1387.B EACCES
1388.I option
1389is
0478944d
MK
1390.BR PR_SET_MM ,
1391and
1392.I arg3
1393is
1394.BR PR_SET_MM_EXE_FILE ,
1395the file is not executable.
1396.TP
1397.B EBADF
1398.I option
1399is
1400.BR PR_SET_MM ,
1401.I arg3
1402is
1403.BR PR_SET_MM_EXE_FILE ,
1404and the file descriptor passed in
1405.I arg4
1406is not valid.
1407.TP
1408.B EBUSY
1409.I option
1410is
1411.BR PR_SET_MM ,
1412.I arg3
1413is
1414.BR PR_SET_MM_EXE_FILE ,
1415and this the second attempt to change the
1416.I /proc/pid/exe
1417symbolic link, which is prohibited.
1418.TP
8ab8b43f
MK
1419.B EFAULT
1420.I arg2
1421is an invalid address.
1422.TP
e35a0512
KC
1423.B EFAULT
1424.I option
1425is
1426.BR PR_SET_SECCOMP ,
1427.I arg2
1428is
1429.BR SECCOMP_MODE_FILTER ,
1430the system was built with
64c626f7 1431.BR CONFIG_SECCOMP_FILTER ,
e35a0512
KC
1432and
1433.I arg3
1434is an invalid address.
1435.TP
fea681da
MK
1436.B EINVAL
1437The value of
1438.I option