]> granicus.if.org Git - strace/blobdiff - syscall.c
Print kernel_ureg_t and kernel_scno_t using dedicated format strings
[strace] / syscall.c
index 2b30f58c4b8c458d4277a6d81c70cd7b730bf374..d19777e834ba055db99b443e969ab2c76112769e 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -82,6 +82,7 @@
 #define MA MAX_ARGS
 #define SI STACKTRACE_INVALIDATE_CACHE
 #define SE STACKTRACE_CAPTURE_ON_ENTER
+#define CST COMPAT_SYSCALL_TYPES
 
 #define SEN(syscall_name) SEN_ ## syscall_name, SYS_FUNC_NAME(sys_ ## syscall_name)
 
@@ -116,6 +117,7 @@ static const struct_sysent sysent2[] = {
 #undef MA
 #undef SI
 #undef SE
+#undef CST
 
 /*
  * `ioctlent[012].h' files are automatically generated by the auxiliary
@@ -257,6 +259,17 @@ static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
 };
 # endif
 
+# ifndef current_klongsize
+unsigned current_klongsize;
+static const int personality_klongsize[SUPPORTED_PERSONALITIES] = {
+       PERSONALITY0_KLONGSIZE,
+       PERSONALITY1_KLONGSIZE,
+#  if SUPPORTED_PERSONALITIES > 2
+       PERSONALITY2_KLONGSIZE,
+#  endif
+};
+# endif
+
 void
 set_personality(int personality)
 {
@@ -301,6 +314,9 @@ set_personality(int personality)
 # ifndef current_wordsize
        current_wordsize = personality_wordsize[personality];
 # endif
+# ifndef current_klongsize
+       current_klongsize = personality_klongsize[personality];
+# endif
 }
 
 static void
@@ -345,7 +361,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];
 
@@ -475,10 +491,10 @@ dumpio(struct tcb *tcp)
                case SEN_pwritev:
                case SEN_pwritev2:
                case SEN_vmsplice:
-                       dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
+                       dumpiov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1], -1);
                        break;
                case SEN_sendmsg:
-                       dumpiov_in_msghdr(tcp, tcp->u_arg[1], -1UL);
+                       dumpiov_in_msghdr(tcp, tcp->u_arg[1], -1);
                        break;
                case SEN_sendmmsg:
                        dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
@@ -491,10 +507,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 +520,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 +533,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 +558,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 *);
 
@@ -808,7 +822,7 @@ trace_syscall_exiting(struct tcb *tcp)
                        if (syscall_fault_injected(tcp))
                                tprints(" (INJECTED)");
                } else {
-                       tprintf("= %#lx", tcp->u_rval);
+                       tprintf("= %#" PRI_krx, tcp->u_rval);
                }
        }
        else if (!(sys_res & RVAL_NONE) && u_error) {
@@ -888,12 +902,12 @@ trace_syscall_exiting(struct tcb *tcp)
                        switch (sys_res & RVAL_MASK) {
                        case RVAL_HEX:
 #if SUPPORTED_PERSONALITIES > 1
-                               if (current_wordsize < sizeof(long))
+                               if (current_wordsize < sizeof(tcp->u_rval))
                                        tprintf("= %#x",
                                                (unsigned int) tcp->u_rval);
                                else
 #endif
-                                       tprintf("= %#lx", tcp->u_rval);
+                                       tprintf("= %#" PRI_krx, tcp->u_rval);
                                break;
                        case RVAL_OCTAL:
                                tprints("= ");
@@ -901,15 +915,15 @@ trace_syscall_exiting(struct tcb *tcp)
                                break;
                        case RVAL_UDECIMAL:
 #if SUPPORTED_PERSONALITIES > 1
-                               if (current_wordsize < sizeof(long))
+                               if (current_wordsize < sizeof(tcp->u_rval))
                                        tprintf("= %u",
                                                (unsigned int) tcp->u_rval);
                                else
 #endif
-                                       tprintf("= %lu", tcp->u_rval);
+                                       tprintf("= %" PRI_kru, tcp->u_rval);
                                break;
                        case RVAL_DECIMAL:
-                               tprintf("= %ld", tcp->u_rval);
+                               tprintf("= %" PRI_krd, tcp->u_rval);
                                break;
                        case RVAL_FD:
                                if (show_fd_path) {
@@ -917,7 +931,7 @@ trace_syscall_exiting(struct tcb *tcp)
                                        printfd(tcp, tcp->u_rval);
                                }
                                else
-                                       tprintf("= %ld", tcp->u_rval);
+                                       tprintf("= %" PRI_krd, tcp->u_rval);
                                break;
 #if HAVE_STRUCT_TCB_EXT_ARG
                        /*
@@ -1012,22 +1026,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) {
+#ifndef current_klongsize
+       if (current_klongsize < sizeof(val)) {
                val = (uint32_t) val;
                max = (uint32_t) max;
        }
-#elif SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-       if (current_wordsize < sizeof(val)) {
-               val = (uint32_t) val;
-               max = (uint32_t) max;
-       }
-#endif
+#endif /* !current_klongsize */
 
        return val >= max;
 }
@@ -1044,7 +1048,7 @@ print_pc(struct tcb *tcp)
 #if defined ARCH_PC_REG
 # define ARCH_GET_PC 0
 #elif defined ARCH_PC_PEEK_ADDR
-       long pc;
+       kernel_ureg_t pc;
 # define ARCH_PC_REG pc
 # define ARCH_GET_PC upeek(tcp->pid, ARCH_PC_PEEK_ADDR, &pc)
 #else
@@ -1054,8 +1058,9 @@ print_pc(struct tcb *tcp)
                tprints(current_wordsize == 4 ? "[????????] "
                                              : "[????????????????] ");
        else
-               tprintf(current_wordsize == 4 ? "[%08lx] " : "[%016lx] ",
-                       (unsigned long) ARCH_PC_REG);
+               tprintf(current_wordsize == 4
+                       ? "[%08" PRI_krx "] " : "[%016" PRI_krx "] ",
+                       (kernel_ureg_t) ARCH_PC_REG);
 }
 
 #include "getregs_old.h"
@@ -1185,7 +1190,7 @@ set_regs(pid_t pid)
 struct sysent_buf {
        struct tcb *tcp;
        struct_sysent ent;
-       char buf[sizeof("syscall_%lu") + sizeof(long) * 3];
+       char buf[sizeof("syscall_%lu") + sizeof(kernel_scno_t) * 3];
 };
 
 static void
@@ -1224,7 +1229,7 @@ get_scno(struct tcb *tcp)
                s->ent.sen = SEN_printargs;
                s->ent.sys_func = printargs;
                s->ent.sys_name = s->buf;
-               sprintf(s->buf, "syscall_%lu", shuffle_scno(tcp->scno));
+               sprintf(s->buf, "syscall_%" PRI_kru, shuffle_scno(tcp->scno));
 
                tcp->s_ent = &s->ent;
                tcp->qual_flg = QUAL_RAW | DEFAULT_QUAL_FLAGS;
@@ -1232,7 +1237,8 @@ get_scno(struct tcb *tcp)
                set_tcb_priv_data(tcp, s, free_sysent_buf);
 
                if (debug_flag)
-                       error_msg("pid %d invalid syscall %ld", tcp->pid, tcp->scno);
+                       error_msg("pid %d invalid syscall %" PRI_krd,
+                                 tcp->pid, tcp->scno);
        }
        return 1;
 }
@@ -1272,7 +1278,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)