|
|
760e82 |
From c9e41cd3485fa1a65dc6206c5b210b4be4c5597c Mon Sep 17 00:00:00 2001
|
|
|
760e82 |
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
|
|
|
760e82 |
Date: Sat, 13 Jun 2020 18:18:32 +0200
|
|
|
760e82 |
Subject: [PATCH 120/138] Move ilog* functions from util.c to defs.h
|
|
|
760e82 |
|
|
|
760e82 |
* util.c (ILOG2_ITER_, ilog2_klong, ilog2_64, ilog2_32): Move ...
|
|
|
760e82 |
* defs.h: ... here.
|
|
|
760e82 |
---
|
|
|
760e82 |
defs.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
760e82 |
util.c | 62 --------------------------------------------------------------
|
|
|
760e82 |
2 files changed, 60 insertions(+), 62 deletions(-)
|
|
|
760e82 |
|
|
|
760e82 |
diff --git a/defs.h b/defs.h
|
|
|
760e82 |
index 3aa07fb..d8bd513 100644
|
|
|
760e82 |
--- a/defs.h
|
|
|
760e82 |
+++ b/defs.h
|
|
|
760e82 |
@@ -1698,4 +1698,64 @@ scno_is_valid(kernel_ulong_t scno)
|
|
|
760e82 |
|
|
|
760e82 |
# define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(sys_ ## syscall_name)(struct tcb *tcp)
|
|
|
760e82 |
|
|
|
760e82 |
+#define ILOG2_ITER_(val_, ret_, bit_) \
|
|
|
760e82 |
+ do { \
|
|
|
760e82 |
+ typeof(ret_) shift_ = \
|
|
|
760e82 |
+ ((val_) > ((((typeof(val_)) 1) \
|
|
|
760e82 |
+ << (1 << (bit_))) - 1)) << (bit_); \
|
|
|
760e82 |
+ (val_) >>= shift_; \
|
|
|
760e82 |
+ (ret_) |= shift_; \
|
|
|
760e82 |
+ } while (0)
|
|
|
760e82 |
+
|
|
|
760e82 |
+/**
|
|
|
760e82 |
+ * Calculate floor(log2(val)), with the exception of val == 0, for which 0
|
|
|
760e82 |
+ * is returned as well.
|
|
|
760e82 |
+ *
|
|
|
760e82 |
+ * @param val 64-bit value to calculate integer base-2 logarithm for.
|
|
|
760e82 |
+ * @return (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
|
|
|
760e82 |
+ */
|
|
|
760e82 |
+static inline unsigned int
|
|
|
760e82 |
+ilog2_64(uint64_t val)
|
|
|
760e82 |
+{
|
|
|
760e82 |
+ unsigned int ret = 0;
|
|
|
760e82 |
+
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 5);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 4);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 3);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 2);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 1);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 0);
|
|
|
760e82 |
+
|
|
|
760e82 |
+ return ret;
|
|
|
760e82 |
+}
|
|
|
760e82 |
+
|
|
|
760e82 |
+/**
|
|
|
760e82 |
+ * Calculate floor(log2(val)), with the exception of val == 0, for which 0
|
|
|
760e82 |
+ * is returned as well.
|
|
|
760e82 |
+ *
|
|
|
760e82 |
+ * @param val 32-bit value to calculate integer base-2 logarithm for.
|
|
|
760e82 |
+ * @return (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
|
|
|
760e82 |
+ */
|
|
|
760e82 |
+static inline unsigned int
|
|
|
760e82 |
+ilog2_32(uint32_t val)
|
|
|
760e82 |
+{
|
|
|
760e82 |
+ unsigned int ret = 0;
|
|
|
760e82 |
+
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 4);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 3);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 2);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 1);
|
|
|
760e82 |
+ ILOG2_ITER_(val, ret, 0);
|
|
|
760e82 |
+
|
|
|
760e82 |
+ return ret;
|
|
|
760e82 |
+}
|
|
|
760e82 |
+
|
|
|
760e82 |
+#if SIZEOF_KERNEL_LONG_T > 4
|
|
|
760e82 |
+# define ilog2_klong ilog2_64
|
|
|
760e82 |
+#else
|
|
|
760e82 |
+# define ilog2_klong ilog2_32
|
|
|
760e82 |
+#endif
|
|
|
760e82 |
+
|
|
|
760e82 |
+#undef ILOG2_ITER_
|
|
|
760e82 |
+
|
|
|
760e82 |
#endif /* !STRACE_DEFS_H */
|
|
|
760e82 |
diff --git a/util.c b/util.c
|
|
|
760e82 |
index 59696b5..cde76c1 100644
|
|
|
760e82 |
--- a/util.c
|
|
|
760e82 |
+++ b/util.c
|
|
|
760e82 |
@@ -1120,68 +1120,6 @@ dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr,
|
|
|
760e82 |
#undef iov
|
|
|
760e82 |
}
|
|
|
760e82 |
|
|
|
760e82 |
-#define ILOG2_ITER_(val_, ret_, bit_) \
|
|
|
760e82 |
- do { \
|
|
|
760e82 |
- typeof(ret_) shift_ = \
|
|
|
760e82 |
- ((val_) > ((((typeof(val_)) 1) \
|
|
|
760e82 |
- << (1 << (bit_))) - 1)) << (bit_); \
|
|
|
760e82 |
- (val_) >>= shift_; \
|
|
|
760e82 |
- (ret_) |= shift_; \
|
|
|
760e82 |
- } while (0)
|
|
|
760e82 |
-
|
|
|
760e82 |
-#if SIZEOF_KERNEL_LONG_T > 4
|
|
|
760e82 |
-
|
|
|
760e82 |
-# define ilog2_klong ilog2_64
|
|
|
760e82 |
-/**
|
|
|
760e82 |
- * Calculate floor(log2(val)), with the exception of val == 0, for which 0
|
|
|
760e82 |
- * is returned as well.
|
|
|
760e82 |
- *
|
|
|
760e82 |
- * @param val 64-bit value to calculate integer base-2 logarithm for.
|
|
|
760e82 |
- * @return (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
|
|
|
760e82 |
- */
|
|
|
760e82 |
-static inline unsigned int
|
|
|
760e82 |
-ilog2_64(uint64_t val)
|
|
|
760e82 |
-{
|
|
|
760e82 |
- unsigned int ret = 0;
|
|
|
760e82 |
-
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 5);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 4);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 3);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 2);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 1);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 0);
|
|
|
760e82 |
-
|
|
|
760e82 |
- return ret;
|
|
|
760e82 |
-}
|
|
|
760e82 |
-
|
|
|
760e82 |
-#else /* SIZEOF_KERNEL_LONG_T == 4 */
|
|
|
760e82 |
-
|
|
|
760e82 |
-# define ilog2_klong ilog2_32
|
|
|
760e82 |
-/**
|
|
|
760e82 |
- * Calculate floor(log2(val)), with the exception of val == 0, for which 0
|
|
|
760e82 |
- * is returned as well.
|
|
|
760e82 |
- *
|
|
|
760e82 |
- * @param val 32-bit value to calculate integer base-2 logarithm for.
|
|
|
760e82 |
- * @return (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
|
|
|
760e82 |
- */
|
|
|
760e82 |
-static inline unsigned int
|
|
|
760e82 |
-ilog2_32(uint32_t val)
|
|
|
760e82 |
-{
|
|
|
760e82 |
- unsigned int ret = 0;
|
|
|
760e82 |
-
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 4);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 3);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 2);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 1);
|
|
|
760e82 |
- ILOG2_ITER_(val, ret, 0);
|
|
|
760e82 |
-
|
|
|
760e82 |
- return ret;
|
|
|
760e82 |
-}
|
|
|
760e82 |
-
|
|
|
760e82 |
-#endif /* SIZEOF_KERNEL_LONG_T */
|
|
|
760e82 |
-
|
|
|
760e82 |
-#undef ILOG2_ITER_
|
|
|
760e82 |
-
|
|
|
760e82 |
void
|
|
|
760e82 |
dumpstr(struct tcb *const tcp, const kernel_ulong_t addr,
|
|
|
760e82 |
const kernel_ulong_t len)
|
|
|
760e82 |
--
|
|
|
760e82 |
2.1.4
|
|
|
760e82 |
|