OSDN Git Service

LDP: Update original to LDP v3.68
[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-04-14 "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 and should be null-terminated if it contains fewer bytes.
244 This is the same attribute that can be set via
245 .BR pthread_setname_np (3)
246 and retrieved using
247 .BR pthread_getname_np (3).
248 The attribute is likewise accessible via
249 .IR /proc/self/task/[tid]/comm ,
250 where
251 .I tid
252 is the name of the calling thread.
253 .TP
254 .BR PR_GET_NAME " (since Linux 2.6.11)"
255 Return the name of the calling thread,
256 in the buffer pointed to by
257 .IR "(char\ *) arg2" .
258 The buffer should allow space for up to 16 bytes;
259 the returned string will be null-terminated if it is shorter than that.
260 .TP
261 .BR PR_SET_NO_NEW_PRIVS " (since Linux 3.5)"
262 Set the calling process's
263 .I no_new_privs
264 bit to the value in
265 .IR arg2 .
266 With
267 .I no_new_privs
268 set to 1,
269 .BR execve (2)
270 promises not to grant privileges to do anything
271 that could not have been done without the
272 .BR execve (2)
273 call (for example,
274 rendering the set-user-ID and set-group-ID permission bits,
275 and file capabilities non-functional).
276 Once set, this bit cannot be unset.
277 The setting of this bit is inherited by children created by
278 .BR fork (2)
279 and
280 .BR clone (2),
281 and preserved across
282 .BR execve (2).
283
284 For more information, see the kernel source file
285 .IR Documentation/prctl/no_new_privs.txt .
286 .TP
287 .BR PR_GET_NO_NEW_PRIVS " (since Linux 3.5)"
288 Return (as the function result) the value of the
289 .I no_new_privs
290 bit for the current process.
291 A value of 0 indicates the regular
292 .BR execve (2)
293 behavior.
294 A value of 1 indicates
295 .BR execve (2)
296 will operate in the privilege-restricting mode described above.
297 .TP
298 .BR PR_SET_PDEATHSIG " (since Linux 2.1.57)"
299 Set the parent process death signal
300 of the calling process to \fIarg2\fP (either a signal value
301 in the range 1..maxsig, or 0 to clear).
302 This is the signal that the calling process will get when its
303 parent dies.
304 This value is cleared for the child of a
305 .BR fork (2)
306 and (since Linux 2.4.36 / 2.6.23)
307 when executing a set-user-ID or set-group-ID binary.
308 This value is preserved across
309 .BR execve (2).
310 .TP
311 .BR PR_GET_PDEATHSIG " (since Linux 2.3.15)"
312 Return the current value of the parent process death signal,
313 in the location pointed to by
314 .IR "(int\ *) arg2" .
315 .TP
316 .BR PR_SET_PTRACER " (since Linux 3.4)"
317 .\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb
318 .\" commit bf06189e4d14641c0148bea16e9dd24943862215
319 This is meaningful only when the Yama LSM is enabled and in mode 1
320 ("restricted ptrace", visible via
321 .IR /proc/sys/kernel/yama/ptrace_scope ).
322 When a "ptracer process ID" is passed in \fIarg2\fP,
323 the caller is declaring that the ptracer process can
324 .BR ptrace (2)
325 the calling process as if it were a direct process ancestor.
326 Each
327 .B PR_SET_PTRACER
328 operation replaces the previous "ptracer process ID".
329 Employing
330 .B PR_SET_PTRACER
331 with
332 .I arg2
333 set to 0 clears the caller's "ptracer process ID".
334 If
335 .I arg2
336 is
337 .BR PR_SET_PTRACER_ANY ,
338 the ptrace restrictions introduced by Yama are effectively disabled for the
339 calling process.
340
341 For further information, see the kernel source file
342 .IR Documentation/security/Yama.txt .
343 .TP
344 .BR PR_SET_SECCOMP " (since Linux 2.6.23)"
345 .\" See http://thread.gmane.org/gmane.linux.kernel/542632
346 .\" [PATCH 0 of 2] seccomp updates
347 .\" andrea@cpushare.com
348 Set the secure computing (seccomp) mode for the calling thread, to limit
349 the available system calls.
350 The seccomp mode is selected via
351 .IR arg2 .
352 (The seccomp constants are defined in
353 .IR <linux/seccomp.h> .)
354
355 With
356 .IR arg2
357 set to
358 .BR SECCOMP_MODE_STRICT
359 the only system calls that the thread is permitted to make are
360 .BR read (2),
361 .BR write (2),
362 .BR _exit (2),
363 and
364 .BR sigreturn (2).
365 Other system calls result in the delivery of a
366 .BR SIGKILL
367 signal.
368 Strict secure computing mode is useful for number-crunching applications
369 that may need to execute untrusted byte code,
370 perhaps obtained by reading from a pipe or socket.
371 This operation is available only
372 if the kernel is configured with
373 .B CONFIG_SECCOMP
374 enabled.
375
376 With
377 .IR arg2
378 set to
379 .BR SECCOMP_MODE_FILTER " (since Linux 3.5)"
380 the system calls allowed are defined by a pointer
381 to a Berkeley Packet Filter passed in
382 .IR arg3 .
383 This argument is a pointer to
384 .IR "struct sock_fprog" ;
385 it can be designed to filter
386 arbitrary system calls and system call arguments.
387 This mode is available only if the kernel is configured with
388 .B CONFIG_SECCOMP_FILTER
389 enabled.
390
391 If
392 .BR SECCOMP_MODE_FILTER
393 filters permit
394 .BR fork (2),
395 then the seccomp mode is inherited by children created by
396 .BR fork (2);
397 if
398 .BR execve (2)
399 is permitted, then the seccomp mode is preserved across
400 .BR execve (2).
401 If the filters permit
402 .BR prctl ()
403 calls, then additional filters can be added;
404 they are run in order until the first non-allow result is seen.
405
406 For further information, see the kernel source file
407 .IR Documentation/prctl/seccomp_filter.txt .
408 .TP
409 .BR PR_GET_SECCOMP " (since Linux 2.6.23)"
410 Return (as the function result)
411 the secure computing mode of the calling thread.
412 If the caller is not in secure computing mode, this operation returns 0;
413 if the caller is in strict secure computing mode, then the
414 .BR prctl ()
415 call will cause a
416 .B SIGKILL
417 signal to be sent to the process.
418 If the caller is in filter mode, and this system call is allowed by the
419 seccomp filters, it returns 2.
420 This operation is available only
421 if the kernel is configured with
422 .B CONFIG_SECCOMP
423 enabled.
424 .TP
425 .BR PR_SET_SECUREBITS " (since Linux 2.6.26)"
426 Set the "securebits" flags of the calling thread to the value supplied in
427 .IR arg2 .
428 See
429 .BR capabilities (7).
430 .TP
431 .BR PR_GET_SECUREBITS " (since Linux 2.6.26)"
432 Return (as the function result)
433 the "securebits" flags of the calling thread.
434 See
435 .BR capabilities (7).
436 .TP
437 .BR PR_SET_THP_DISABLE " (since Linux 3.15)"
438 .\" commit a0715cc22601e8830ace98366c0c2bd8da52af52
439 Set the state of the "THP disable" flag for the calling thread.
440 If
441 .I arg2
442 has a nonzero value, the flag is set, otherwise it is cleared.
443 Setting this flag provides a method
444 for disabling transparent huge pages
445 for jobs where the code cannot be modified, and using a malloc hook with
446 .BR madvise (2)
447 is not an option (i.e., statically allocated data).
448 The setting of the "THP disable" flag is inherited by a child created via
449 .BR fork (2)
450 and is preserved across
451 .BR execve (2).
452 .TP
453 .BR PR_GET_THP_DISABLE " (since Linux 3.15)"
454 Return (via the function result) the current setting of the "THP disable"
455 flag for the calling thread:
456 either 1, if the flag is set, or 0, if it is not.
457 .TP
458 .BR PR_GET_TID_ADDRESS " (since Linux 3.5)"
459 .\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d
460 Retrieve the
461 .I clear_child_tid
462 address set by
463 .BR set_tid_address (2)
464 and the
465 .BR clone (2)
466 .B CLONE_CHILD_CLEARTID
467 flag, in the location pointed to by
468 .IR "(int\ **)\ arg2" .
469 This feature is available only if the kernel is built with the
470 .BR CONFIG_CHECKPOINT_RESTORE
471 option enabled.
472 .TP
473 .BR PR_SET_TIMERSLACK " (since Linux 2.6.28)"
474 .\" See https://lwn.net/Articles/369549/
475 .\" commit 6976675d94042fbd446231d1bd8b7de71a980ada
476 Set the current timer slack for the calling thread to the nanosecond value
477 supplied in
478 .IR arg2 .
479 If
480 .I arg2
481 is less than or equal to zero,
482 .\" It seems that it's not possible to set the timer slack to zero;
483 .\" The minimum value is 1? Seems a little strange.
484 reset the current timer slack to the thread's default timer slack value.
485 The timer slack is used by the kernel to group timer expirations
486 for the calling thread that are close to one another;
487 as a consequence, timer expirations for the thread may be
488 up to the specified number of nanoseconds late (but will never expire early).
489 Grouping timer expirations can help reduce system power consumption
490 by minimizing CPU wake-ups.
491
492 The timer expirations affected by timer slack are those set by
493 .BR select (2),
494 .BR pselect (2),
495 .BR poll (2),
496 .BR ppoll (2),
497 .BR epoll_wait (2),
498 .BR epoll_pwait (2),
499 .BR clock_nanosleep (2),
500 .BR nanosleep (2),
501 and
502 .BR futex (2)
503 (and thus the library functions implemented via futexes, including
504 .\" List obtained by grepping for futex usage in glibc source
505 .BR pthread_cond_timedwait (3),
506 .BR pthread_mutex_timedlock (3),
507 .BR pthread_rwlock_timedrdlock (3),
508 .BR pthread_rwlock_timedwrlock (3),
509 and
510 .BR sem_timedwait (3)).
511
512 Timer slack is not applied to threads that are scheduled under
513 a real-time scheduling policy (see
514 .BR sched_setscheduler (2)).
515
516 Each thread has two associated timer slack values:
517 a "default" value, and a "current" value.
518 The current value is the one that governs grouping
519 of timer expirations.
520 When a new thread is created,
521 the two timer slack values are made the same as the current value
522 of the creating thread.
523 Thereafter, a thread can adjust its current timer slack value via
524 .BR PR_SET_TIMERSLACK
525 (the default value can't be changed).
526 The timer slack values of
527 .IR init
528 (PID 1), the ancestor of all processes,
529 are 50,000 nanoseconds (50 microseconds).
530 The timer slack values are preserved across
531 .BR execve (2).
532 .TP
533 .BR PR_GET_TIMERSLACK " (since Linux 2.6.28)"
534 Return (as the function result)
535 the current timer slack value of the calling thread.
536 .TP
537 .BR PR_SET_TIMING " (since Linux 2.6.0-test4)"
538 Set whether to use (normal, traditional) statistical process timing or
539 accurate timestamp-based process timing, by passing
540 .B PR_TIMING_STATISTICAL
541 .\" 0
542 or
543 .B PR_TIMING_TIMESTAMP
544 .\" 1
545 to \fIarg2\fP.
546 .B PR_TIMING_TIMESTAMP
547 is not currently implemented
548 (attempting to set this mode will yield the error
549 .BR EINVAL ).
550 .\" PR_TIMING_TIMESTAMP doesn't do anything in 2.6.26-rc8,
551 .\" and looking at the patch history, it appears
552 .\" that it never did anything.
553 .TP
554 .BR PR_GET_TIMING " (since Linux 2.6.0-test4)"
555 Return (as the function result) which process timing method is currently
556 in use.
557 .TP
558 .BR PR_TASK_PERF_EVENTS_DISABLE " (since Linux 2.6.31)"
559 Disable all performance counters attached to the calling process,
560 regardless of whether the counters were created by
561 this process or another process.
562 Performance counters created by the calling process for other
563 processes are unaffected.
564 For more information on performance counters, see the Linux kernel source file
565 .IR tools/perf/design.txt .
566 .IP
567 Originally called
568 .BR PR_TASK_PERF_COUNTERS_DISABLE ;
569 .\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
570 renamed (with same numerical value)
571 in Linux 2.6.32.
572 .TP
573 .BR PR_TASK_PERF_EVENTS_ENABLE " (since Linux 2.6.31)"
574 The converse of
575 .BR PR_TASK_PERF_EVENTS_DISABLE ;
576 enable performance counters attached to the calling process.
577 .IP
578 Originally called
579 .BR PR_TASK_PERF_COUNTERS_ENABLE ;
580 .\" commit 1d1c7ddbfab358445a542715551301b7fc363e28
581 renamed
582 .\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6
583 in Linux 2.6.32.
584 .TP
585 .BR PR_SET_TSC " (since Linux 2.6.26, x86 only)"
586 Set the state of the flag determining whether the timestamp counter
587 can be read by the process.
588 Pass
589 .B PR_TSC_ENABLE
590 to
591 .I arg2
592 to allow it to be read, or
593 .B PR_TSC_SIGSEGV
594 to generate a
595 .B SIGSEGV
596 when the process tries to read the timestamp counter.
597 .TP
598 .BR PR_GET_TSC " (since Linux 2.6.26, x86 only)"
599 Return the state of the flag determining whether the timestamp counter
600 can be read,
601 in the location pointed to by
602 .IR "(int\ *) arg2" .
603 .TP
604 .B PR_SET_UNALIGN
605 (Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
606 PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22)
607 Set unaligned access control bits to \fIarg2\fP.
608 Pass
609 \fBPR_UNALIGN_NOPRINT\fP to silently fix up unaligned user accesses,
610 or \fBPR_UNALIGN_SIGBUS\fP to generate
611 .B SIGBUS
612 on unaligned user access.
613 .TP
614 .B PR_GET_UNALIGN
615 (see
616 .B PR_SET_UNALIGN
617 for information on versions and architectures)
618 Return unaligned access control bits, in the location pointed to by
619 .IR "(int\ *) arg2" .
620 .TP
621 .BR PR_MCE_KILL " (since Linux 2.6.32)"
622 Set the machine check memory corruption kill policy for the current thread.
623 If
624 .I arg2
625 is
626 .BR PR_MCE_KILL_CLEAR ,
627 clear the thread memory corruption kill policy and use the system-wide default.
628 (The system-wide default is defined by
629 .IR /proc/sys/vm/memory_failure_early_kill ;
630 see
631 .BR proc (5).)
632 If
633 .I arg2
634 is
635 .BR PR_MCE_KILL_SET ,
636 use a thread-specific memory corruption kill policy.
637 In this case,
638 .I arg3
639 defines whether the policy is
640 .I early kill
641 .RB ( PR_MCE_KILL_EARLY ),
642 .I late kill
643 .RB ( PR_MCE_KILL_LATE ),
644 or the system-wide default
645 .RB ( PR_MCE_KILL_DEFAULT ).
646 Early kill means that the thread receives a
647 .B SIGBUS
648 signal as soon as hardware memory corruption is detected inside
649 its address space.
650 In late kill mode, the process is killed only when it accesses a corrupted page.
651 See
652 .BR sigaction (2)
653 for more information on the
654 .BR SIGBUS
655 signal.
656 The policy is inherited by children.
657 The remaining unused
658 .BR prctl ()
659 arguments must be zero for future compatibility.
660 .TP
661 .BR PR_MCE_KILL_GET " (since Linux 2.6.32)"
662 Return the current per-process machine check kill policy.
663 All unused
664 .BR prctl ()
665 arguments must be zero.
666 .TP
667 .BR PR_SET_MM " (since Linux 3.3)"
668 .\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036
669 Modify certain kernel memory map descriptor fields
670 of the calling process.
671 Usually these fields are set by the kernel and dynamic loader (see
672 .BR ld.so (8)
673 for more information) and a regular application should not use this feature.
674 However, there are cases, such as self-modifying programs,
675 where a program might find it useful to change its own memory map.
676 This feature is available only if the kernel is built with the
677 .BR CONFIG_CHECKPOINT_RESTORE
678 option enabled.
679 The calling process must have the
680 .BR CAP_SYS_RESOURCE
681 capability.
682 The value in
683 .I arg2
684 is one of the options below, while
685 .I arg3
686 provides a new value for the option.
687 .RS
688 .TP
689 .BR PR_SET_MM_START_CODE
690 Set the address above which the program text can run.
691 The corresponding memory area must be readable and executable,
692 but not writable or sharable (see
693 .BR mprotect (2)
694 and
695 .BR mmap (2)
696 for more information).
697 .TP
698 .BR PR_SET_MM_END_CODE
699 Set the address below which the program text can run.
700 The corresponding memory area must be readable and executable,
701 but not writable or sharable.
702 .TP
703 .BR PR_SET_MM_START_DATA
704 Set the address above which initialized and
705 uninitialized (bss) data are placed.
706 The corresponding memory area must be readable and writable,
707 but not executable or sharable.
708 .TP
709 .B PR_SET_MM_END_DATA
710 Set the address below which initialized and
711 uninitialized (bss) data are placed.
712 The corresponding memory area must be readable and writable,
713 but not executable or sharable.
714 .TP
715 .BR PR_SET_MM_START_STACK
716 Set the start address of the stack.
717 The corresponding memory area must be readable and writable.
718 .TP
719 .BR PR_SET_MM_START_BRK
720 Set the address above which the program heap can be expanded with
721 .BR brk (2)
722 call.
723 The address must be greater than the ending address of
724 the current program data segment.
725 In addition, the combined size of the resulting heap and
726 the size of the data segment can't exceed the
727 .BR RLIMIT_DATA
728 resource limit (see
729 .BR setrlimit (2)).
730 .TP
731 .BR PR_SET_MM_BRK
732 Set the current
733 .BR brk (2)
734 value.
735 The requirements for the address are the same as for the
736 .BR PR_SET_MM_START_BRK
737 option.
738 .P
739 The following options are available since Linux 3.5.
740 .\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7
741 .TP
742 .BR PR_SET_MM_ARG_START
743 Set the address above which the program command line is placed.
744 .TP
745 .BR PR_SET_MM_ARG_END
746 Set the address below which the program command line is placed.
747 .TP
748 .BR PR_SET_MM_ENV_START
749 Set the address above which the program environment is placed.
750 .TP
751 .BR PR_SET_MM_ENV_END
752 Set the address below which the program environment is placed.
753 .IP
754 The address passed with
755 .BR PR_SET_MM_ARG_START ,
756 .BR PR_SET_MM_ARG_END ,
757 .BR PR_SET_MM_ENV_START ,
758 and
759 .BR PR_SET_MM_ENV_END
760 should belong to a process stack area.
761 Thus, the corresponding memory area must be readable, writable, and
762 (depending on the kernel configuration) have the
763 .BR MAP_GROWSDOWN
764 attribute set (see
765 .BR mmap (2)).
766 .TP
767 .BR PR_SET_MM_AUXV
768 Set a new auxiliary vector.
769 The
770 .I arg3
771 argument should provide the address of the vector.
772 The
773 .I arg4
774 is the size of the vector.
775 .TP
776 .BR PR_SET_MM_EXE_FILE
777 .\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6
778 Supersede the
779 .IR /proc/pid/exe
780 symbolic link with a new one pointing to a new executable file
781 identified by the file descriptor provided in
782 .I arg3
783 argument.
784 The file descriptor should be obtained with a regular
785 .BR open (2)
786 call.
787 .IP
788 To change the symbolic link, one needs to unmap all existing
789 executable memory areas, including those created by the kernel itself
790 (for example the kernel usually creates at least one executable
791 memory area for the ELF
792 .IR \.text
793 section).
794 .IP
795 The second limitation is that such transitions can be done only once
796 in a process life time.
797 Any further attempts will be rejected.
798 This should help system administrators monitor unusual
799 symbolic-link transitions over all processes running on a system.
800 .RE
801 .\"
802 .SH RETURN VALUE
803 On success,
804 .BR PR_GET_DUMPABLE ,
805 .BR PR_GET_KEEPCAPS ,
806 .BR PR_GET_NO_NEW_PRIVS ,
807 .BR PR_GET_THP_DISABLE ,
808 .BR PR_CAPBSET_READ ,
809 .BR PR_GET_TIMING ,
810 .BR PR_GET_TIMERSLACK ,
811 .BR PR_GET_SECUREBITS ,
812 .BR PR_MCE_KILL_GET ,
813 and (if it returns)
814 .BR PR_GET_SECCOMP
815 return the nonnegative values described above.
816 All other
817 .I option
818 values return 0 on success.
819 On error, \-1 is returned, and
820 .I errno
821 is set appropriately.
822 .SH ERRORS
823 .TP
824 .B EFAULT
825 .I arg2
826 is an invalid address.
827 .TP
828 .B EINVAL
829 The value of
830 .I option
831 is not recognized.
832 .TP
833 .B EINVAL
834 .I option
835 is
836 .BR PR_MCE_KILL
837 or
838 .BR PR_MCE_KILL_GET
839 or
840 .BR PR_SET_MM ,
841 and unused
842 .BR prctl ()
843 arguments were not specified as zero.
844 .TP
845 .B EINVAL
846 .I arg2
847 is not valid value for this
848 .IR option .
849 .TP
850 .B EINVAL
851 .I option
852 is
853 .BR PR_SET_SECCOMP
854 or
855 .BR PR_GET_SECCOMP ,
856 and the kernel was not configured with
857 .BR CONFIG_SECCOMP .
858 .TP
859 .B EINVAL
860 .I option
861 is
862 .BR PR_SET_MM ,
863 and one of the following is true
864 .RS
865 .IP * 3
866 .I arg4
867 or
868 .I arg5
869 is nonzero;
870 .IP *
871 .I arg3
872 is greater than
873 .B TASK_SIZE
874 (the limit on the size of the user address space for this architecture);
875 .IP *
876 .I arg2
877 is
878 .BR PR_SET_MM_START_CODE ,
879 .BR PR_SET_MM_END_CODE ,
880 .BR PR_SET_MM_START_DATA ,
881 .BR PR_SET_MM_END_DATA ,
882 or
883 .BR PR_SET_MM_START_STACK ,
884 and the permissions of the corresponding memory area are not as required;
885 .IP *
886 .I arg2
887 is
888 .BR PR_SET_MM_START_BRK
889 or
890 .BR PR_SET_MM_BRK ,
891 and
892 .I arg3
893 is less than or equal to the end of the data segment
894 or specifies a value that would cause the
895 .B RLIMIT_DATA
896 resource limit to be exceeded.
897 .RE
898 .TP
899 .B EINVAL
900 .I option
901 is
902 .BR PR_SET_PTRACER
903 and
904 .I arg2
905 is not 0,
906 .BR PR_SET_PTRACER_ANY ,
907 or the PID of an existing process.
908 .TP
909 .B EINVAL
910 .I option
911 is
912 .B PR_SET_PDEATHSIG
913 and
914 .I arg2
915 is not a valid signal number.
916 .TP
917 .B EINVAL
918 .I option
919 is
920 .BR PR_SET_DUMPABLE
921 and
922 .I arg2
923 is neither
924 .B SUID_DUMP_DISABLE
925 nor
926 .BR SUID_DUMP_USER .
927 .TP
928 .B EINVAL
929 .I option
930 is
931 .BR PR_SET_TIMING
932 and
933 .I arg2
934 is not
935 .BR PR_TIMING_STATISTICAL .
936 .TP
937 .B EINVAL
938 .I option
939 is
940 .BR PR_SET_NO_NEW_PRIVS
941 and
942 .I arg2
943 is not equal to 1
944 or
945 .IR arg3 ,
946 .IR arg4 ,
947 or
948 .IR arg5
949 is nonzero.
950 .TP
951 .B EINVAL
952 .I option
953 is
954 .BR PR_GET_NO_NEW_PRIVS
955 and
956 .IR arg2 ,
957 .IR arg3 ,
958 .IR arg4 ,
959 or
960 .IR arg5
961 is nonzero.
962 .TP
963 .B EINVAL
964 .I option
965 is
966 .BR PR_SET_THP_DISABLE
967 and
968 .IR arg3 ,
969 .IR arg4 ,
970 or
971 .IR arg5
972 is nonzero.
973 .TP
974 .B EINVAL
975 .I option
976 is
977 .BR PR_GET_THP_DISABLE
978 and
979 .IR arg2 ,
980 .IR arg3 ,
981 .IR arg4 ,
982 or
983 .IR arg5
984 is nonzero.
985 .TP
986 .B EPERM
987 .I option
988 is
989 .BR PR_SET_SECUREBITS ,
990 and the caller does not have the
991 .B CAP_SETPCAP
992 capability,
993 or tried to unset a "locked" flag,
994 or tried to set a flag whose corresponding locked flag was set
995 (see
996 .BR capabilities (7)).
997 .TP
998 .B EPERM
999 .I option
1000 is
1001 .BR PR_SET_KEEPCAPS ,
1002 and the callers's
1003 .B SECURE_KEEP_CAPS_LOCKED
1004 flag is set
1005 (see
1006 .BR capabilities (7)).
1007 .TP
1008 .B EPERM
1009 .I option
1010 is
1011 .BR PR_CAPBSET_DROP ,
1012 and the caller does not have the
1013 .B CAP_SETPCAP
1014 capability.
1015 .TP
1016 .B EPERM
1017 .I option
1018 is
1019 .BR PR_SET_MM ,
1020 and the caller does not have the
1021 .B CAP_SYS_RESOURCE
1022 capability.
1023 .TP
1024 .B EACCES
1025 .I option
1026 is
1027 .BR PR_SET_MM ,
1028 and
1029 .I arg3
1030 is
1031 .BR PR_SET_MM_EXE_FILE ,
1032 the file is not executable.
1033 .TP
1034 .B EBUSY
1035 .I option
1036 is
1037 .BR PR_SET_MM ,
1038 .I arg3
1039 is
1040 .BR PR_SET_MM_EXE_FILE ,
1041 and this the second attempt to change the
1042 .I /proc/pid/exe
1043 symbolic link, which is prohibited.
1044 .TP
1045 .B EBADF
1046 .I option
1047 is
1048 .BR PR_SET_MM ,
1049 .I arg3
1050 is
1051 .BR PR_SET_MM_EXE_FILE ,
1052 and the file descriptor passed in
1053 .I arg4
1054 is not valid.
1055 .\" The following can't actually happen, because prctl() in
1056 .\" seccomp mode will cause SIGKILL.
1057 .\" .TP
1058 .\" .B EPERM
1059 .\" .I option
1060 .\" is
1061 .\" .BR PR_SET_SECCOMP ,
1062 .\" and secure computing mode is already 1.
1063 .SH VERSIONS
1064 The
1065 .BR prctl ()
1066 system call was introduced in Linux 2.1.57.
1067 .\" The library interface was added in glibc 2.0.6
1068 .SH CONFORMING TO
1069 This call is Linux-specific.
1070 IRIX has a
1071 .BR prctl ()
1072 system call (also introduced in Linux 2.1.44
1073 as irix_prctl on the MIPS architecture),
1074 with prototype
1075 .sp
1076 .BI "ptrdiff_t prctl(int " option ", int " arg2 ", int " arg3 );
1077 .sp
1078 and options to get the maximum number of processes per user,
1079 get the maximum number of processors the calling process can use,
1080 find out whether a specified process is currently blocked,
1081 get or set the maximum stack size, and so on.
1082 .SH SEE ALSO
1083 .BR signal (2),
1084 .BR core (5)
1085 .SH COLOPHON
1086 This page is part of release 3.68 of the Linux
1087 .I man-pages
1088 project.
1089 A description of the project,
1090 information about reporting bugs,
1091 and the latest version of this page,
1092 can be found at
1093 \%http://www.kernel.org/doc/man\-pages/.