From: Dmitry V. Levin Date: Mon, 19 Dec 2016 12:05:31 +0000 (+0000) Subject: struct tcb: make types of syscall arguments unsigned X-Git-Tag: v4.16~336 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc346f1d9125ad7fdda748923ac733f4f00fd272;p=strace struct tcb: make types of syscall arguments unsigned 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. --- diff --git a/defs.h b/defs.h index 09af8d08..8232d3cf 100644 --- 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 4add78e7..dc47a7f0 100644 --- 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 45c553e0..3d2425b9 100644 --- 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 diff --git a/kernel_types.h b/kernel_types.h index 60cb629e..c54af74e 100644 --- a/kernel_types.h +++ b/kernel_types.h @@ -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 1846abe4..708250cf 100644 --- 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 453a64e3..437b8ea5 100644 --- 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); diff --git a/pathtrace.c b/pathtrace.c index 8f7ea749..0dbf55dc 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -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 289e59d3..d7d7c047 100644 --- 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 }