ptrace(3) should be varargs.

Bug: 16352070
Change-Id: Ied72e6e79eaf912fc93fc49ae7637af321a31a59
This commit is contained in:
Elliott Hughes 2014-07-16 15:18:54 -07:00
parent f13aa6fc5b
commit 98b088dce7
2 changed files with 25 additions and 23 deletions

View file

@ -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;
}

View file

@ -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