amd64-linux32.c (171055) | amd64-linux32.c (179051) |
---|---|
1/* 2 * Copryight 1997 Sean Eric Fagan 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 17 unchanged lines hidden (view full) --- 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#ifndef lint 33static const char rcsid[] = | 1/* 2 * Copryight 1997 Sean Eric Fagan 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 17 unchanged lines hidden (view full) --- 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#ifndef lint 33static const char rcsid[] = |
34 "$FreeBSD: head/usr.bin/truss/amd64-linux32.c 171055 2007-06-26 22:42:37Z delphij $"; | 34 "$FreeBSD: head/usr.bin/truss/amd64-linux32.c 179051 2008-05-16 15:34:06Z jhb $"; |
35#endif /* not lint */ 36 37/* 38 * Linux/i386-specific system call handling. Given how much of this code 39 * is taken from the freebsd equivalent, I can probably put even more of 40 * it in support routines that can be used by any personality support. 41 */ 42 --- 13 unchanged lines hidden (view full) --- 56#include <unistd.h> 57 58#include "truss.h" 59#include "syscall.h" 60#include "extern.h" 61 62static int cpid = -1; 63 | 35#endif /* not lint */ 36 37/* 38 * Linux/i386-specific system call handling. Given how much of this code 39 * is taken from the freebsd equivalent, I can probably put even more of 40 * it in support routines that can be used by any personality support. 41 */ 42 --- 13 unchanged lines hidden (view full) --- 56#include <unistd.h> 57 58#include "truss.h" 59#include "syscall.h" 60#include "extern.h" 61 62static int cpid = -1; 63 |
64#include "linux_syscalls.h" | 64#include "linux32_syscalls.h" |
65 66static int nsyscalls = | 65 66static int nsyscalls = |
67 sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]); | 67 sizeof(linux32_syscallnames) / sizeof(linux32_syscallnames[0]); |
68 69/* 70 * This is what this particular file uses to keep track of a system call. 71 * It is probably not quite sufficient -- I can probably use the same 72 * structure for the various syscall personalities, and I also probably 73 * need to nest system calls (for signal handlers). 74 * 75 * 'struct syscall' describes the system call; it may be NULL, however, --- 24 unchanged lines hidden (view full) --- 100/* 101 * Called when a process has entered a system call. nargs is the 102 * number of words, not number of arguments (a necessary distinction 103 * in some cases). Note that if the STOPEVENT() code in i386/i386/trap.c 104 * is ever changed these functions need to keep up. 105 */ 106 107void | 68 69/* 70 * This is what this particular file uses to keep track of a system call. 71 * It is probably not quite sufficient -- I can probably use the same 72 * structure for the various syscall personalities, and I also probably 73 * need to nest system calls (for signal handlers). 74 * 75 * 'struct syscall' describes the system call; it may be NULL, however, --- 24 unchanged lines hidden (view full) --- 100/* 101 * Called when a process has entered a system call. nargs is the 102 * number of words, not number of arguments (a necessary distinction 103 * in some cases). Note that if the STOPEVENT() code in i386/i386/trap.c 104 * is ever changed these functions need to keep up. 105 */ 106 107void |
108i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) { | 108amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs) { |
109 struct reg regs; 110 int syscall_num; 111 int i; 112 struct syscall *sc; 113 114 cpid = trussinfo->curthread->tid; 115 116 clear_fsc(); 117 118 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) 119 { 120 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 121 return; 122 } | 109 struct reg regs; 110 int syscall_num; 111 int i; 112 struct syscall *sc; 113 114 cpid = trussinfo->curthread->tid; 115 116 clear_fsc(); 117 118 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) 119 { 120 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 121 return; 122 } |
123 syscall_num = regs.r_eax; | 123 syscall_num = regs.r_rax; |
124 125 fsc.number = syscall_num; 126 fsc.name = | 124 125 fsc.number = syscall_num; 126 fsc.name = |
127 (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux_syscallnames[syscall_num]; | 127 (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux32_syscallnames[syscall_num]; |
128 if (!fsc.name) { 129 fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num); 130 } 131 132 if (fsc.name && (trussinfo->flags & FOLLOWFORKS) 133 && ((!strcmp(fsc.name, "linux_fork") 134 || !strcmp(fsc.name, "linux_vfork")))) 135 { --- 6 unchanged lines hidden (view full) --- 142 /* 143 * Linux passes syscall arguments in registers, not 144 * on the stack. Fortunately, we've got access to the 145 * register set. Note that we don't bother checking the 146 * number of arguments. And what does linux do for syscalls 147 * that have more than five arguments? 148 */ 149 | 128 if (!fsc.name) { 129 fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num); 130 } 131 132 if (fsc.name && (trussinfo->flags & FOLLOWFORKS) 133 && ((!strcmp(fsc.name, "linux_fork") 134 || !strcmp(fsc.name, "linux_vfork")))) 135 { --- 6 unchanged lines hidden (view full) --- 142 /* 143 * Linux passes syscall arguments in registers, not 144 * on the stack. Fortunately, we've got access to the 145 * register set. Note that we don't bother checking the 146 * number of arguments. And what does linux do for syscalls 147 * that have more than five arguments? 148 */ 149 |
150 fsc.args[0] = regs.r_ebx; 151 fsc.args[1] = regs.r_ecx; 152 fsc.args[2] = regs.r_edx; 153 fsc.args[3] = regs.r_esi; 154 fsc.args[4] = regs.r_edi; | 150 fsc.args[0] = regs.r_rbx; 151 fsc.args[1] = regs.r_rcx; 152 fsc.args[2] = regs.r_rdx; 153 fsc.args[3] = regs.r_rsi; 154 fsc.args[4] = regs.r_rdi; |
155 156 sc = get_syscall(fsc.name); 157 if (sc) { 158 fsc.nargs = sc->nargs; 159 } else { 160#if DEBUG 161 fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n", 162 fsc.name, nargs); --- 74 unchanged lines hidden (view full) --- 237 -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, 238 -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, 239 -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, 240 -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, 241 -6, 242}; 243 244long | 155 156 sc = get_syscall(fsc.name); 157 if (sc) { 158 fsc.nargs = sc->nargs; 159 } else { 160#if DEBUG 161 fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n", 162 fsc.name, nargs); --- 74 unchanged lines hidden (view full) --- 237 -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, 238 -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, 239 -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, 240 -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, 241 -6, 242}; 243 244long |
245i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) | 245amd64_linux32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) |
246{ 247 struct reg regs; 248 long retval; 249 int i; 250 int errorp; 251 struct syscall *sc; 252 253 if (fsc.name == NULL) 254 return (-1); 255 256 cpid = trussinfo->curthread->tid; 257 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) 258 { 259 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 260 return (-1); 261 } 262 | 246{ 247 struct reg regs; 248 long retval; 249 int i; 250 int errorp; 251 struct syscall *sc; 252 253 if (fsc.name == NULL) 254 return (-1); 255 256 cpid = trussinfo->curthread->tid; 257 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) 258 { 259 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 260 return (-1); 261 } 262 |
263 retval = regs.r_eax; 264 errorp = !!(regs.r_eflags & PSL_C); | 263 retval = regs.r_rax; 264 errorp = !!(regs.r_rflags & PSL_C); |
265 266 /* 267 * This code, while simpler than the initial versions I used, could 268 * stand some significant cleaning. 269 */ 270 271 sc = fsc.sc; 272 if (!sc) { --- 44 unchanged lines hidden --- | 265 266 /* 267 * This code, while simpler than the initial versions I used, could 268 * stand some significant cleaning. 269 */ 270 271 sc = fsc.sc; 272 if (!sc) { --- 44 unchanged lines hidden --- |