1 .\" Copyright (C) 2011 Christopher Yeoh <cyeoh@au1.ibm.com>
2 .\" and Copyright (C) 2012 Mike Frysinger <vapier@gentoo.org>
3 .\" and Copyright (C) 2012 Michael Kerrisk <mtk.man-pages@gmail.com>
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" Commit fcf634098c00dd9cd247447368495f0b79be12d1
29 .TH PROCESS_VM_READV 2 2017-09-15 "Linux" "Linux Programmer's Manual"
31 process_vm_readv, process_vm_writev \- transfer data between process address spaces
34 .B #include <sys/uio.h>
36 .BI "ssize_t process_vm_readv(pid_t " pid ,
37 .BI " const struct iovec *" local_iov ,
38 .BI " unsigned long " liovcnt ,
39 .BI " const struct iovec *" remote_iov ,
40 .BI " unsigned long " riovcnt ,
41 .BI " unsigned long " flags ");"
43 .BI "ssize_t process_vm_writev(pid_t " pid ,
44 .BI " const struct iovec *" local_iov ,
45 .BI " unsigned long " liovcnt ,
46 .BI " const struct iovec *" remote_iov ,
47 .BI " unsigned long " riovcnt ,
48 .BI " unsigned long " flags ");"
52 Feature Test Macro Requirements for glibc (see
53 .BR feature_test_macros (7)):
56 .BR process_vm_readv (),
57 .BR process_vm_writev ():
66 These system calls transfer data between the address space
67 of the calling process ("the local process") and the process identified by
69 ("the remote process").
70 The data moves directly between the address spaces of the two processes,
71 without passing through kernel space.
74 .BR process_vm_readv ()
75 system call transfers data from the remote process to the local process.
76 The data to be transferred is identified by
81 is a pointer to an array describing address ranges in the process
85 specifies the number of elements in
87 The data is transferred to the locations specified by
92 is a pointer to an array describing address ranges in the calling process,
95 specifies the number of elements in
99 .BR process_vm_writev ()
100 system call is the converse of
101 .BR process_vm_readv ()\(emit
102 transfers data from the local process to the remote process.
103 Other than the direction of the transfer, the arguments
109 have the same meaning as for
110 .BR process_vm_readv ().
116 arguments point to an array of
118 structures, defined in
125 void *iov_base; /* Starting address */
126 size_t iov_len; /* Number of bytes to transfer */
131 Buffers are processed in array order.
133 .BR process_vm_readv ()
141 is completely read before proceeding to
146 .BR process_vm_writev ()
147 writes out the entire contents of
151 and it completely fills
157 .I remote_iov[i].iov_len
159 .I local_iov[i].iov_len
160 do not have to be the same.
161 Thus, it is possible to split a single local buffer
162 into multiple remote buffers, or vice versa.
166 argument is currently unused and must be set to 0.
168 The values specified in the
172 arguments must be less than or equal to
176 or accessible via the call
177 .IR sysconf(_SC_IOV_MAX) ).
178 .\" In time, glibc might provide a wrapper that works around this limit,
179 .\" as is done for readv()/writev()
181 The count arguments and
183 are checked before doing any transfers.
184 If the counts are too big, or
187 or the addresses refer to regions that are inaccessible to the local process,
188 none of the vectors will be processed
189 and an error will be returned immediately.
191 Note, however, that these system calls do not check the memory regions
192 in the remote process until just before doing the read/write.
193 Consequently, a partial read/write (see RETURN VALUE)
194 may result if one of the
196 elements points to an invalid memory region in the remote process.
197 No further reads/writes will be attempted beyond that point.
198 Keep this in mind when attempting to read data of unknown length
199 (such as C strings that are null-terminated) from a remote process,
200 by avoiding spanning memory pages (typically 4\ KiB) in a single remote
203 (Instead, split the remote read into two
205 elements and have them merge back into a single write
208 The first read entry goes up to the page boundary,
209 while the second starts on the next page boundary.)
211 Permission to read from or write to another process
212 is governed by a ptrace access mode
213 .B PTRACE_MODE_ATTACH_REALCREDS
218 .BR process_vm_readv ()
219 returns the number of bytes read and
220 .BR process_vm_writev ()
221 returns the number of bytes written.
222 This return value may be less than the total number of requested bytes,
223 if a partial read/write occurred.
224 (Partial transfers apply at the granularity of
227 These system calls won't perform a partial transfer that splits a single
230 The caller should check the return value to determine whether
231 a partial read/write occurred.
233 On error, \-1 is returned and
235 is set appropriately.
239 The memory described by
241 is outside the caller's accessible address space.
244 The memory described by
246 is outside the accessible address space of the process
271 Could not allocate memory for internal copies of the
276 The caller does not have permission to access the address space of the process
284 These system calls were added in Linux 3.2.
285 Support is provided in glibc since version 2.15.
287 These system calls are nonstandard Linux extensions.
289 The data transfers performed by
290 .BR process_vm_readv ()
292 .BR process_vm_writev ()
293 are not guaranteed to be atomic in any way.
295 These system calls were designed to permit fast message passing
296 by allowing messages to be exchanged with a single copy operation
297 (rather than the double copy that would be required
298 when using, for example, shared memory or pipes).
299 .\" Original user is MPI, http://www.mcs.anl.gov/research/projects/mpi/
300 .\" See also some benchmarks at http://lwn.net/Articles/405284/
301 .\" and http://marc.info/?l=linux-mm&m=130105930902915&w=2
303 The following code sample demonstrates the use of
304 .BR process_vm_readv ().
305 It reads 20 bytes at the address 0x10000 from the process with PID 10
306 and writes the first 10 bytes into
308 and the second 10 bytes into
317 struct iovec local[2];
318 struct iovec remote[1];
322 pid_t pid = 10; /* PID of remote process */
324 local[0].iov_base = buf1;
325 local[0].iov_len = 10;
326 local[1].iov_base = buf2;
327 local[1].iov_len = 10;
328 remote[0].iov_base = (void *) 0x10000;
329 remote[0].iov_len = 20;
331 nread = process_vm_readv(pid, local, 2, remote, 1, 0);