blob: 0d68ae09799d7f94eabca1fb49deb9f287cbbedd [file] [log] [blame]
Juan Cespedesd44c6b81998-09-25 14:48:42 +02001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
Juan Cespedes8e3e0821998-09-24 13:49:55 +02005#include <sys/types.h>
6#include <sys/wait.h>
7#include <signal.h>
8#include <sys/ptrace.h>
9#include <asm/ptrace.h>
10
11#include "ltrace.h"
12
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
21/* syscall tracing protocol: ArmLinux
22 on the way in, ip is 0
23 on the way out, ip is non-zero
24*/
25#define off_r0 0
26#define off_ip 48
27#define off_pc 60
28
Ian Wienand3219f322006-02-16 06:00:00 +010029void get_arch_dep(struct process *proc)
30{
Juan Cespedes5c3fe062004-06-14 18:08:37 +020031}
32
Juan Cespedes8e3e0821998-09-24 13:49:55 +020033/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
34 */
Ian Wienand3219f322006-02-16 06:00:00 +010035int syscall_p(struct process *proc, int status, int *sysnum)
36{
37 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
Juan Cespedes8e3e0821998-09-24 13:49:55 +020038 /* get the user's pc (plus 8) */
39 int pc = ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0);
40 /* fetch the SWI instruction */
Ian Wienand3219f322006-02-16 06:00:00 +010041 int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
42
Juan Cespedes8e3e0821998-09-24 13:49:55 +020043 *sysnum = insn & 0xFFFF;
44 /* if it is a syscall, return 1 or 2 */
45 if ((insn & 0xFFFF0000) == 0xef900000) {
Ian Wienand3219f322006-02-16 06:00:00 +010046 return ptrace(PTRACE_PEEKUSER, proc->pid, off_ip,
47 0) ? 2 : 1;
Juan Cespedes8e3e0821998-09-24 13:49:55 +020048 }
49 }
50 return 0;
51}
Ian Wienand3219f322006-02-16 06:00:00 +010052
53long gimme_arg(enum tof type, struct process *proc, int arg_num)
54{
55 if (arg_num == -1) { /* return value */
Juan Cespedes8e3e0821998-09-24 13:49:55 +020056 return ptrace(PTRACE_PEEKUSER, proc->pid, off_r0, 0);
57 }
58
59 /* deal with the ARM calling conventions */
Ian Wienand3219f322006-02-16 06:00:00 +010060 if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
61 if (arg_num < 4) {
62 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num,
63 0);
Juan Cespedes8e3e0821998-09-24 13:49:55 +020064 } else {
Ian Wienand3219f322006-02-16 06:00:00 +010065 return ptrace(PTRACE_PEEKDATA, proc->pid,
66 proc->stack_pointer + 4 * (arg_num - 4),
67 0);
Juan Cespedes8e3e0821998-09-24 13:49:55 +020068 }
Ian Wienand3219f322006-02-16 06:00:00 +010069 } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
70 if (arg_num < 5) {
71 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num,
72 0);
Juan Cespedes8e3e0821998-09-24 13:49:55 +020073 } else {
Ian Wienand3219f322006-02-16 06:00:00 +010074 return ptrace(PTRACE_PEEKDATA, proc->pid,
75 proc->stack_pointer + 4 * (arg_num - 5),
76 0);
Juan Cespedes8e3e0821998-09-24 13:49:55 +020077 }
78 } else {
79 fprintf(stderr, "gimme_arg called with wrong arguments\n");
80 exit(1);
81 }
82
83 return 0;
84}
Juan Cespedes5c3fe062004-06-14 18:08:37 +020085
Ian Wienand3219f322006-02-16 06:00:00 +010086void save_register_args(enum tof type, struct process *proc)
87{
Juan Cespedes5c3fe062004-06-14 18:08:37 +020088}