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 2014-08-19 "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 ():
67 These system calls transfer data between the address space
68 of the calling process ("the local process") and the process identified by
70 ("the remote process").
71 The data moves directly between the address spaces of the two processes,
72 without passing through kernel space.
75 .BR process_vm_readv ()
76 system call transfers data from the remote process to the local process.
77 The data to be transferred is identified by
82 is a pointer to an array describing address ranges in the process
86 specifies the number of elements in
88 The data is transferred to the locations specified by
93 is a pointer to an array describing address ranges in the calling process,
96 specifies the number of elements in
100 .BR process_vm_writev ()
101 system call is the converse of
102 .BR process_vm_readv ()\(emit
103 transfers data from the local process to the remote process.
104 Other than the direction of the transfer, the arguments
110 have the same meaning as for
111 .BR process_vm_readv ().
117 arguments point to an array of
119 structures, defined in
126 void *iov_base; /* Starting address */
127 size_t iov_len; /* Number of bytes to transfer */
132 Buffers are processed in array order.
134 .BR process_vm_readv ()
142 is completely read before proceeding to
147 .BR process_vm_writev ()
148 writes out the entire contents of
152 and it completely fills
158 .I remote_iov[i].iov_len
160 .I local_iov[i].iov_len
161 do not have to be the same.
162 Thus, it is possible to split a single local buffer
163 into multiple remote buffers, or vice versa.
167 argument is currently unused and must be set to 0.
169 The values specified in the
173 arguments must be less than or equal to
177 or accessible via the call
178 .IR sysconf(_SC_IOV_MAX) ).
179 .\" In time, glibc might provide a wrapper that works around this limit,
180 .\" as is done for readv()/writev()
182 The count arguments and
184 are checked before doing any transfers.
185 If the counts are too big, or
188 or the addresses refer to regions that are inaccessible to the local process,
189 none of the vectors will be processed
190 and an error will be returned immediately.
192 Note, however, that these system calls do not check the memory regions
193 in the remote process until just before doing the read/write.
194 Consequently, a partial read/write (see RETURN VALUE)
195 may result if one of the
197 elements points to an invalid memory region in the remote process.
198 No further reads/writes will be attempted beyond that point.
199 Keep this in mind when attempting to read data of unknown length
200 (such as C strings that are null-terminated) from a remote process,
201 by avoiding spanning memory pages (typically 4KiB) in a single remote
204 (Instead, split the remote read into two
206 elements and have them merge back into a single write
209 The first read entry goes up to the page boundary,
210 while the second starts on the next page boundary.)
212 In order to read from or write to another process,
213 either the caller must have the capability
216 the real user ID, effective user ID, and saved set-user-ID
217 of the remote process must match the real user ID of the caller
219 the real group ID, effective group ID, and saved set-group-ID
220 of the remote process must match the real group ID of the caller.
221 (The permission required is exactly the same as that required to perform a
224 on the remote process.)
227 .BR process_vm_readv ()
228 returns the number of bytes read and
229 .BR process_vm_writev ()
230 returns the number of bytes written.
231 This return value may be less than the total number of requested bytes,
232 if a partial read/write occurred.
233 (Partial transfers apply at the granularity of
236 These system calls won't perform a partial transfer that splits a single
239 The caller should check the return value to determine whether
240 a partial read/write occurred.
242 On error, \-1 is returned and
244 is set appropriately.
269 The memory described by
271 is outside the caller's accessible address space.
274 The memory described by
276 is outside the accessible address space of the process
280 Could not allocate memory for internal copies of the
285 The caller does not have permission to access the address space of the process
293 These system calls were added in Linux 3.2.
294 Support is provided in glibc since version 2.15.
296 These system calls are nonstandard Linux extensions.
298 The data transfers performed by
299 .BR process_vm_readv ()
301 .BR process_vm_writev ()
302 are not guaranteed to be atomic in any way.
304 These system calls were designed to permit fast message passing
305 by allowing messages to be exchanged with a single copy operation
306 (rather than the double copy that would be required
307 when using, for example, shared memory or pipes).
308 .\" Original user is MPI, http://www.mcs.anl.gov/research/projects/mpi/
309 .\" See also some benchmarks at http://lwn.net/Articles/405284/
310 .\" and http://marc.info/?l=linux-mm&m=130105930902915&w=2
312 The following code sample demonstrates the use of
313 .BR process_vm_readv ().
314 It reads 20 bytes at the address 0x10000 from the process with PID 10
315 and writes the first 10 bytes into
317 and the second 10 bytes into
326 struct iovec local[2];
327 struct iovec remote[1];
331 pid_t pid = 10; /* PID of remote process */
333 local[0].iov_base = buf1;
334 local[0].iov_len = 10;
335 local[1].iov_base = buf2;
336 local[1].iov_len = 10;
337 remote[0].iov_base = (void *) 0x10000;
338 remote[0].iov_len = 20;
340 nread = process_vm_readv(pid, local, 2, remote, 1, 0);
351 This page is part of release 3.79 of the Linux
354 A description of the project,
355 information about reporting bugs,
356 and the latest version of this page,
358 \%http://www.kernel.org/doc/man\-pages/.