| 1 | /* |
| 2 | * Copyright (c) 2000-2007 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 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce |
| 30 | * support for mandatory and extensible security protections. This notice |
| 31 | * is included in support of clause 2.2 (b) of the Apple Public License, |
| 32 | * Version 2.0. |
| 33 | */ |
| 34 | |
| 35 | #ifndef _MACH_KMOD_H_ |
| 36 | #define _MACH_KMOD_H_ |
| 37 | |
| 38 | #include <mach/kern_return.h> |
| 39 | #include <mach/mach_types.h> |
| 40 | |
| 41 | #include <sys/cdefs.h> |
| 42 | |
| 43 | __BEGIN_DECLS |
| 44 | |
| 45 | #if PRAGMA_MARK |
| 46 | #pragma mark Basic macros & typedefs |
| 47 | #endif |
| 48 | /*********************************************************************** |
| 49 | * Basic macros & typedefs |
| 50 | ***********************************************************************/ |
| 51 | #define KMOD_MAX_NAME 64 |
| 52 | |
| 53 | #define KMOD_RETURN_SUCCESS KERN_SUCCESS |
| 54 | #define KMOD_RETURN_FAILURE KERN_FAILURE |
| 55 | |
| 56 | typedef int kmod_t; |
| 57 | |
| 58 | struct kmod_info; |
| 59 | typedef kern_return_t kmod_start_func_t(struct kmod_info * ki, void * data); |
| 60 | typedef kern_return_t kmod_stop_func_t(struct kmod_info * ki, void * data); |
| 61 | |
| 62 | #if PRAGMA_MARK |
| 63 | #pragma mark Structure definitions |
| 64 | #endif |
| 65 | /*********************************************************************** |
| 66 | * Structure definitions |
| 67 | * |
| 68 | * All structures must be #pragma pack(4). |
| 69 | ***********************************************************************/ |
| 70 | #pragma pack(push, 4) |
| 71 | |
| 72 | /* Run-time struct only; never saved to a file */ |
| 73 | typedef struct kmod_reference { |
| 74 | struct kmod_reference * next; |
| 75 | struct kmod_info * info; |
| 76 | } kmod_reference_t; |
| 77 | |
| 78 | /*********************************************************************** |
| 79 | * Warning: Any changes to the kmod_info structure affect the |
| 80 | * KMOD_..._DECL macros below. |
| 81 | ***********************************************************************/ |
| 82 | |
| 83 | /* The kmod_info_t structure is only safe to use inside the running |
| 84 | * kernel. If you need to work with a kmod_info_t structure outside |
| 85 | * the kernel, please use the compatibility definitions below. |
| 86 | */ |
| 87 | typedef struct kmod_info { |
| 88 | struct kmod_info * next; |
| 89 | int32_t info_version; // version of this structure |
| 90 | uint32_t id; |
| 91 | char name[KMOD_MAX_NAME]; |
| 92 | char version[KMOD_MAX_NAME]; |
| 93 | int32_t reference_count; // # linkage refs to this |
| 94 | kmod_reference_t * reference_list; // who this refs (links on) |
| 95 | vm_address_t address; // starting address |
| 96 | vm_size_t size; // total size |
| 97 | vm_size_t hdr_size; // unwired hdr size |
| 98 | kmod_start_func_t * start; |
| 99 | kmod_stop_func_t * stop; |
| 100 | } kmod_info_t; |
| 101 | |
| 102 | /* A compatibility definition of kmod_info_t for 32-bit kexts. |
| 103 | */ |
| 104 | typedef struct kmod_info_32_v1 { |
| 105 | uint32_t next_addr; |
| 106 | int32_t info_version; |
| 107 | uint32_t id; |
| 108 | uint8_t name[KMOD_MAX_NAME]; |
| 109 | uint8_t version[KMOD_MAX_NAME]; |
| 110 | int32_t reference_count; |
| 111 | uint32_t reference_list_addr; |
| 112 | uint32_t address; |
| 113 | uint32_t size; |
| 114 | uint32_t hdr_size; |
| 115 | uint32_t start_addr; |
| 116 | uint32_t stop_addr; |
| 117 | } kmod_info_32_v1_t; |
| 118 | |
| 119 | /* A compatibility definition of kmod_info_t for 64-bit kexts. |
| 120 | */ |
| 121 | typedef struct kmod_info_64_v1 { |
| 122 | uint64_t next_addr; |
| 123 | int32_t info_version; |
| 124 | uint32_t id; |
| 125 | uint8_t name[KMOD_MAX_NAME]; |
| 126 | uint8_t version[KMOD_MAX_NAME]; |
| 127 | int32_t reference_count; |
| 128 | uint64_t reference_list_addr; |
| 129 | uint64_t address; |
| 130 | uint64_t size; |
| 131 | uint64_t hdr_size; |
| 132 | uint64_t start_addr; |
| 133 | uint64_t stop_addr; |
| 134 | } kmod_info_64_v1_t; |
| 135 | |
| 136 | #pragma pack(pop) |
| 137 | |
| 138 | #if PRAGMA_MARK |
| 139 | #pragma mark Kmod structure declaration macros |
| 140 | #endif |
| 141 | /*********************************************************************** |
| 142 | * Kmod structure declaration macros |
| 143 | ***********************************************************************/ |
| 144 | #define KMOD_INFO_NAME kmod_info |
| 145 | #define KMOD_INFO_VERSION 1 |
| 146 | |
| 147 | #define KMOD_DECL(name, version) \ |
| 148 | static kmod_start_func_t name ## _module_start; \ |
| 149 | static kmod_stop_func_t name ## _module_stop; \ |
| 150 | kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1U, \ |
| 151 | { #name }, { version }, -1, 0, 0, 0, 0, \ |
| 152 | name ## _module_start, \ |
| 153 | name ## _module_stop }; |
| 154 | |
| 155 | #define KMOD_EXPLICIT_DECL(name, version, start, stop) \ |
| 156 | kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1U, \ |
| 157 | { #name }, { version }, -1, 0, 0, 0, 0, \ |
| 158 | start, stop }; |
| 159 | |
| 160 | #if PRAGMA_MARK |
| 161 | #pragma mark Kernel private declarations |
| 162 | #endif |
| 163 | /*********************************************************************** |
| 164 | * Kernel private declarations. |
| 165 | ***********************************************************************/ |
| 166 | #ifdef KERNEL_PRIVATE |
| 167 | |
| 168 | /* Implementation now in libkern/OSKextLib.cpp. */ |
| 169 | extern void kmod_panic_dump(vm_offset_t * addr, unsigned int dump_cnt); |
| 170 | |
| 171 | #if CONFIG_DTRACE |
| 172 | /* |
| 173 | * DTrace can take a flag indicating whether it should instrument |
| 174 | * probes immediately based on kernel symbols. This per kext |
| 175 | * flag overrides system mode in dtrace_modload(). |
| 176 | */ |
| 177 | #define KMOD_DTRACE_FORCE_INIT 0x01 |
| 178 | #define KMOD_DTRACE_STATIC_KEXT 0x02 |
| 179 | #define KMOD_DTRACE_NO_KERNEL_SYMS 0x04 |
| 180 | #endif /* CONFIG_DTRACE */ |
| 181 | |
| 182 | #endif /* KERNEL_PRIVATE */ |
| 183 | |
| 184 | |
| 185 | #if PRAGMA_MARK |
| 186 | #pragma mark Obsolete kmod stuff |
| 187 | #endif |
| 188 | /*********************************************************************** |
| 189 | * These 3 should be dropped but they're referenced by MIG declarations. |
| 190 | ***********************************************************************/ |
| 191 | typedef void * kmod_args_t; |
| 192 | typedef int kmod_control_flavor_t; |
| 193 | typedef kmod_info_t * kmod_info_array_t; |
| 194 | |
| 195 | __END_DECLS |
| 196 | |
| 197 | #endif /* _MACH_KMOD_H_ */ |
| 198 | |