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 2021-03-22 "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 ");"
42 .BI "ssize_t process_vm_writev(pid_t " pid ,
43 .BI " const struct iovec *" local_iov ,
44 .BI " unsigned long " liovcnt ,
45 .BI " const struct iovec *" remote_iov ,
46 .BI " unsigned long " riovcnt ,
47 .BI " unsigned long " flags ");"
51 Feature Test Macro Requirements for glibc (see
52 .BR feature_test_macros (7)):
55 .BR process_vm_readv (),
56 .BR process_vm_writev ():
61 These system calls transfer data between the address space
62 of the calling process ("the local process") and the process identified by
64 ("the remote process").
65 The data moves directly between the address spaces of the two processes,
66 without passing through kernel space.
69 .BR process_vm_readv ()
70 system call transfers data from the remote process to the local process.
71 The data to be transferred is identified by
76 is a pointer to an array describing address ranges in the process
80 specifies the number of elements in
82 The data is transferred to the locations specified by
87 is a pointer to an array describing address ranges in the calling process,
90 specifies the number of elements in
94 .BR process_vm_writev ()
95 system call is the converse of
96 .BR process_vm_readv ()\(emit
97 transfers data from the local process to the remote process.
98 Other than the direction of the transfer, the arguments
104 have the same meaning as for
105 .BR process_vm_readv ().
111 arguments point to an array of
113 structures, defined in
120 void *iov_base; /* Starting address */
121 size_t iov_len; /* Number of bytes to transfer */
126 Buffers are processed in array order.
128 .BR process_vm_readv ()
136 is completely read before proceeding to
141 .BR process_vm_writev ()
142 writes out the entire contents of
146 and it completely fills
152 .I remote_iov[i].iov_len
154 .I local_iov[i].iov_len
155 do not have to be the same.
156 Thus, it is possible to split a single local buffer
157 into multiple remote buffers, or vice versa.
161 argument is currently unused and must be set to 0.
163 The values specified in the
167 arguments must be less than or equal to
171 or accessible via the call
172 .IR sysconf(_SC_IOV_MAX) ).
173 .\" In time, glibc might provide a wrapper that works around this limit,
174 .\" as is done for readv()/writev()
176 The count arguments and
178 are checked before doing any transfers.
179 If the counts are too big, or
182 or the addresses refer to regions that are inaccessible to the local process,
183 none of the vectors will be processed
184 and an error will be returned immediately.
186 Note, however, that these system calls do not check the memory regions
187 in the remote process until just before doing the read/write.
188 Consequently, a partial read/write (see RETURN VALUE)
189 may result if one of the
191 elements points to an invalid memory region in the remote process.
192 No further reads/writes will be attempted beyond that point.
193 Keep this in mind when attempting to read data of unknown length
194 (such as C strings that are null-terminated) from a remote process,
195 by avoiding spanning memory pages (typically 4\ KiB) in a single remote
198 (Instead, split the remote read into two
200 elements and have them merge back into a single write
203 The first read entry goes up to the page boundary,
204 while the second starts on the next page boundary.)
206 Permission to read from or write to another process
207 is governed by a ptrace access mode
208 .B PTRACE_MODE_ATTACH_REALCREDS
213 .BR process_vm_readv ()
214 returns the number of bytes read and
215 .BR process_vm_writev ()
216 returns the number of bytes written.
217 This return value may be less than the total number of requested bytes,
218 if a partial read/write occurred.
219 (Partial transfers apply at the granularity of
222 These system calls won't perform a partial transfer that splits a single
225 The caller should check the return value to determine whether
226 a partial read/write occurred.
228 On error, \-1 is returned and
230 is set to indicate the error.
234 The memory described by
236 is outside the caller's accessible address space.
239 The memory described by
241 is outside the accessible address space of the process
266 Could not allocate memory for internal copies of the
271 The caller does not have permission to access the address space of the process
279 These system calls were added in Linux 3.2.
280 Support is provided in glibc since version 2.15.
282 These system calls are nonstandard Linux extensions.
284 The data transfers performed by
285 .BR process_vm_readv ()
287 .BR process_vm_writev ()
288 are not guaranteed to be atomic in any way.
290 These system calls were designed to permit fast message passing
291 by allowing messages to be exchanged with a single copy operation
292 (rather than the double copy that would be required
293 when using, for example, shared memory or pipes).
294 .\" Original user is MPI, http://www.mcs.anl.gov/research/projects/mpi/
295 .\" See also some benchmarks at http://lwn.net/Articles/405284/
296 .\" and http://marc.info/?l=linux-mm&m=130105930902915&w=2
298 The following code sample demonstrates the use of
299 .BR process_vm_readv ().
300 It reads 20 bytes at the address 0x10000 from the process with PID 10
301 and writes the first 10 bytes into
303 and the second 10 bytes into
312 struct iovec local[2];
313 struct iovec remote[1];
317 pid_t pid = 10; /* PID of remote process */
319 local[0].iov_base = buf1;
320 local[0].iov_len = 10;
321 local[1].iov_base = buf2;
322 local[1].iov_len = 10;
323 remote[0].iov_base = (void *) 0x10000;
324 remote[0].iov_len = 20;
326 nread = process_vm_readv(pid, local, 2, remote, 1, 0);