From: Dmitry V. Levin Date: Sun, 18 Dec 2016 17:20:44 +0000 (+0000) Subject: Change scno type from long to unsigned long X-Git-Tag: v4.16~340 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0547dc1ad5cbaf5b12bbad8749ab1cd38f115c69;p=strace Change scno type from long to unsigned long Use an unsigned type for syscall numbers as they are not intended for signed arithmetics. Introduce kernel_scno_t as a typedef to unsigned long, that could be changed later to kernel_ulong_t. * kernel_types.h (kernel_scno_t): New type, typedef to unsigned long. * defs.h (struct tcb): Change type of scno field from long to kernel_scno_t. (syscall_name): Change argument type from long to kernel_scno_t. (scno_in_range, scno_is_valid): Change argument type from unsigned long to kernel_scno_t. * linux/aarch64/set_scno.c (arch_set_scno): Change scno argument type from long to kernel_scno_t. * linux/alpha/set_scno.c (arch_set_scno): Likewise. * linux/arc/set_scno.c (arch_set_scno): Likewise. * linux/arm/set_scno.c (arch_set_scno): Likewise. * linux/avr32/set_scno.c (arch_set_scno): Likewise. * linux/bfin/set_scno.c (arch_set_scno): Likewise. * linux/crisv10/set_scno.c (arch_set_scno): Likewise. * linux/hppa/set_scno.c (arch_set_scno): Likewise. * linux/i386/set_scno.c (arch_set_scno): Likewise. * linux/ia64/set_scno.c (arch_set_scno): Likewise. * linux/m68k/set_scno.c (arch_set_scno): Likewise. * linux/metag/set_scno.c (arch_set_scno): Likewise. * linux/microblaze/set_scno.c (arch_set_scno): Likewise. * linux/mips/set_scno.c (arch_set_scno): Likewise. * linux/nios2/set_scno.c (arch_set_scno): Likewise. * linux/or1k/set_scno.c (arch_set_scno): Likewise. * linux/powerpc/set_scno.c (arch_set_scno): Likewise. * linux/riscv/set_scno.c (arch_set_scno): Likewise. * linux/s390/set_scno.c (arch_set_scno): Likewise. * linux/sh/set_scno.c (arch_set_scno): Likewise. * linux/sh64/set_scno.c (arch_set_scno): Likewise. * linux/sparc/set_scno.c (arch_set_scno): Likewise. * linux/tile/set_scno.c (arch_set_scno): Likewise. * linux/x86_64/set_scno.c (arch_set_scno): Likewise. * linux/xtensa/set_scno.c (arch_set_scno): Likewise. * linux/aarch64/get_scno.c (arch_get_scno): Change scno variable type from long to kernel_scno_t. * linux/alpha/get_scno.c (arch_get_scno): Likewise. * linux/arm/get_scno.c (arch_get_scno): Likewise. * linux/sh/get_scno.c (arch_get_scno): Likewise. * linux/x86_64/get_scno.c (arch_get_scno): Likewise. * syscall.c (arch_set_scno): Likewise. (shuffle_scno): Change return type from long to kernel_scno_t. (syscall_name): Change argument type from long to kernel_scno_t. --- diff --git a/defs.h b/defs.h index 83f09f94..09af8d08 100644 --- a/defs.h +++ b/defs.h @@ -229,7 +229,7 @@ struct tcb { int pid; /* If 0, this tcb is free */ int qual_flg; /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */ unsigned long u_error; /* Error code */ - long scno; /* System call number */ + kernel_scno_t scno; /* System call number */ long u_arg[MAX_ARGS]; /* System call arguments */ #if HAVE_STRUCT_TCB_EXT_ARG long long ext_arg[MAX_ARGS]; @@ -467,7 +467,7 @@ extern int get_scno(struct tcb *tcp); * @return String literal corresponding to the syscall number in case latter * is valid; NULL otherwise. */ -extern const char *syscall_name(long scno); +extern const char *syscall_name(kernel_scno_t scno); extern const char *err_name(unsigned long err); extern bool is_erestart(struct tcb *); @@ -879,7 +879,7 @@ extern struct fault_opts *fault_vec[SUPPORTED_PERSONALITIES]; /* Checks that sysent[scno] is not out of range. */ static inline bool -scno_in_range(unsigned long scno) +scno_in_range(kernel_scno_t scno) { return scno < nsyscalls; } @@ -890,7 +890,7 @@ scno_in_range(unsigned long scno) * and its sysent[scno].sys_flags has no TRACE_INDIRECT_SUBCALL flag set. */ static inline bool -scno_is_valid(unsigned long scno) +scno_is_valid(kernel_scno_t scno) { return scno_in_range(scno) && sysent[scno].sys_func diff --git a/kernel_types.h b/kernel_types.h index 5a276135..60cb629e 100644 --- a/kernel_types.h +++ b/kernel_types.h @@ -47,6 +47,8 @@ typedef unsigned long kernel_ulong_t; # endif +typedef unsigned long kernel_scno_t; + typedef struct { kernel_ulong_t d_ino; kernel_ulong_t d_off; diff --git a/linux/aarch64/get_scno.c b/linux/aarch64/get_scno.c index c0fd4822..6dc4962e 100644 --- a/linux/aarch64/get_scno.c +++ b/linux/aarch64/get_scno.c @@ -2,7 +2,7 @@ static int arch_get_scno(struct tcb *tcp) { - long scno = 0; + kernel_scno_t scno = 0; switch (aarch64_io.iov_len) { case sizeof(aarch64_regs): diff --git a/linux/aarch64/set_scno.c b/linux/aarch64/set_scno.c index 24498d50..e66297af 100644 --- a/linux/aarch64/set_scno.c +++ b/linux/aarch64/set_scno.c @@ -7,7 +7,7 @@ */ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { unsigned int n = (uint16_t) scno; const struct iovec io = { diff --git a/linux/alpha/get_scno.c b/linux/alpha/get_scno.c index 65b9a77d..13002775 100644 --- a/linux/alpha/get_scno.c +++ b/linux/alpha/get_scno.c @@ -2,7 +2,7 @@ static int arch_get_scno(struct tcb *tcp) { - long scno = 0; + kernel_scno_t scno = 0; if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) return -1; diff --git a/linux/alpha/set_scno.c b/linux/alpha/set_scno.c index 21c603aa..4607ce45 100644 --- a/linux/alpha/set_scno.c +++ b/linux/alpha/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, REG_R0, scno); } diff --git a/linux/arc/set_scno.c b/linux/arc/set_scno.c index afac740e..bc6c9dc7 100644 --- a/linux/arc/set_scno.c +++ b/linux/arc/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { arc_regs.scratch.r8 = scno; return set_regs(tcp->pid); diff --git a/linux/arm/get_scno.c b/linux/arm/get_scno.c index 4dced92a..e312d163 100644 --- a/linux/arm/get_scno.c +++ b/linux/arm/get_scno.c @@ -31,7 +31,7 @@ static int arch_get_scno(struct tcb *tcp) { - long scno = 0; + kernel_scno_t scno = 0; /* Note: we support only 32-bit CPUs, not 26-bit */ @@ -47,7 +47,7 @@ arch_get_scno(struct tcb *tcp) if (errno) return -1; /* EABI syscall convention? */ - if ((unsigned long) scno != 0xef000000) { + if (scno != 0xef000000) { /* No, it's OABI */ if ((scno & 0x0ff00000) != 0x0f900000) { error_msg("pid %d unknown syscall trap 0x%08lx", diff --git a/linux/arm/set_scno.c b/linux/arm/set_scno.c index 928f1e92..085e539e 100644 --- a/linux/arm/set_scno.c +++ b/linux/arm/set_scno.c @@ -7,7 +7,7 @@ */ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { unsigned int n = (uint16_t) scno; int rc = ptrace(PTRACE_SET_SYSCALL, tcp->pid, NULL, (unsigned long) n); diff --git a/linux/avr32/set_scno.c b/linux/avr32/set_scno.c index 1090d2f3..d8f87d11 100644 --- a/linux/avr32/set_scno.c +++ b/linux/avr32/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { avr32_regs.r8 = scno; return set_regs(tcp->pid); diff --git a/linux/bfin/set_scno.c b/linux/bfin/set_scno.c index 235dbb3a..8f60274d 100644 --- a/linux/bfin/set_scno.c +++ b/linux/bfin/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, PT_ORIG_P0, scno); } diff --git a/linux/crisv10/set_scno.c b/linux/crisv10/set_scno.c index 4ccba5ac..f728c769 100644 --- a/linux/crisv10/set_scno.c +++ b/linux/crisv10/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, 4 * PT_R9, scno); } diff --git a/linux/hppa/set_scno.c b/linux/hppa/set_scno.c index 21321a02..3d85f4a5 100644 --- a/linux/hppa/set_scno.c +++ b/linux/hppa/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, PT_GR20, scno); } diff --git a/linux/i386/set_scno.c b/linux/i386/set_scno.c index 1affa3a1..1b633f32 100644 --- a/linux/i386/set_scno.c +++ b/linux/i386/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { #ifdef HAVE_GETREGS_OLD return upoke(tcp->pid, 4 * ORIG_EAX, scno); diff --git a/linux/ia64/set_scno.c b/linux/ia64/set_scno.c index 3450f1c3..a8f9cd87 100644 --- a/linux/ia64/set_scno.c +++ b/linux/ia64/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { if (ia64_ia32mode) ia64_regs.gr[0] = scno; diff --git a/linux/m68k/set_scno.c b/linux/m68k/set_scno.c index f8753b34..17fa989d 100644 --- a/linux/m68k/set_scno.c +++ b/linux/m68k/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { m68k_regs.orig_d0 = scno; return set_regs(tcp->pid); diff --git a/linux/metag/set_scno.c b/linux/metag/set_scno.c index 72198d66..8b13e1da 100644 --- a/linux/metag/set_scno.c +++ b/linux/metag/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { metag_regs.dx[0][1] = scno; return set_regs(tcp->pid); diff --git a/linux/microblaze/set_scno.c b/linux/microblaze/set_scno.c index 0f7ce9ec..ff233035 100644 --- a/linux/microblaze/set_scno.c +++ b/linux/microblaze/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, 0, scno); } diff --git a/linux/mips/set_scno.c b/linux/mips/set_scno.c index fc7a63bb..7d8fe9bc 100644 --- a/linux/mips/set_scno.c +++ b/linux/mips/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { mips_REG_V0 = scno; return set_regs(tcp->pid); diff --git a/linux/nios2/set_scno.c b/linux/nios2/set_scno.c index e8e06beb..64f1ccda 100644 --- a/linux/nios2/set_scno.c +++ b/linux/nios2/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { nios2_regs.regs[2] = scno; return set_regs(tcp->pid); diff --git a/linux/or1k/set_scno.c b/linux/or1k/set_scno.c index 5cf7672a..0ce465ac 100644 --- a/linux/or1k/set_scno.c +++ b/linux/or1k/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { or1k_regs.gpr[11] = scno; return set_regs(tcp->pid); diff --git a/linux/powerpc/set_scno.c b/linux/powerpc/set_scno.c index 9c1acd0a..aa4a9110 100644 --- a/linux/powerpc/set_scno.c +++ b/linux/powerpc/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { #ifdef HAVE_GETREGS_OLD return upoke(tcp->pid, sizeof(long) * PT_R0, scno); diff --git a/linux/riscv/set_scno.c b/linux/riscv/set_scno.c index 4ef3d6ef..858a0671 100644 --- a/linux/riscv/set_scno.c +++ b/linux/riscv/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { riscv_regs.a7 = scno; return set_regs(tcp->pid); diff --git a/linux/s390/set_scno.c b/linux/s390/set_scno.c index e21c5409..ffa600cf 100644 --- a/linux/s390/set_scno.c +++ b/linux/s390/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { s390_regset.gprs[2] = scno; return set_regs(tcp->pid); diff --git a/linux/sh/get_scno.c b/linux/sh/get_scno.c index a9bc5d8f..971f5547 100644 --- a/linux/sh/get_scno.c +++ b/linux/sh/get_scno.c @@ -2,7 +2,7 @@ static int arch_get_scno(struct tcb *tcp) { - long scno = 0; + kernel_scno_t scno = 0; /* * In the new syscall ABI, the system call number is in R3. @@ -10,11 +10,11 @@ arch_get_scno(struct tcb *tcp) if (upeek(tcp->pid, 4*(REG_REG0+3), &scno) < 0) return -1; - if (scno < 0) { + if ((long) scno < 0) { /* Odd as it may seem, a glibc bug has been known to cause glibc to issue bogus negative syscall numbers. So for our purposes, make strace print what it *should* have been */ - long correct_scno = (scno & 0xff); + kernel_scno_t correct_scno = (scno & 0xff); if (debug_flag) error_msg("Detected glibc bug: bogus system call" " number = %ld, correcting to %ld", diff --git a/linux/sh/set_scno.c b/linux/sh/set_scno.c index 83d603e6..63e5529a 100644 --- a/linux/sh/set_scno.c +++ b/linux/sh/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, 4 * (REG_REG0 + 3), scno); } diff --git a/linux/sh64/set_scno.c b/linux/sh64/set_scno.c index 212ce2ec..cae7d500 100644 --- a/linux/sh64/set_scno.c +++ b/linux/sh64/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, REG_SYSCALL, scno); } diff --git a/linux/sparc/set_scno.c b/linux/sparc/set_scno.c index bba124a8..0ba7f08f 100644 --- a/linux/sparc/set_scno.c +++ b/linux/sparc/set_scno.c @@ -4,7 +4,7 @@ */ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { sparc_regs.u_regs[U_REG_G1] = scno; return set_regs(tcp->pid); diff --git a/linux/tile/set_scno.c b/linux/tile/set_scno.c index 5ba19638..84c06767 100644 --- a/linux/tile/set_scno.c +++ b/linux/tile/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { tile_regs.regs[10] = scno; return set_regs(tcp->pid); diff --git a/linux/x86_64/get_scno.c b/linux/x86_64/get_scno.c index a87987e1..cbde17be 100644 --- a/linux/x86_64/get_scno.c +++ b/linux/x86_64/get_scno.c @@ -40,7 +40,7 @@ static int arch_get_scno(struct tcb *tcp) { - long scno = 0; + kernel_scno_t scno = 0; unsigned int currpers; #ifndef __X32_SYSCALL_BIT diff --git a/linux/x86_64/set_scno.c b/linux/x86_64/set_scno.c index af1910b9..c7d5413c 100644 --- a/linux/x86_64/set_scno.c +++ b/linux/x86_64/set_scno.c @@ -5,7 +5,7 @@ #endif /* !HAVE_GETREGS_OLD */ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { #ifdef HAVE_GETREGS_OLD return upoke(tcp->pid, 8 * ORIG_RAX, scno); diff --git a/linux/xtensa/set_scno.c b/linux/xtensa/set_scno.c index 532814f2..a869a2b1 100644 --- a/linux/xtensa/set_scno.c +++ b/linux/xtensa/set_scno.c @@ -1,5 +1,5 @@ static int -arch_set_scno(struct tcb *tcp, long scno) +arch_set_scno(struct tcb *tcp, kernel_scno_t scno) { return upoke(tcp->pid, SYSCALL_NR, scno); } diff --git a/syscall.c b/syscall.c index 2b30f58c..81489af7 100644 --- a/syscall.c +++ b/syscall.c @@ -345,7 +345,7 @@ decode_socket_subcall(struct tcb *tcp) if (call < 1 || call >= SYS_socket_nsubcalls) return; - const unsigned long scno = SYS_socket_subcall + call; + const kernel_scno_t scno = SYS_socket_subcall + call; const unsigned int nargs = sysent[scno].nargs; uint64_t buf[nargs]; @@ -491,10 +491,10 @@ dumpio(struct tcb *tcp) * Shuffle syscall numbers so that we don't have huge gaps in syscall table. * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n. */ -#if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */ -static long -shuffle_scno(unsigned long scno) +static kernel_scno_t +shuffle_scno(kernel_scno_t scno) { +#if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */ if (scno < ARM_FIRST_SHUFFLED_SYSCALL) return scno; @@ -504,7 +504,7 @@ shuffle_scno(unsigned long scno) if (scno == 0x000ffff0) return ARM_FIRST_SHUFFLED_SYSCALL; -#define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1) +# define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1) /* * Is it ARM specific syscall? * Swap [0x000f0000, 0x000f0000 + LAST_SPECIAL] range @@ -517,12 +517,10 @@ shuffle_scno(unsigned long scno) if (scno <= ARM_SECOND_SHUFFLED_SYSCALL + ARM_LAST_SPECIAL_SYSCALL) { return scno + 0x000f0000 - ARM_SECOND_SHUFFLED_SYSCALL; } +#endif /* ARM || AARCH64 */ return scno; } -#else -# define shuffle_scno(scno) ((long)(scno)) -#endif const char * err_name(unsigned long err) @@ -544,7 +542,7 @@ clear_regs(void) static int get_syscall_args(struct tcb *); static int get_syscall_result(struct tcb *); static int arch_get_scno(struct tcb *tcp); -static int arch_set_scno(struct tcb *, long); +static int arch_set_scno(struct tcb *, kernel_scno_t); static void get_error(struct tcb *, const bool); static int arch_set_error(struct tcb *); @@ -1272,7 +1270,7 @@ get_syscall_result(struct tcb *tcp) #endif const char * -syscall_name(long scno) +syscall_name(kernel_scno_t scno) { #if defined X32_PERSONALITY_NUMBER && defined __X32_SYSCALL_BIT if (current_personality == X32_PERSONALITY_NUMBER)