summaryrefslogtreecommitdiffstats
path: root/usr.bin/truss/syscalls.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2003-11-09 03:48:13 +0000
committermarcel <marcel@FreeBSD.org>2003-11-09 03:48:13 +0000
commit3f532e652b08331243d297085d4f13318e94f586 (patch)
tree89caf91024722473ad91738e243659a20d561f8b /usr.bin/truss/syscalls.c
parent9162843df044ab6081d73ed699fe186f4a6fe779 (diff)
downloadFreeBSD-src-3f532e652b08331243d297085d4f13318e94f586.zip
FreeBSD-src-3f532e652b08331243d297085d4f13318e94f586.tar.gz
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.
Diffstat (limited to 'usr.bin/truss/syscalls.c')
-rw-r--r--usr.bin/truss/syscalls.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c
index 1b7318e..7d02183 100644
--- a/usr.bin/truss/syscalls.c
+++ b/usr.bin/truss/syscalls.c
@@ -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);
}
}
OpenPOWER on IntegriCloud