- Make truss thread-aware.

Approved by:	kib (mentor)
MFC after:	2 weeks
This commit is contained in:
Andrey Zonov 2012-09-16 14:38:01 +00:00
parent 54202ab3d1
commit 5695afded4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=240562
14 changed files with 804 additions and 721 deletions

View File

@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -77,30 +75,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -115,14 +118,14 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
int i, reg, syscall_num; int i, reg, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -142,57 +145,60 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
break; break;
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0|| strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
for (i = 0; i < nargs && reg < 6; i++, reg++) { for (i = 0; i < nargs && reg < 6; i++, reg++) {
switch (reg) { switch (reg) {
case 0: fsc.args[i] = regs.r_rdi; break; case 0: fsc->args[i] = regs.r_rdi; break;
case 1: fsc.args[i] = regs.r_rsi; break; case 1: fsc->args[i] = regs.r_rsi; break;
case 2: fsc.args[i] = regs.r_rdx; break; case 2: fsc->args[i] = regs.r_rdx; break;
case 3: fsc.args[i] = regs.r_rcx; break; case 3: fsc->args[i] = regs.r_rcx; break;
case 4: fsc.args[i] = regs.r_r8; break; case 4: fsc->args[i] = regs.r_r8; break;
case 5: fsc.args[i] = regs.r_r9; break; case 5: fsc->args[i] = regs.r_r9; break;
} }
} }
if (nargs > i) { if (nargs > i) {
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t)); iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t));
iorequest.piod_addr = &fsc.args[i]; iorequest.piod_addr = &fsc->args[i];
iorequest.piod_len = (nargs - i) * sizeof(register_t); iorequest.piod_len = (nargs - i) * sizeof(register_t);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
} }
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -202,19 +208,19 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%lx%s", sc ? fprintf(stderr, "0x%lx%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -226,30 +232,29 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -263,16 +268,18 @@ long
amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -285,10 +292,11 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -303,18 +311,18 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -322,9 +330,9 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "freebsd32_syscalls.h" #include "freebsd32_syscalls.h"
static int nsyscalls = sizeof(freebsd32_syscallnames) / static int nsyscalls = sizeof(freebsd32_syscallnames) /
@ -78,7 +76,7 @@ static int nsyscalls = sizeof(freebsd32_syscallnames) /
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd32_syscall { struct freebsd32_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
@ -86,25 +84,29 @@ static struct freebsd32_syscall {
unsigned int *args32; unsigned int *args32;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd32_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd32_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd32_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); free(fsc->args32);
if (fsc.args32) if (fsc->s_args) {
free(fsc.args32); for (i = 0; i < fsc->nargs; i++)
if (fsc.s_args) { free(fsc->s_args[i]);
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args);
if (fsc.s_args[i])
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -119,15 +121,15 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd32_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
unsigned long parm_offset; unsigned long parm_offset;
int i, syscall_num; int i, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -141,60 +143,63 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_rax; syscall_num = regs.r_rax;
switch (syscall_num) { switch (syscall_num) {
case SYS_syscall: case SYS_syscall:
syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0); syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(int); parm_offset += sizeof(int);
break; break;
case SYS___syscall: case SYS___syscall:
syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0); syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(quad_t); parm_offset += sizeof(quad_t);
break; break;
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : freebsd32_syscallnames[syscall_num]; NULL : freebsd32_syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0|| strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args32 = malloc((1 + nargs) * sizeof(unsigned int)); fsc->args32 = malloc((1 + nargs) * sizeof(unsigned int));
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset; iorequest.piod_offs = (void *)parm_offset;
iorequest.piod_addr = fsc.args32; iorequest.piod_addr = fsc->args32;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned int); iorequest.piod_len = (1 + nargs) * sizeof(unsigned int);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
for (i = 0; i < nargs + 1; i++) for (i = 0; i < nargs + 1; i++)
fsc.args[i] = fsc.args32[i]; fsc->args[i] = fsc->args32[i];
sc = NULL; sc = NULL;
if (fsc.name) if (fsc->name)
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -204,19 +209,19 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -228,30 +233,29 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "freebsd32_execve") == 0|| if (fsc->name != NULL && (strcmp(fsc->name, "freebsd32_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "freebsd32_execve") == 0) { if (strcmp(fsc->name, "freebsd32_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -265,16 +269,18 @@ long
amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd32_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -287,10 +293,11 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -305,18 +312,18 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "freebsd32_execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "freebsd32_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -324,9 +331,9 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -59,8 +59,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "linux32_syscalls.h" #include "linux32_syscalls.h"
static int nsyscalls = static int nsyscalls =
@ -75,28 +73,34 @@ static int nsyscalls =
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct linux_syscall { struct linux_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long args[5]; unsigned long args[5];
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct linux_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct linux_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct linux_syscall *fsc)
{ {
int i; int i;
if (fsc.s_args) { if (fsc->s_args) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
if (fsc.s_args[i]) free(fsc->s_args[i]);
free(fsc.s_args[i]); free(fsc->s_args);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -110,31 +114,34 @@ void
amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs) amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct reg regs; struct reg regs;
struct linux_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
int i, syscall_num; int i, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
syscall_num = regs.r_rax; syscall_num = regs.r_rax;
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : linux32_syscallnames[syscall_num]; NULL : linux32_syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "linux_fork") == 0|| (strcmp(fsc->name, "linux_fork") == 0 ||
strcmp(fsc.name, "linux_vfork") == 0)) strcmp(fsc->name, "linux_vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
@ -148,25 +155,25 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* that have more than five arguments? * that have more than five arguments?
*/ */
fsc.args[0] = regs.r_rbx; fsc->args[0] = regs.r_rbx;
fsc.args[1] = regs.r_rcx; fsc->args[1] = regs.r_rcx;
fsc.args[2] = regs.r_rdx; fsc->args[2] = regs.r_rdx;
fsc.args[3] = regs.r_rsi; fsc->args[3] = regs.r_rsi;
fsc.args[4] = regs.r_rdi; fsc->args[4] = regs.r_rdi;
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -176,19 +183,19 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -200,30 +207,29 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "linux_execve") == 0) { if (strcmp(fsc->name, "linux_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -246,16 +252,18 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
int syscall_num __unused) int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct linux_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -268,10 +276,11 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -286,12 +295,12 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
@ -308,13 +317,13 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
errorp ? i : retval, fsc.sc); errorp ? i : retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -77,30 +75,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -115,15 +118,15 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
unsigned int parm_offset; unsigned int parm_offset;
int i, syscall_num; int i, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -137,56 +140,59 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_eax; syscall_num = regs.r_eax;
switch (syscall_num) { switch (syscall_num) {
case SYS_syscall: case SYS_syscall:
syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0); syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(int); parm_offset += sizeof(int);
break; break;
case SYS___syscall: case SYS___syscall:
syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0); syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(quad_t); parm_offset += sizeof(quad_t);
break; break;
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset; iorequest.piod_offs = (void *)parm_offset;
iorequest.piod_addr = fsc.args; iorequest.piod_addr = fsc->args;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned long); iorequest.piod_len = (1 + nargs) * sizeof(unsigned long);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
sc = NULL; sc = NULL;
if (fsc.name) if (fsc->name)
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -196,19 +202,19 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -220,30 +226,29 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -257,16 +262,18 @@ long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -279,10 +286,11 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -297,18 +305,18 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -316,9 +324,9 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -59,8 +59,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "linux_syscalls.h" #include "linux_syscalls.h"
static int nsyscalls = static int nsyscalls =
@ -75,28 +73,34 @@ static int nsyscalls =
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct linux_syscall { struct linux_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long args[5]; unsigned long args[5];
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct linux_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct linux_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct linux_syscall *fsc)
{ {
int i; int i;
if (fsc.s_args) { if (fsc->s_args) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
if (fsc.s_args[i]) free(fsc->s_args[i]);
free(fsc.s_args[i]); free(fsc->s_args);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -110,31 +114,34 @@ void
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct reg regs; struct reg regs;
struct linux_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
int i, syscall_num; int i, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
syscall_num = regs.r_eax; syscall_num = regs.r_eax;
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : linux_syscallnames[syscall_num]; NULL : linux_syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "linux_fork") == 0 || (strcmp(fsc->name, "linux_fork") == 0 ||
strcmp(fsc.name, "linux_vfork") == 0)) strcmp(fsc->name, "linux_vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
@ -148,25 +155,25 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
* that have more than five arguments? * that have more than five arguments?
*/ */
fsc.args[0] = regs.r_ebx; fsc->args[0] = regs.r_ebx;
fsc.args[1] = regs.r_ecx; fsc->args[1] = regs.r_ecx;
fsc.args[2] = regs.r_edx; fsc->args[2] = regs.r_edx;
fsc.args[3] = regs.r_esi; fsc->args[3] = regs.r_esi;
fsc.args[4] = regs.r_edi; fsc->args[4] = regs.r_edi;
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -176,19 +183,19 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -200,30 +207,29 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "linux_execve") == 0) { if (strcmp(fsc->name, "linux_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -245,16 +251,18 @@ long
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct linux_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -267,10 +275,11 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -285,12 +294,12 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
@ -307,13 +316,13 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
errorp ? i : retval, fsc.sc); errorp ? i : retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -76,30 +74,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -113,15 +116,15 @@ void
ia64_syscall_entry(struct trussinfo *trussinfo, int nargs) ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
unsigned long *parm_offset; unsigned long *parm_offset;
lwpid_t tid;
int i, syscall_num; int i, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -136,39 +139,42 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) if (syscall_num == SYS_syscall || syscall_num == SYS___syscall)
syscall_num = (int)*parm_offset++; syscall_num = (int)*parm_offset++;
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
memcpy(fsc.args, parm_offset, nargs * sizeof(long)); memcpy(fsc->args, parm_offset, nargs * sizeof(long));
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -178,19 +184,19 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -202,30 +208,29 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -239,16 +244,18 @@ long
ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1); return (-1);
} }
@ -261,10 +268,11 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -279,27 +287,28 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
* It would probably be a good idea to merge the error handling, * It would probably be a good idea to merge the error handling,
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -163,6 +163,7 @@ strsig(int sig)
int int
main(int ac, char **av) main(int ac, char **av)
{ {
struct timespec timediff;
struct sigaction sa; struct sigaction sa;
struct ex_types *funcs; struct ex_types *funcs;
struct trussinfo *trussinfo; struct trussinfo *trussinfo;
@ -170,7 +171,7 @@ main(int ac, char **av)
char *signame; char *signame;
char **command; char **command;
pid_t childpid; pid_t childpid;
int c, i, initial_open, status; int c, initial_open, status;
fname = NULL; fname = NULL;
initial_open = 1; initial_open = 1;
@ -286,18 +287,17 @@ main(int ac, char **av)
clock_gettime(CLOCK_REALTIME, &trussinfo->start_time); clock_gettime(CLOCK_REALTIME, &trussinfo->start_time);
do { do {
struct timespec timediff;
waitevent(trussinfo); waitevent(trussinfo);
switch (i = trussinfo->pr_why) { switch (trussinfo->pr_why) {
case S_SCE: case S_SCE:
funcs->enter_syscall(trussinfo, MAXARGS); funcs->enter_syscall(trussinfo, MAXARGS);
clock_gettime(CLOCK_REALTIME, clock_gettime(CLOCK_REALTIME,
&trussinfo->before); &trussinfo->curthread->before);
break; break;
case S_SCX: case S_SCX:
clock_gettime(CLOCK_REALTIME, clock_gettime(CLOCK_REALTIME,
&trussinfo->after); &trussinfo->curthread->after);
if (trussinfo->curthread->in_fork && if (trussinfo->curthread->in_fork &&
(trussinfo->flags & FOLLOWFORKS)) { (trussinfo->flags & FOLLOWFORKS)) {
@ -326,15 +326,15 @@ main(int ac, char **av)
fprintf(trussinfo->outfile, "%5d: ", fprintf(trussinfo->outfile, "%5d: ",
trussinfo->pid); trussinfo->pid);
if (trussinfo->flags & ABSOLUTETIMESTAMPS) { if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
timespecsubt(&trussinfo->after, timespecsubt(&trussinfo->curthread->after,
&trussinfo->start_time, &timediff); &trussinfo->start_time, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ", fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, (long)timediff.tv_sec,
timediff.tv_nsec); timediff.tv_nsec);
} }
if (trussinfo->flags & RELATIVETIMESTAMPS) { if (trussinfo->flags & RELATIVETIMESTAMPS) {
timespecsubt(&trussinfo->after, timespecsubt(&trussinfo->curthread->after,
&trussinfo->before, &timediff); &trussinfo->curthread->before, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ", fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, (long)timediff.tv_sec,
timediff.tv_nsec); timediff.tv_nsec);
@ -352,15 +352,15 @@ main(int ac, char **av)
fprintf(trussinfo->outfile, "%5d: ", fprintf(trussinfo->outfile, "%5d: ",
trussinfo->pid); trussinfo->pid);
if (trussinfo->flags & ABSOLUTETIMESTAMPS) { if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
timespecsubt(&trussinfo->after, timespecsubt(&trussinfo->curthread->after,
&trussinfo->start_time, &timediff); &trussinfo->start_time, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ", fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, (long)timediff.tv_sec,
timediff.tv_nsec); timediff.tv_nsec);
} }
if (trussinfo->flags & RELATIVETIMESTAMPS) { if (trussinfo->flags & RELATIVETIMESTAMPS) {
timespecsubt(&trussinfo->after, timespecsubt(&trussinfo->curthread->after,
&trussinfo->before, &timediff); &trussinfo->curthread->before, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ", fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec); (long)timediff.tv_sec, timediff.tv_nsec);
} }

View File

@ -66,8 +66,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -81,30 +79,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -119,15 +122,15 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
int i, syscall_num; int i, syscall_num;
int indir; /* indirect system call */ int indir; /* indirect system call */
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -139,30 +142,33 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_regs[A0]; syscall_num = regs.r_regs[A0];
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
#if 0 // XXX #if 0 // XXX
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset; iorequest.piod_offs = (void *)parm_offset;
iorequest.piod_addr = fsc.args; iorequest.piod_addr = fsc->args;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned long); iorequest.piod_len = (1 + nargs) * sizeof(unsigned long);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
#else #else
@ -192,35 +198,35 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_regs[SP] + iorequest.piod_offs = (void *)(regs.r_regs[SP] +
4 * sizeof(uint32_t)); 4 * sizeof(uint32_t));
iorequest.piod_addr = &fsc.args[4]; iorequest.piod_addr = &fsc->args[4];
iorequest.piod_len = (nargs - 4) * sizeof(fsc.args[0]); iorequest.piod_len = (nargs - 4) * sizeof(fsc->args[0]);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
case 4: fsc.args[3] = regs.r_regs[A3]; case 4: fsc->args[3] = regs.r_regs[A3];
case 3: fsc.args[2] = regs.r_regs[A2]; case 3: fsc->args[2] = regs.r_regs[A2];
case 2: fsc.args[1] = regs.r_regs[A1]; case 2: fsc->args[1] = regs.r_regs[A1];
case 1: fsc.args[0] = regs.r_regs[A0]; case 1: fsc->args[0] = regs.r_regs[A0];
case 0: break; case 0: break;
} }
if (indir) { if (indir) {
memmove(&fsc.args[0], &fsc.args[1], memmove(&fsc->args[0], &fsc->args[1],
(nargs - 1) * sizeof(fsc.args[0])); (nargs - 1) * sizeof(fsc->args[0]));
} }
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -230,19 +236,19 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -254,30 +260,29 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -291,16 +296,18 @@ long
mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
return (-1); return (-1);
} }
@ -313,10 +320,11 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -331,18 +339,18 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -350,9 +358,9 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#ifdef __powerpc64__ /* 32-bit compatibility */ #ifdef __powerpc64__ /* 32-bit compatibility */
#include "freebsd32_syscalls.h" #include "freebsd32_syscalls.h"
#define syscallnames freebsd32_syscallnames #define syscallnames freebsd32_syscallnames
@ -81,30 +79,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -119,18 +122,18 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
void *args; void *args;
lwpid_t tid;
int i, regargs, syscall_num; int i, regargs, syscall_num;
/* Account for a 64-bit argument with corresponding alignment. */ /* Account for a 64-bit argument with corresponding alignment. */
nargs += 2; nargs += 2;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -153,51 +156,54 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.fixreg[4]; syscall_num = regs.fixreg[4];
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
if (nargs > regargs) { if (nargs > regargs) {
memmove(&fsc.args[0], args, regargs * sizeof(fsc.args[0])); memmove(&fsc->args[0], args, regargs * sizeof(fsc->args[0]));
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.fixreg[1] + 8); iorequest.piod_offs = (void *)(regs.fixreg[1] + 8);
iorequest.piod_addr = &fsc.args[regargs]; iorequest.piod_addr = &fsc->args[regargs];
iorequest.piod_len = (nargs - regargs) * sizeof(fsc.args[0]); iorequest.piod_len = (nargs - regargs) * sizeof(fsc->args[0]);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
} else } else
memmove(&fsc.args[0], args, nargs * sizeof(fsc.args[0])); memmove(&fsc->args[0], args, nargs * sizeof(fsc->args[0]));
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -207,19 +213,19 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -231,30 +237,29 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -268,16 +273,18 @@ long
powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
return (-1); return (-1);
} }
@ -290,10 +297,11 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* On 32-bit big-endian, the low word of a 64-bit return is * On 32-bit big-endian, the low word of a 64-bit return is
@ -316,18 +324,18 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -335,9 +343,9 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -76,30 +74,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -114,15 +117,15 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
void *args; void *args;
lwpid_t tid;
int i, regargs, syscall_num; int i, regargs, syscall_num;
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -141,51 +144,54 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.fixreg[3]; syscall_num = regs.fixreg[3];
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
if (nargs > regargs) { if (nargs > regargs) {
memmove(&fsc.args[0], args, regargs * sizeof(fsc.args[0])); memmove(&fsc->args[0], args, regargs * sizeof(fsc->args[0]));
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.fixreg[1] + 48); iorequest.piod_offs = (void *)(regs.fixreg[1] + 48);
iorequest.piod_addr = &fsc.args[regargs]; iorequest.piod_addr = &fsc->args[regargs];
iorequest.piod_len = (nargs - regargs) * sizeof(fsc.args[0]); iorequest.piod_len = (nargs - regargs) * sizeof(fsc->args[0]);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
} else } else
memmove(&fsc.args[0], args, nargs * sizeof(fsc.args[0])); memmove(&fsc->args[0], args, nargs * sizeof(fsc->args[0]));
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -195,19 +201,19 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -219,30 +225,29 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name && (strcmp(fsc.name, "execve") == 0 || if (fsc->name && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -256,16 +261,18 @@ long
powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
return (-1); return (-1);
} }
@ -278,10 +285,11 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -296,18 +304,18 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -315,9 +323,9 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -161,12 +161,10 @@ find_thread(struct trussinfo *info, lwpid_t lwpid)
} }
} }
np = (struct threadinfo *)malloc(sizeof(struct threadinfo)); np = (struct threadinfo *)calloc(1, sizeof(struct threadinfo));
if (np == NULL) if (np == NULL)
errx(1, "malloc() failed"); err(1, "calloc() failed");
np->tid = lwpid; np->tid = lwpid;
np->in_fork = 0;
np->in_syscall = 0;
SLIST_INSERT_HEAD(&info->threadlist, np, entries); SLIST_INSERT_HEAD(&info->threadlist, np, entries);
info->curthread = np; info->curthread = np;
} }

View File

@ -67,8 +67,6 @@ static const char rcsid[] =
#include "syscall.h" #include "syscall.h"
#include "extern.h" #include "extern.h"
static int cpid = -1;
#include "syscalls.h" #include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@ -82,30 +80,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however, * 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet. * if we don't know about this particular system call yet.
*/ */
static struct freebsd_syscall { struct freebsd_syscall {
struct syscall *sc; struct syscall *sc;
const char *name; const char *name;
int number; int number;
unsigned long *args; unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */ int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */ char **s_args; /* the printable arguments */
} fsc; };
static struct freebsd_syscall *
alloc_fsc(void)
{
return (malloc(sizeof(struct freebsd_syscall)));
}
/* Clear up and free parts of the fsc structure. */ /* Clear up and free parts of the fsc structure. */
static __inline void static void
clear_fsc(void) free_fsc(struct freebsd_syscall *fsc)
{ {
int i; int i;
if (fsc.args) free(fsc->args);
free(fsc.args); if (fsc->s_args) {
if (fsc.s_args) { for (i = 0; i < fsc->nargs; i++)
for (i = 0; i < fsc.nargs; i++) free(fsc->s_args[i]);
if (fsc.s_args[i]) free(fsc->s_args);
free(fsc.s_args[i]);
free(fsc.s_args);
} }
memset(&fsc, 0, sizeof(fsc)); free(fsc);
} }
/* /*
@ -120,15 +123,15 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{ {
struct ptrace_io_desc iorequest; struct ptrace_io_desc iorequest;
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
int i, syscall_num; int i, syscall_num;
int indir; /* indirect system call */ int indir; /* indirect system call */
clear_fsc(); tid = trussinfo->curthread->tid;
cpid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return; return;
} }
@ -145,24 +148,27 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_out[0]; syscall_num = regs.r_out[0];
} }
fsc.number = syscall_num; fsc = alloc_fsc();
fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ? if (fsc == NULL)
return;
fsc->number = syscall_num;
fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num]; NULL : syscallnames[syscall_num];
if (!fsc.name) { if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num); syscall_num);
} }
if (fsc.name && (trussinfo->flags & FOLLOWFORKS) && if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
(strcmp(fsc.name, "fork") == 0 || (strcmp(fsc->name, "fork") == 0 ||
strcmp(fsc.name, "rfork") == 0 || strcmp(fsc->name, "rfork") == 0 ||
strcmp(fsc.name, "vfork") == 0)) strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1; trussinfo->curthread->in_fork = 1;
if (nargs == 0) if (nargs == 0)
return; return;
fsc.args = malloc((1 + nargs) * sizeof(unsigned long)); fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
switch (nargs) { switch (nargs) {
default: default:
/* /*
@ -183,38 +189,38 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
iorequest.piod_op = PIOD_READ_D; iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF + iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF +
offsetof(struct frame, fr_pad[6])); offsetof(struct frame, fr_pad[6]));
iorequest.piod_addr = &fsc.args[6]; iorequest.piod_addr = &fsc->args[6];
iorequest.piod_len = (nargs - 6) * sizeof(fsc.args[0]); iorequest.piod_len = (nargs - 6) * sizeof(fsc->args[0]);
ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0); ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0) if (iorequest.piod_len == 0)
return; return;
case 6: fsc.args[5] = regs.r_out[5]; case 6: fsc->args[5] = regs.r_out[5];
case 5: fsc.args[4] = regs.r_out[4]; case 5: fsc->args[4] = regs.r_out[4];
case 4: fsc.args[3] = regs.r_out[3]; case 4: fsc->args[3] = regs.r_out[3];
case 3: fsc.args[2] = regs.r_out[2]; case 3: fsc->args[2] = regs.r_out[2];
case 2: fsc.args[1] = regs.r_out[1]; case 2: fsc->args[1] = regs.r_out[1];
case 1: fsc.args[0] = regs.r_out[0]; case 1: fsc->args[0] = regs.r_out[0];
case 0: case 0:
break; break;
} }
if (indir) if (indir)
memmove(&fsc.args[0], &fsc.args[1], (nargs - 1) * memmove(&fsc->args[0], &fsc->args[1], (nargs - 1) *
sizeof(fsc.args[0])); sizeof(fsc->args[0]));
sc = get_syscall(fsc.name); sc = get_syscall(fsc->name);
if (sc) if (sc)
fsc.nargs = sc->nargs; fsc->nargs = sc->nargs;
else { else {
#if DEBUG #if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting " fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
"args to %d\n", fsc.name, nargs); "args to %d\n", fsc->name, nargs);
#endif #endif
fsc.nargs = nargs; fsc->nargs = nargs;
} }
fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *)); fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
fsc.sc = sc; fsc->sc = sc;
/* /*
* At this point, we set up the system call arguments. * At this point, we set up the system call arguments.
@ -224,19 +230,19 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however. * passed in *and* out, however.
*/ */
if (fsc.name) { if (fsc->name) {
#if DEBUG #if DEBUG
fprintf(stderr, "syscall %s(", fsc.name); fprintf(stderr, "syscall %s(", fsc->name);
#endif #endif
for (i = 0; i < fsc.nargs; i++) { for (i = 0; i < fsc->nargs; i++) {
#if DEBUG #if DEBUG
fprintf(stderr, "0x%x%s", sc ? fprintf(stderr, "0x%x%s", sc ?
fsc.args[sc->args[i].offset] : fsc.args[i], fsc->args[sc->args[i].offset] : fsc->args[i],
i < (fsc.nargs - 1) ? "," : ""); i < (fsc->nargs - 1) ? "," : "");
#endif #endif
if (sc && !(sc->args[i].type & OUT)) { if (sc && !(sc->args[i].type & OUT)) {
fsc.s_args[i] = print_arg(&sc->args[i], fsc->s_args[i] = print_arg(&sc->args[i],
fsc.args, 0, trussinfo); fsc->args, 0, trussinfo);
} }
} }
#if DEBUG #if DEBUG
@ -248,30 +254,29 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
#endif #endif
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) { strcmp(fsc->name, "exit") == 0)) {
/* /*
* XXX * XXX
* This could be done in a more general * This could be done in a more general
* manner but it still wouldn't be very pretty. * manner but it still wouldn't be very pretty.
*/ */
if (strcmp(fsc.name, "execve") == 0) { if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) { if ((trussinfo->flags & EXECVEARGS) == 0) {
if (fsc.s_args[1]) { if (fsc->s_args[1]) {
free(fsc.s_args[1]); free(fsc->s_args[1]);
fsc.s_args[1] = NULL; fsc->s_args[1] = NULL;
} }
} }
if ((trussinfo->flags & EXECVEENVS) == 0) { if ((trussinfo->flags & EXECVEENVS) == 0) {
if (fsc.s_args[2]) { if (fsc->s_args[2]) {
free(fsc.s_args[2]); free(fsc->s_args[2]);
fsc.s_args[2] = NULL; fsc->s_args[2] = NULL;
} }
} }
} }
} }
trussinfo->curthread->fsc = fsc;
return;
} }
/* /*
@ -285,16 +290,18 @@ long
sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{ {
struct reg regs; struct reg regs;
struct freebsd_syscall *fsc;
struct syscall *sc; struct syscall *sc;
lwpid_t tid;
long retval; long retval;
int errorp, i; int errorp, i;
if (fsc.name == NULL) if (trussinfo->curthread->fsc == NULL)
return (-1); return (-1);
cpid = trussinfo->curthread->tid; tid = trussinfo->curthread->tid;
if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) { if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n"); fprintf(trussinfo->outfile, "\n");
return (-1); return (-1);
} }
@ -307,10 +314,11 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning. * stand some significant cleaning.
*/ */
sc = fsc.sc; fsc = trussinfo->curthread->fsc;
sc = fsc->sc;
if (!sc) { if (!sc) {
for (i = 0; i < fsc.nargs; i++) for (i = 0; i < fsc->nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]); asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else { } else {
/* /*
* Here, we only look for arguments that have OUT masked in -- * Here, we only look for arguments that have OUT masked in --
@ -325,18 +333,18 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/ */
if (errorp) { if (errorp) {
asprintf(&temp, "0x%lx", asprintf(&temp, "0x%lx",
fsc.args[sc->args[i].offset]); fsc->args[sc->args[i].offset]);
} else { } else {
temp = print_arg(&sc->args[i], temp = print_arg(&sc->args[i],
fsc.args, retval, trussinfo); fsc->args, retval, trussinfo);
} }
fsc.s_args[i] = temp; fsc->s_args[i] = temp;
} }
} }
} }
if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 || if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
strcmp(fsc.name, "exit") == 0)) strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1; trussinfo->curthread->in_syscall = 1;
/* /*
@ -344,9 +352,9 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably. * but that complicates things considerably.
*/ */
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
retval, fsc.sc); retval, fsc->sc);
clear_fsc(); free_fsc(fsc);
return (retval); return (retval);
} }

View File

@ -1120,20 +1120,21 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs,
if (trussinfo->flags & FOLLOWFORKS) if (trussinfo->flags & FOLLOWFORKS)
len += fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid); len += fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid);
if (name != NULL && (strcmp(name, "execve") == 0|| if (name != NULL && (strcmp(name, "execve") == 0 ||
strcmp(name, "exit") == 0)) { strcmp(name, "exit") == 0)) {
clock_gettime(CLOCK_REALTIME, &trussinfo->after); clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->after);
} }
if (trussinfo->flags & ABSOLUTETIMESTAMPS) { if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
timespecsubt(&trussinfo->after, &trussinfo->start_time, timespecsubt(&trussinfo->curthread->after,
&timediff); &trussinfo->start_time, &timediff);
len += fprintf(trussinfo->outfile, "%ld.%09ld ", len += fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec); (long)timediff.tv_sec, timediff.tv_nsec);
} }
if (trussinfo->flags & RELATIVETIMESTAMPS) { if (trussinfo->flags & RELATIVETIMESTAMPS) {
timespecsubt(&trussinfo->after, &trussinfo->before, &timediff); timespecsubt(&trussinfo->curthread->after,
&trussinfo->curthread->before, &timediff);
len += fprintf(trussinfo->outfile, "%ld.%09ld ", len += fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec); (long)timediff.tv_sec, timediff.tv_nsec);
} }
@ -1163,8 +1164,9 @@ print_syscall_ret(struct trussinfo *trussinfo, const char *name, int nargs,
if (trussinfo->flags & COUNTONLY) { if (trussinfo->flags & COUNTONLY) {
if (!sc) if (!sc)
return; return;
clock_gettime(CLOCK_REALTIME, &trussinfo->after); clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->after);
timespecsubt(&trussinfo->after, &trussinfo->before, &timediff); timespecsubt(&trussinfo->curthread->after,
&trussinfo->curthread->before, &timediff);
timespecadd(&sc->time, &timediff, &sc->time); timespecadd(&sc->time, &timediff, &sc->time);
sc->ncalls++; sc->ncalls++;
if (errorp) if (errorp)

View File

@ -41,6 +41,9 @@ struct threadinfo
lwpid_t tid; lwpid_t tid;
int in_syscall; int in_syscall;
int in_fork; int in_fork;
void *fsc;
struct timespec before;
struct timespec after;
}; };
struct trussinfo struct trussinfo
@ -53,8 +56,6 @@ struct trussinfo
FILE *outfile; FILE *outfile;
struct timespec start_time; struct timespec start_time;
struct timespec before;
struct timespec after;
struct threadinfo *curthread; struct threadinfo *curthread;