1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//! Waiting for any change of state of a child, and reaching into another
//! process: its memory, its handles.
use Stop;
use crate;
use crate::;
/// Whom [`wait`] waits for.
crateflags!
/// What happened to a child: part of what [`wait`] returns.
/// A change of state of a child: what [`wait`] returns.
/// Waits for a change of state of a child of the caller, of the kinds
/// `flags` names: `waitid`. This is the wait of a shell, of a tracer and
/// of a process that adopts orphans
/// ([`set_child_subreaper`](super::set_child_subreaper)): it reports
/// children that stop and go on as well as those that end, and it can
/// wait for any child at all. [`Child::wait`](crate::process::Child::wait)
/// and [`pidfd_wait`](super::pidfd_wait) are for the end of one child.
///
/// `flags` must name a kind of event: [`WaitFlags::EXITED`],
/// [`STOPPED`](WaitFlags::STOPPED) or
/// [`CONTINUED`](WaitFlags::CONTINUED). Returns `None` with
/// [`WaitFlags::NO_HANG`] when no child has anything to report.
///
/// **A child whose end is reported here is collected**, and a
/// [`Child`](crate::process::Child) for it then finds it gone, as with
/// [`pidfd_wait`](super::pidfd_wait): wait for the end of a child one way
/// or the other. Leaving [`WaitFlags::EXITED`] out, or adding
/// [`WaitFlags::NO_WAIT`], collects nothing.
///
/// A child that ends *while it is only waited for to stop* ends the wait
/// with `ECHILD`, as measured: what was waited for can no longer happen.
///
/// # Errors
///
/// `ECHILD` when the caller has no child that fits, or none left that
/// could report what is asked;
/// [`InvalidInput`](crate::ErrorKind::InvalidInput) for no kind of event;
/// [`Interrupted`](crate::ErrorKind::Interrupted) when a signal handler
/// runs during the wait.
/// A range of the memory of another process: where
/// [`read_memory_vectored`] reads and [`write_memory_vectored`] writes
/// (a `struct iovec` of addresses that are not the caller's).
const _: = assert!;
/// Reads the memory of the process `pid` at `address` into `buf`, and
/// returns how many bytes were read: `process_vm_readv`. The other
/// process is not stopped, not traced, and not told.
///
/// Fewer bytes than asked are read when the range runs into memory the
/// other process does not have: what comes before the first page that
/// cannot be read is returned.
///
/// This is how the supervisor of a system call filter reads what an
/// argument points to; see [`seccomp`](super::seccomp) for why what it
/// reads may change under it.
///
/// # Errors
///
/// [`PermissionDenied`](crate::ErrorKind::PermissionDenied) when the
/// caller may not trace the process (the rules of
/// [`ptrace::seize`](super::ptrace::seize));
/// [`NoSuchProcess`](crate::ErrorKind::NoSuchProcess); `EFAULT` when not
/// even the first byte can be read;
/// [`Unsupported`](crate::ErrorKind::Unsupported) on a kernel built
/// without the call (`CONFIG_CROSS_MEMORY_ATTACH`), and under an
/// emulator that lacks it.
/// Writes `data` to the memory of the process `pid` at `address`, and
/// returns how many bytes were written: `process_vm_writev`. As
/// [`read_memory`], for memory the other process itself may write: its
/// code and its read-only data are refused (`EFAULT`), where
/// [`ptrace::poke`](super::ptrace::poke) writes them.
/// Reads several ranges of the memory of the process `pid` into several
/// buffers, in one call: `process_vm_readv`. The bytes of the ranges of
/// `remote`, in order, fill the buffers of `bufs`, in order; the two
/// lists need not be cut at the same places. Returns how many bytes were
/// read, which is less than asked as for [`read_memory`], range by range.
///
/// # Errors
///
/// As [`read_memory`]; [`InvalidInput`](crate::ErrorKind::InvalidInput)
/// for more than 1024 buffers or ranges, and for lengths whose sum does
/// not fit in a signed number.
/// Writes several buffers to several ranges of the memory of the process
/// `pid`, in one call: `process_vm_writev`. As [`read_memory_vectored`],
/// the other way.
/// Opens, in the caller, the file that the handle numbered `fd` of
/// another process is open on: `pidfd_getfd` (Linux 5.6). The two then
/// share one open file, with its position and its flags, as after a
/// [`duplicate`](crate::io::duplicate) across processes.
///
/// `pidfd` names the process ([`pidfd_open`](super::pidfd_open), a
/// [`Child`](crate::process::Child)). The new handle is close-on-exec.
///
/// With [`seccomp::add_handle`](super::seccomp::add_handle), which goes
/// the other way, this lets a supervisor work on the handles of the
/// process it supervises.
///
/// # Errors
///
/// [`PermissionDenied`](crate::ErrorKind::PermissionDenied) when the
/// caller may not trace the process (the rules of
/// [`ptrace::seize`](super::ptrace::seize));
/// [`BadHandle`](crate::ErrorKind::BadHandle) for a `pidfd` that is not
/// one, and for a number the process has nothing open under;
/// [`NoSuchProcess`](crate::ErrorKind::NoSuchProcess) for a process that
/// has ended.
Sized>