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