1 /* 2 * Copyright (c) 2023 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef _VM_VM_KERN_INTERNAL_H_ 30 #define _VM_VM_KERN_INTERNAL_H_ 31 32 #include <sys/cdefs.h> 33 #include <vm/vm_kern_xnu.h> 34 35 __BEGIN_DECLS 36 37 #ifdef MACH_KERNEL_PRIVATE 38 39 #pragma mark kmem range methods 40 41 extern struct mach_vm_range kmem_ranges[KMEM_RANGE_COUNT]; 42 extern struct mach_vm_range kmem_large_ranges[KMEM_RANGE_COUNT]; 43 #define KMEM_RANGE_MASK 0x3fff 44 #define KMEM_HASH_SET 0x4000 45 #define KMEM_DIRECTION_MASK 0x8000 46 47 __stateful_pure 48 extern mach_vm_size_t mach_vm_range_size( 49 const struct mach_vm_range *r); 50 51 __attribute__((overloadable, pure)) 52 extern bool mach_vm_range_contains( 53 const struct mach_vm_range *r, 54 mach_vm_offset_t addr); 55 56 __attribute__((overloadable, pure)) 57 extern bool mach_vm_range_contains( 58 const struct mach_vm_range *r, 59 mach_vm_offset_t addr, 60 mach_vm_offset_t size); 61 62 __attribute__((overloadable, pure)) 63 extern bool mach_vm_range_intersects( 64 const struct mach_vm_range *r1, 65 const struct mach_vm_range *r2); 66 67 __attribute__((overloadable, pure)) 68 extern bool mach_vm_range_intersects( 69 const struct mach_vm_range *r1, 70 mach_vm_offset_t addr, 71 mach_vm_offset_t size); 72 73 /* 74 * @function kmem_range_id_contains 75 * 76 * @abstract Return whether the region of `[addr, addr + size)` is completely 77 * within the memory range. 78 */ 79 __pure2 80 extern bool kmem_range_id_contains( 81 kmem_range_id_t range_id, 82 vm_map_offset_t addr, 83 vm_map_size_t size); 84 85 __pure2 86 extern kmem_range_id_t kmem_addr_get_range( 87 vm_map_offset_t addr, 88 vm_map_size_t size); 89 90 extern kmem_range_id_t kmem_adjust_range_id( 91 uint32_t hash); 92 93 94 95 __startup_func 96 extern uint16_t kmem_get_random16( 97 uint16_t upper_limit); 98 99 __startup_func 100 extern void kmem_shuffle( 101 uint16_t *shuffle_buf, 102 uint16_t count); 103 104 #endif /* MACH_KERNEL_PRIVATE */ 105 106 __END_DECLS 107 108 #endif /* _VM_VM_KERN_INTERNAL_H_ */ 109