| Petr Machata | e99af27 | 2012-10-26 00:29:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 1998,2001,2004,2008,2009 Juan Cespedes |
| 4 | * Copyright (C) 2009 Juan Cespedes |
| 5 | * Copyright (C) 2006 Ian Wienand |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of the |
| 10 | * License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | */ |
| 22 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 23 | #include "config.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 24 | |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/wait.h> |
| 27 | #include <signal.h> |
| 28 | #include <sys/ptrace.h> |
| 29 | #include <asm/ptrace.h> |
| 30 | |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame] | 31 | #include "proc.h" |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 32 | #include "common.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 33 | |
| 34 | #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) |
| 35 | # define PTRACE_PEEKUSER PTRACE_PEEKUSR |
| 36 | #endif |
| 37 | |
| 38 | #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) |
| 39 | # define PTRACE_POKEUSER PTRACE_POKEUSR |
| 40 | #endif |
| 41 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 42 | void |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 43 | get_arch_dep(struct process *proc) |
| 44 | { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 47 | /* Returns 1 if syscall, 2 if sysret, 0 otherwise. |
| 48 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 49 | int |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 50 | syscall_p(struct process *proc, int status, int *sysnum) |
| 51 | { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 52 | int depth; |
| 53 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 54 | if (WIFSTOPPED(status) |
| 55 | && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { |
| 56 | *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_ORIG_D0, 0); |
| 57 | if (*sysnum == -1) |
| 58 | return 0; |
| 59 | if (*sysnum >= 0) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 60 | depth = proc->callstack_depth; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 61 | if (depth > 0 && |
| Juan Cespedes | 3e94cbf | 2009-05-22 19:12:07 +0200 | [diff] [blame] | 62 | proc->callstack[depth - 1].is_syscall && |
| 63 | proc->callstack[depth - 1].c_un.syscall == *sysnum) { |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 64 | return 2; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 65 | } else { |
| 66 | return 1; |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
| 70 | return 0; |
| 71 | } |