Permalink
Browse files

Start to separate ptrace.c into a library.

  • Loading branch information...
nelhage committed Jan 17, 2011
1 parent 1fb6ce8 commit 648ff264b0ab4b025eea931d9737f4ecf02e8e22
Showing with 40 additions and 16 deletions.
  1. +2 −0 Makefile
  2. +4 −16 ptrace.c
  3. +34 −0 ptrace.h
View
@@ -3,6 +3,8 @@ STUB_CFLAGS=$(CFLAGS) -nostdlib -Wl,-r -fomit-frame-pointer
all: reptyr stub.o
reptyr: reptyr.o ptrace.o
stub.o: stub.c
$(CC) -c $(STUB_CFLAGS) -o $@ $^
! nm $@ | grep ' U '
View
@@ -11,6 +11,8 @@
#include <sys/mman.h>
#include <assert.h>
#include "ptrace.h"
#ifdef __amd64__
#include "arch/amd64.h"
#else
@@ -23,22 +25,6 @@
#define offsetof(a, b) __builtin_offsetof(a,b)
enum child_state {
ptrace_detached = 0,
ptrace_at_syscall,
ptrace_after_syscall,
ptrace_running,
ptrace_stopped,
ptrace_exited
};
struct ptrace_child {
pid_t pid;
struct user user;
enum child_state state;
int status;
};
int ptrace_wait(struct ptrace_child *child);
int ptrace_attach_child(struct ptrace_child *child, pid_t pid) {
@@ -159,6 +145,7 @@ void reset_user_struct(struct user *user) {
user->regs.reg_ax = user->regs.orig_ax;
}
#ifdef BUILD_PTRACE_MAIN
int main(int argc, char **argv) {
struct ptrace_child child;
pid_t pid;
@@ -182,3 +169,4 @@ int main(int argc, char **argv) {
return 0;
}
#endif
View
@@ -0,0 +1,34 @@
#include <sys/ptrace.h>
#include <sys/user.h>
#include <unistd.h>
enum child_state {
ptrace_detached = 0,
ptrace_at_syscall,
ptrace_after_syscall,
ptrace_running,
ptrace_stopped,
ptrace_exited
};
struct ptrace_child {
pid_t pid;
struct user user;
enum child_state state;
int status;
};
int ptrace_wait(struct ptrace_child *child);
int ptrace_attach_child(struct ptrace_child *child, pid_t pid);
int ptrace_detach_child(struct ptrace_child *child);
int ptrace_wait(struct ptrace_child *child);
int ptrace_advance_to_state(struct ptrace_child *child,
enum child_state desired);
int ptrace_save_regs(struct ptrace_child *child);
int ptrace_restore_regs(struct ptrace_child *child);
unsigned long ptrace_remote_syscall(struct ptrace_child *child,
unsigned long sysno,
unsigned long p0, unsigned long p1,
unsigned long p2, unsigned long p3,
unsigned long p4, unsigned long p5);
void reset_user_struct(struct user *user);

0 comments on commit 648ff26

Please sign in to comment.