From b3d82da686aee7ceb11b81abe149b5315f3bc3f3 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 19 Dec 2016 18:30:22 +0000 Subject: [PATCH] Check for current_klongsize instead of current_personality where appropriate current_klongsize checks are more universal, therefore they are usually shorter and easier to comprehend. * desc.c (umove_kulong_array_or_printaddr): Check for current_klongsize instead of current_personality and current_wordsize. * io.c (print_lld_from_low_high_val): Likewise. * lseek.c (SYS_FUNC(lseek)): Likewise. * resource.c (decode_rlimit): Likewise. * syscall.c (is_negated_errno): Likewise. * util.c (getllval, getarg_klu): Likewise. --- desc.c | 8 +++----- io.c | 24 ++++++++++-------------- lseek.c | 15 +++++---------- resource.c | 6 +----- syscall.c | 16 +++------------- util.c | 37 +++++++++++++++++-------------------- 6 files changed, 39 insertions(+), 67 deletions(-) diff --git a/desc.c b/desc.c index 4183c778..45dc8419 100644 --- a/desc.c +++ b/desc.c @@ -230,11 +230,8 @@ static int umove_kulong_array_or_printaddr(struct tcb *tcp, const long addr, kernel_ulong_t *ptr, size_t n) { -#if defined X86_64 || defined X32 - if (current_personality == 1) { -#else - if (current_wordsize < sizeof(*ptr)) { -#endif +#ifndef current_klongsize + if (current_klongsize < sizeof(*ptr)) { uint32_t ptr32[n]; int r = umove_or_printaddr(tcp, addr, &ptr32); if (!r) { @@ -245,6 +242,7 @@ umove_kulong_array_or_printaddr(struct tcb *tcp, const long addr, } return r; } +#endif /* !current_klongsize */ return umoven_or_printaddr(tcp, addr, n * sizeof(*ptr), ptr); } diff --git a/io.c b/io.c index 3d2425b9..53419ed8 100644 --- a/io.c +++ b/io.c @@ -184,29 +184,25 @@ static void print_lld_from_low_high_val(struct tcb *tcp, int arg) { #if SIZEOF_LONG > 4 && SIZEOF_LONG == SIZEOF_LONG_LONG -# if SUPPORTED_PERSONALITIES > 1 -# ifdef X86_64 - if (current_personality != 1) -# else - if (current_wordsize == sizeof(long)) -# endif -# endif - tprintf("%ld", tcp->u_arg[arg]); -# if SUPPORTED_PERSONALITIES > 1 - else +# ifndef current_klongsize + if (current_klongsize < SIZEOF_LONG) { tprintf("%ld", (tcp->u_arg[arg + 1] << current_wordsize * 8) | tcp->u_arg[arg]); -# endif + } else +# endif /* !current_klongsize */ + { + tprintf("%ld", tcp->u_arg[arg]); + } #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) { +# ifndef current_klongsize + if (current_klongsize < SIZEOF_LONG_LONG) { tprintf("%lld", (zero_extend_signed_to_ull(tcp->u_arg[arg + 1]) << sizeof(long) * 8) | zero_extend_signed_to_ull(tcp->u_arg[arg])); } else -# endif +# endif /* !current_klongsize */ { tprintf("%lld", tcp->ext_arg[arg]); } diff --git a/lseek.c b/lseek.c index 708250cf..886d6204 100644 --- a/lseek.c +++ b/lseek.c @@ -50,12 +50,12 @@ SYS_FUNC(lseek) printfd(tcp, tcp->u_arg[0]); long long offset; -# if SUPPORTED_PERSONALITIES > 1 +# ifndef current_klongsize /* tcp->ext_arg is not initialized for compat personality */ - if (current_personality == 1) { + if (current_klongsize < sizeof(*tcp->ext_arg)) { offset = (long) tcp->u_arg[1]; } else -# endif +# endif /* !current_klongsize */ { offset = tcp->ext_arg[1]; } @@ -72,14 +72,9 @@ SYS_FUNC(lseek) printfd(tcp, tcp->u_arg[0]); long offset = -# if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 -# ifdef X86_64 - current_personality == 1 ? - (long) (int) tcp->u_arg[1] : (long) tcp->u_arg[1]; -# else - current_wordsize == 4 ? +# ifndef current_klongsize + current_klongsize < sizeof(long) ? (long) (int) tcp->u_arg[1] : (long) tcp->u_arg[1]; -# endif # else tcp->u_arg[1]; # endif diff --git a/resource.c b/resource.c index 475afc26..4e968246 100644 --- a/resource.c +++ b/resource.c @@ -96,17 +96,13 @@ print_rlimit32(struct tcb *tcp, unsigned long addr) static void decode_rlimit(struct tcb *tcp, unsigned long addr) { -# if defined(X86_64) || defined(X32) /* * i386 is the only personality on X86_64 and X32 * with 32-bit rlim_t. * When current_personality is X32, current_wordsize * equals to 4 but rlim_t is 64-bit. */ - if (current_personality == 1) -# else - if (current_wordsize == 4) -# endif + if (current_klongsize == 4) print_rlimit32(tcp, addr); else print_rlimit64(tcp, addr); diff --git a/syscall.c b/syscall.c index e346958c..e3924c58 100644 --- a/syscall.c +++ b/syscall.c @@ -1024,22 +1024,12 @@ is_negated_errno(kernel_ulong_t val) /* Linux kernel defines MAX_ERRNO to 4095. */ kernel_ulong_t max = -(kernel_long_t) 4095; -#if defined X86_64 || defined X32 - /* - * current_wordsize is 4 for x32 personality - * but truncation _must not_ be done in it, so - * check current_personality instead. - */ - if (current_personality == 1) { - val = (uint32_t) val; - max = (uint32_t) max; - } -#elif SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 - if (current_wordsize < sizeof(val)) { +#ifndef current_klongsize + if (current_klongsize < sizeof(val)) { val = (uint32_t) val; max = (uint32_t) max; } -#endif +#endif /* !current_klongsize */ return val >= max; } diff --git a/util.c b/util.c index 2805091a..4ec43da7 100644 --- a/util.c +++ b/util.c @@ -297,34 +297,29 @@ int getllval(struct tcb *tcp, unsigned long long *val, int arg_no) { #if SIZEOF_LONG > 4 && SIZEOF_LONG == SIZEOF_LONG_LONG -# if SUPPORTED_PERSONALITIES > 1 -# ifdef X86_64 - if (current_personality != 1) { -# else - if (current_wordsize > 4) { -# endif -# endif - *val = tcp->u_arg[arg_no]; - arg_no++; -# if SUPPORTED_PERSONALITIES > 1 - } else { +# ifndef current_klongsize + if (current_klongsize < SIZEOF_LONG) { # if defined(AARCH64) || defined(POWERPC64) /* Align arg_no to the next even number. */ arg_no = (arg_no + 1) & 0xe; # endif /* AARCH64 || POWERPC64 */ *val = LONG_LONG(tcp->u_arg[arg_no], tcp->u_arg[arg_no + 1]); arg_no += 2; + } else +# endif /* !current_klongsize */ + { + *val = tcp->u_arg[arg_no]; + arg_no++; } -# endif /* SUPPORTED_PERSONALITIES > 1 */ #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) { +# ifndef current_klongsize + if (current_klongsize < SIZEOF_LONG_LONG) { *val = LONG_LONG(tcp->u_arg[arg_no], tcp->u_arg[arg_no + 1]); arg_no += 2; } else -# endif +# endif /* !current_klongsize */ { *val = tcp->ext_arg[arg_no]; arg_no++; @@ -1494,12 +1489,14 @@ kernel_ulong_t getarg_klu(struct tcb *tcp, int argn) { #if HAVE_STRUCT_TCB_EXT_ARG -# if SUPPORTED_PERSONALITIES > 1 - if (current_personality == 1) +# ifndef current_klongsize + if (current_klongsize < sizeof(*tcp->ext_arg)) { return tcp->u_arg[argn]; - else -# endif - return tcp->ext_arg[argn]; + } else +# endif /* !current_klongsize */ + { + return tcp->ext_arg[argn]; + } #else return tcp->u_arg[argn]; #endif -- 2.50.1