OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man2 / prctl.2
1 .\" Copyright (C) 1998 Andries Brouwer (aeb@cwi.nl)
2 .\" and Copyright (C) 2002, 2006, 2008, 2012, 2013 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" and Copyright Guillem Jover <guillem@hadrons.org>
4 .\" and Copyright (C) 2014 Dave Hansen / Intel
5 .\"
6 .\" %%%LICENSE_START(VERBATIM)
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.
15 .\"
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.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" %%%LICENSE_END
27 .\"
28 .\" Modified Thu Nov 11 04:19:42 MET 1999, aeb: added PR_GET_PDEATHSIG
29 .\" Modified 27 Jun 02, Michael Kerrisk
30 .\"     Added PR_SET_DUMPABLE, PR_GET_DUMPABLE,
31 .\"     PR_SET_KEEPCAPS, PR_GET_KEEPCAPS
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
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
41 .\" 2009-10-03 Andi Kleen, document PR_MCE_KILL
42 .\" 2012-04 Cyrill Gorcunov, Document PR_SET_MM
43 .\" 2012-04-25 Michael Kerrisk, Document PR_TASK_PERF_EVENTS_DISABLE and
44 .\"                             PR_TASK_PERF_EVENTS_ENABLE
45 .\" 2012-09-20 Kees Cook, update PR_SET_SECCOMP for mode 2
46 .\" 2012-09-20 Kees Cook, document PR_SET_NO_NEW_PRIVS, PR_GET_NO_NEW_PRIVS
47 .\" 2012-10-25 Michael Kerrisk, Document PR_SET_TIMERSLACK and
48 .\"                             PR_GET_TIMERSLACK
49 .\" 2013-01-10 Kees Cook, document PR_SET_PTRACER
50 .\" 2012-02-04 Michael kerrisk, document PR_{SET,GET}_CHILD_SUBREAPER
51 .\" 2014-11-10 Dave Hansen, document PR_MPX_{EN,DIS}ABLE_MANAGEMENT
52 .\"
53 .\"
54 .TH PRCTL 2 2015-02-01 "Linux" "Linux Programmer's Manual"
55 .SH NAME
56 prctl \- operations on a process
57 .SH SYNOPSIS
58 .nf
59 .B #include <sys/prctl.h>
60 .sp
61 .BI "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 ,
62 .BI "          unsigned long " arg4 ", unsigned long " arg5 );
63 .fi
64 .SH DESCRIPTION
65 .BR prctl ()
66 is called with a first argument describing what to do
67 (with values defined in \fI<linux/prctl.h>\fP), and further
68 arguments with a significance depending on the first one.
69 The first argument can be:
70 .TP
71 .BR PR_CAPBSET_READ " (since Linux 2.6.25)"
72 Return (as the function result) 1 if the capability specified in
73 .I arg2
74 is in the calling thread's capability bounding set,
75 or 0 if it is not.
76 (The capability constants are defined in
77 .IR <linux/capability.h> .)
78 The capability bounding set dictates
79 whether the process can receive the capability through a
80 file's permitted capability set on a subsequent call to
81 .BR execve (2).
82
83 If the capability specified in
84 .I arg2
85 is not valid, then the call fails with the error
86 .BR EINVAL .
87 .TP
88 .BR PR_CAPBSET_DROP " (since Linux 2.6.25)"
89 If the calling thread has the
90 .B CAP_SETPCAP
91 capability, then drop the capability specified by
92 .I arg2
93 from the calling thread's capability bounding set.
94 Any children of the calling thread will inherit the newly
95 reduced bounding set.
96
97 The call fails with the error:
98 .B EPERM
99 if the calling thread does not have the
100 .BR CAP_SETPCAP ;
101 .BR EINVAL
102 if
103 .I arg2
104 does not represent a valid capability; or
105 .BR EINVAL
106 if file capabilities are not enabled in the kernel,
107 in which case bounding sets are not supported.
108 .TP
109 .BR PR_SET_CHILD_SUBREAPER " (since Linux 3.4)"
110 .\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b
111 If
112 .I arg2
113 is nonzero,
114 set the "child subreaper" attribute of the calling process;
115 if
116 .I arg2
117 is zero, unset the attribute.
118 When a process is marked as a child subreaper,
119 all of the children that it creates, and their descendants,
120 will be marked as having a subreaper.
121 In effect, a subreaper fulfills the role of
122 .BR init (1)
123 for its descendant processes.
124 Upon termination of a process
125 that is orphaned (i.e., its immediate parent has already terminated)
126 and marked as having a subreaper,
127 the nearest still living ancestor subreaper
128 will receive a
129 .BR SIGCHLD
130 signal and be able to
131 .BR wait (2)
132 on the process to discover its termination status.
133 .TP
134 .BR PR_GET_CHILD_SUBREAPER " (since Linux 3.4)"
135 Return the "child subreaper" setting of the caller,
136 in the location pointed to by
137 .IR "(int\ *) arg2" .
138 .TP
139 .BR PR_SET_DUMPABLE " (since Linux 2.3.20)"
140 Set the state of the flag determining whether core dumps are produced
141 for the calling process upon delivery of a signal whose default behavior is
142 to produce a core dump.
143 (Normally, this flag is set for a process by default, but it is cleared
144 when a set-user-ID or set-group-ID program is executed and also by
145 various system calls that manipulate process UIDs and GIDs).
146 In kernels up to and including 2.6.12,
147 .I arg2
148 must be either 0 (process is not dumpable) or 1 (process is dumpable).
149 Between kernels 2.6.13 and 2.6.17, the value 2 was also permitted,
150 which caused any binary which normally would not be dumped
151 to be dumped readable by root only;
152 for security reasons, this feature has been removed.
153 .\" See http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2
154 .\" Subject:    Fix prctl privilege escalation (CVE-2006-2451)
155 .\" From:       Marcel Holtmann <marcel () holtmann ! org>
156 .\" Date:       2006-07-12 11:12:00
157 (See also the description of
158 .I /proc/sys/fs/suid_dumpable
159 in
160 .BR proc (5).)
161 Processes that are not dumpable can not be attached via
162 .BR ptrace (2)
163 .BR PTRACE_ATTACH .
164 .TP
165 .BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
166 Return (as the function result) the current state of the calling
167 process's dumpable flag.
168 .\" Since Linux 2.6.13, the dumpable flag can have the value 2,
169 .\" but in 2.6.13 PR_GET_DUMPABLE simply returns 1 if the dumpable
170 .\" flags has a nonzero value.  This was fixed in 2.6.14.
171 .TP
172 .BR PR_SET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
173 Set the endian-ness of the calling process to the value given
174 in \fIarg2\fP, which should be one of the following:
175 .\" Respectively 0, 1, 2
176 .BR PR_ENDIAN_BIG ,
177 .BR PR_ENDIAN_LITTLE ,
178 or
179 .B PR_ENDIAN_PPC_LITTLE
180 (PowerPC pseudo little endian).
181 .TP
182 .BR PR_GET_ENDIAN " (since Linux 2.6.18, PowerPC only)"
183 Return the endian-ness of the calling process,
184 in the location pointed to by
185 .IR "(int\ *) arg2" .
186 .TP
187 .BR PR_SET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
188 Set floating-point emulation control bits to \fIarg2\fP.
189 Pass \fBPR_FPEMU_NOPRINT\fP to silently emulate fp operations accesses, or
190 \fBPR_FPEMU_SIGFPE\fP to not emulate fp operations and send
191 .B SIGFPE
192 instead.
193 .TP
194 .BR PR_GET_FPEMU " (since Linux 2.4.18, 2.5.9, only on ia64)"
195 Return floating-point emulation control bits,
196 in the location pointed to by
197 .IR "(int\ *) arg2" .
198 .TP
199 .BR PR_SET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
200 Set floating-point exception mode to \fIarg2\fP.
201 Pass \fBPR_FP_EXC_SW_ENABLE\fP to use FPEXC for FP exception enables,
202 \fBPR_FP_EXC_DIV\fP for floating-point divide by zero,
203 \fBPR_FP_EXC_OVF\fP for floating-point overflow,
204 \fBPR_FP_EXC_UND\fP for floating-point underflow,
205 \fBPR_FP_EXC_RES\fP for floating-point inexact result,
206 \fBPR_FP_EXC_INV\fP for floating-point invalid operation,
207 \fBPR_FP_EXC_DISABLED\fP for FP exceptions disabled,
208 \fBPR_FP_EXC_NONRECOV\fP for async nonrecoverable exception mode,
209 \fBPR_FP_EXC_ASYNC\fP for async recoverable exception mode,
210 \fBPR_FP_EXC_PRECISE\fP for precise exception mode.
211 .TP
212 .BR PR_GET_FPEXC " (since Linux 2.4.21, 2.5.32, only on PowerPC)"
213 Return floating-point exception mode,
214 in the location pointed to by
215 .IR "(int\ *) arg2" .
216 .TP
217 .BR PR_SET_KEEPCAPS " (since Linux 2.2.18)"
218 Set the state of the thread's "keep capabilities" flag,
219 which determines whether the threads's permitted
220 capability set is cleared when a change is made to the threads's user IDs
221 such that the threads's real UID, effective UID, and saved set-user-ID
222 all become nonzero when at least one of them previously had the value 0.
223 By default, the permitted capability set is cleared when such a change is made;
224 setting the "keep capabilities" flag prevents it from being cleared.
225 .I arg2
226 must be either 0 (permitted capabilities are cleared)
227 or 1 (permitted capabilities are kept).
228 (A thread's
229 .I effective
230 capability set is always cleared when such a credential change is made,
231 regardless of the setting of the "keep capabilities" flag.)
232 The "keep capabilities" value will be reset to 0 on subsequent calls to
233 .BR execve (2).
234 .TP
235 .BR PR_GET_KEEPCAPS " (since Linux 2.2.18)"
236 Return (as the function result) the current state of the calling threads's
237 "keep capabilities" flag.
238 .TP
239 .BR PR_SET_NAME " (since Linux 2.6.9)"
240 Set the name of the calling thread,
241 using the value in the location pointed to by
242 .IR "(char\ *) arg2" .
243 The name can be up to 16 bytes long,
244 .\" TASK_COMM_LEN in include/linux/sched.h
245 including the terminating null byte.
246 (If the length of the string, including the terminating null byte,
247 exceeds 16 bytes, the string is silently truncated.)
248 This is the same attribute that can be set via
249 .BR pthread_setname_np (3)
250 and retrieved using
251 .BR pthread_getname_np (3).
252 The attribute is likewise accessible via
253 .IR /proc/self/task/[tid]/comm ,
254 where
255 .I tid
256 is the name of the calling thread.
257 .TP
258 .BR PR_GET_NAME " (since Linux 2.6.11)"
259 Return the name of the calling thread,
260 in the buffer pointed to by
261 .IR "(char\ *) arg2" .
262 The buffer should allow space for up to 16 bytes;
263 the returned string will be null-terminated.
264 .TP
265 .BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
266 Set the calling process's
267 .I no_new_privs
268 bit to the value in
269 .IR arg2 .
270 With
271 .I no_new_privs
272 set to 1,
273 .BR execve (2)
274 promises not to grant privileges to do anything
275 that could not have been done without the
276 .BR execve (2)
277 call (for example,
278 rendering the set-user-ID and set-group-ID permission bits,
279 and file capabilities non-functional).
280 Once set, this bit cannot be unset.
281 The setting of this bit is inherited by children created by
282 .BR fork (2)
283 and
284 .BR clone (2),
285 and preserved across
286 .BR execve (2).
287
288 For more information, see the kernel source file
289 .IR Documentation/prctl/no_new_privs.txt .
290 .TP
291 .BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
292 Return (as the function result) the value of the
293 .I no_new_privs
294 bit for the current process.
295 A value of 0 indicates the regular
296 .BR execve (2)
297 behavior.
298 A value of 1 indicates
299 .BR execve (2)
300 will operate in the privilege-restricting mode described above.
301 .TP
302 .BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
303 Set the parent process death signal
304 of the calling process to \fIarg2\fP (either a signal value
305 in the range 1..maxsig, or 0 to clear).
306 This is the signal that the calling process will get when its
307 parent dies.
308 This value is cleared for the child of a
309 .BR fork (2)
310 and (since Linux 2.4.36 / 2.6.23)
311 when executing a set-user-ID or set-group-ID binary.
312 This value is preserved across
313 .BR execve (2).
314 .TP
315 .BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
316 Return the current value of the parent process death signal,
317 in the location pointed to by
318 .IR "(int\ *) arg2" .
319 .TP
320 .BR PR_SET_PTRACER " (since Linux 3.4)"
321 .\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
322 .\" commit bf06189e4d14641c0148bea16e9dd24943862215
323 This is meaningful only when the Yama LSM is enabled and in mode 1
324 ("restricted ptrace", visible via
325 .IR /proc/sys/kernel/yama/ptrace_scope ).
326 When a "ptracer process ID" is passed in \fIarg2\fP,
327 the caller is declaring that the ptracer process can
328 .BR ptrace (2)
329 the calling process as if it were a direct process ancestor.
330 Each
331 .B PR_SET_PTRACER
332 operation replaces the previous "ptracer process ID".
333 Employing
334 .B PR_SET_PTRACER
335 with
336 .I arg2
337 set to 0 clears the caller's "ptracer process ID".
338 If
339 .I arg2
340 is
341 .BR PR_SET_PTRACER_ANY ,
342 the ptrace restrictions introduced by Yama are effectively disabled for the
343 calling process.
344
345 For further information, see the kernel source file
346 .IR Documentation/security/Yama.txt .
347 .TP
348 .BR PR_SET_SECCOMP " (since Linux 2.6.23)"
349 .\" See http://thread.gmane.org/gmane.linux.kernel/542632
350 .\" [PATCH 0 of 2] seccomp updates
351 .\" andrea@cpushare.com
352 Set the secure computing (seccomp) mode for the calling thread, to limit
353 the available system calls.
354 The more recent
355 .BR seccomp (2)
356 system call provides a superset of the functionality of
357 .BR PR_SET_SECCOMP .
358
359 The seccomp mode is selected via
360 .IR arg2 .
361 (The seccomp constants are defined in
362 .IR <linux/seccomp.h> .)
363
364 With
365 .IR arg2
366 set to
367 .BR SECCOMP_MODE_STRICT ,
368 the only system calls that the thread is permitted to make are
369 .BR read (2),
370 .BR write (2),
371 .BR _exit (2),
372 and
373 .BR sigreturn (2).
374 Other system calls result in the delivery of a
375 .BR SIGKILL
376 signal.
377 Strict secure computing mode is useful for number-crunching applications
378 that may need to execute untrusted byte code,
379 perhaps obtained by reading from a pipe or socket.
380 This operation is available only
381 if the kernel is configured with
382 .B CONFIG_SECCOMP
383 enabled.
384
385 With
386 .IR arg2
387 set to
388 .BR SECCOMP_MODE_FILTER " (since Linux 3.5),"
389 the system calls allowed are defined by a pointer
390 to a Berkeley Packet Filter passed in
391 .IR arg3 .
392 This argument is a pointer to
393 .IR "struct sock_fprog" ;
394 it can be designed to filter
395 arbitrary system calls and system call arguments.
396 This mode is available only if the kernel is configured with
397 .B CONFIG_SECCOMP_FILTER
398 enabled.
399
400 If
401 .BR SECCOMP_MODE_FILTER
402 filters permit
403 .BR fork (2),
404 then the seccomp mode is inherited by children created by
405 .BR fork (2);
406 if
407 .BR execve (2)
408 is permitted, then the seccomp mode is preserved across
409 .BR execve (2).
410 If the filters permit
411 .BR prctl ()
412 calls, then additional filters can be added;
413 they are run in order until the first non-allow result is seen.
414
415 For further information, see the kernel source file
416 .IR Documentation/prctl/seccomp_filter.txt .
417 .TP
418 .BR PR_GET_SECCOMP " (since Linux 2.6.23)"
419 Return (as the function result)
420 the secure computing mode of the calling thread.
421 If the caller is not in secure computing mode, this operation returns 0;
422 if the caller is in strict secure computing mode, then the
423 .BR prctl ()
424 call will cause a
425 .B SIGKILL
426 signal to be sent to the process.
427 If the caller is in filter mode, and this system call is allowed by the
428 seccomp filters, it returns 2; otherwise, the process is killed with a
429 .BR SIGKILL
430 signal.
431 This operation is available only
432 if the kernel is configured with
433 .B CONFIG_SECCOMP
434 enabled.
435
436 Since Linux 3.8, the
437 .IR Seccomp
438 field of the
439 .IR /proc/[pid]/status
440 file provides a method of obtaining the same information,
441 without the risk that the process is killed; see
442 .BR proc (5).
443 .TP
444 .BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
445 Set the "securebits" flags of the calling thread to the value supplied in
446 .IR arg2 .
447 See
448 .BR capabilities (7).
449 .TP
450 .BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
451 Return (as the function result)
452 the "securebits" flags of the calling thread.
453 See
454 .BR capabilities (7).
455 .TP
456 .BR PR_SET_THP_DISABLE " (since Linux 3.15)"
457 .\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
458 Set the state of the "THP disable" flag for the calling thread.
459 If
460 .I arg2
461 has a nonzero value, the flag is set, otherwise it is cleared.
462 Setting this flag provides a method
463 for disabling transparent huge pages
464 for jobs where the code cannot be modified, and using a malloc hook with
465 .BR madvise (2)
466 is not an option (i.e., statically allocated data).
467 The setting of the "THP disable" flag is inherited by a child created via
468 .BR fork (2)
469 and is preserved across
470 .BR execve (2).
471 .TP
472 .BR PR_GET_THP_DISABLE " (since Linux 3.15)"
473 Return (via the function result) the current setting of the "THP disable"
474 flag for the calling thread:
475 either 1, if the flag is set, or 0, if it is not.
476 .TP
477 .BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
478 .\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
479 Retrieve the
480 .I clear_child_tid
481 address set by
482 .BR set_tid_address (2)
483 and the
484 .BR clone (2)
485 .B CLONE_CHILD_CLEARTID
486 flag, in the location pointed to by
487 .IR "(int\ **)\ arg2" .
488 This feature is available only if the kernel is built with the
489 .BR CONFIG_CHECKPOINT_RESTORE
490 option enabled.
491 .TP
492 .BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
493 .\" See https://lwn.net/Articles/369549/
494 .\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
495 Set the current timer slack for the calling thread to the nanosecond value
496 supplied in
497 .IR arg2 .
498 If
499 .I arg2
500 is less than or equal to zero,
501 .\" It seems that it's not possible to set the timer slack to zero;
502 .\" The minimum value is 1? Seems a little strange.
503 reset the current timer slack to the thread's default timer slack value.
504 The timer slack is used by the kernel to group timer expirations
505 for the calling thread that are close to one another;
506 as a consequence, timer expirations for the thread may be
507 up to the specified number of nanoseconds late (but will never expire early).
508 Grouping timer expirations can help reduce system power consumption
509 by minimizing CPU wake-ups.
510
511 The timer expirations affected by timer slack are those set by
512 .BR select (2),
513 .BR pselect (2),
514 .BR poll (2),
515 .BR ppoll (2),
516 .BR epoll_wait (2),
517 .BR epoll_pwait (2),
518 .BR clock_nanosleep (2),
519 .BR nanosleep (2),
520 and
521 .BR futex (2)
522 (and thus the library functions implemented via futexes, including
523 .\" List obtained by grepping for futex usage in glibc source
524 .BR pthread_cond_timedwait (3),
525 .BR pthread_mutex_timedlock (3),
526 .BR pthread_rwlock_timedrdlock (3),
527 .BR pthread_rwlock_timedwrlock (3),
528 and
529 .BR sem_timedwait (3)).
530
531 Timer slack is not applied to threads that are scheduled under
532 a real-time scheduling policy (see
533 .BR sched_setscheduler (2)).
534
535 Each thread has two associated timer slack values:
536 a "default" value, and a "current" value.
537 The current value is the one that governs grouping
538 of timer expirations.
539 When a new thread is created,
540 the two timer slack values are made the same as the current value
541 of the creating thread.
542 Thereafter, a thread can adjust its current timer slack value via
543 .BR PR_SET_TIMERSLACK
544 (the default value can't be changed).
545 The timer slack values of
546 .IR init
547 (PID 1), the ancestor of all processes,
548 are 50,000 nanoseconds (50 microseconds).
549 The timer slack values are preserved across
550 .BR execve (2).
551 .TP
552 .BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
553 Return (as the function result)
554 the current timer slack value of the calling thread.
555 .TP
556 .BR PR_SET_TIMING " (since Linux 2.6.0-test4)"
557 Set whether to use (normal, traditional) statistical process timing or
558 accurate timestamp-based process timing, by passing
559 .B PR_TIMING_STATISTICAL
560 .\" 0
561 or
562 .B PR_TIMING_TIMESTAMP
563 .\" 1
564 to \fIarg2\fP.
565 .B PR_TIMING_TIMESTAMP
566 is not currently implemented
567 (attempting to set this mode will yield the error
568 .BR EINVAL ).
569 .\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
570 .\" and looking at the patch history, it appears
571 .\" that it never did anything.
572 .TP
573 .BR PR_GET_TIMING " (since Linux 2.6.0-test4)"
574 Return (as the function result) which process timing method is currently
575 in use.
576 .TP
577 .BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
578 Disable all performance counters attached to the calling process,
579 regardless of whether the counters were created by
580 this process or another process.
581 Performance counters created by the calling process for other
582 processes are unaffected.
583 For more information on performance counters, see the Linux kernel source file
584 .IR tools/perf/design.txt .
585 .IP
586 Originally called
587 .BR PR_TASK_PERF_COUNTERS_DISABLE ;
588 .\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
589 renamed (with same numerical value)
590 in Linux 2.6.32.
591 .TP
592 .BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
593 The converse of
594 .BR PR_TASK_PERF_EVENTS_DISABLE ;
595 enable performance counters attached to the calling process.
596 .IP
597 Originally called
598 .BR PR_TASK_PERF_COUNTERS_ENABLE ;
599 .\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
600 renamed
601 .\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
602 in Linux 2.6.32.
603 .TP
604 .BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
605 Set the state of the flag determining whether the timestamp counter
606 can be read by the process.
607 Pass
608 .B PR_TSC_ENABLE
609 to
610 .I arg2
611 to allow it to be read, or
612 .B PR_TSC_SIGSEGV
613 to generate a
614 .B SIGSEGV
615 when the process tries to read the timestamp counter.
616 .TP
617 .BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
618 Return the state of the flag determining whether the timestamp counter
619 can be read,
620 in the location pointed to by
621 .IR "(int\ *) arg2" .
622 .TP
623 .B PR_SET_UNALIGN
624 (Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
625 PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22)
626 Set unaligned access control bits to \fIarg2\fP.
627 Pass
628 \fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
629 or \fBPR_UNALIGN_SIGBUS\fP to generate
630 .B SIGBUS
631 on unaligned user access.
632 .TP
633 .B PR_GET_UNALIGN
634 (see
635 .B PR_SET_UNALIGN
636 for information on versions and architectures)
637 Return unaligned access control bits, in the location pointed to by
638 .IR "(int\ *) arg2" .
639 .TP
640 .BR PR_MCE_KILL " (since Linux 2.6.32)"
641 Set the machine check memory corruption kill policy for the current thread.
642 If
643 .I arg2
644 is
645 .BR PR_MCE_KILL_CLEAR ,
646 clear the thread memory corruption kill policy and use the system-wide default.
647 (The system-wide default is defined by
648 .IR /proc/sys/vm/memory_failure_early_kill ;
649 see
650 .BR proc (5).)
651 If
652 .I arg2
653 is
654 .BR PR_MCE_KILL_SET ,
655 use a thread-specific memory corruption kill policy.
656 In this case,
657 .I arg3
658 defines whether the policy is
659 .I early kill
660 .RB ( PR_MCE_KILL_EARLY ),
661 .I late kill
662 .RB ( PR_MCE_KILL_LATE ),
663 or the system-wide default
664 .RB ( PR_MCE_KILL_DEFAULT ).
665 Early kill means that the thread receives a
666 .B SIGBUS
667 signal as soon as hardware memory corruption is detected inside
668 its address space.
669 In late kill mode, the process is killed only when it accesses a corrupted page.
670 See
671 .BR sigaction (2)
672 for more information on the
673 .BR SIGBUS
674 signal.
675 The policy is inherited by children.
676 The remaining unused
677 .BR prctl ()
678 arguments must be zero for future compatibility.
679 .TP
680 .BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
681 Return the current per-process machine check kill policy.
682 All unused
683 .BR prctl ()
684 arguments must be zero.
685 .TP
686 .BR PR_SET_MM " (since Linux 3.3)"
687 .\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
688 Modify certain kernel memory map descriptor fields
689 of the calling process.
690 Usually these fields are set by the kernel and dynamic loader (see
691 .BR ld.so (8)
692 for more information) and a regular application should not use this feature.
693 However, there are cases, such as self-modifying programs,
694 where a program might find it useful to change its own memory map.
695 This feature is available only if the kernel is built with the
696 .BR CONFIG_CHECKPOINT_RESTORE
697 option enabled.
698 The calling process must have the
699 .BR CAP_SYS_RESOURCE
700 capability.
701 The value in
702 .I arg2
703 is one of the options below, while
704 .I arg3
705 provides a new value for the option.
706 .RS
707 .TP
708 .BR PR_SET_MM_START_CODE
709 Set the address above which the program text can run.
710 The corresponding memory area must be readable and executable,
711 but not writable or sharable (see
712 .BR mprotect (2)
713 and
714 .BR mmap (2)
715 for more information).
716 .TP
717 .BR PR_SET_MM_END_CODE
718 Set the address below which the program text can run.
719 The corresponding memory area must be readable and executable,
720 but not writable or sharable.
721 .TP
722 .BR PR_SET_MM_START_DATA
723 Set the address above which initialized and
724 uninitialized (bss) data are placed.
725 The corresponding memory area must be readable and writable,
726 but not executable or sharable.
727 .TP
728 .B PR_SET_MM_END_DATA
729 Set the address below which initialized and
730 uninitialized (bss) data are placed.
731 The corresponding memory area must be readable and writable,
732 but not executable or sharable.
733 .TP
734 .BR PR_SET_MM_START_STACK
735 Set the start address of the stack.
736 The corresponding memory area must be readable and writable.
737 .TP
738 .BR PR_SET_MM_START_BRK
739 Set the address above which the program heap can be expanded with
740 .BR brk (2)
741 call.
742 The address must be greater than the ending address of
743 the current program data segment.
744 In addition, the combined size of the resulting heap and
745 the size of the data segment can't exceed the
746 .BR RLIMIT_DATA
747 resource limit (see
748 .BR setrlimit (2)).
749 .TP
750 .BR PR_SET_MM_BRK
751 Set the current
752 .BR brk (2)
753 value.
754 The requirements for the address are the same as for the
755 .BR PR_SET_MM_START_BRK
756 option.
757 .P
758 The following options are available since Linux 3.5.
759 .\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
760 .TP
761 .BR PR_SET_MM_ARG_START
762 Set the address above which the program command line is placed.
763 .TP
764 .BR PR_SET_MM_ARG_END
765 Set the address below which the program command line is placed.
766 .TP
767 .BR PR_SET_MM_ENV_START
768 Set the address above which the program environment is placed.
769 .TP
770 .BR PR_SET_MM_ENV_END
771 Set the address below which the program environment is placed.
772 .IP
773 The address passed with
774 .BR PR_SET_MM_ARG_START ,
775 .BR PR_SET_MM_ARG_END ,
776 .BR PR_SET_MM_ENV_START ,
777 and
778 .BR PR_SET_MM_ENV_END
779 should belong to a process stack area.
780 Thus, the corresponding memory area must be readable, writable, and
781 (depending on the kernel configuration) have the
782 .BR MAP_GROWSDOWN
783 attribute set (see
784 .BR mmap (2)).
785 .TP
786 .BR PR_SET_MM_AUXV
787 Set a new auxiliary vector.
788 The
789 .I arg3
790 argument should provide the address of the vector.
791 The
792 .I arg4
793 is the size of the vector.
794 .TP
795 .BR PR_SET_MM_EXE_FILE
796 .\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
797 Supersede the
798 .IR /proc/pid/exe
799 symbolic link with a new one pointing to a new executable file
800 identified by the file descriptor provided in
801 .I arg3
802 argument.
803 The file descriptor should be obtained with a regular
804 .BR open (2)
805 call.
806 .IP
807 To change the symbolic link, one needs to unmap all existing
808 executable memory areas, including those created by the kernel itself
809 (for example the kernel usually creates at least one executable
810 memory area for the ELF
811 .IR \.text
812 section).
813 .IP
814 The second limitation is that such transitions can be done only once
815 in a process life time.
816 Any further attempts will be rejected.
817 This should help system administrators monitor unusual
818 symbolic-link transitions over all processes running on a system.
819 .RE
820 .TP
821 .BR PR_MPX_ENABLE_MANAGEMENT ", " PR_MPX_DISABLE_MANAGEMENT " (since Linux 3.19) "
822 .\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c
823 .\" See also http://lwn.net/Articles/582712/
824 .\" See also https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
825 Enable or disable kernel management of Memory Protection eXtensions (MPX)
826 bounds tables.
827 The
828 .IR arg2 ,
829 .IR arg3 ,
830 .IR arg4 ,
831 and
832 .IR arg5
833 .\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88
834 arguments must be zero.
835
836 MPX is a hardware-assisted mechanism for performing bounds checking on
837 pointers.
838 It consists of a set of registers storing bounds information
839 and a set of special instruction prefixes that tell the CPU on which
840 instructions it should do bounds enforcement.
841 There is a limited number of these registers and
842 when there are more pointers than registers,
843 their contents must be "spilled" into a set of tables.
844 These tables are called "bounds tables" and the MPX
845 .BR prctl ()
846 operations control
847 whether the kernel manages their allocation and freeing.
848
849 When management is enabled, the kernel will take over allocation
850 and freeing of the bounds tables.
851 It does this by trapping the #BR exceptions that result
852 at first use of missing bounds tables and
853 instead of delivering the exception to user space,
854 it allocates the table and populates the bounds directory
855 with the location of the new table.
856 For freeing, the kernel checks to see if bounds tables are
857 present for memory which is not allocated, and frees them if so.
858
859 Before enabling MPX management using
860 .BR PR_MPX_ENABLE_MANAGEMENT ,
861 the application must first have allocated a user-space buffer for
862 the bounds directory and placed the location of that directory in the
863 .I bndcfgu
864 register.
865
866 These calls will fail if the CPU or kernel does not support MPX.
867 Kernel support for MPX is enabled via the
868 .BR CONFIG_X86_INTEL_MPX
869 configuration option.
870 You can check whether the CPU supports MPX by looking for the 'mpx'
871 CPUID bit, like with the following command:
872
873         cat /proc/cpuinfo | grep ' mpx '
874
875 A thread may not switch in or out of long (64-bit) mode while MPX is
876 enabled.
877
878 All threads in a process are affected by these calls.
879
880 The child of a
881 .BR fork (2)
882 inherits the state of MPX management.
883 During
884 .BR execve (2),
885 MPX management is reset to a state as if
886 .BR PR_MPX_DISABLE_MANAGEMENT
887 had been called.
888
889 For further information on Intel MPX, see the kernel source file
890 .IR Documentation/x86/intel_mpx.txt .
891 .\"
892 .SH RETURN VALUE
893 On success,
894 .BR PR_GET_DUMPABLE ,
895 .BR PR_GET_KEEPCAPS ,
896 .BR PR_GET_NO_NEW_PRIVS ,
897 .BR PR_GET_THP_DISABLE ,
898 .BR PR_CAPBSET_READ ,
899 .BR PR_GET_TIMING ,
900 .BR PR_GET_TIMERSLACK ,
901 .BR PR_GET_SECUREBITS ,
902 .BR PR_MCE_KILL_GET ,
903 and (if it returns)
904 .BR PR_GET_SECCOMP
905 return the nonnegative values described above.
906 All other
907 .I option
908 values return 0 on success.
909 On error, \-1 is returned, and
910 .I errno
911 is set appropriately.
912 .SH ERRORS
913 .TP
914 .B EFAULT
915 .I arg2
916 is an invalid address.
917 .TP
918 .B EFAULT
919 .I option
920 is
921 .BR PR_SET_SECCOMP ,
922 .I arg2
923 is
924 .BR SECCOMP_MODE_FILTER ,
925 the system was built with
926 .BR CONFIG_SECCOMP_FILTER ,
927 and
928 .I arg3
929 is an invalid address.
930 .TP
931 .B EINVAL
932 The value of
933 .I option
934 is not recognized.
935 .TP
936 .B EINVAL
937 .I option
938 is
939 .BR PR_MCE_KILL
940 or
941 .BR PR_MCE_KILL_GET
942 or
943 .BR PR_SET_MM ,
944 and unused
945 .BR prctl ()
946 arguments were not specified as zero.
947 .TP
948 .B EINVAL
949 .I arg2
950 is not valid value for this
951 .IR option .
952 .TP
953 .B EINVAL
954 .I option
955 is
956 .BR PR_SET_SECCOMP
957 or
958 .BR PR_GET_SECCOMP ,
959 and the kernel was not configured with
960 .BR CONFIG_SECCOMP .
961 .TP
962 .B EINVAL
963 .I option
964 is
965 .BR PR_SET_SECCOMP ,
966 .I arg2
967 is
968 .BR SECCOMP_MODE_FILTER ,
969 and the kernel was not configured with
970 .BR CONFIG_SECCOMP_FILTER .
971 .TP
972 .B EINVAL
973 .I option
974 is
975 .BR PR_SET_MM ,
976 and one of the following is true
977 .RS
978 .IP * 3
979 .I arg4
980 or
981 .I arg5
982 is nonzero;
983 .IP *
984 .I arg3
985 is greater than
986 .B TASK_SIZE
987 (the limit on the size of the user address space for this architecture);
988 .IP *
989 .I arg2
990 is
991 .BR PR_SET_MM_START_CODE ,
992 .BR PR_SET_MM_END_CODE ,
993 .BR PR_SET_MM_START_DATA ,
994 .BR PR_SET_MM_END_DATA ,
995 or
996 .BR PR_SET_MM_START_STACK ,
997 and the permissions of the corresponding memory area are not as required;
998 .IP *
999 .I arg2
1000 is
1001 .BR PR_SET_MM_START_BRK
1002 or
1003 .BR PR_SET_MM_BRK ,
1004 and
1005 .I arg3
1006 is less than or equal to the end of the data segment
1007 or specifies a value that would cause the
1008 .B RLIMIT_DATA
1009 resource limit to be exceeded.
1010 .RE
1011 .TP
1012 .B EINVAL
1013 .I option
1014 is
1015 .BR PR_SET_PTRACER
1016 and
1017 .I arg2
1018 is not 0,
1019 .BR PR_SET_PTRACER_ANY ,
1020 or the PID of an existing process.
1021 .TP
1022 .B EINVAL
1023 .I option
1024 is
1025 .B PR_SET_PDEATHSIG
1026 and
1027 .I arg2
1028 is not a valid signal number.
1029 .TP
1030 .B EINVAL
1031 .I option
1032 is
1033 .BR PR_SET_DUMPABLE
1034 and
1035 .I arg2
1036 is neither
1037 .B SUID_DUMP_DISABLE
1038 nor
1039 .BR SUID_DUMP_USER .
1040 .TP
1041 .B EINVAL
1042 .I option
1043 is
1044 .BR PR_SET_TIMING
1045 and
1046 .I arg2
1047 is not
1048 .BR PR_TIMING_STATISTICAL .
1049 .TP
1050 .B EINVAL
1051 .I option
1052 is
1053 .BR PR_SET_NO_NEW_PRIVS
1054 and
1055 .I arg2
1056 is not equal to 1
1057 or
1058 .IR arg3 ,
1059 .IR arg4 ,
1060 or
1061 .IR arg5
1062 is nonzero.
1063 .TP
1064 .B EINVAL
1065 .I option
1066 is
1067 .BR PR_GET_NO_NEW_PRIVS
1068 and
1069 .IR arg2 ,
1070 .IR arg3 ,
1071 .IR arg4 ,
1072 or
1073 .IR arg5
1074 is nonzero.
1075 .TP
1076 .B EINVAL
1077 .I option
1078 is
1079 .BR PR_SET_THP_DISABLE
1080 and
1081 .IR arg3 ,
1082 .IR arg4 ,
1083 or
1084 .IR arg5
1085 is nonzero.
1086 .TP
1087 .B EINVAL
1088 .I option
1089 is
1090 .BR PR_GET_THP_DISABLE
1091 and
1092 .IR arg2 ,
1093 .IR arg3 ,
1094 .IR arg4 ,
1095 or
1096 .IR arg5
1097 is nonzero.
1098 .TP
1099 .B EPERM
1100 .I option
1101 is
1102 .BR PR_SET_SECUREBITS ,
1103 and the caller does not have the
1104 .B CAP_SETPCAP
1105 capability,
1106 or tried to unset a "locked" flag,
1107 or tried to set a flag whose corresponding locked flag was set
1108 (see
1109 .BR capabilities (7)).
1110 .TP
1111 .B EPERM
1112 .I option
1113 is
1114 .BR PR_SET_KEEPCAPS ,
1115 and the callers's
1116 .B SECURE_KEEP_CAPS_LOCKED
1117 flag is set
1118 (see
1119 .BR capabilities (7)).
1120 .TP
1121 .B EPERM
1122 .I option
1123 is
1124 .BR PR_CAPBSET_DROP ,
1125 and the caller does not have the
1126 .B CAP_SETPCAP
1127 capability.
1128 .TP
1129 .B EPERM
1130 .I option
1131 is
1132 .BR PR_SET_MM ,
1133 and the caller does not have the
1134 .B CAP_SYS_RESOURCE
1135 capability.
1136 .TP
1137 .B EACCES
1138 .I option
1139 is
1140 .BR PR_SET_MM ,
1141 and
1142 .I arg3
1143 is
1144 .BR PR_SET_MM_EXE_FILE ,
1145 the file is not executable.
1146 .TP
1147 .B EBUSY
1148 .I option
1149 is
1150 .BR PR_SET_MM ,
1151 .I arg3
1152 is
1153 .BR PR_SET_MM_EXE_FILE ,
1154 and this the second attempt to change the
1155 .I /proc/pid/exe
1156 symbolic link, which is prohibited.
1157 .TP
1158 .B EBADF
1159 .I option
1160 is
1161 .BR PR_SET_MM ,
1162 .I arg3
1163 is
1164 .BR PR_SET_MM_EXE_FILE ,
1165 and the file descriptor passed in
1166 .I arg4
1167 is not valid.
1168 .\" The following can't actually happen, because prctl() in
1169 .\" seccomp mode will cause SIGKILL.
1170 .\" .TP
1171 .\" .B EPERM
1172 .\" .I option
1173 .\" is
1174 .\" .BR PR_SET_SECCOMP ,
1175 .\" and secure computing mode is already 1.
1176 .TP
1177 .B ENXIO
1178 .I option
1179 was
1180 .BR PR_MPX_ENABLE_MANAGEMENT
1181 or
1182 .BR PR_MPX_DISABLE_MANAGEMENT
1183 and the kernel or the CPU does not support MPX management.
1184 Check that the kernel and processor have MPX support.
1185 .SH VERSIONS
1186 The
1187 .BR prctl ()
1188 system call was introduced in Linux 2.1.57.
1189 .\" The library interface was added in glibc 2.0.6
1190 .SH CONFORMING TO
1191 This call is Linux-specific.
1192 IRIX has a
1193 .BR prctl ()
1194 system call (also introduced in Linux 2.1.44
1195 as irix_prctl on the MIPS architecture),
1196 with prototype
1197 .sp
1198 .BI "ptrdiff_t prctl(int " option ", int " arg2 ", int " arg3 );
1199 .sp
1200 and options to get the maximum number of processes per user,
1201 get the maximum number of processors the calling process can use,
1202 find out whether a specified process is currently blocked,
1203 get or set the maximum stack size, and so on.
1204 .SH SEE ALSO
1205 .BR signal (2),
1206 .BR core (5)
1207 .SH COLOPHON
1208 This page is part of release 3.79 of the Linux
1209 .I man-pages
1210 project.
1211 A description of the project,
1212 information about reporting bugs,
1213 and the latest version of this page,
1214 can be found at
1215 \%http://www.kernel.org/doc/man\-pages/.