7 #include <libunwind-ptrace.h>
12 * Libunwind namespace implementation using process_vm_readv.
17 /** Partial structure of libunwind-ptrace context in order to get the PID
19 * The context type for libunwind-race is an opaque type. We need to get the
20 * PID which is the first field. This is a hack which might break if the
21 * libunwind-ptrace structure changes.
28 /** Get the PID of a `libunwind-ptrace` context
31 pid_t _UPT_getpid(void* arg)
33 struct _UPT_info* info = arg;
37 /** Read from the memory, avoid using `ptrace` (libunwind method)
39 static int access_mem(const unw_addr_space_t as,
40 const unw_word_t addr, unw_word_t* const valp,
41 const int write, void* const arg)
45 pid_t pid = _UPT_getpid(arg);
46 size_t size = sizeof(unw_word_t);
48 #ifdef HAVE_PROCESS_VM_READV
49 // process_vm_read implementation.
50 // This is only available since Linux 3.2.
52 struct iovec local = { valp, size };
53 struct iovec remote = { (void*) addr, size };
54 ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0);
61 if (s < 0 && errno != ENOSYS)
65 // /proc/${pid}/mem implementation.
66 // On recent kernels, we do not need to ptrace the target process.
67 // On older kernels, it is necessary to ptrace the target process.
69 off_t off = (off_t) addr;
70 char* buf = (char*) valp;
71 int fd = MC_process_vm_open(pid, O_RDONLY);
75 ssize_t s = pread(fd, buf, count, off);
92 // ptrace implementation.
93 // We need to have PTRACE_ATTACH-ed it before.
94 return _UPT_access_mem(as, addr, valp, write, arg);
97 unw_accessors_t mc_unw_vmread_accessors =
99 .find_proc_info = &_UPT_find_proc_info,
100 .put_unwind_info = &_UPT_put_unwind_info,
101 .get_dyn_info_list_addr = &_UPT_get_dyn_info_list_addr,
102 .access_mem = &access_mem,
103 .access_reg = &_UPT_access_reg,
104 .access_fpreg = &_UPT_access_fpreg,
105 .resume = &_UPT_resume,
106 .get_proc_name = &_UPT_get_proc_name