diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-03-18 07:44:52 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-03-18 23:36:08 -0400 |
commit | 2641abe6d67ecaa89a1ed7bd6dad93cf63bdd6c0 (patch) | |
tree | 3177d5c052bdee022ca6920be595c18fbbf55b97 /libsandbox/trace | |
parent | sandbox: add desktop/icon files (diff) | |
download | sandbox-2641abe6d67ecaa89a1ed7bd6dad93cf63bdd6c0.tar.gz sandbox-2641abe6d67ecaa89a1ed7bd6dad93cf63bdd6c0.tar.bz2 sandbox-2641abe6d67ecaa89a1ed7bd6dad93cf63bdd6c0.zip |
libsandbox: initial support for tracing of static binaries via ptrace()
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/trace')
-rw-r--r-- | libsandbox/trace/common.c | 3 | ||||
-rw-r--r-- | libsandbox/trace/linux/arch.c | 17 | ||||
-rw-r--r-- | libsandbox/trace/linux/common.c | 13 | ||||
-rw-r--r-- | libsandbox/trace/linux/i386.c | 24 | ||||
-rw-r--r-- | libsandbox/trace/linux/x86_64.c | 24 | ||||
-rw-r--r-- | libsandbox/trace/os.c | 14 |
6 files changed, 95 insertions, 0 deletions
diff --git a/libsandbox/trace/common.c b/libsandbox/trace/common.c new file mode 100644 index 0000000..20fcb7e --- /dev/null +++ b/libsandbox/trace/common.c @@ -0,0 +1,3 @@ +static int trace_sysnum(void); +static long trace_raw_ret(void *vregs); +static unsigned long trace_arg(void *vregs, int num); diff --git a/libsandbox/trace/linux/arch.c b/libsandbox/trace/linux/arch.c new file mode 100644 index 0000000..5897b2f --- /dev/null +++ b/libsandbox/trace/linux/arch.c @@ -0,0 +1,17 @@ +#include "common.c" + +/* Linux uses ptrace() */ +#if !defined(HAVE_PTRACE) || !defined(HAVE_SYS_PTRACE_H) || !defined(HAVE_SYS_USER_H) +# define SB_NO_TRACE_ARCH +#elif defined(__i386__) +# include "i386.c" +#elif defined(__x86_64__) +# include "x86_64.c" +#else +# define SB_NO_TRACE_ARCH +#endif + +#ifdef SB_NO_TRACE_ARCH +# warning "trace: sorry, no support for your architecture" +# define SB_NO_TRACE +#endif diff --git a/libsandbox/trace/linux/common.c b/libsandbox/trace/linux/common.c new file mode 100644 index 0000000..287af0a --- /dev/null +++ b/libsandbox/trace/linux/common.c @@ -0,0 +1,13 @@ +static long do_peekuser(long offset); + +static int trace_errno(long err) +{ + return (err < 0 && err > -4096) ? err * -1 : 0; +} + +static long trace_result(void *vregs, int *error) +{ + long sr = trace_raw_ret(vregs); + *error = trace_errno(sr); + return *error ? -1 : sr; +} diff --git a/libsandbox/trace/linux/i386.c b/libsandbox/trace/linux/i386.c new file mode 100644 index 0000000..83cc094 --- /dev/null +++ b/libsandbox/trace/linux/i386.c @@ -0,0 +1,24 @@ +static int trace_sysnum(void) +{ + return do_peekuser(4 * ORIG_EAX); +} + +static long trace_raw_ret(void *vregs) +{ + struct user_regs_struct *regs = vregs; + return regs->eax; +} + +static unsigned long trace_arg(void *vregs, int num) +{ + struct user_regs_struct *regs = vregs; + switch (num) { + case 1: return regs->ebx; + case 2: return regs->ecx; + case 3: return regs->edx; + case 4: return regs->esi; + case 5: return regs->edi; + case 6: return regs->ebp; + default: return -1; + } +} diff --git a/libsandbox/trace/linux/x86_64.c b/libsandbox/trace/linux/x86_64.c new file mode 100644 index 0000000..1f40036 --- /dev/null +++ b/libsandbox/trace/linux/x86_64.c @@ -0,0 +1,24 @@ +static int trace_sysnum(void) +{ + return do_peekuser(8 * ORIG_RAX); +} + +static long trace_raw_ret(void *vregs) +{ + struct user_regs_struct *regs = vregs; + return regs->rax; +} + +static unsigned long trace_arg(void *vregs, int num) +{ + struct user_regs_struct *regs = vregs; + switch (num) { + case 1: return regs->rdi; + case 2: return regs->rsi; + case 3: return regs->rdx; + case 4: return regs->r10; + case 5: return regs->r8; + case 6: return regs->r9; + default: return -1; + } +} diff --git a/libsandbox/trace/os.c b/libsandbox/trace/os.c new file mode 100644 index 0000000..945cc61 --- /dev/null +++ b/libsandbox/trace/os.c @@ -0,0 +1,14 @@ +#include "common.c" + +#undef SB_NO_TRACE +#if 0 +#elif defined(__linux__) +# include "linux/arch.c" +#else +# define SB_NO_TRACE_OS +#endif + +#ifdef SB_NO_TRACE_OS +# warning "trace: sorry, no support for your OS" +# define SB_NO_TRACE +#endif |