]> granicus.if.org Git - strace/commitdiff
Replace widen_to_long with truncate_klong_to_current_wordsize
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 26 Dec 2016 17:55:59 +0000 (17:55 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 26 Dec 2016 17:55:59 +0000 (17:55 +0000)
* defs.h (widen_to_long): Remove.
(truncate_klong_to_current_wordsize): New static inline function.
* aio.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents): Use it
instead of widen_to_long.
* linux/sparc64/get_syscall_args.c (get_syscall_args): Update comment.
* linux/x86_64/get_syscall_args.c (get_syscall_args): Likewise.

aio.c
defs.h
linux/sparc64/get_syscall_args.c
linux/x86_64/get_syscall_args.c

diff --git a/aio.c b/aio.c
index dc9ce4673f75f1c3ac50e519fc3666cf2fea11b2..47a4038aca0765cbac29d9b264951b22bdd79e89 100644 (file)
--- a/aio.c
+++ b/aio.c
@@ -180,12 +180,13 @@ print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 
 SYS_FUNC(io_submit)
 {
-       const long nr = widen_to_long(tcp->u_arg[1]);
+       const kernel_long_t nr =
+               truncate_klong_to_current_wordsize(tcp->u_arg[1]);
        const kernel_ulong_t addr = tcp->u_arg[2];
        kernel_ulong_t iocbp;
 
        printaddr(tcp->u_arg[0]);
-       tprintf(", %ld, ", nr);
+       tprintf(", %" PRI_kld ", ", nr);
 
        if (nr < 0)
                printaddr(addr);
@@ -236,9 +237,9 @@ SYS_FUNC(io_getevents)
 {
        if (entering(tcp)) {
                printaddr(tcp->u_arg[0]);
-               tprintf(", %ld, %ld, ",
-                       widen_to_long(tcp->u_arg[1]),
-                       widen_to_long(tcp->u_arg[2]));
+               tprintf(", %" PRI_kld ", %" PRI_kld ", ",
+                       truncate_klong_to_current_wordsize(tcp->u_arg[1]),
+                       truncate_klong_to_current_wordsize(tcp->u_arg[2]));
        } else {
                struct io_event buf;
                print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
diff --git a/defs.h b/defs.h
index d6155a8e13ea73b67b0cefb74d05110c35bdcc25..fbf0d40e778f7fdf2634e7928a56e66754804422 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -861,15 +861,19 @@ DECL_PRINTPAIR(int);
 DECL_PRINTPAIR(int64);
 #undef DECL_PRINTPAIR
 
-/* In many, many places we play fast and loose and use
- * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
- * We probably need to use widen_to_long() instead:
- */
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-# define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
-#else
-# define widen_to_long(v) ((long)(v))
+static inline kernel_long_t
+truncate_klong_to_current_wordsize(const kernel_long_t v)
+{
+#if SIZEOF_KERNEL_LONG_T > 4 \
+ && (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
+       if (current_wordsize < sizeof(v)) {
+               return (int) v;
+       } else
 #endif
+       {
+               return v;
+       }
+}
 
 static inline kernel_ulong_t
 truncate_kulong_to_current_wordsize(const kernel_ulong_t v)
index 11f003e0ec316956fa14e9458aeb1a9df9f6dca3..f5c1aa6f6dfbcc16636967401ee4450416737dba 100644 (file)
@@ -5,7 +5,8 @@ get_syscall_args(struct tcb *tcp)
        if (tcp->currpers == 1) {
                /*
                 * Zero-extend from 32 bits.
-                * Use widen_to_long(tcp->u_arg[N]) in syscall handlers
+                * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
+                * in syscall handlers
                 * if you need to use *sign-extended* parameter.
                 */
                tcp->u_arg[0] = (uint32_t) sparc_regs.u_regs[U_REG_O0 + 0];
index df3691a66ba70c62aa84dabec9ce62ebce1cca00..f285ac32e7116bf41b76d775aa75ec214fdb42f2 100644 (file)
@@ -7,7 +7,8 @@ get_syscall_args(struct tcb *tcp)
                if (tcp->s_ent->sys_flags & COMPAT_SYSCALL_TYPES) {
                        /*
                         * X32 compat syscall: zero-extend from 32 bits.
-                        * Use widen_to_long(tcp->u_arg[N]) in syscall handlers
+                        * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
+                        * in syscall handlers
                         * if you need to use *sign-extended* parameter.
                         */
                        tcp->u_arg[0] = (uint32_t) x86_64_regs.rdi;
@@ -27,7 +28,8 @@ get_syscall_args(struct tcb *tcp)
        } else {
                /*
                 * i386 ABI: zero-extend from 32 bits.
-                * Use widen_to_long(tcp->u_arg[N]) in syscall handlers
+                * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
+                * in syscall handlers
                 * if you need to use *sign-extended* parameter.
                 */
                tcp->u_arg[0] = (uint32_t) i386_regs.ebx;