-#define VM_KERNEL_UNSLIDE(_v) \
- ((VM_KERNEL_IS_SLID(_v) || \
- VM_KERNEL_IS_KEXT(_v)) ? \
- (vm_offset_t)(_v) - vm_kernel_slide : \
- (vm_offset_t)(_v))
-
-#define VM_KERNEL_ADDRPERM(_v) \
- (((vm_offset_t)(_v) == 0) ? \
- (vm_offset_t)(0) : \
- (vm_offset_t)(_v) + vm_kernel_addrperm)
-
-#define VM_KERNEL_UNSLIDE_OR_PERM(_v) \
- ((VM_KERNEL_IS_SLID(_v) || \
- VM_KERNEL_IS_KEXT(_v)) ? \
- (vm_offset_t)(_v) - vm_kernel_slide : \
- VM_KERNEL_ADDRPERM(_v))
-
+
+__BEGIN_DECLS
+extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr);
+__END_DECLS
+
+#define __DO_UNSLIDE(_v) ((vm_offset_t)(_v) - vm_kernel_slide)
+
+#if DEBUG || DEVELOPMENT
+# define VM_KERNEL_ADDRHIDE(_v) (VM_KERNEL_IS_SLID(_v) ? __DO_UNSLIDE(_v) : (vm_address_t)(_v))
+#else
+# define VM_KERNEL_ADDRHIDE(_v) (VM_KERNEL_IS_SLID(_v) ? __DO_UNSLIDE(_v) : (vm_address_t)0)
+#endif
+
+#define VM_KERNEL_ADDRHASH(_v) vm_kernel_addrhash((vm_offset_t)(_v))
+
+#define VM_KERNEL_UNSLIDE_OR_PERM(_v) ({ \
+ VM_KERNEL_IS_SLID(_v) ? __DO_UNSLIDE(_v) : \
+ VM_KERNEL_ADDRESS(_v) ? ((vm_offset_t)(_v) + vm_kernel_addrperm) : \
+ (vm_offset_t)(_v); \
+ })
+
+#define VM_KERNEL_UNSLIDE(_v) ({ \
+ VM_KERNEL_IS_SLID(_v) ? __DO_UNSLIDE(_v) : (vm_offset_t)0; \
+ })
+
+#define VM_KERNEL_ADDRPERM(_v) VM_KERNEL_UNSLIDE_OR_PERM(_v)
+
+#undef mach_vm_round_page
+#undef round_page
+#undef round_page_32
+#undef round_page_64
+
+static inline mach_vm_offset_t
+mach_vm_round_page(mach_vm_offset_t x)
+{
+ if (round_page_overflow(x, &x)) {
+ panic("overflow detected");
+ }
+ return x;
+}
+
+static inline vm_offset_t
+round_page(vm_offset_t x)
+{
+ if (round_page_overflow(x, &x)) {
+ panic("overflow detected");
+ }
+ return x;
+}
+
+static inline mach_vm_offset_t
+round_page_64(mach_vm_offset_t x)
+{
+ if (round_page_overflow(x, &x)) {
+ panic("overflow detected");
+ }
+ return x;
+}
+
+static inline uint32_t
+round_page_32(uint32_t x)
+{
+ if (round_page_overflow(x, &x)) {
+ panic("overflow detected");
+ }
+ return x;
+}