1PROCESS_VM_READV(2) Linux Programmer's Manual PROCESS_VM_READV(2)
2
3
4
6 process_vm_readv, process_vm_writev - transfer data between process ad‐
7 dress spaces
8
10 #include <sys/uio.h>
11
12 ssize_t process_vm_readv(pid_t pid,
13 const struct iovec *local_iov,
14 unsigned long liovcnt,
15 const struct iovec *remote_iov,
16 unsigned long riovcnt,
17 unsigned long flags);
18 ssize_t process_vm_writev(pid_t pid,
19 const struct iovec *local_iov,
20 unsigned long liovcnt,
21 const struct iovec *remote_iov,
22 unsigned long riovcnt,
23 unsigned long flags);
24
25 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
26
27 process_vm_readv(), process_vm_writev():
28 _GNU_SOURCE
29
31 These system calls transfer data between the address space of the call‐
32 ing process ("the local process") and the process identified by pid
33 ("the remote process"). The data moves directly between the address
34 spaces of the two processes, without passing through kernel space.
35
36 The process_vm_readv() system call transfers data from the remote
37 process to the local process. The data to be transferred is identified
38 by remote_iov and riovcnt: remote_iov is a pointer to an array describ‐
39 ing address ranges in the process pid, and riovcnt specifies the number
40 of elements in remote_iov. The data is transferred to the locations
41 specified by local_iov and liovcnt: local_iov is a pointer to an array
42 describing address ranges in the calling process, and liovcnt specifies
43 the number of elements in local_iov.
44
45 The process_vm_writev() system call is the converse of
46 process_vm_readv()—it transfers data from the local process to the re‐
47 mote process. Other than the direction of the transfer, the arguments
48 liovcnt, local_iov, riovcnt, and remote_iov have the same meaning as
49 for process_vm_readv().
50
51 The local_iov and remote_iov arguments point to an array of iovec
52 structures, defined in <sys/uio.h> as:
53
54 struct iovec {
55 void *iov_base; /* Starting address */
56 size_t iov_len; /* Number of bytes to transfer */
57 };
58
59 Buffers are processed in array order. This means that
60 process_vm_readv() completely fills local_iov[0] before proceeding to
61 local_iov[1], and so on. Likewise, remote_iov[0] is completely read
62 before proceeding to remote_iov[1], and so on.
63
64 Similarly, process_vm_writev() writes out the entire contents of lo‐
65 cal_iov[0] before proceeding to local_iov[1], and it completely fills
66 remote_iov[0] before proceeding to remote_iov[1].
67
68 The lengths of remote_iov[i].iov_len and local_iov[i].iov_len do not
69 have to be the same. Thus, it is possible to split a single local buf‐
70 fer into multiple remote buffers, or vice versa.
71
72 The flags argument is currently unused and must be set to 0.
73
74 The values specified in the liovcnt and riovcnt arguments must be less
75 than or equal to IOV_MAX (defined in <limits.h> or accessible via the
76 call sysconf(_SC_IOV_MAX)).
77
78 The count arguments and local_iov are checked before doing any trans‐
79 fers. If the counts are too big, or local_iov is invalid, or the ad‐
80 dresses refer to regions that are inaccessible to the local process,
81 none of the vectors will be processed and an error will be returned im‐
82 mediately.
83
84 Note, however, that these system calls do not check the memory regions
85 in the remote process until just before doing the read/write. Conse‐
86 quently, a partial read/write (see RETURN VALUE) may result if one of
87 the remote_iov elements points to an invalid memory region in the re‐
88 mote process. No further reads/writes will be attempted beyond that
89 point. Keep this in mind when attempting to read data of unknown
90 length (such as C strings that are null-terminated) from a remote
91 process, by avoiding spanning memory pages (typically 4 KiB) in a sin‐
92 gle remote iovec element. (Instead, split the remote read into two re‐
93 mote_iov elements and have them merge back into a single write lo‐
94 cal_iov entry. The first read entry goes up to the page boundary,
95 while the second starts on the next page boundary.)
96
97 Permission to read from or write to another process is governed by a
98 ptrace access mode PTRACE_MODE_ATTACH_REALCREDS check; see ptrace(2).
99
101 On success, process_vm_readv() returns the number of bytes read and
102 process_vm_writev() returns the number of bytes written. This return
103 value may be less than the total number of requested bytes, if a par‐
104 tial read/write occurred. (Partial transfers apply at the granularity
105 of iovec elements. These system calls won't perform a partial transfer
106 that splits a single iovec element.) The caller should check the re‐
107 turn value to determine whether a partial read/write occurred.
108
109 On error, -1 is returned and errno is set to indicate the error.
110
112 EFAULT The memory described by local_iov is outside the caller's acces‐
113 sible address space.
114
115 EFAULT The memory described by remote_iov is outside the accessible ad‐
116 dress space of the process pid.
117
118 EINVAL The sum of the iov_len values of either local_iov or remote_iov
119 overflows a ssize_t value.
120
121 EINVAL flags is not 0.
122
123 EINVAL liovcnt or riovcnt is too large.
124
125 ENOMEM Could not allocate memory for internal copies of the iovec
126 structures.
127
128 EPERM The caller does not have permission to access the address space
129 of the process pid.
130
131 ESRCH No process with ID pid exists.
132
134 These system calls were added in Linux 3.2. Support is provided in
135 glibc since version 2.15.
136
138 These system calls are nonstandard Linux extensions.
139
141 The data transfers performed by process_vm_readv() and
142 process_vm_writev() are not guaranteed to be atomic in any way.
143
144 These system calls were designed to permit fast message passing by al‐
145 lowing messages to be exchanged with a single copy operation (rather
146 than the double copy that would be required when using, for example,
147 shared memory or pipes).
148
150 The following code sample demonstrates the use of process_vm_readv().
151 It reads 20 bytes at the address 0x10000 from the process with PID 10
152 and writes the first 10 bytes into buf1 and the second 10 bytes into
153 buf2.
154
155 #include <sys/uio.h>
156
157 int
158 main(void)
159 {
160 struct iovec local[2];
161 struct iovec remote[1];
162 char buf1[10];
163 char buf2[10];
164 ssize_t nread;
165 pid_t pid = 10; /* PID of remote process */
166
167 local[0].iov_base = buf1;
168 local[0].iov_len = 10;
169 local[1].iov_base = buf2;
170 local[1].iov_len = 10;
171 remote[0].iov_base = (void *) 0x10000;
172 remote[0].iov_len = 20;
173
174 nread = process_vm_readv(pid, local, 2, remote, 1, 0);
175 if (nread != 20)
176 return 1;
177 else
178 return 0;
179 }
180
182 readv(2), writev(2)
183
185 This page is part of release 5.13 of the Linux man-pages project. A
186 description of the project, information about reporting bugs, and the
187 latest version of this page, can be found at
188 https://www.kernel.org/doc/man-pages/.
189
190
191
192Linux 2021-03-22 PROCESS_VM_READV(2)