2 * Test whether process_vm_readv and PTRACE_PEEKDATA work.
4 * Copyright (c) 2016-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2017-2018 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <sys/ptrace.h>
21 #include "test_ucopy.h"
23 #ifndef HAVE_PROCESS_VM_READV
25 # include <asm/unistd.h>
28 strace_process_vm_readv(pid_t pid,
29 const struct iovec *lvec,
30 unsigned long liovcnt,
31 const struct iovec *rvec,
32 unsigned long riovcnt,
35 return syscall(__NR_process_vm_readv,
36 (long) pid, lvec, liovcnt, rvec, riovcnt, flags);
38 # define process_vm_readv strace_process_vm_readv
40 #endif /* !HAVE_PROCESS_VM_READV */
43 call_process_vm_readv(const int pid, long *const addr)
47 const struct iovec local = {
49 .iov_len = sizeof(data)
51 const struct iovec remote = {
53 .iov_len = sizeof(*addr)
56 return process_vm_readv(pid, &local, 1, &remote, 1, 0) == sizeof(data)
61 call_ptrace_peekdata(const int pid, long *const addr)
63 return ptrace(PTRACE_PEEKDATA, pid, addr, 0) == 1;
67 test_ucopy(bool (*fn)(int pid, long *addr))
77 perror_msg_and_fail("fork");
81 if (ptrace(PTRACE_TRACEME, 0, 0, 0))
82 perror_msg_and_fail("PTRACE_TRACEME");
91 tracee = wait(&status);
98 perror_msg_and_fail("wait");
100 if (WIFEXITED(status)) {
101 if (WEXITSTATUS(status) == 0)
103 error_msg_and_fail("unexpected exit status %u",
104 WEXITSTATUS(status));
106 if (WIFSIGNALED(status))
107 error_msg_and_fail("unexpected signal %u",
109 if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) {
111 error_msg_and_fail("unexpected wait status %x",
120 if (ptrace(PTRACE_CONT, pid, 0, 0)) {
124 perror_msg_and_fail("PTRACE_CONT");
134 test_process_vm_readv(void)
136 return test_ucopy(call_process_vm_readv);
140 test_ptrace_peekdata(void)
142 return test_ucopy(call_ptrace_peekdata);