PROCESS_VM_READV(2) NAME process_vm_readv, process_vm_writev - read/write from/to another processes' address space. SYNPOSIS #include ssize_t process_vm_readv(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags); ssize_t process_vm_writev(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags); DESCRIPTION The process_vm_readv() function reads from the memory locations described by riovcnt buffers from rvec in the process with PID of pid into liovcnt buffers described by lvec in the current process. The process_vm_writev() function writes into the memory locations described by riovcnt buffers from rvec in the process with PID of pid into liovcnt buffers described by lvec in the current process. The pointers lvec and rvec point to an arrays of iovec structures, defined in as: struct iovec { void *iov_base; /* Starting address */ size_t iov_len; /* Number of bytes to transfer */ }; Buffers are processed in array order. This means that the process_vm_readv() function completely fills lvec[0] before proceeding to lvec[1], and so on. process_vm_readv() reads completely from rvec[0] before proceeding to rvec[1]. Similarly the process_vm_writev() function writes out the entire contents of lvec[0] before proceeding to lvec[1]. And it completely fill revc[0] before proceeding to rvec[1]. The lengths of rvec[i] and lvec[i] do not have to be the same. The data transfers of process_vm_readv and process_vm_writev are not guaranteed to be atomic. The flags parameter is currently unused and must be set to 0. In order to read or write from or to another process you must have the capability CAP_SYS_PTRACE or have the same uid and gid of target process. The permission required is exactly the same as that of being able to succesfully perform a ptrace wtih PTRACE_ATTACH on the target process. RETURN VALUE On success process_vm_readv() function returns the number of bytes read; the process_vm_writev() function returns the number of bytes written. The On error, the number of bytes read or written is returned or -1 if it was unable to read/write any bytes and errno is set appropriately ERRORS EINVAL The sum of the iov_len values of either lvec or rvec overflows an ssize_t value EINVAL The value of the flags parameter is not 0 EFAULT lvec or rvec is outside your accessible address space EFAULT the memory described by lvec is outside your accessible address space EFAULT the memory described by rvec is outside the accessible address space of process pid ENOMEM Out of memory EPERM For the process_vm_readv() function you do not have permission to read from process pid EPERM For the process_vm_writev() function you do not have permission to write to process pid ESRCH THe pid does not exist EXAMPLE The following code sample demonstrates the use of process_vm_readv(). It reads 20 bytes at the address 0x10000 from the process with PID 10 and writes the first 10 bytes into buf1 and the second 10 bytes into buf2 struct iovec local[2]; struct iovec remote[1]; unsigned long addr; unsigned long len; char buf1[10]; char buf2[10]; ssize_t nread; pid_t pid = 10; /* PID of target process */ local[0].iov_base = buf1; local[0].iov_len = 10; local[1].iov_base = buf2; local[1].iov_len = 10; remote.iov_base = 0x10000; remote.iov_len = 20; nread = process_vm_readv(pid, local, 2, remote, 1, 0); SEE ALSO readv(2), writev(2)