]> granicus.if.org Git - strace/commitdiff
defs.h: introduce {opt,dispatch}_{word,klong}size
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 15 Jul 2019 23:56:46 +0000 (01:56 +0200)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 8 Sep 2019 23:12:26 +0000 (00:12 +0100)
* defs.h (set_personality, current_personality, current_wordsize,
current_klongsize, max_addr, max_kaddr): Move upwards.
(opt_wordsize): New macro, calls the first or the second argument
depending on the word size.
(dispatch_wordsize): New macro, calls the first or the second function
with the rest of macro parameters as arguments depending on the word
size.
(opt_klongsize): New macro, calls the first or the second argument
depending on the kernel long size.
(dispatch_klongsize): New macro, calls the first or the second function
with the rest of macro parameters as arguments depending on the kernel
long size.

defs.h

diff --git a/defs.h b/defs.h
index 67467c12e42088338f3192d1859f5c61b307e30f..d3241230e0c5c75373086f3cca04ef24300928fd 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -153,6 +153,63 @@ extern char *stpcpy(char *dst, const char *src);
 #  define is_bigendian false
 # endif
 
+# if SUPPORTED_PERSONALITIES > 1
+extern void set_personality(unsigned int personality);
+extern unsigned current_personality;
+# else
+#  define set_personality(personality) ((void)0)
+#  define current_personality 0
+# endif
+
+# if SUPPORTED_PERSONALITIES == 1
+#  define current_wordsize PERSONALITY0_WORDSIZE
+#  define current_klongsize PERSONALITY0_KLONGSIZE
+# else
+#  if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
+#   define current_wordsize PERSONALITY0_WORDSIZE
+#  else
+extern unsigned current_wordsize;
+#  endif
+#  if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_KLONGSIZE == PERSONALITY1_KLONGSIZE
+#   define current_klongsize PERSONALITY0_KLONGSIZE
+#  else
+extern unsigned current_klongsize;
+#  endif
+# endif
+
+# define max_addr() (~0ULL >> ((8 - current_wordsize) * 8))
+# define max_kaddr() (~0ULL >> ((8 - current_klongsize) * 8))
+
+/* Shorthands for defining word/klong-based dispatcher function bodies */
+# ifndef current_wordsize
+#  define opt_wordsize(opt_64_, opt_32_) \
+       ((current_wordsize > sizeof(uint32_t)) ? (opt_64_) : (opt_32_))
+#  define dispatch_wordsize(call_64_, call_32_, ...) \
+       ((current_wordsize > sizeof(uint32_t)) \
+               ? (call_64_)(__VA_ARGS__) : (call_32_)(__VA_ARGS__))
+# elif current_wordsize > 4
+#  define opt_wordsize(opt_64_, opt_32_) (opt_64_)
+#  define dispatch_wordsize(call_64_, call_32_, ...) ((call_64_)(__VA_ARGS__))
+# else /* current_wordsize == 4 */
+#  define opt_wordsize(opt_64_, opt_32_) (opt_32_)
+#  define dispatch_wordsize(call_64_, call_32_, ...) ((call_32_)(__VA_ARGS__))
+# endif
+
+# ifndef current_klongsize
+#  define opt_klongsize(opt_64_, opt_32_) \
+       ((current_klongsize > sizeof(uint32_t)) ? (opt_64_) : (opt_32_))
+#  define dispatch_klongsize(call_64_, call_32_, ...) \
+       ((current_klongsize > sizeof(uint32_t)) \
+               ? (call_64_)(__VA_ARGS__) : (call_32_)(__VA_ARGS__))
+# elif current_klongsize > 4
+#  define opt_klongsize(opt_64_, opt_32_) (opt_64_)
+#  define dispatch_klongsize(call_64_, call_32_, ...) ((call_64_)(__VA_ARGS__))
+# else /* current_klongsize == 4 */
+#  define opt_klongsize(opt_64_, opt_32_) (opt_32_)
+#  define dispatch_klongsize(call_64_, call_32_, ...) ((call_32_)(__VA_ARGS__))
+# endif
+
+
 typedef struct ioctlent {
        const char *symbol;
        unsigned int code;
@@ -1160,33 +1217,6 @@ printaddr_comment(const kernel_ulong_t addr)
        tprintf_comment("%#llx", (unsigned long long) addr);
 }
 
-# if SUPPORTED_PERSONALITIES > 1
-extern void set_personality(unsigned int personality);
-extern unsigned current_personality;
-# else
-#  define set_personality(personality) ((void)0)
-#  define current_personality 0
-# endif
-
-# if SUPPORTED_PERSONALITIES == 1
-#  define current_wordsize PERSONALITY0_WORDSIZE
-#  define current_klongsize PERSONALITY0_KLONGSIZE
-# else
-#  if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
-#   define current_wordsize PERSONALITY0_WORDSIZE
-#  else
-extern unsigned current_wordsize;
-#  endif
-#  if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_KLONGSIZE == PERSONALITY1_KLONGSIZE
-#   define current_klongsize PERSONALITY0_KLONGSIZE
-#  else
-extern unsigned current_klongsize;
-#  endif
-# endif
-
-# 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