shmop.2: wfix
[man-pages.git] / man2 / get_robust_list.2
blob66b27d9051d60b7d76c1488bb0e24c5a3cf96475
1 .\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
2 .\" Written by Ivana Varekova <varekova@redhat.com>
3 .\" and Copyright (c) 2017, Michael Kerrisk <mtk.manpages@gmail.com>
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 .\" FIXME Something could be added to this page (or exit(2))
28 .\" about exit_robust_list processing
29 .\"
30 .TH GET_ROBUST_LIST 2 2021-03-22 Linux "Linux System Calls"
31 .SH NAME
32 get_robust_list, set_robust_list \- get/set list of robust futexes
33 .SH SYNOPSIS
34 .nf
35 .BR "#include <linux/futex.h>" \
36 "   /* Definition of " "struct robust_list_head" " */"
37 .BR "#include <sys/syscall.h>" "   /* Definition of " SYS_* " constants */"
38 .B #include <unistd.h>
39 .PP
40 .BI "long syscall(SYS_get_robust_list, int " pid ,
41 .BI "             struct robust_list_head **" head_ptr ", size_t *" len_ptr );
42 .BI "long syscall(SYS_set_robust_list,"
43 .BI "             struct robust_list_head *" head ", size_t " len );
44 .fi
45 .PP
46 .IR Note :
47 glibc provides no wrappers for these system calls,
48 necessitating the use of
49 .BR syscall (2).
50 .SH DESCRIPTION
51 These system calls deal with per-thread robust futex lists.
52 These lists are managed in user space:
53 the kernel knows only about the location of the head of the list.
54 A thread can inform the kernel of the location of its robust futex list using
55 .BR set_robust_list ().
56 The address of a thread's robust futex list can be obtained using
57 .BR get_robust_list ().
58 .PP
59 The purpose of the robust futex list is to ensure that if a thread
60 accidentally fails to unlock a futex before terminating or calling
61 .BR execve (2),
62 another thread that is waiting on that futex is notified that
63 the former owner of the futex has died.
64 This notification consists of two pieces: the
65 .BR FUTEX_OWNER_DIED
66 bit is set in the futex word, and the kernel performs a
67 .BR futex (2)
68 .BR FUTEX_WAKE
69 operation on one of the threads waiting on the futex.
70 .PP
71 The
72 .BR get_robust_list ()
73 system call returns the head of the robust futex list of the thread
74 whose thread ID is specified in
75 .IR pid .
77 .I pid
78 is 0,
79 the head of the list for the calling thread is returned.
80 The list head is stored in the location pointed to by
81 .IR head_ptr .
82 The size of the object pointed to by
83 .I **head_ptr
84 is stored in
85 .IR len_ptr .
86 .PP
87 Permission to employ
88 .BR get_robust_list ()
89 is governed by a ptrace access mode
90 .B PTRACE_MODE_READ_REALCREDS
91 check; see
92 .BR ptrace (2).
93 .PP
94 The
95 .BR set_robust_list ()
96 system call requests the kernel to record the head of the list of
97 robust futexes owned by the calling thread.
98 The
99 .I head
100 argument is the list head to record.
102 .I len
103 argument should be
104 .IR sizeof(*head) .
105 .SH RETURN VALUE
107 .BR set_robust_list ()
109 .BR get_robust_list ()
110 system calls return zero when the operation is successful,
111 an error code otherwise.
112 .SH ERRORS
114 .BR set_robust_list ()
115 system call can fail with the following error:
117 .B EINVAL
118 .I len
119 does not equal
120 .IR "sizeof(struct\ robust_list_head)" .
123 .BR get_robust_list ()
124 system call can fail with the following errors:
126 .B EFAULT
127 The head of the robust futex list can't be stored at the location
128 .IR head .
130 .B EPERM
131 The calling process does not have permission to see the robust futex list of
132 the thread with the thread ID
133 .IR pid ,
134 and does not have the
135 .BR CAP_SYS_PTRACE
136 capability.
138 .B ESRCH
139 No thread with the thread ID
140 .I pid
141 could be found.
142 .SH VERSIONS
143 These system calls were added in Linux 2.6.17.
144 .SH NOTES
145 These system calls are not needed by normal applications.
147 A thread can have only one robust futex list;
148 therefore applications that wish
149 to use this functionality should use the robust mutexes provided by glibc.
151 In the initial implementation,
152 a thread waiting on a futex was notified that the owner had died
153 only if the owner terminated.
154 Starting with Linux 2.6.28,
155 .\" commit 8141c7f3e7aee618312fa1c15109e1219de784a7
156 notification was extended to include the case where the owner performs an
157 .BR execve (2).
159 The thread IDs mentioned in the main text are
160 .I kernel
161 thread IDs of the kind returned by
162 .BR clone (2)
164 .BR gettid (2).
165 .SH SEE ALSO
166 .BR futex (2),
167 .BR pthread_mutexattr_setrobust (3)
169 .IR Documentation/robust\-futexes.txt
171 .IR Documentation/robust\-futex\-ABI.txt
172 in the Linux kernel source tree
173 .\" http://lwn.net/Articles/172149/