diff options
author | Elliott Hughes <enh@google.com> | 2014-07-16 15:18:54 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-07-16 16:07:10 -0700 |
commit | 98b088dce70a2625d5cfa1872e427af5f06bfd99 (patch) | |
tree | 700f61f789e13229ca9300c6eecdf212a7936596 | |
parent | f13aa6fc5b66d1c98b7fd4b43e20515033707e56 (diff) | |
download | bionic-98b088dce70a2625d5cfa1872e427af5f06bfd99.zip bionic-98b088dce70a2625d5cfa1872e427af5f06bfd99.tar.gz bionic-98b088dce70a2625d5cfa1872e427af5f06bfd99.tar.bz2 |
ptrace(3) should be varargs.
Bug: 16352070
Change-Id: Ied72e6e79eaf912fc93fc49ae7637af321a31a59
-rw-r--r-- | libc/bionic/ptrace.cpp | 40 | ||||
-rw-r--r-- | libc/include/sys/ptrace.h | 8 |
2 files changed, 25 insertions, 23 deletions
diff --git a/libc/bionic/ptrace.cpp b/libc/bionic/ptrace.cpp index 5715b09..5156ec2 100644 --- a/libc/bionic/ptrace.cpp +++ b/libc/bionic/ptrace.cpp @@ -26,28 +26,30 @@ * SUCH DAMAGE. */ -#include <sys/types.h> +#include <stdarg.h> #include <sys/ptrace.h> -extern "C" long __ptrace(int request, pid_t pid, void* addr, void* data); +extern "C" long __ptrace(int req, pid_t pid, void* addr, void* data); -long ptrace(int request, pid_t pid, void* addr, void* data) { - switch (request) { - case PTRACE_PEEKUSR: - case PTRACE_PEEKTEXT: - case PTRACE_PEEKDATA: - { - long word; - long ret = __ptrace(request, pid, addr, &word); - if (ret == 0) { - return word; - } else { - // __ptrace already set errno for us. - return -1; - } - } +long ptrace(int req, ...) { + bool is_peek = (req == PTRACE_PEEKUSR || req == PTRACE_PEEKTEXT || req == PTRACE_PEEKDATA); + long peek_result; - default: - return __ptrace(request, pid, addr, data); + va_list args; + va_start(args, req); + pid_t pid = va_arg(args, pid_t); + void* addr = va_arg(args, void*); + void* data; + if (is_peek) { + data = &peek_result; + } else { + data = va_arg(args, void*); } + va_end(args); + + long result = __ptrace(req, pid, addr, data); + if (is_peek && result == 0) { + return peek_result; + } + return result; } diff --git a/libc/include/sys/ptrace.h b/libc/include/sys/ptrace.h index 848416b..8bba9fe 100644 --- a/libc/include/sys/ptrace.h +++ b/libc/include/sys/ptrace.h @@ -30,15 +30,15 @@ #include <sys/cdefs.h> #include <sys/types.h> -/* For all of the defines */ #include <linux/ptrace.h> __BEGIN_DECLS -#define PTRACE_POKEUSER PTRACE_POKEUSR -#define PTRACE_PEEKUSER PTRACE_PEEKUSR +/* glibc uses different names from the kernel for these two... */ +#define PTRACE_POKEUSER PTRACE_POKEUSR +#define PTRACE_PEEKUSER PTRACE_PEEKUSR -extern long ptrace(int request, pid_t pid, void *addr, void *data); +extern long ptrace(int, ...); __END_DECLS |