process_vm_readv(2)
Read from or write to another process's virtual address space in one syscall, without attaching via ptrace.
- Since
- Linux 3.2check your kernel →
- glibc
- glibc 2.15
- System
- Linux
- Man page
- process_vm_readv(2)
Synopsis
#include <sys/uio.h>
ssize_t process_vm_readv(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags);
ssize_t process_vm_writev(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags);Rod's take
process_vm_readv(2) reads another process's memory in one syscall without attaching or stopping the target. ptrace PTRACE_PEEKDATA costs one syscall per word; process_vm_readv with a multi-element remote_iov costs one syscall for any number of ranges. gdb and rr use it on Linux for live memory inspection. The catch: reads are not atomic. The target keeps running, so fields with consistency invariants can be torn between the start and end of a multi-vector read.
Flags and arguments that matter
Browse flag index →| Name | What it does |
|---|---|
| flags (reserved) | Must be 0. Reserved for future use. |
Errors you will actually hit
| errno | Meaning |
|---|---|
| EFAULT | A range in local_iov is not mapped in the caller's address space. |
| ENOMEM | A range in remote_iov is not mapped in the target process's address space. |
| EPERM | The caller does not have permission to trace the target process (PTRACE_MODE_ATTACH_REALCREDS check). |
| ESRCH | The target process does not exist. |
Example
#include <sys/uio.h>
long word;
struct iovec local = { .iov_base = &word, .iov_len = sizeof(long) };
struct iovec remote = { .iov_base = remote_addr, .iov_len = sizeof(long) };
/* no PTRACE_ATTACH, no SIGSTOP */
ssize_t n = process_vm_readv(pid, &local, 1, &remote, 1, 0);Trimmed from the full walkthrough in process_vm_readv(2): read another process's memory without stopping it.
BSD equivalent
FreeBSD/OpenBSD: no direct equivalent. Use ptrace(2) with PT_IO for bulk cross-process memory transfers; semantically similar but requires an attach.
The long version, from the console
Sources
Version numbers are read off the cited man pages, not memory. Spot one that's wrong? Tell Rod.
