ptrace(3) should be varargs.

Bug: 16352070

(cherry picked from commit 98b088dce7)

Change-Id: I6193ef44df9a5668020916eaca90b47fc4c8ab77
This commit is contained in:
Elliott Hughes 2014-07-16 15:18:54 -07:00
parent 3002131da3
commit 9a7fdb2dae
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