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 2012-04-25 "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 ");"
51 These system calls transfer data between the address space
52 of the calling process ("the local process") and the process identified by
54 ("the remote process").
55 The data moves directly between the address spaces of the two processes,
56 without passing through kernel space.
59 .BR process_vm_readv ()
60 system call transfers data from the remote process to the local process.
61 The data to be transferred is identified by
66 is a pointer to an array describing address ranges in the process
70 specifies the number of elements in
72 The data is transferred to the locations specified by
77 is a pointer to an array describing address ranges in the calling process,
80 specifies the number of elements in
84 .BR process_vm_writev ()
85 system call is the converse of
86 .BR process_vm_readv ()\(emit
87 transfers data from the local process to the remote process.
88 Other than the direction of the transfer, the arguments
94 have the same meaning as for
95 .BR process_vm_readv ().
101 arguments point to an array of
103 structures, defined in
110 void *iov_base; /* Starting address */
111 size_t iov_len; /* Number of bytes to transfer */
116 Buffers are processed in array order.
118 .BR process_vm_readv ()
126 is completely read before proceeding to
131 .BR process_vm_writev ()
132 writes out the entire contents of
136 and it completely fills
142 .I remote_iov[i].iov_len
144 .I local_iov[i].iov_len
145 do not have to be the same.
146 Thus, it is possible to split a single local buffer
147 into multiple remote buffers, or vice versa.
151 argument is currently unused and must be set to 0.
153 The values specified in the
157 arguments must be less than or equal to
161 or accessible via the call
162 .IR sysconf(_SC_IOV_MAX) ).
163 .\" In time, glibc might provide a wrapper that works around this limit,
164 .\" as is done for readv()/writev()
166 The count arguments and
168 are checked before doing any transfers.
169 If the counts are too big, or
172 or the addresses refer to regions that are inaccessible to the local process,
173 none of the vectors will be processed
174 and an error will be returned immediately.
176 Note, however, that these system calls do not check the memory regions
177 in the remote process until just before doing the read/write.
178 Consequently, a partial read/write (see RETURN VALUE)
179 may result if one of the
181 elements points to an invalid memory region in the remote process.
182 No further reads/writes will be attempted beyond that point.
183 Keep this in mind when attempting to read data of unknown length
184 (such as C strings that are null-terminated) from a remote process,
185 by avoiding spanning memory pages (typically 4KiB) in a single remote
188 (Instead, split the remote read into two
190 elements and have them merge back into a single write
193 The first read entry goes up to the page boundary,
194 while the second starts on the next page boundary.)
196 In order to read from or write to another process,
197 either the caller must have the capability
200 the real user ID, effective user ID, and saved set-user-ID
201 of the remote process must match the real user ID of the caller
203 the real group ID, effective group ID, and saved set-group-ID
204 of the remote process must match the real group ID of the caller.
205 (The permission required is exactly the same as that required to perform a
208 on the remote process.)
211 .BR process_vm_readv ()
212 returns the number of bytes read and
213 .BR process_vm_writev ()
214 returns the number of bytes written.
215 This return value may be less than the total number of requested bytes,
216 if a partial read/write occurred.
217 (Partial transfers apply at the granularity of
220 These system calls won't perform a partial transfer that splits a single
223 The caller should check the return value to determine whether
224 a partial read/write occurred.
226 On error, \-1 is returned and
228 is set appropriately.
253 The memory described by
255 is outside the caller's accessible address space.
258 The memory described by
260 is outside the accessible address space of the process
264 Could not allocate memory for internal copies of the
269 The caller does not have permission to access the address space of the process
277 These system calls were added in Linux 3.2.
278 Support is provided in glibc since version 2.15.
280 These system calls are nonstandard Linux extensions.
282 The data transfers performed by
283 .BR process_vm_readv ()
285 .BR process_vm_writev ()
286 are not guaranteed to be atomic in any way.
288 These system calls were designed to permit fast message passing
289 by allowing messages to be exchanged with a single copy operation
290 (rather than the double copy that would be required
291 when using, for example, shared memory or pipes).
292 .\" Original user is MPI, http://www.mcs.anl.gov/research/projects/mpi/
293 .\" See also some benchmarks at http://lwn.net/Articles/405284/
294 .\" and http://marc.info/?l=linux-mm&m=130105930902915&w=2
296 The following code sample demonstrates the use of
297 .BR process_vm_readv ().
298 It reads 20 bytes at the address 0x10000 from the process with PID 10
299 and writes the first 10 bytes into
301 and the second 10 bytes into
310 struct iovec local[2];
311 struct iovec remote[1];
315 pid_t pid = 10; /* PID of remote process */
317 local[0].iov_base = buf1;
318 local[0].iov_len = 10;
319 local[1].iov_base = buf2;
320 local[1].iov_len = 10;
321 remote[0].iov_base = (void *) 0x10000;
322 remote[1].iov_len = 20;
324 nread = process_vm_readv(pid, local, 2, remote, 1, 0);
335 This page is part of release 3.65 of the Linux
338 A description of the project,
339 and information about reporting bugs,
341 \%http://www.kernel.org/doc/man\-pages/.