From: Denys Vlasenko Date: Thu, 16 Apr 2009 12:06:16 +0000 (+0000) Subject: * file.c (print_dirfd): Use int for file descriptor, not a long. X-Git-Tag: v4.5.19~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e740fd31d2dd4720de2c39f10b5096e9eac40484;p=strace * file.c (print_dirfd): Use int for file descriptor, not a long. * process.c (printwaitn): Use int for PID, not a long. --- diff --git a/ChangeLog b/ChangeLog index 6ae08a34..0db8a630 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-16 Denys Vlasenko + + * file.c (print_dirfd): Use int for file descriptor, not a long. + * process.c (printwaitn): Use int for PID, not a long. + 2009-04-15 Denys Vlasenko * signal (sys_rt_sigtimedwait): Fix sigtimedwait syscall decoding. @@ -86,7 +91,7 @@ In some cases, missing error checking is added. Error handling for trace_syscall() failures and other cases where tcp->ptrace_errno is nonzero is cleaned up a bit - and made more verbose if we see error other than ESRC. + and made more verbose if we see error other than ESRCH. Some comments are added or expanded. * defs.h: Declare ptrace_cmds[]. Modify do_ptrace declaration (last parameter is long, not void *). diff --git a/file.c b/file.c index a8401cfa..080e10b0 100644 --- a/file.c +++ b/file.c @@ -327,13 +327,16 @@ const struct xlat open_mode_flags[] = { # define AT_FDCWD -100 #endif +/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign + * extension to get the right value. We do this by declaring fd as int here. + */ static void -print_dirfd(long fd) +print_dirfd(int fd) { if (fd == AT_FDCWD) tprintf("AT_FDCWD, "); else - tprintf("%ld, ", fd); + tprintf("%d, ", fd); } #endif diff --git a/process.c b/process.c index 9ddae086..1ddf2f32 100644 --- a/process.c +++ b/process.c @@ -1998,21 +1998,24 @@ printwaitn(struct tcb *tcp, int n, int bitness) int exited = 0; if (entering(tcp)) { - /* - * Sign-extend a 32-bit value when that's what it is. - * - * NB: On Linux, kernel-side pid_t is typedef'ed to int - * on all arches; also, glibc-2.8 truncates wait3 and wait4 +#ifdef LINUX + /* On Linux, kernel-side pid_t is typedef'ed to int + * on all arches. Also, glibc-2.8 truncates wait3 and wait4 * pid argument to int on 64bit arches, producing, * for example, wait4(4294967295, ...) instead of -1 - * in strace. - * Therefore, maybe it makes sense to *unconditionally* - * widen int to long here... + * in strace. We have to use int here, not long. + */ + int pid = tcp->u_arg[0]; + tprintf("%d, ", pid); +#else + /* + * Sign-extend a 32-bit value when that's what it is. */ long pid = tcp->u_arg[0]; if (personality_wordsize[current_personality] < sizeof pid) pid = (long) (int) pid; tprintf("%ld, ", pid); +#endif } else { /* status */ if (!tcp->u_arg[1])