| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 1 | #include "config.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 2 | |
| Juan Cespedes | 504a385 | 2003-02-04 23:24:38 +0100 | [diff] [blame] | 3 | #include <stdlib.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 4 | #include <sys/types.h> |
| 5 | #include <sys/wait.h> |
| 6 | #include <signal.h> |
| 7 | #include <sys/ptrace.h> |
| Juan Cespedes | 64c6dfb | 1998-07-14 13:49:47 +0200 | [diff] [blame] | 8 | #include <asm/ptrace.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 9 | |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame^] | 10 | #include "proc.h" |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 11 | #include "common.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 12 | |
| Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 13 | #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) |
| 14 | # define PTRACE_PEEKUSER PTRACE_PEEKUSR |
| 15 | #endif |
| 16 | |
| 17 | #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) |
| 18 | # define PTRACE_POKEUSER PTRACE_POKEUSR |
| 19 | #endif |
| 20 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 21 | void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 22 | get_arch_dep(Process *proc) { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 25 | /* Returns 1 if syscall, 2 if sysret, 0 otherwise. |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 26 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 27 | int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 28 | syscall_p(Process *proc, int status, int *sysnum) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 29 | if (WIFSTOPPED(status) |
| 30 | && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { |
| 31 | *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0); |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 32 | |
| 33 | if (proc->callstack_depth > 0 && |
| Juan Cespedes | 3e94cbf | 2009-05-22 19:12:07 +0200 | [diff] [blame] | 34 | proc->callstack[proc->callstack_depth - 1].is_syscall && |
| 35 | proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) { |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 36 | return 2; |
| 37 | } |
| 38 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 39 | if (*sysnum >= 0) { |
| Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 40 | return 1; |
| Juan Cespedes | f0fdae9 | 1998-03-11 00:03:00 +0100 | [diff] [blame] | 41 | } |
| 42 | } |
| Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 43 | return 0; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 46 | long |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 47 | gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 48 | if (arg_num == -1) { /* return value */ |
| 49 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EAX, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 52 | if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) { |
| 53 | return ptrace(PTRACE_PEEKTEXT, proc->pid, |
| 54 | proc->stack_pointer + 4 * (arg_num + 1), 0); |
| 55 | } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 56 | #if 0 |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 57 | switch (arg_num) { |
| 58 | case 0: |
| 59 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EBX, 0); |
| 60 | case 1: |
| 61 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ECX, 0); |
| 62 | case 2: |
| 63 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDX, 0); |
| 64 | case 3: |
| 65 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ESI, 0); |
| 66 | case 4: |
| 67 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDI, 0); |
| 68 | default: |
| 69 | fprintf(stderr, |
| 70 | "gimme_arg called with wrong arguments\n"); |
| 71 | exit(2); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 72 | } |
| 73 | #else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 74 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 75 | #endif |
| 76 | } else { |
| 77 | fprintf(stderr, "gimme_arg called with wrong arguments\n"); |
| 78 | exit(1); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 83 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 84 | void |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 85 | save_register_args(enum tof type, Process *proc) { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 86 | } |