sparc64-freebsd.c (158626) | sparc64-freebsd.c (168569) |
---|---|
1/* 2 * Copryight 1998 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 1998 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/sparc64-fbsd.c 158626 2006-05-15 21:03:02Z pav $"; | 34 "$FreeBSD: head/usr.bin/truss/sparc64-fbsd.c 168569 2007-04-10 04:03:34Z delphij $"; |
35#endif /* not lint */ 36 37/* 38 * FreeBSD/sparc64-specific system call handling. This is probably the most 39 * complex part of the entire truss program, although I've got lots of 40 * it handled relatively cleanly now. The system call names are generated 41 * automatically, thanks to /usr/src/sys/kern/syscalls.master. The 42 * names used for the various structures are confusing, I sadly admit. 43 * 44 * This file is almost nothing more than a slightly-edited i386-fbsd.c. 45 */ 46 47#include <sys/types.h> | 35#endif /* not lint */ 36 37/* 38 * FreeBSD/sparc64-specific system call handling. This is probably the most 39 * complex part of the entire truss program, although I've got lots of 40 * it handled relatively cleanly now. The system call names are generated 41 * automatically, thanks to /usr/src/sys/kern/syscalls.master. The 42 * names used for the various structures are confusing, I sadly admit. 43 * 44 * This file is almost nothing more than a slightly-edited i386-fbsd.c. 45 */ 46 47#include <sys/types.h> |
48#include <sys/ioctl.h> 49#include <sys/pioctl.h> | 48#include <sys/ptrace.h> |
50#include <sys/syscall.h> 51 52#include <machine/frame.h> 53#include <machine/reg.h> 54#include <machine/tstate.h> 55 56#include <err.h> 57#include <errno.h> --- 5 unchanged lines hidden (view full) --- 63#include <string.h> 64#include <time.h> 65#include <unistd.h> 66 67#include "truss.h" 68#include "syscall.h" 69#include "extern.h" 70 | 49#include <sys/syscall.h> 50 51#include <machine/frame.h> 52#include <machine/reg.h> 53#include <machine/tstate.h> 54 55#include <err.h> 56#include <errno.h> --- 5 unchanged lines hidden (view full) --- 62#include <string.h> 63#include <time.h> 64#include <unistd.h> 65 66#include "truss.h" 67#include "syscall.h" 68#include "extern.h" 69 |
71static int fd = -1; | |
72static int cpid = -1; 73 74#include "syscalls.h" 75 76static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); 77 78/* 79 * This is what this particular file uses to keep track of a system call. --- 33 unchanged lines hidden (view full) --- 113 * Called when a process has entered a system call. nargs is the 114 * number of words, not number of arguments (a necessary distinction 115 * in some cases). Note that if the STOPEVENT() code in sparc64/sparc64/trap.c 116 * is ever changed these functions need to keep up. 117 */ 118 119void 120sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) { | 70static int cpid = -1; 71 72#include "syscalls.h" 73 74static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); 75 76/* 77 * This is what this particular file uses to keep track of a system call. --- 33 unchanged lines hidden (view full) --- 111 * Called when a process has entered a system call. nargs is the 112 * number of words, not number of arguments (a necessary distinction 113 * in some cases). Note that if the STOPEVENT() code in sparc64/sparc64/trap.c 114 * is ever changed these functions need to keep up. 115 */ 116 117void 118sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) { |
121 char buf[32]; | |
122 struct reg regs; 123 int syscall_num; 124 int i; 125 struct syscall *sc; 126 int indir = 0; /* indirect system call */ | 119 struct reg regs; 120 int syscall_num; 121 int i; 122 struct syscall *sc; 123 int indir = 0; /* indirect system call */ |
124 struct ptrace_io_desc iorequest; |
|
127 | 125 |
128 if (fd == -1 || trussinfo->pid != cpid) { 129 sprintf(buf, "/proc/%d/regs", trussinfo->pid); 130 fd = open(buf, O_RDWR); 131 if (fd == -1) { 132 fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n"); 133 return; 134 } 135 cpid = trussinfo->pid; 136 } | 126 cpid = trussinfo->curthread->tid; |
137 138 clear_fsc(); | 127 128 clear_fsc(); |
139 lseek(fd, 0L, 0); 140 if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) { | 129 130 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) { |
141 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 142 return; 143 } 144 145 /* 146 * FreeBSD has two special kinds of system call redirctions -- 147 * SYS_syscall, and SYS___syscall. The former is the old syscall() 148 * routine, basicly; the latter is for quad-aligned arguments. --- 11 unchanged lines hidden (view full) --- 160 fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num); 161 } 162 163 if (fsc.name && (trussinfo->flags & FOLLOWFORKS) 164 && ((!strcmp(fsc.name, "fork") 165 || !strcmp(fsc.name, "rfork") 166 || !strcmp(fsc.name, "vfork")))) 167 { | 131 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); 132 return; 133 } 134 135 /* 136 * FreeBSD has two special kinds of system call redirctions -- 137 * SYS_syscall, and SYS___syscall. The former is the old syscall() 138 * routine, basicly; the latter is for quad-aligned arguments. --- 11 unchanged lines hidden (view full) --- 150 fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num); 151 } 152 153 if (fsc.name && (trussinfo->flags & FOLLOWFORKS) 154 && ((!strcmp(fsc.name, "fork") 155 || !strcmp(fsc.name, "rfork") 156 || !strcmp(fsc.name, "vfork")))) 157 { |
168 trussinfo->in_fork = 1; | 158 trussinfo->curthread->in_fork = 1; |
169 } 170 171 if (nargs == 0) 172 return; 173 174 fsc.args = malloc((1+nargs) * sizeof(unsigned long)); 175 switch (nargs) { 176 default: --- 4 unchanged lines hidden (view full) --- 181 warn("More than 10 words (%d) of arguments!\n", nargs); 182 break; 183 case 10: case 9: case 8: case 7: 184 /* 185 * If there are 7-10 words of arguments, they are placed 186 * on the stack, as is normal for other processors. 187 * The fall-through for all of these is deliberate!!! 188 */ | 159 } 160 161 if (nargs == 0) 162 return; 163 164 fsc.args = malloc((1+nargs) * sizeof(unsigned long)); 165 switch (nargs) { 166 default: --- 4 unchanged lines hidden (view full) --- 171 warn("More than 10 words (%d) of arguments!\n", nargs); 172 break; 173 case 10: case 9: case 8: case 7: 174 /* 175 * If there are 7-10 words of arguments, they are placed 176 * on the stack, as is normal for other processors. 177 * The fall-through for all of these is deliberate!!! 178 */ |
189 lseek(Procfd, regs.r_out[6] + SPOFF + 190 offsetof(struct frame, fr_pad[6]), SEEK_SET); 191 read(fd, &fsc.args[6], (nargs - 6) * sizeof(fsc.args[0])); | 179 iorequest.piod_op = PIOD_READ_D; 180 iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF + 181 offsetof(struct frame, fr_pad[6])); 182 iorequest.piod_addr = &fsc.args[6]; 183 iorequest.piod_len = (nargs - 6) * sizeof(fsc.args[0]); 184 ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); 185 if (iorequest.piod_len == 0) return; 186 |
192 case 6: fsc.args[5] = regs.r_out[5]; 193 case 5: fsc.args[4] = regs.r_out[4]; 194 case 4: fsc.args[3] = regs.r_out[3]; 195 case 3: fsc.args[2] = regs.r_out[2]; 196 case 2: fsc.args[1] = regs.r_out[1]; 197 case 1: fsc.args[0] = regs.r_out[0]; 198 case 0: 199 break; --- 35 unchanged lines hidden (view full) --- 235#if DEBUG 236 fprintf(stderr, "0x%x%s", 237 sc 238 ? fsc.args[sc->args[i].offset] 239 : fsc.args[i], 240 i < (fsc.nargs - 1) ? "," : ""); 241#endif 242 if (sc && !(sc->args[i].type & OUT)) { | 187 case 6: fsc.args[5] = regs.r_out[5]; 188 case 5: fsc.args[4] = regs.r_out[4]; 189 case 4: fsc.args[3] = regs.r_out[3]; 190 case 3: fsc.args[2] = regs.r_out[2]; 191 case 2: fsc.args[1] = regs.r_out[1]; 192 case 1: fsc.args[0] = regs.r_out[0]; 193 case 0: 194 break; --- 35 unchanged lines hidden (view full) --- 230#if DEBUG 231 fprintf(stderr, "0x%x%s", 232 sc 233 ? fsc.args[sc->args[i].offset] 234 : fsc.args[i], 235 i < (fsc.nargs - 1) ? "," : ""); 236#endif 237 if (sc && !(sc->args[i].type & OUT)) { |
243 fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo); | 238 fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo); |
244 } 245 } 246#if DEBUG 247 fprintf(stderr, ")\n"); 248#endif 249 } 250 251#if DEBUG --- 38 unchanged lines hidden (view full) --- 290 * And when the system call is done, we handle it here. 291 * Currently, no attempt is made to ensure that the system calls 292 * match -- this needs to be fixed (and is, in fact, why S_SCX includes 293 * the sytem call number instead of, say, an error status). 294 */ 295 296long 297sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) { | 239 } 240 } 241#if DEBUG 242 fprintf(stderr, ")\n"); 243#endif 244 } 245 246#if DEBUG --- 38 unchanged lines hidden (view full) --- 285 * And when the system call is done, we handle it here. 286 * Currently, no attempt is made to ensure that the system calls 287 * match -- this needs to be fixed (and is, in fact, why S_SCX includes 288 * the sytem call number instead of, say, an error status). 289 */ 290 291long 292sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) { |
298 char buf[32]; | |
299 struct reg regs; 300 long retval; 301 int i; 302 int errorp; 303 struct syscall *sc; 304 | 293 struct reg regs; 294 long retval; 295 int i; 296 int errorp; 297 struct syscall *sc; 298 |
305 if (fd == -1 || trussinfo->pid != cpid) { 306 sprintf(buf, "/proc/%d/regs", trussinfo->pid); 307 fd = open(buf, O_RDONLY); 308 if (fd == -1) { 309 fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n"); 310 return (-1); 311 } 312 cpid = trussinfo->pid; 313 } | 299 cpid = trussinfo->curthread->tid; |
314 | 300 |
315 lseek(fd, 0L, 0); 316 if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) { | 301 if (ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0) < 0) { |
317 fprintf(trussinfo->outfile, "\n"); 318 return (-1); 319 } 320 retval = regs.r_out[0]; 321 errorp = !!(regs.r_tstate & TSTATE_XCC_C); 322 323 /* 324 * This code, while simpler than the initial versions I used, could --- 14 unchanged lines hidden (view full) --- 339 if (sc->args[i].type & OUT) { 340 /* 341 * If an error occurred, than don't bothe getting the data; 342 * it may not be valid. 343 */ 344 if (errorp) 345 asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); 346 else | 302 fprintf(trussinfo->outfile, "\n"); 303 return (-1); 304 } 305 retval = regs.r_out[0]; 306 errorp = !!(regs.r_tstate & TSTATE_XCC_C); 307 308 /* 309 * This code, while simpler than the initial versions I used, could --- 14 unchanged lines hidden (view full) --- 324 if (sc->args[i].type & OUT) { 325 /* 326 * If an error occurred, than don't bothe getting the data; 327 * it may not be valid. 328 */ 329 if (errorp) 330 asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]); 331 else |
347 temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo); | 332 temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo); |
348 fsc.s_args[i] = temp; 349 } 350 } 351 } 352 353 /* 354 * It would probably be a good idea to merge the error handling, 355 * but that complicates things considerably. 356 */ 357 358 print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval); 359 clear_fsc(); 360 361 return (retval); 362} | 333 fsc.s_args[i] = temp; 334 } 335 } 336 } 337 338 /* 339 * It would probably be a good idea to merge the error handling, 340 * but that complicates things considerably. 341 */ 342 343 print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval); 344 clear_fsc(); 345 346 return (retval); 347} |