]> granicus.if.org Git - strace/commitdiff
Check for current_klongsize instead of current_personality where appropriate
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 19 Dec 2016 18:30:22 +0000 (18:30 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 19 Dec 2016 19:58:16 +0000 (19:58 +0000)
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
io.c
lseek.c
resource.c
syscall.c
util.c

diff --git a/desc.c b/desc.c
index 4183c778a8b5e2761f6bfbcb104be3529a7678af..45dc841932b965001135e55484de77392fe8ffe9 100644 (file)
--- 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 3d2425b9ff2ec692c6716a6daf160d97c5b1315c..53419ed81d0d783c6a0a0c6f34e2e2b1b85cb0ba 100644 (file)
--- 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 708250cf49683792586c6de20db4a818e514092d..886d62046f7603af2c225d12a4fc4f4bd2df1d18 100644 (file)
--- 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
index 475afc26e61f2e5b8afb031111f1479ba8830e3a..4e96824620d77ad0afd6b697c9e7e36a41186646 100644 (file)
@@ -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);
index e346958c6f9bc960a4d840c4d47d6f3cbc6fc619..e3924c58890ae85e20536b43cbd6c4147c976621 100644 (file)
--- 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 2805091aef856975db65c36e7b13dfda11fa959a..4ec43da7950810fc0e5c1b9f93a4149802c36755 100644 (file)
--- 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