Port truss(1) to 64-bit architectures:

o  Syscall return values do not fit in int on 64-bit architectures.
   Change the type of retval in <arch>_syscall_exit() to long and
   change the prototype of said function to return a long as well.
o  Change the prototype of print_syscall_ret() to take a long for
   the return address and change the format string accordingly.
o  Replace the code sequence
	tmp = malloc(X);
	sprintf(tmp, format, ...);
   with X by definition too small on 64-bit platforms by
        asprintf(&tmp, format, ...);

With these changes the output makes sense again, although it does
mess up the tabulation on ia64. Go widescreen...

Not tested on: alpha, sparc64.
This commit is contained in:
Marcel Moolenaar 2003-11-09 03:48:13 +00:00
parent 68153f43b6
commit 1bcb5f5a96
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122348
11 changed files with 84 additions and 113 deletions

View File

@ -291,11 +291,12 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
* the sytem call number instead of, say, an error status).
*/
int
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -325,10 +326,8 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -341,12 +340,10 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -270,11 +270,12 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
* the sytem call number instead of, say, an error status).
*/
int
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -304,10 +305,8 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -320,12 +319,10 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -261,11 +261,12 @@ const int bsd_to_linux_errno[] = {
-6,
};
int
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -295,10 +296,8 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -311,12 +310,10 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -37,19 +37,19 @@ extern void restore_proc(int);
extern const char *ioctlname(register_t val);
#ifdef __alpha__
extern void alpha_syscall_entry(struct trussinfo *, int);
extern int alpha_syscall_exit(struct trussinfo *, int);
extern long alpha_syscall_exit(struct trussinfo *, int);
#endif
#ifdef __i386__
extern void i386_syscall_entry(struct trussinfo *, int);
extern int i386_syscall_exit(struct trussinfo *, int);
extern long i386_syscall_exit(struct trussinfo *, int);
extern void i386_linux_syscall_entry(struct trussinfo *, int);
extern int i386_linux_syscall_exit(struct trussinfo *, int);
extern long i386_linux_syscall_exit(struct trussinfo *, int);
#endif
#ifdef __ia64__
extern void ia64_syscall_entry(struct trussinfo *, int);
extern int ia64_syscall_exit(struct trussinfo *, int);
extern long ia64_syscall_exit(struct trussinfo *, int);
#endif
#ifdef __sparc64__
extern void sparc64_syscall_entry(struct trussinfo *, int);
extern int sparc64_syscall_exit(struct trussinfo *, int);
extern long sparc64_syscall_exit(struct trussinfo *, int);
#endif

View File

@ -270,11 +270,12 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
* the sytem call number instead of, say, an error status).
*/
int
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -304,10 +305,8 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -320,12 +319,10 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -261,11 +261,12 @@ const int bsd_to_linux_errno[] = {
-6,
};
int
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -295,10 +296,8 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -311,12 +310,10 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -257,11 +257,12 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
* the sytem call number instead of, say, an error status).
*/
int
ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
long
ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -291,10 +292,8 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -307,12 +306,10 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -79,7 +79,7 @@ usage(void)
struct ex_types {
const char *type;
void (*enter_syscall)(struct trussinfo *, int);
int (*exit_syscall)(struct trussinfo *, int);
long (*exit_syscall)(struct trussinfo *, int);
} ex_types[] = {
#ifdef __alpha__
{ "FreeBSD ELF", alpha_syscall_entry, alpha_syscall_exit },

View File

@ -293,11 +293,11 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
* the sytem call number instead of, say, an error status).
*/
int
long
sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
char buf[32];
struct reg regs;
int retval;
long retval;
int i;
int errorp;
struct syscall *sc;
@ -327,10 +327,8 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
sc = fsc.sc;
if (!sc) {
for (i = 0; i < fsc.nargs; i++) {
fsc.s_args[i] = malloc(12);
sprintf(fsc.s_args[i], "0x%lx", fsc.args[i]);
}
for (i = 0; i < fsc.nargs; i++)
asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@ -343,12 +341,10 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
* If an error occurred, than don't bothe getting the data;
* it may not be valid.
*/
if (errorp) {
temp = malloc(12);
sprintf(temp, "0x%lx", fsc.args[sc->args[i].offset]);
} else {
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
temp = print_arg(Procfd, &sc->args[i], fsc.args);
}
fsc.s_args[i] = temp;
}
}

View File

@ -45,4 +45,5 @@ struct syscall *get_syscall(const char*);
char *get_string(int, void*, int);
char *print_arg(int, struct syscall_args *, unsigned long*);
void print_syscall(struct trussinfo *, const char *, int, char **);
void print_syscall_ret(struct trussinfo *, const char *, int, char **, int, int);
void print_syscall_ret(struct trussinfo *, const char *, int, char **, int,
long);

View File

@ -257,23 +257,19 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
char *tmp = NULL;
switch (sc->type & ARG_MASK) {
case Hex:
tmp = malloc(12);
sprintf(tmp, "0x%lx", args[sc->offset]);
asprintf(&tmp, "0x%lx", args[sc->offset]);
break;
case Octal:
tmp = malloc(13);
sprintf(tmp, "0%lo", args[sc->offset]);
asprintf(&tmp, "0%lo", args[sc->offset]);
break;
case Int:
tmp = malloc(12);
sprintf(tmp, "%ld", args[sc->offset]);
asprintf(&tmp, "%ld", args[sc->offset]);
break;
case String:
{
char *tmp2;
tmp2 = get_string(fd, (void*)args[sc->offset], 0);
tmp = malloc(strlen(tmp2) + 3);
sprintf(tmp, "\"%s\"", tmp2);
asprintf(&tmp, "\"%s\"", tmp2);
free(tmp2);
}
break;
@ -318,23 +314,19 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
l1 = args[sc->offset];
l2 = args[sc->offset+1];
t = make_quad(l1, l2);
tmp = malloc(24);
sprintf(tmp, "0x%qx", t);
asprintf(&tmp, "0x%qx", t);
break;
}
case Ptr:
tmp = malloc(12);
sprintf(tmp, "0x%lx", args[sc->offset]);
asprintf(&tmp, "0x%lx", args[sc->offset]);
break;
case Ioctl:
{
const char *temp = ioctlname(args[sc->offset]);
if (temp)
tmp = strdup(temp);
else {
tmp = malloc(12);
sprintf(tmp, "0x%lx", args[sc->offset]);
}
else
asprintf(&tmp, "0x%lx", args[sc->offset]);
}
break;
case Signal:
@ -342,15 +334,13 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
long sig;
sig = args[sc->offset];
tmp = malloc(12);
if (sig > 0 && sig < NSIG) {
int i;
sprintf(tmp, "sig%s", sys_signame[sig]);
asprintf(&tmp, "sig%s", sys_signame[sig]);
for (i = 0; tmp[i] != '\0'; ++i)
tmp[i] = toupper(tmp[i]);
} else {
sprintf(tmp, "%ld", sig);
}
} else
asprintf(&tmp, "%ld", sig);
}
break;
case Sockaddr:
@ -475,11 +465,13 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs, char **s
}
void
print_syscall_ret(struct trussinfo *trussinfo, const char *name, int nargs, char **s_args, int errorp, int retval) {
print_syscall_ret(struct trussinfo *trussinfo, const char *name, int nargs,
char **s_args, int errorp, long retval)
{
print_syscall(trussinfo, name, nargs, s_args);
if (errorp) {
fprintf(trussinfo->outfile, " ERR#%d '%s'\n", retval, strerror(retval));
} else {
fprintf(trussinfo->outfile, " = %d (0x%x)\n", retval, retval);
fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval, retval);
}
}