]> granicus.if.org Git - strace/commitdiff
struct tcb: make types of syscall arguments unsigned
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 19 Dec 2016 12:05:31 +0000 (12:05 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 19 Dec 2016 12:38:29 +0000 (12:38 +0000)
This is the first step in the direction of revisiting current practice
of indiscriminate use of signed types for syscall arguments and memory
addresses.

* kernel_types.h (kernel_ureg_t): New type, typedef to unsigned long.
* defs.h (struct tcb): Change type of u_arg from long to kernel_ureg_t.
[HAVE_STRUCT_TCB_EXT_ARG]: Change type of ext_arg from long long
to unsigned long long.
* desc.c (decode_select): Change type of syscall arguments from long
to kernel_ureg_t.
(SYS_FUNC(oldselect)): Change type of select_args from long
to kernel_ureg_t.
* io.c (print_lld_from_low_high_val): Remove no longer needed cast
of syscall arguments to unsigned long.
* lseek.c (SYS_FUNC(lseek)): Cast syscall argument from unsigned long
to long.
* mem.c (print_mmap): Change type of syscall arguments from long
to kernel_ureg_t.
(SYS_FUNC(old_mmap), SYS_FUNC(old_mmap_pgoff)): Change type of u_arg
from long to kernel_ureg_t.
(SYS_FUNC(mmap), SYS_FUNC(mmap_pgoff), SYS_FUNC(mmap_pgoff)): Remove
no longer needed cast of syscall arguments to unsigned long.
* pathtrace.c (pathtrace_match): Change type of args and select_args
from long to kernel_ureg_t.
* util.c (getarg_ull): Remove no longer needed casts of syscall
arguments to unsigned types.

defs.h
desc.c
io.c
kernel_types.h
lseek.c
mem.c
pathtrace.c
util.c

diff --git a/defs.h b/defs.h
index 09af8d083ca743dc847b941209d56e53842613c9..8232d3cf8ae5b02b7e1f6ecf11f149542e8f732f 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -230,9 +230,9 @@ struct tcb {
        int qual_flg;           /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
        unsigned long u_error;  /* Error code */
        kernel_scno_t scno;     /* System call number */
-       long u_arg[MAX_ARGS];   /* System call arguments */
+       kernel_ureg_t u_arg[MAX_ARGS];  /* System call arguments */
 #if HAVE_STRUCT_TCB_EXT_ARG
-       long long ext_arg[MAX_ARGS];
+       unsigned long long ext_arg[MAX_ARGS];
        long long u_lrval;      /* long long return value */
 #endif
        long u_rval;            /* Return value */
diff --git a/desc.c b/desc.c
index 4add78e734d0ef9125fbbb6abb67883f0d7e3375..dc47a7f0aeac9e1d17f77f1459ff55f969150d22 100644 (file)
--- a/desc.c
+++ b/desc.c
@@ -69,7 +69,7 @@ SYS_FUNC(dup3)
 }
 
 static int
-decode_select(struct tcb *tcp, long *args,
+decode_select(struct tcb *tcp, kernel_ureg_t *args,
              void (*print_tv_ts) (struct tcb *, const long),
              const char * (*sprint_tv_ts) (struct tcb *, const long))
 {
@@ -192,7 +192,7 @@ decode_select(struct tcb *tcp, long *args,
 
 SYS_FUNC(oldselect)
 {
-       long select_args[5];
+       kernel_ureg_t select_args[5];
        unsigned int oldselect_args[5];
 
        if (sizeof(*select_args) == sizeof(*oldselect_args)) {
diff --git a/io.c b/io.c
index 45c553e0828a2408da0b3e3035ca01c012fd6d78..3d2425b9ff2ec692c6716a6daf160d97c5b1315c 100644 (file)
--- a/io.c
+++ b/io.c
@@ -194,9 +194,8 @@ print_lld_from_low_high_val(struct tcb *tcp, int arg)
                tprintf("%ld", tcp->u_arg[arg]);
 # if SUPPORTED_PERSONALITIES > 1
        else
-               tprintf("%ld",
-                       ((unsigned long) tcp->u_arg[arg + 1] << current_wordsize * 8)
-                       | (unsigned long) tcp->u_arg[arg]);
+               tprintf("%ld", (tcp->u_arg[arg + 1] << current_wordsize * 8)
+                              | tcp->u_arg[arg]);
 # endif
 #elif SIZEOF_LONG > 4
 # error Unsupported configuration: SIZEOF_LONG > 4 && SIZEOF_LONG_LONG > SIZEOF_LONG
index 60cb629ed0b235a2273b8f56dac4c5771b2c67d1..c54af74e7c06c33927ca62cfac9da571d8303cb6 100644 (file)
@@ -48,6 +48,7 @@ typedef unsigned long kernel_ulong_t;
 # endif
 
 typedef unsigned long kernel_scno_t;
+typedef unsigned long kernel_ureg_t;
 
 typedef struct {
        kernel_ulong_t  d_ino;
diff --git a/lseek.c b/lseek.c
index 1846abe46fad96a6f4d4ce1500d0d44c73e9ccbb..708250cf49683792586c6de20db4a818e514092d 100644 (file)
--- a/lseek.c
+++ b/lseek.c
@@ -53,7 +53,7 @@ SYS_FUNC(lseek)
 # if SUPPORTED_PERSONALITIES > 1
        /* tcp->ext_arg is not initialized for compat personality */
        if (current_personality == 1) {
-               offset = tcp->u_arg[1];
+               offset = (long) tcp->u_arg[1];
        } else
 # endif
        {
@@ -75,10 +75,10 @@ SYS_FUNC(lseek)
 # if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
 #  ifdef X86_64
                current_personality == 1 ?
-                       (long)(int) tcp->u_arg[1] : tcp->u_arg[1];
+                       (long) (int) tcp->u_arg[1] : (long) tcp->u_arg[1];
 #  else
                current_wordsize == 4 ?
-                       (long)(int) tcp->u_arg[1] : tcp->u_arg[1];
+                       (long) (int) tcp->u_arg[1] : (long) tcp->u_arg[1];
 #  endif
 # else
                tcp->u_arg[1];
diff --git a/mem.c b/mem.c
index 453a64e33e6748990652a0f4a3ff3bf072a6c25e..437b8ea560df7d946fa91d254bd46c32a1571dea 100644 (file)
--- a/mem.c
+++ b/mem.c
@@ -55,7 +55,7 @@ SYS_FUNC(brk)
 #include "xlat/mmap_flags.h"
 
 static void
-print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
+print_mmap(struct tcb *tcp, kernel_ureg_t *u_arg, unsigned long long offset)
 {
        const unsigned long addr = u_arg[0];
        const unsigned long len = u_arg[1];
@@ -93,7 +93,7 @@ print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
 /* Params are pointed to by u_arg[0], offset is in bytes */
 SYS_FUNC(old_mmap)
 {
-       long u_arg[6];
+       kernel_ureg_t u_arg[6];
 # if defined AARCH64 || defined X86_64
        /* We are here only in a 32-bit personality. */
        unsigned int narrow_arg[6];
@@ -116,7 +116,7 @@ SYS_FUNC(old_mmap)
 /* Params are pointed to by u_arg[0], offset is in pages */
 SYS_FUNC(old_mmap_pgoff)
 {
-       long u_arg[5];
+       kernel_ureg_t u_arg[5];
        int i;
        unsigned narrow_arg[6];
        unsigned long long offset;
@@ -139,7 +139,7 @@ SYS_FUNC(mmap)
 #if HAVE_STRUCT_TCB_EXT_ARG
                tcp->ext_arg[5];        /* try test/x32_mmap.c */
 #else
-               (unsigned long) tcp->u_arg[5];
+               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
@@ -156,7 +156,7 @@ SYS_FUNC(mmap_pgoff)
 {
        /* Try test/mmap_offset_decode.c */
        unsigned long long offset;
-       offset = (unsigned long) tcp->u_arg[5];
+       offset = tcp->u_arg[5];
        offset *= get_pagesize();
        print_mmap(tcp, tcp->u_arg, offset);
 
@@ -167,7 +167,7 @@ SYS_FUNC(mmap_pgoff)
 SYS_FUNC(mmap_4koff)
 {
        unsigned long long offset;
-       offset = (unsigned long) tcp->u_arg[5];
+       offset = tcp->u_arg[5];
        offset <<= 12;
        print_mmap(tcp, tcp->u_arg, offset);
 
index 8f7ea749e17fb3ece8fbdf675508fdcda97fb6a5..0dbf55dc6cfcd048690803c1fec009609e09656a 100644 (file)
@@ -248,8 +248,8 @@ pathtrace_match(struct tcb *tcp)
        {
                int     i, j;
                int     nfds;
-               long   *args;
-               long    select_args[5];
+               kernel_ureg_t *args;
+               kernel_ureg_t select_args[5];
                unsigned int oldselect_args[5];
                unsigned int fdsize;
                fd_set *fds;
diff --git a/util.c b/util.c
index 289e59d323fa875fc4a8edcd4733b783d6c09c3f..d7d7c0472b35c1a3b81f80becec9e8b07b7d9e0b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1511,12 +1511,12 @@ getarg_ull(struct tcb *tcp, int argn)
 #if HAVE_STRUCT_TCB_EXT_ARG
 # if SUPPORTED_PERSONALITIES > 1
        if (current_personality == 1)
-               return (unsigned long) tcp->u_arg[argn];
+               return tcp->u_arg[argn];
        else
 # endif
-       return (unsigned long long) tcp->ext_arg[argn];
+       return tcp->ext_arg[argn];
 #else
-       return (unsigned long) tcp->u_arg[argn];
+       return tcp->u_arg[argn];
 #endif
 }