[haiku-commits] r40093 - haiku/trunk/headers/private/kernel

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 3 Jan 2011 18:56:04 +0100 (CET)

Author: bonefish
Date: 2011-01-03 18:56:04 +0100 (Mon, 03 Jan 2011)
New Revision: 40093
Changeset: http://dev.haiku-os.org/changeset/40093

Modified:
   haiku/trunk/headers/private/kernel/kernel.h
Log:
* IS_KERNEL_ADDRESS(): Avoid the check against KERNEL_BASE or KERNEL_TOP, if
  that's the limit of the addr_t domain anyway.
* Defined IS_USER_ADDRESS() to !IS_KERNEL_ADDRESS(), which semantically it was
  already, just more verbosely.

Should, in the future, avoid hundreds of useless Coverity tickets where the
macros are used.


Modified: haiku/trunk/headers/private/kernel/kernel.h
===================================================================
--- haiku/trunk/headers/private/kernel/kernel.h 2011-01-03 17:15:18 UTC (rev 
40092)
+++ haiku/trunk/headers/private/kernel/kernel.h 2011-01-03 17:56:04 UTC (rev 
40093)
@@ -9,16 +9,25 @@
 #define _KERNEL_KERNEL_H
 
 
+#include <config/types.h>
+
 #include <arch_kernel.h>
 #include <arch_config.h>
 
 
-/* Passed in buffers from user-space shouldn't point into the kernel */
-#define IS_USER_ADDRESS(x) \
-       ((addr_t)(x) < KERNEL_BASE || (addr_t)(x) > KERNEL_TOP)
+// macro to check whether an address is in the kernel address space (avoid
+// always-true checks)
+#if KERNEL_BASE == 0
+#      define IS_KERNEL_ADDRESS(x)             ((addr_t)(x) <= KERNEL_TOP)
+#elif KERNEL_TOP == __HAIKU_ADDR_MAX
+#      define IS_KERNEL_ADDRESS(x)             ((addr_t)(x) >= KERNEL_BASE)
+#else
+#      define IS_KERNEL_ADDRESS(x) \
+               ((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
+#endif
 
-#define IS_KERNEL_ADDRESS(x) \
-       ((addr_t)(x) >= KERNEL_BASE && (addr_t)(x) <= KERNEL_TOP)
+// Buffers passed in from user-space shouldn't point into the kernel.
+#define IS_USER_ADDRESS(x)                     (!IS_KERNEL_ADDRESS(x))
 
 #define DEBUG_KERNEL_STACKS
        // Note, debugging kernel stacks doesn't really work yet. Since the


Other related posts:

  • » [haiku-commits] r40093 - haiku/trunk/headers/private/kernel - ingo_weinhold