]> granicus.if.org Git - strace/commitdiff
Introduce print_big_u64_addr
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 26 Mar 2018 04:13:23 +0000 (06:13 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 4 Apr 2018 12:24:19 +0000 (12:24 +0000)
This is needed at least for bpf, btrfs, and sg_io, as 32-bit tracer
cannot figure out whether the kernel is 32-bit or 64-bit,
and its behaviour differs when it handles u64 as a pointer.

* linux/arch_defs_.h [!CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL]
(CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL): New definition, default to 0.
* linux/arm/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Define to 1.
* linux/i386/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/mips/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/powerpc/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/riscv/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/s390/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/sparc/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/tile/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* defs.h (print_big_u64_addr): New function.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
defs.h
linux/arch_defs_.h
linux/arm/arch_defs_.h
linux/i386/arch_defs_.h
linux/mips/arch_defs_.h
linux/powerpc/arch_defs_.h
linux/riscv/arch_defs_.h
linux/s390/arch_defs_.h
linux/sparc/arch_defs_.h
linux/tile/arch_defs_.h

diff --git a/defs.h b/defs.h
index e5a2a1228e213e3da884755ee25133e167ea0d84..8c53d8f0475ac5030276af3cca5da5a2dede48a3 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -867,6 +867,31 @@ extern unsigned current_klongsize;
 #define max_addr() (~0ULL >> ((8 - current_wordsize) * 8))
 #define max_kaddr() (~0ULL >> ((8 - current_klongsize) * 8))
 
+/*
+ * When u64 is interpreted by the kernel as an address, there is a difference
+ * in behaviour between 32-bit and 64-bit kernel in the way u64_to_user_ptr
+ * works (32-bit kernel trims higher bits during conversion which may result
+ * to a valid address).  Since 32-bit strace cannot figure out what kind of
+ * kernel the tracee is running on, it has to account for both possibilities.
+ */
+#if CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL
+
+/**
+ * Print raw 64-bit value as an address if it's too big to fit in strace's
+ * kernel_long_t.
+ */
+static inline void
+print_big_u64_addr(const uint64_t addr)
+{
+       if (sizeof(kernel_long_t) < 8 && addr > max_kaddr()) {
+               printaddr64(addr);
+               tprints(" or ");
+       }
+}
+#else /* !CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL */
+# define print_big_u64_addr(addr_) ((void) 0)
+#endif /* CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL */
+
 #if SIZEOF_KERNEL_LONG_T > 4           \
  && (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined(current_wordsize))
 # define ANY_WORDSIZE_LESS_THAN_KERNEL_LONG    1
index a66be2624a1c74b1dd03be7e0cc3e4493f521b44..87e200636b14bd19b354028129113c1ff58d9d0f 100644 (file)
@@ -31,3 +31,7 @@
 #ifndef HAVE_ARCH_DEDICATED_ERR_REG
 # define HAVE_ARCH_DEDICATED_ERR_REG 0
 #endif
+
+#ifndef CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL
+# define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 0
+#endif
index a8e961f34603b98383159dea7ec40ae8a50df5c7..1a7e176f59a66e850fdf976e5bb8158a992f4008 100644 (file)
@@ -1,3 +1,4 @@
 #define HAVE_ARCH_OLD_MMAP 1
 #define HAVE_ARCH_OLD_SELECT 1
 #define HAVE_ARCH_UID16_SYSCALLS 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index a8e961f34603b98383159dea7ec40ae8a50df5c7..1a7e176f59a66e850fdf976e5bb8158a992f4008 100644 (file)
@@ -1,3 +1,4 @@
 #define HAVE_ARCH_OLD_MMAP 1
 #define HAVE_ARCH_OLD_SELECT 1
 #define HAVE_ARCH_UID16_SYSCALLS 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index f6fe59e5eb5397709483550fa9d429cac3891f08..1f20dab06e73b4983534bf79f9325b787299b48d 100644 (file)
@@ -1,2 +1,3 @@
 #define HAVE_ARCH_GETRVAL2 1
 #define HAVE_ARCH_DEDICATED_ERR_REG 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index ef3f342e7e5ebdb85c5d0f56f386bd09ffe9537c..06b6da9554e913e481dfad9390fa5fbfdc80469f 100644 (file)
@@ -1,2 +1,3 @@
 #define HAVE_ARCH_OLD_SELECT 1
 #define HAVE_ARCH_DEDICATED_ERR_REG 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index 33494f5d9e708e26ade3e1e7a6f242b112a3c27e..b223c48c2e78b9426530b9aad9f39e1b72885b65 100644 (file)
@@ -1,2 +1,3 @@
 #define HAVE_ARCH_UID16_SYSCALLS 1
 #define SUPPORTED_PERSONALITIES 2
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index 59fee837f082b175bd63dbd1fea034893d8f2725..d739fd02e64ed12b72af5dbd585f84720b319216 100644 (file)
@@ -1,3 +1,4 @@
 #define HAVE_ARCH_OLD_MMAP 1
 #define HAVE_ARCH_OLD_MMAP_PGOFF 1
 #define HAVE_ARCH_UID16_SYSCALLS 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index e30336abe8d0bd708db8a9bd92e03e78b2f2469c..94f6e2bd293cd3960ba5508a81a41d30e52a7aac 100644 (file)
@@ -2,3 +2,4 @@
 #define HAVE_ARCH_UID16_SYSCALLS 1
 #define HAVE_ARCH_SA_RESTORER 1
 #define HAVE_ARCH_DEDICATED_ERR_REG 1
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
index 34a56248f0ce07b5f8de05823f6f19b814a10cf7..b926597940e9d9b6b0c88037572af9f3837b7f8e 100644 (file)
@@ -1,4 +1,5 @@
 #define SUPPORTED_PERSONALITIES 2
+#define CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL 1
 
 #ifdef __tilepro__
 # define DEFAULT_PERSONALITY 1