-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_vm_writev.html
406 lines (309 loc) · 11.7 KB
/
process_vm_writev.html
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:18 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>PROCESS_VM_READV</title>
</head>
<body>
<h1 align="center">PROCESS_VM_READV</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#EXAMPLE">EXAMPLE</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">process_vm_readv,
process_vm_writev - transfer data between process address
spaces</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/uio.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>ssize_t
process_vm_readv(pid_t</b> <i>pid</i><b>, <br>
const struct iovec *</b><i>local_iov</i><b>, <br>
unsigned long</b> <i>liovcnt</i><b>, <br>
const struct iovec *</b><i>remote_iov</i><b>, <br>
unsigned long</b> <i>riovcnt</i><b>, <br>
unsigned long</b> <i>flags</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>ssize_t
process_vm_writev(pid_t</b> <i>pid</i><b>, <br>
const struct iovec *</b><i>local_iov</i><b>, <br>
unsigned long</b> <i>liovcnt</i><b>, <br>
const struct iovec *</b><i>remote_iov</i><b>, <br>
unsigned long</b> <i>riovcnt</i><b>, <br>
unsigned long</b> <i>flags</i><b>);</b></p>
<p style="margin-left:5%; margin-top: 1em">Feature Test
Macro Requirements for glibc (see
<b>feature_test_macros</b>(7)):</p>
<p style="margin-left:11%; margin-top: 1em"><b>process_vm_readv</b>(),
<b>process_vm_writev</b>():</p>
<p style="margin-left:17%;"><b>_GNU_SOURCE</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls transfer data between the address space of the calling
process ("the local process") and the process
identified by <i>pid</i> ("the remote process").
The data moves directly between the address spaces of the
two processes, without passing through kernel space.</p>
<p style="margin-left:11%; margin-top: 1em">The
<b>process_vm_readv</b>() system call transfers data from
the remote process to the local process. The data to be
transferred is identified by <i>remote_iov</i> and
<i>riovcnt</i>: <i>remote_iov</i> is a pointer to an array
describing address ranges in the process <i>pid</i>, and
<i>riovcnt</i> specifies the number of elements in
<i>remote_iov</i>. The data is transferred to the locations
specified by <i>local_iov</i> and <i>liovcnt</i>:
<i>local_iov</i> is a pointer to an array describing address
ranges in the calling process, and <i>liovcnt</i> specifies
the number of elements in <i>local_iov</i>.</p>
<p style="margin-left:11%; margin-top: 1em">The
<b>process_vm_writev</b>() system call is the converse of
<b>process_vm_readv</b>()—it transfers data from the
local process to the remote process. Other than the
direction of the transfer, the arguments <i>liovcnt</i>,
<i>local_iov</i>, <i>riovcnt</i>, and <i>remote_iov</i> have
the same meaning as for <b>process_vm_readv</b>().</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>local_iov</i> and <i>remote_iov</i> arguments point to an
array of <i>iovec</i> structures, defined in
<i><sys/uio.h></i> as:</p>
<p style="margin-left:17%; margin-top: 1em">struct iovec {
<br>
void *iov_base; /* Starting address */ <br>
size_t iov_len; /* Number of bytes to transfer */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">Buffers are
processed in array order. This means that
<b>process_vm_readv</b>() completely fills
<i>local_iov[0]</i> before proceeding to
<i>local_iov[1]</i>, and so on. Likewise,
<i>remote_iov[0]</i> is completely read before proceeding to
<i>remote_iov[1]</i>, and so on.</p>
<p style="margin-left:11%; margin-top: 1em">Similarly,
<b>process_vm_writev</b>() writes out the entire contents of
<i>local_iov[0]</i> before proceeding to
<i>local_iov[1]</i>, and it completely fills
<i>remote_iov[0]</i> before proceeding to
<i>remote_iov[1]</i>.</p>
<p style="margin-left:11%; margin-top: 1em">The lengths of
<i>remote_iov[i].iov_len</i> and <i>local_iov[i].iov_len</i>
do not have to be the same. Thus, it is possible to split a
single local buffer into multiple remote buffers, or vice
versa.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument is currently unused and must be set to
0.</p>
<p style="margin-left:11%; margin-top: 1em">The values
specified in the <i>liovcnt</i> and <i>riovcnt</i> arguments
must be less than or equal to <b>IOV_MAX</b> (defined in
<i><limits.h></i> or accessible via the call
<i>sysconf(_SC_IOV_MAX)</i>).</p>
<p style="margin-left:11%; margin-top: 1em">The count
arguments and <i>local_iov</i> are checked before doing any
transfers. If the counts are too big, or <i>local_iov</i> is
invalid, or the addresses refer to regions that are
inaccessible to the local process, none of the vectors will
be processed and an error will be returned immediately.</p>
<p style="margin-left:11%; margin-top: 1em">Note, however,
that these system calls do not check the memory regions in
the remote process until just before doing the read/write.
Consequently, a partial read/write (see RETURN VALUE) may
result if one of the <i>remote_iov</i> elements points to an
invalid memory region in the remote process. No further
reads/writes will be attempted beyond that point. Keep this
in mind when attempting to read data of unknown length (such
as C strings that are null-terminated) from a remote
process, by avoiding spanning memory pages (typically
4 KiB) in a single remote <i>iovec</i> element.
(Instead, split the remote read into two <i>remote_iov</i>
elements and have them merge back into a single write
<i>local_iov</i> entry. The first read entry goes up to the
page boundary, while the second starts on the next page
boundary.)</p>
<p style="margin-left:11%; margin-top: 1em">Permission to
read from or write to another process is governed by a
ptrace access mode <b>PTRACE_MODE_ATTACH_REALCREDS</b>
check; see <b>ptrace</b>(2).</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>process_vm_readv</b>() returns the number of bytes read
and <b>process_vm_writev</b>() returns the number of bytes
written. This return value may be less than the total number
of requested bytes, if a partial read/write occurred.
(Partial transfers apply at the granularity of <i>iovec</i>
elements. These system calls won’t perform a partial
transfer that splits a single <i>iovec</i> element.) The
caller should check the return value to determine whether a
partial read/write occurred.</p>
<p style="margin-left:11%; margin-top: 1em">On error, -1 is
returned and <i>errno</i> is set appropriately.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The memory described by
<i>local_iov</i> is outside the caller’s accessible
address space.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The memory described by <i>remote_iov</i> is outside the
accessible address space of the process <i>pid</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The sum of the <i>iov_len</i> values of either
<i>local_iov</i> or <i>remote_iov</i> overflows a
<i>ssize_t</i> value.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>flags</i> is not 0.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>liovcnt</i> or <i>riovcnt</i> is too large.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Could not allocate memory for internal copies of the
<i>iovec</i> structures.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The caller does not have permission to access the
address space of the process <i>pid</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ESRCH</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>No process with ID <i>pid</i> exists.</p></td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls were added in Linux 3.2. Support is provided in glibc
since version 2.15.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls are nonstandard Linux extensions.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The data
transfers performed by <b>process_vm_readv</b>() and
<b>process_vm_writev</b>() are not guaranteed to be atomic
in any way.</p>
<p style="margin-left:11%; margin-top: 1em">These system
calls were designed to permit fast message passing by
allowing messages to be exchanged with a single copy
operation (rather than the double copy that would be
required when using, for example, shared memory or
pipes).</p>
<h2>EXAMPLE
<a name="EXAMPLE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The following
code sample demonstrates the use of
<b>process_vm_readv</b>(). It reads 20 bytes at the address
0x10000 from the process with PID 10 and writes the first 10
bytes into <i>buf1</i> and the second 10 bytes into
<i>buf2</i>.</p>
<p style="margin-left:11%; margin-top: 1em">#include
<sys/uio.h></p>
<p style="margin-left:11%; margin-top: 1em">int <br>
main(void) <br>
{ <br>
struct iovec local[2]; <br>
struct iovec remote[1]; <br>
char buf1[10]; <br>
char buf2[10]; <br>
ssize_t nread; <br>
pid_t pid = 10; /* PID of remote process */</p>
<p style="margin-left:11%; margin-top: 1em">local[0].iov_base
= buf1; <br>
local[0].iov_len = 10; <br>
local[1].iov_base = buf2; <br>
local[1].iov_len = 10; <br>
remote[0].iov_base = (void *) 0x10000; <br>
remote[0].iov_len = 20;</p>
<p style="margin-left:11%; margin-top: 1em">nread =
process_vm_readv(pid, local, 2, remote, 1, 0); <br>
if (nread != 20) <br>
return 1; <br>
else <br>
return 0; <br>
}</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>readv</b>(2),
<b>writev</b>(2)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>