From: Dmitry V. Levin Date: Fri, 17 Jun 2016 16:12:13 +0000 (+0000) Subject: Introduce HAVE_STRUCT_TCB_EXT_ARG macro X-Git-Tag: v4.13~128 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0c51131a38355dfaaed5b13b887f333cb20dfa7;p=strace Introduce HAVE_STRUCT_TCB_EXT_ARG macro Check for "if HAVE_STRUCT_TCB_EXT_ARG" instead of "if defined LINUX_MIPSN32 || defined X32". * defs.h (HAVE_STRUCT_TCB_EXT_ARG): Define for LINUX_MIPSN32 || X32. (struct tcb): Check it instead of LINUX_MIPSN32 || X32. (RVAL_LUDECIMAL): Likewise. * io.c (print_lld_from_low_high_val): Likewise. * lseek.c (SYS_FUNC(lseek)): Likewise. * mem.c (SYS_FUNC(mmap)): Likewise. * syscall.c (trace_syscall_exiting): Likewise. * util.c (getllval): Likewise. --- diff --git a/defs.h b/defs.h index 724d4f3c..61794d4a 100644 --- a/defs.h +++ b/defs.h @@ -288,6 +288,12 @@ typedef struct ioctlent { unsigned int code; } struct_ioctlent; +#if defined LINUX_MIPSN32 || defined X32 +# define HAVE_STRUCT_TCB_EXT_ARG 1 +#else +# define HAVE_STRUCT_TCB_EXT_ARG 0 +#endif + /* Trace Control Block */ struct tcb { int flags; /* See below for TCB_ values */ @@ -296,7 +302,7 @@ struct tcb { int u_error; /* Error code */ long scno; /* System call number */ long u_arg[MAX_ARGS]; /* System call arguments */ -#if defined(LINUX_MIPSN32) || defined(X32) +#if HAVE_STRUCT_TCB_EXT_ARG long long ext_arg[MAX_ARGS]; long long u_lrval; /* long long return value */ #endif @@ -382,14 +388,14 @@ extern const struct xlat whence_codes[]; #define RVAL_HEX 001 /* hex format */ #define RVAL_OCTAL 002 /* octal format */ #define RVAL_UDECIMAL 003 /* unsigned decimal format */ -#if defined(LINUX_MIPSN32) || defined(X32) +#if HAVE_STRUCT_TCB_EXT_ARG # if 0 /* unused so far */ # define RVAL_LDECIMAL 004 /* long decimal format */ # define RVAL_LHEX 005 /* long hex format */ # define RVAL_LOCTAL 006 /* long octal format */ # endif # define RVAL_LUDECIMAL 007 /* long unsigned decimal format */ -#endif +#endif /* HAVE_STRUCT_TCB_EXT_ARG */ #define RVAL_FD 010 /* file descriptor */ #define RVAL_MASK 017 /* mask for these values */ diff --git a/io.c b/io.c index 87b5f47f..3025486b 100644 --- a/io.c +++ b/io.c @@ -180,7 +180,7 @@ SYS_FUNC(pwrite) static void print_lld_from_low_high_val(struct tcb *tcp, int arg) { -#if SIZEOF_LONG == SIZEOF_LONG_LONG +#if SIZEOF_LONG > 4 && SIZEOF_LONG == SIZEOF_LONG_LONG # if SUPPORTED_PERSONALITIES > 1 # ifdef X86_64 if (current_personality != 1) @@ -195,12 +195,20 @@ print_lld_from_low_high_val(struct tcb *tcp, int arg) ((unsigned long) tcp->u_arg[arg + 1] << current_wordsize * 8) | (unsigned long) tcp->u_arg[arg]); # endif -#else -# ifdef X32 - if (current_personality == 0) - tprintf("%lld", tcp->ext_arg[arg]); - else +#elif SIZEOF_LONG > 4 +# error Unsupported configuration: SIZEOF_LONG > 4 && SIZEOF_LONG_LONG > SIZEOF_LONG +#elif HAVE_STRUCT_TCB_EXT_ARG +# if SUPPORTED_PERSONALITIES > 1 + if (current_personality == 1) { + tprintf("%lld", + (widen_to_ull(tcp->u_arg[arg + 1]) << sizeof(long) * 8) + | widen_to_ull(tcp->u_arg[arg])); + } else # endif + { + tprintf("%lld", tcp->ext_arg[arg]); + } +#else /* SIZEOF_LONG_LONG > SIZEOF_LONG && !HAVE_STRUCT_TCB_EXT_ARG */ tprintf("%lld", (widen_to_ull(tcp->u_arg[arg + 1]) << sizeof(long) * 8) | widen_to_ull(tcp->u_arg[arg])); diff --git a/lseek.c b/lseek.c index 133ddd85..8d05dc1a 100644 --- a/lseek.c +++ b/lseek.c @@ -44,19 +44,21 @@ * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument. * Use test/x32_lseek.c to test lseek decoding. */ -#if defined(LINUX_MIPSN32) || defined(X32) +#if HAVE_STRUCT_TCB_EXT_ARG SYS_FUNC(lseek) { printfd(tcp, tcp->u_arg[0]); long long offset; -# ifdef X32 - /* tcp->ext_arg is not initialized for i386 personality */ - if (current_personality == 1) +# if SUPPORTED_PERSONALITIES > 1 + /* tcp->ext_arg is not initialized for compat personality */ + if (current_personality == 1) { offset = tcp->u_arg[1]; - else + } else # endif - offset = tcp->ext_arg[1]; + { + offset = tcp->ext_arg[1]; + } int whence = tcp->u_arg[2]; tprintf(", %lld, ", offset); diff --git a/mem.c b/mem.c index b2c7abbc..affc9355 100644 --- a/mem.c +++ b/mem.c @@ -135,10 +135,11 @@ SYS_FUNC(old_mmap_pgoff) /* Params are passed directly, offset is in bytes */ SYS_FUNC(mmap) { - unsigned long long offset = (unsigned long) tcp->u_arg[5]; -#if defined(LINUX_MIPSN32) || defined(X32) - /* Try test/x32_mmap.c */ - offset = tcp->ext_arg[5]; + unsigned long long offset = +#if HAVE_STRUCT_TCB_EXT_ARG + tcp->ext_arg[5]; /* try test/x32_mmap.c */ +#else + (unsigned long) tcp->u_arg[5]; #endif /* Example of kernel-side handling of this variety of mmap: * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls diff --git a/syscall.c b/syscall.c index 01e4b31d..c61f827e 100644 --- a/syscall.c +++ b/syscall.c @@ -1042,7 +1042,7 @@ trace_syscall_exiting(struct tcb *tcp) else tprintf("= %ld", tcp->u_rval); break; -#if defined(LINUX_MIPSN32) || defined(X32) +#if HAVE_STRUCT_TCB_EXT_ARG /* case RVAL_LHEX: tprintf("= %#llx", tcp->u_lrval); @@ -1059,7 +1059,7 @@ trace_syscall_exiting(struct tcb *tcp) tprintf("= %lld", tcp->u_lrval); break; */ -#endif +#endif /* HAVE_STRUCT_TCB_EXT_ARG */ default: error_msg("invalid rval format"); break; diff --git a/util.c b/util.c index ea2e8699..bb23eeb5 100644 --- a/util.c +++ b/util.c @@ -257,16 +257,16 @@ getllval(struct tcb *tcp, unsigned long long *val, int arg_no) # endif /* SUPPORTED_PERSONALITIES > 1 */ #elif SIZEOF_LONG > 4 # error Unsupported configuration: SIZEOF_LONG > 4 && SIZEOF_LONG_LONG > SIZEOF_LONG -#elif defined LINUX_MIPSN32 - *val = tcp->ext_arg[arg_no]; - arg_no++; -#elif defined X32 - if (current_personality == 0) { - *val = tcp->ext_arg[arg_no]; - arg_no++; - } else { +#elif HAVE_STRUCT_TCB_EXT_ARG +# if SUPPORTED_PERSONALITIES > 1 + if (current_personality == 1) { *val = LONG_LONG(tcp->u_arg[arg_no], tcp->u_arg[arg_no + 1]); arg_no += 2; + } else +# endif + { + *val = tcp->ext_arg[arg_no]; + arg_no++; } #else # if defined __ARM_EABI__ || \