OSDN Git Service

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