1*e3723e1fSApple OSS Distributions /* 2*e3723e1fSApple OSS Distributions * Copyright (c) 2008 Apple Inc. All rights reserved. 3*e3723e1fSApple OSS Distributions * 4*e3723e1fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*e3723e1fSApple OSS Distributions * 6*e3723e1fSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*e3723e1fSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*e3723e1fSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*e3723e1fSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*e3723e1fSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*e3723e1fSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*e3723e1fSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*e3723e1fSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*e3723e1fSApple OSS Distributions * 15*e3723e1fSApple OSS Distributions * Please obtain a copy of the License at 16*e3723e1fSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*e3723e1fSApple OSS Distributions * 18*e3723e1fSApple OSS Distributions * The Original Code and all software distributed under the License are 19*e3723e1fSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*e3723e1fSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*e3723e1fSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*e3723e1fSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*e3723e1fSApple OSS Distributions * Please see the License for the specific language governing rights and 24*e3723e1fSApple OSS Distributions * limitations under the License. 25*e3723e1fSApple OSS Distributions * 26*e3723e1fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*e3723e1fSApple OSS Distributions */ 28*e3723e1fSApple OSS Distributions 29*e3723e1fSApple OSS Distributions #ifndef _LIBKERN_OSKEXTLIB_H 30*e3723e1fSApple OSS Distributions #define _LIBKERN_OSKEXTLIB_H 31*e3723e1fSApple OSS Distributions 32*e3723e1fSApple OSS Distributions #include <sys/cdefs.h> 33*e3723e1fSApple OSS Distributions #include <stdint.h> 34*e3723e1fSApple OSS Distributions #include <mach/kmod.h> 35*e3723e1fSApple OSS Distributions #include <mach/vm_types.h> 36*e3723e1fSApple OSS Distributions #include <uuid/uuid.h> 37*e3723e1fSApple OSS Distributions 38*e3723e1fSApple OSS Distributions #ifdef KERNEL 39*e3723e1fSApple OSS Distributions #include <libkern/OSTypes.h> 40*e3723e1fSApple OSS Distributions #include <libkern/OSReturn.h> 41*e3723e1fSApple OSS Distributions #else 42*e3723e1fSApple OSS Distributions #include <libkern/OSReturn.h> 43*e3723e1fSApple OSS Distributions #endif /* KERNEL */ 44*e3723e1fSApple OSS Distributions 45*e3723e1fSApple OSS Distributions __BEGIN_DECLS 46*e3723e1fSApple OSS Distributions 47*e3723e1fSApple OSS Distributions /*! 48*e3723e1fSApple OSS Distributions * @header 49*e3723e1fSApple OSS Distributions * 50*e3723e1fSApple OSS Distributions * Declares functions, basic return values, and other constants 51*e3723e1fSApple OSS Distributions * related to kernel extensions (kexts). 52*e3723e1fSApple OSS Distributions */ 53*e3723e1fSApple OSS Distributions 54*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 55*e3723e1fSApple OSS Distributions #pragma mark - 56*e3723e1fSApple OSS Distributions /********************************************************************/ 57*e3723e1fSApple OSS Distributions #pragma mark OSReturn Values for Kernel Extensions 58*e3723e1fSApple OSS Distributions /********************************************************************/ 59*e3723e1fSApple OSS Distributions #endif 60*e3723e1fSApple OSS Distributions /*! 61*e3723e1fSApple OSS Distributions * @group OSReturn Values for Kernel Extensions 62*e3723e1fSApple OSS Distributions * Many kext-related functions return these values, 63*e3723e1fSApple OSS Distributions * as well as those defined under 64*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/tdef/OSReturn OSReturn@/link</code> 65*e3723e1fSApple OSS Distributions * and other variants of <code>kern_return_t</code>. 66*e3723e1fSApple OSS Distributions */ 67*e3723e1fSApple OSS Distributions 68*e3723e1fSApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 69*e3723e1fSApple OSS Distributions /********************************************************************* 70*e3723e1fSApple OSS Distributions * Check libsyscall/mach/err_libkern.sub when editing or adding 71*e3723e1fSApple OSS Distributions * result codes! 72*e3723e1fSApple OSS Distributions *********************************************************************/ 73*e3723e1fSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 74*e3723e1fSApple OSS Distributions 75*e3723e1fSApple OSS Distributions #define sub_libkern_kext err_sub(2) 76*e3723e1fSApple OSS Distributions #define libkern_kext_err(code) (sys_libkern|sub_libkern_kext|(code)) 77*e3723e1fSApple OSS Distributions 78*e3723e1fSApple OSS Distributions 79*e3723e1fSApple OSS Distributions /*! 80*e3723e1fSApple OSS Distributions * @define kOSKextReturnInternalError 81*e3723e1fSApple OSS Distributions * @abstract An internal error in the kext library. 82*e3723e1fSApple OSS Distributions * Contrast with <code>@link //apple_ref/c/econst/OSReturnError 83*e3723e1fSApple OSS Distributions * OSReturnError@/link</code>. 84*e3723e1fSApple OSS Distributions */ 85*e3723e1fSApple OSS Distributions #define kOSKextReturnInternalError libkern_kext_err(0x1) 86*e3723e1fSApple OSS Distributions 87*e3723e1fSApple OSS Distributions /*! 88*e3723e1fSApple OSS Distributions * @define kOSKextReturnNoMemory 89*e3723e1fSApple OSS Distributions * @abstract Memory allocation failed. 90*e3723e1fSApple OSS Distributions */ 91*e3723e1fSApple OSS Distributions #define kOSKextReturnNoMemory libkern_kext_err(0x2) 92*e3723e1fSApple OSS Distributions 93*e3723e1fSApple OSS Distributions /*! 94*e3723e1fSApple OSS Distributions * @define kOSKextReturnNoResources 95*e3723e1fSApple OSS Distributions * @abstract Some resource other than memory (such as available load tags) 96*e3723e1fSApple OSS Distributions * is exhausted. 97*e3723e1fSApple OSS Distributions */ 98*e3723e1fSApple OSS Distributions #define kOSKextReturnNoResources libkern_kext_err(0x3) 99*e3723e1fSApple OSS Distributions 100*e3723e1fSApple OSS Distributions /*! 101*e3723e1fSApple OSS Distributions * @define kOSKextReturnNotPrivileged 102*e3723e1fSApple OSS Distributions * @abstract The caller lacks privileges to perform the requested operation. 103*e3723e1fSApple OSS Distributions */ 104*e3723e1fSApple OSS Distributions #define kOSKextReturnNotPrivileged libkern_kext_err(0x4) 105*e3723e1fSApple OSS Distributions 106*e3723e1fSApple OSS Distributions /*! 107*e3723e1fSApple OSS Distributions * @define kOSKextReturnInvalidArgument 108*e3723e1fSApple OSS Distributions * @abstract Invalid argument. 109*e3723e1fSApple OSS Distributions */ 110*e3723e1fSApple OSS Distributions #define kOSKextReturnInvalidArgument libkern_kext_err(0x5) 111*e3723e1fSApple OSS Distributions 112*e3723e1fSApple OSS Distributions /*! 113*e3723e1fSApple OSS Distributions * @define kOSKextReturnNotFound 114*e3723e1fSApple OSS Distributions * @abstract Search item not found. 115*e3723e1fSApple OSS Distributions */ 116*e3723e1fSApple OSS Distributions #define kOSKextReturnNotFound libkern_kext_err(0x6) 117*e3723e1fSApple OSS Distributions 118*e3723e1fSApple OSS Distributions /*! 119*e3723e1fSApple OSS Distributions * @define kOSKextReturnBadData 120*e3723e1fSApple OSS Distributions * @abstract Malformed data (not used for XML). 121*e3723e1fSApple OSS Distributions */ 122*e3723e1fSApple OSS Distributions #define kOSKextReturnBadData libkern_kext_err(0x7) 123*e3723e1fSApple OSS Distributions 124*e3723e1fSApple OSS Distributions /*! 125*e3723e1fSApple OSS Distributions * @define kOSKextReturnSerialization 126*e3723e1fSApple OSS Distributions * @abstract Error converting or (un)serializing URL, string, or XML. 127*e3723e1fSApple OSS Distributions */ 128*e3723e1fSApple OSS Distributions #define kOSKextReturnSerialization libkern_kext_err(0x8) 129*e3723e1fSApple OSS Distributions 130*e3723e1fSApple OSS Distributions /*! 131*e3723e1fSApple OSS Distributions * @define kOSKextReturnUnsupported 132*e3723e1fSApple OSS Distributions * @abstract Operation is no longer or not yet supported. 133*e3723e1fSApple OSS Distributions */ 134*e3723e1fSApple OSS Distributions #define kOSKextReturnUnsupported libkern_kext_err(0x9) 135*e3723e1fSApple OSS Distributions 136*e3723e1fSApple OSS Distributions /*! 137*e3723e1fSApple OSS Distributions * @define kOSKextReturnDisabled 138*e3723e1fSApple OSS Distributions * @abstract Operation is currently disabled. 139*e3723e1fSApple OSS Distributions */ 140*e3723e1fSApple OSS Distributions #define kOSKextReturnDisabled libkern_kext_err(0xa) 141*e3723e1fSApple OSS Distributions 142*e3723e1fSApple OSS Distributions /*! 143*e3723e1fSApple OSS Distributions * @define kOSKextReturnNotAKext 144*e3723e1fSApple OSS Distributions * @abstract Bundle is not a kernel extension. 145*e3723e1fSApple OSS Distributions */ 146*e3723e1fSApple OSS Distributions #define kOSKextReturnNotAKext libkern_kext_err(0xb) 147*e3723e1fSApple OSS Distributions 148*e3723e1fSApple OSS Distributions /*! 149*e3723e1fSApple OSS Distributions * @define kOSKextReturnValidation 150*e3723e1fSApple OSS Distributions * @abstract Validation failures encountered; check diagnostics for details. 151*e3723e1fSApple OSS Distributions */ 152*e3723e1fSApple OSS Distributions #define kOSKextReturnValidation libkern_kext_err(0xc) 153*e3723e1fSApple OSS Distributions 154*e3723e1fSApple OSS Distributions /*! 155*e3723e1fSApple OSS Distributions * @define kOSKextReturnAuthentication 156*e3723e1fSApple OSS Distributions * @abstract Authetication failures encountered; check diagnostics for details. 157*e3723e1fSApple OSS Distributions */ 158*e3723e1fSApple OSS Distributions #define kOSKextReturnAuthentication libkern_kext_err(0xd) 159*e3723e1fSApple OSS Distributions 160*e3723e1fSApple OSS Distributions /*! 161*e3723e1fSApple OSS Distributions * @define kOSKextReturnDependencies 162*e3723e1fSApple OSS Distributions * @abstract Dependency resolution failures encountered; check diagnostics for details. 163*e3723e1fSApple OSS Distributions */ 164*e3723e1fSApple OSS Distributions #define kOSKextReturnDependencies libkern_kext_err(0xe) 165*e3723e1fSApple OSS Distributions 166*e3723e1fSApple OSS Distributions /*! 167*e3723e1fSApple OSS Distributions * @define kOSKextReturnArchNotFound 168*e3723e1fSApple OSS Distributions * @abstract Kext does not contain code for the requested architecture. 169*e3723e1fSApple OSS Distributions */ 170*e3723e1fSApple OSS Distributions #define kOSKextReturnArchNotFound libkern_kext_err(0xf) 171*e3723e1fSApple OSS Distributions 172*e3723e1fSApple OSS Distributions /*! 173*e3723e1fSApple OSS Distributions * @define kOSKextReturnCache 174*e3723e1fSApple OSS Distributions * @abstract An error occurred processing a system kext cache. 175*e3723e1fSApple OSS Distributions */ 176*e3723e1fSApple OSS Distributions #define kOSKextReturnCache libkern_kext_err(0x10) 177*e3723e1fSApple OSS Distributions 178*e3723e1fSApple OSS Distributions /*! 179*e3723e1fSApple OSS Distributions * @define kOSKextReturnDeferred 180*e3723e1fSApple OSS Distributions * @abstract Operation has been posted asynchronously to user space (kernel only). 181*e3723e1fSApple OSS Distributions */ 182*e3723e1fSApple OSS Distributions #define kOSKextReturnDeferred libkern_kext_err(0x11) 183*e3723e1fSApple OSS Distributions 184*e3723e1fSApple OSS Distributions /*! 185*e3723e1fSApple OSS Distributions * @define kOSKextReturnBootLevel 186*e3723e1fSApple OSS Distributions * @abstract Kext not loadable or operation not allowed at current boot level. 187*e3723e1fSApple OSS Distributions */ 188*e3723e1fSApple OSS Distributions #define kOSKextReturnBootLevel libkern_kext_err(0x12) 189*e3723e1fSApple OSS Distributions 190*e3723e1fSApple OSS Distributions /*! 191*e3723e1fSApple OSS Distributions * @define kOSKextReturnNotLoadable 192*e3723e1fSApple OSS Distributions * @abstract Kext cannot be loaded; check diagnostics for details. 193*e3723e1fSApple OSS Distributions */ 194*e3723e1fSApple OSS Distributions #define kOSKextReturnNotLoadable libkern_kext_err(0x13) 195*e3723e1fSApple OSS Distributions 196*e3723e1fSApple OSS Distributions /*! 197*e3723e1fSApple OSS Distributions * @define kOSKextReturnLoadedVersionDiffers 198*e3723e1fSApple OSS Distributions * @abstract A different version (or executable UUID, or executable by checksum) 199*e3723e1fSApple OSS Distributions * of the requested kext is already loaded. 200*e3723e1fSApple OSS Distributions */ 201*e3723e1fSApple OSS Distributions #define kOSKextReturnLoadedVersionDiffers libkern_kext_err(0x14) 202*e3723e1fSApple OSS Distributions 203*e3723e1fSApple OSS Distributions /*! 204*e3723e1fSApple OSS Distributions * @define kOSKextReturnDependencyLoadError 205*e3723e1fSApple OSS Distributions * @abstract A load error occurred on a dependency of the kext being loaded. 206*e3723e1fSApple OSS Distributions */ 207*e3723e1fSApple OSS Distributions #define kOSKextReturnDependencyLoadError libkern_kext_err(0x15) 208*e3723e1fSApple OSS Distributions 209*e3723e1fSApple OSS Distributions /*! 210*e3723e1fSApple OSS Distributions * @define kOSKextReturnLinkError 211*e3723e1fSApple OSS Distributions * @abstract A link failure occured with this kext or a dependency. 212*e3723e1fSApple OSS Distributions */ 213*e3723e1fSApple OSS Distributions #define kOSKextReturnLinkError libkern_kext_err(0x16) 214*e3723e1fSApple OSS Distributions 215*e3723e1fSApple OSS Distributions /*! 216*e3723e1fSApple OSS Distributions * @define kOSKextReturnStartStopError 217*e3723e1fSApple OSS Distributions * @abstract The kext start or stop routine returned an error. 218*e3723e1fSApple OSS Distributions */ 219*e3723e1fSApple OSS Distributions #define kOSKextReturnStartStopError libkern_kext_err(0x17) 220*e3723e1fSApple OSS Distributions 221*e3723e1fSApple OSS Distributions /*! 222*e3723e1fSApple OSS Distributions * @define kOSKextReturnInUse 223*e3723e1fSApple OSS Distributions * @abstract The kext is currently in use or has outstanding references, 224*e3723e1fSApple OSS Distributions * and cannot be unloaded. 225*e3723e1fSApple OSS Distributions */ 226*e3723e1fSApple OSS Distributions #define kOSKextReturnInUse libkern_kext_err(0x18) 227*e3723e1fSApple OSS Distributions 228*e3723e1fSApple OSS Distributions /*! 229*e3723e1fSApple OSS Distributions * @define kOSKextReturnTimeout 230*e3723e1fSApple OSS Distributions * @abstract A kext request has timed out. 231*e3723e1fSApple OSS Distributions */ 232*e3723e1fSApple OSS Distributions #define kOSKextReturnTimeout libkern_kext_err(0x19) 233*e3723e1fSApple OSS Distributions 234*e3723e1fSApple OSS Distributions /*! 235*e3723e1fSApple OSS Distributions * @define kOSKextReturnStopping 236*e3723e1fSApple OSS Distributions * @abstract The kext is in the process of stopping; requests cannot be made. 237*e3723e1fSApple OSS Distributions */ 238*e3723e1fSApple OSS Distributions #define kOSKextReturnStopping libkern_kext_err(0x1a) 239*e3723e1fSApple OSS Distributions 240*e3723e1fSApple OSS Distributions /*! 241*e3723e1fSApple OSS Distributions * @define kOSKextReturnSystemPolicy 242*e3723e1fSApple OSS Distributions * @abstract The kext was prevented from loading due to system policy. 243*e3723e1fSApple OSS Distributions */ 244*e3723e1fSApple OSS Distributions #define kOSKextReturnSystemPolicy libkern_kext_err(0x1b) 245*e3723e1fSApple OSS Distributions 246*e3723e1fSApple OSS Distributions /*! 247*e3723e1fSApple OSS Distributions * @define kOSKextReturnKCLoadFailure 248*e3723e1fSApple OSS Distributions * @abstract Loading of the System KC failed 249*e3723e1fSApple OSS Distributions */ 250*e3723e1fSApple OSS Distributions #define kOSKextReturnKCLoadFailure libkern_kext_err(0x1c) 251*e3723e1fSApple OSS Distributions 252*e3723e1fSApple OSS Distributions /*! 253*e3723e1fSApple OSS Distributions * @define kOSKextReturnKCLoadFailureSystemKC 254*e3723e1fSApple OSS Distributions * @abstract Loading of the System KC failed 255*e3723e1fSApple OSS Distributions * 256*e3723e1fSApple OSS Distributions * This a sub-code of kOSKextReturnKCLoadFailure. It can be OR'd together 257*e3723e1fSApple OSS Distributions * with: kOSKextReturnKCLoadFailureAuxKC 258*e3723e1fSApple OSS Distributions * 259*e3723e1fSApple OSS Distributions * If both the System and Aux KCs fail to load, then the error code will be: 260*e3723e1fSApple OSS Distributions * libkern_kext_err(0x1f) 261*e3723e1fSApple OSS Distributions */ 262*e3723e1fSApple OSS Distributions #define kOSKextReturnKCLoadFailureSystemKC libkern_kext_err(0x1d) 263*e3723e1fSApple OSS Distributions 264*e3723e1fSApple OSS Distributions /*! 265*e3723e1fSApple OSS Distributions * @define kOSKextReturnKCLoadFailureAuxKC 266*e3723e1fSApple OSS Distributions * @abstract Loading of the Aux KC failed 267*e3723e1fSApple OSS Distributions * 268*e3723e1fSApple OSS Distributions * This a sub-code of kOSKextReturnKCLoadFailure. It can be OR'd together 269*e3723e1fSApple OSS Distributions * with: kOSKextReturnKCLoadFailureSystemKC 270*e3723e1fSApple OSS Distributions * 271*e3723e1fSApple OSS Distributions * If both the System and Aux KCs fail to load, then the error code will be: 272*e3723e1fSApple OSS Distributions * libkern_kext_err(0x1f) 273*e3723e1fSApple OSS Distributions */ 274*e3723e1fSApple OSS Distributions #define kOSKextReturnKCLoadFailureAuxKC libkern_kext_err(0x1e) 275*e3723e1fSApple OSS Distributions 276*e3723e1fSApple OSS Distributions /* next available error is: libkern_kext_err(0x20) */ 277*e3723e1fSApple OSS Distributions 278*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 279*e3723e1fSApple OSS Distributions #pragma mark - 280*e3723e1fSApple OSS Distributions /********************************************************************/ 281*e3723e1fSApple OSS Distributions #pragma mark Kext/OSBundle Property List Keys 282*e3723e1fSApple OSS Distributions /********************************************************************/ 283*e3723e1fSApple OSS Distributions #endif 284*e3723e1fSApple OSS Distributions /*! 285*e3723e1fSApple OSS Distributions * @group Kext Property List Keys 286*e3723e1fSApple OSS Distributions * These constants cover CFBundle properties defined for kernel extensions. 287*e3723e1fSApple OSS Distributions * Because they are used in the kernel, if you want to use one with 288*e3723e1fSApple OSS Distributions * CFBundle APIs you'll need to wrap it in a <code>CFSTR()</code> macro. 289*e3723e1fSApple OSS Distributions */ 290*e3723e1fSApple OSS Distributions 291*e3723e1fSApple OSS Distributions #ifdef KERNEL 292*e3723e1fSApple OSS Distributions /* Define C-string versions of the CFBundle keys for use in the kernel. 293*e3723e1fSApple OSS Distributions */ 294*e3723e1fSApple OSS Distributions #define kCFBundleIdentifierKey "CFBundleIdentifier" 295*e3723e1fSApple OSS Distributions #define kCFBundleIdentifierKernelKey "CFBundleIdentifierKernel" 296*e3723e1fSApple OSS Distributions #define kCFBundleVersionKey "CFBundleVersion" 297*e3723e1fSApple OSS Distributions #define kCFBundleNameKey "CFBundleName" 298*e3723e1fSApple OSS Distributions #define kCFBundleExecutableKey "CFBundleExecutable" 299*e3723e1fSApple OSS Distributions #define kCFBundlePackageTypeKey "CFBundlePackageType" 300*e3723e1fSApple OSS Distributions #define kCFBundleDriverKitUUIDKey "CFBundleDriverKitUUID" 301*e3723e1fSApple OSS Distributions #define kCFBundleDriverKitExecutableKey "CFBundleUEXTExecutable" 302*e3723e1fSApple OSS Distributions #endif /* KERNEL */ 303*e3723e1fSApple OSS Distributions 304*e3723e1fSApple OSS Distributions /*! 305*e3723e1fSApple OSS Distributions * @define kOSBundleCompatibleVersionKey 306*e3723e1fSApple OSS Distributions * @abstract A string giving the backwards-compatible version of a library kext 307*e3723e1fSApple OSS Distributions * in extended Mac OS 'vers' format (####.##.##s{1-255} where 's' 308*e3723e1fSApple OSS Distributions * is a build stage 'd', 'a', 'b', 'f' or 'fc'). 309*e3723e1fSApple OSS Distributions */ 310*e3723e1fSApple OSS Distributions #define kOSBundleCompatibleVersionKey "OSBundleCompatibleVersion" 311*e3723e1fSApple OSS Distributions 312*e3723e1fSApple OSS Distributions /*! 313*e3723e1fSApple OSS Distributions * @define kOSBundleEnableKextLoggingKey 314*e3723e1fSApple OSS Distributions * @abstract Set to true to have the kernel kext logging spec applied 315*e3723e1fSApple OSS Distributions * to the kext. 316*e3723e1fSApple OSS Distributions * See <code>@link //apple_ref/c/econst/OSKextLogSpec 317*e3723e1fSApple OSS Distributions * OSKextLogSpec@/link</code>. 318*e3723e1fSApple OSS Distributions */ 319*e3723e1fSApple OSS Distributions #define kOSBundleEnableKextLoggingKey "OSBundleEnableKextLogging" 320*e3723e1fSApple OSS Distributions 321*e3723e1fSApple OSS Distributions /*! 322*e3723e1fSApple OSS Distributions * @define kOSBundleIsInterfaceKey 323*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether the kext executable 324*e3723e1fSApple OSS Distributions * contains only symbol references. 325*e3723e1fSApple OSS Distributions */ 326*e3723e1fSApple OSS Distributions #define kOSBundleIsInterfaceKey "OSBundleIsInterface" 327*e3723e1fSApple OSS Distributions 328*e3723e1fSApple OSS Distributions /*! 329*e3723e1fSApple OSS Distributions * @define kOSBundleLibrariesKey 330*e3723e1fSApple OSS Distributions * @abstract A dictionary listing link dependencies for this kext. 331*e3723e1fSApple OSS Distributions * Keys are bundle identifiers, values are version strings. 332*e3723e1fSApple OSS Distributions */ 333*e3723e1fSApple OSS Distributions #define kOSBundleLibrariesKey "OSBundleLibraries" 334*e3723e1fSApple OSS Distributions 335*e3723e1fSApple OSS Distributions /*! 336*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredKey 337*e3723e1fSApple OSS Distributions * @abstract A string indicating in which kinds of startup this kext 338*e3723e1fSApple OSS Distributions * may need to load during early startup (before 339*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/man/8/kextd kextcache(8)@/link</code>). 340*e3723e1fSApple OSS Distributions * @discussion 341*e3723e1fSApple OSS Distributions * The value is one of: 342*e3723e1fSApple OSS Distributions * <ul> 343*e3723e1fSApple OSS Distributions * <li>@link kOSBundleRequiredRoot "OSBundleRequiredRoot"@/link</li> 344*e3723e1fSApple OSS Distributions * <li>@link kOSBundleRequiredLocalRoot "OSBundleRequiredLocalRoot"@/link</li> 345*e3723e1fSApple OSS Distributions * <li>@link kOSBundleRequiredNetworkRoot "OSBundleRequiredNetworkRoot"@/link</li> 346*e3723e1fSApple OSS Distributions * <li>@link kOSBundleRequiredSafeBoot "OSBundleRequiredSafeBoot"@/link</li> 347*e3723e1fSApple OSS Distributions * <li>@link kOSBundleRequiredConsole "OSBundleRequiredConsole"@/link</li> 348*e3723e1fSApple OSS Distributions * </ul> 349*e3723e1fSApple OSS Distributions * 350*e3723e1fSApple OSS Distributions * Use this property judiciously. 351*e3723e1fSApple OSS Distributions * Every kext that declares a value other than "OSBundleRequiredSafeBoot" 352*e3723e1fSApple OSS Distributions * increases startup time, as the booter must read it into memory, 353*e3723e1fSApple OSS Distributions * or startup kext caches must include it. 354*e3723e1fSApple OSS Distributions */ 355*e3723e1fSApple OSS Distributions #define kOSBundleRequiredKey "OSBundleRequired" 356*e3723e1fSApple OSS Distributions 357*e3723e1fSApple OSS Distributions /*! 358*e3723e1fSApple OSS Distributions * @define kOSBundleRequireExplicitLoadKey 359*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether the kext requires an 360*e3723e1fSApple OSS Distributions * explicit kextload in order to start/match. 361*e3723e1fSApple OSS Distributions */ 362*e3723e1fSApple OSS Distributions #define kOSBundleRequireExplicitLoadKey "OSBundleRequireExplicitLoad" 363*e3723e1fSApple OSS Distributions 364*e3723e1fSApple OSS Distributions /*! 365*e3723e1fSApple OSS Distributions * @define kOSBundleAllowUserLoadKey 366*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether 367*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/man/8/kextd kextcache(8)@/link</code> 368*e3723e1fSApple OSS Distributions * will honor a non-root process's request to load a kext. 369*e3723e1fSApple OSS Distributions * @discussion 370*e3723e1fSApple OSS Distributions * See <code>@link //apple_ref/doc/compositePage/c/func/KextManagerLoadKextWithURL 371*e3723e1fSApple OSS Distributions * KextManagerLoadKextWithURL@/link</code> 372*e3723e1fSApple OSS Distributions * and <code>@link //apple_ref/doc/compositePage/c/func/KextManagerLoadKextWithIdentifier 373*e3723e1fSApple OSS Distributions * KextManagerLoadKextWithIdentifier@/link</code>. 374*e3723e1fSApple OSS Distributions */ 375*e3723e1fSApple OSS Distributions #define kOSBundleAllowUserLoadKey "OSBundleAllowUserLoad" 376*e3723e1fSApple OSS Distributions 377*e3723e1fSApple OSS Distributions /*! 378*e3723e1fSApple OSS Distributions * @define kOSBundleAllowUserTerminateKey 379*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether the kextunload tool 380*e3723e1fSApple OSS Distributions * is allowed to issue IOService terminate to classes defined in this kext. 381*e3723e1fSApple OSS Distributions * @discussion A boolean value indicating whether the kextunload tool 382*e3723e1fSApple OSS Distributions * is allowed to issue IOService terminate to classes defined in this kext. 383*e3723e1fSApple OSS Distributions */ 384*e3723e1fSApple OSS Distributions #define kOSBundleAllowUserTerminateKey "OSBundleAllowUserTerminate" 385*e3723e1fSApple OSS Distributions 386*e3723e1fSApple OSS Distributions /*! 387*e3723e1fSApple OSS Distributions * @define kOSKernelResourceKey 388*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether the kext represents a built-in 389*e3723e1fSApple OSS Distributions * component of the kernel. 390*e3723e1fSApple OSS Distributions */ 391*e3723e1fSApple OSS Distributions #define kOSKernelResourceKey "OSKernelResource" 392*e3723e1fSApple OSS Distributions 393*e3723e1fSApple OSS Distributions /*! 394*e3723e1fSApple OSS Distributions * @define kOSKextVariantOverrideKey 395*e3723e1fSApple OSS Distributions * @abstract A dictionary with target names as key and a target-specific variant 396*e3723e1fSApple OSS Distributions * name as value. 397*e3723e1fSApple OSS Distributions */ 398*e3723e1fSApple OSS Distributions #define kOSKextVariantOverrideKey "OSKextVariantOverride" 399*e3723e1fSApple OSS Distributions 400*e3723e1fSApple OSS Distributions /*! 401*e3723e1fSApple OSS Distributions * @define kIOKitPersonalitiesKey 402*e3723e1fSApple OSS Distributions * @abstract A dictionary of dictionaries used in matching for I/O Kit drivers. 403*e3723e1fSApple OSS Distributions */ 404*e3723e1fSApple OSS Distributions #define kIOKitPersonalitiesKey "IOKitPersonalities" 405*e3723e1fSApple OSS Distributions 406*e3723e1fSApple OSS Distributions /* 407*e3723e1fSApple OSS Distributions * @define kIOPersonalityPublisherKey 408*e3723e1fSApple OSS Distributions * @abstract Used in personalities sent to the I/O Kit, 409*e3723e1fSApple OSS Distributions * contains the CFBundleIdentifier of the kext 410*e3723e1fSApple OSS Distributions * that the personality originated in. 411*e3723e1fSApple OSS Distributions */ 412*e3723e1fSApple OSS Distributions #define kIOPersonalityPublisherKey "IOPersonalityPublisher" 413*e3723e1fSApple OSS Distributions 414*e3723e1fSApple OSS Distributions #if CONFIG_KEC_FIPS 415*e3723e1fSApple OSS Distributions /* 416*e3723e1fSApple OSS Distributions * @define kAppleTextHashesKey 417*e3723e1fSApple OSS Distributions * @abstract A dictionary conataining hashes for corecrypto kext. 418*e3723e1fSApple OSS Distributions */ 419*e3723e1fSApple OSS Distributions #define kAppleTextHashesKey "AppleTextHashes" 420*e3723e1fSApple OSS Distributions #endif 421*e3723e1fSApple OSS Distributions 422*e3723e1fSApple OSS Distributions /*! 423*e3723e1fSApple OSS Distributions * @define kOSMutableSegmentCopy 424*e3723e1fSApple OSS Distributions * @abstract A boolean value indicating whether the kext requires a copy of 425*e3723e1fSApple OSS Distributions * its mutable segments to be kept in memory, and then reset when the kext 426*e3723e1fSApple OSS Distributions * unloads. This should be used with caution as it will increase the 427*e3723e1fSApple OSS Distributions * amount of memory used by the kext. 428*e3723e1fSApple OSS Distributions */ 429*e3723e1fSApple OSS Distributions #define kOSMutableSegmentCopy "OSMutableSegmentCopy" 430*e3723e1fSApple OSS Distributions 431*e3723e1fSApple OSS Distributions 432*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 433*e3723e1fSApple OSS Distributions /********************************************************************/ 434*e3723e1fSApple OSS Distributions #pragma mark Kext/OSBundle Property Deprecated Keys 435*e3723e1fSApple OSS Distributions /********************************************************************/ 436*e3723e1fSApple OSS Distributions #endif 437*e3723e1fSApple OSS Distributions /* 438*e3723e1fSApple OSS Distributions * @define kOSBundleDebugLevelKey 439*e3723e1fSApple OSS Distributions * @abstract 440*e3723e1fSApple OSS Distributions * Deprecated (used on some releases of Mac OS X prior to 10.6 Snow Leopard). 441*e3723e1fSApple OSS Distributions * Value is an integer from 1-6, corresponding to the verbose levels 442*e3723e1fSApple OSS Distributions * of kext tools on those releases. 443*e3723e1fSApple OSS Distributions * On 10.6 Snow Leopard, use <code>@link OSKextEnableKextLogging 444*e3723e1fSApple OSS Distributions * OSKextEnableKextLogging@/link</code>. 445*e3723e1fSApple OSS Distributions */ 446*e3723e1fSApple OSS Distributions #define kOSBundleDebugLevelKey "OSBundleDebugLevel" 447*e3723e1fSApple OSS Distributions 448*e3723e1fSApple OSS Distributions /*! 449*e3723e1fSApple OSS Distributions * @define kOSBundleSharedExecutableIdentifierKey 450*e3723e1fSApple OSS Distributions * @abstract Deprecated (used on some releases of Mac OS X 451*e3723e1fSApple OSS Distributions * prior to 10.6 Snow Leopard). 452*e3723e1fSApple OSS Distributions * Value is the bundle identifier of the pseudokext 453*e3723e1fSApple OSS Distributions * that contains an executable shared by this kext. 454*e3723e1fSApple OSS Distributions */ 455*e3723e1fSApple OSS Distributions #define kOSBundleSharedExecutableIdentifierKey "OSBundleSharedExecutableIdentifier" 456*e3723e1fSApple OSS Distributions 457*e3723e1fSApple OSS Distributions 458*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 459*e3723e1fSApple OSS Distributions /********************************************************************/ 460*e3723e1fSApple OSS Distributions #pragma mark Kext/OSBundle Property List Values 461*e3723e1fSApple OSS Distributions /********************************************************************/ 462*e3723e1fSApple OSS Distributions #endif 463*e3723e1fSApple OSS Distributions 464*e3723e1fSApple OSS Distributions /*! 465*e3723e1fSApple OSS Distributions * @group Kext Property List Values 466*e3723e1fSApple OSS Distributions * These constants encompass established values 467*e3723e1fSApple OSS Distributions * for kernel extension bundle properties. 468*e3723e1fSApple OSS Distributions */ 469*e3723e1fSApple OSS Distributions 470*e3723e1fSApple OSS Distributions /*! 471*e3723e1fSApple OSS Distributions * @define kOSKextKernelIdentifier 472*e3723e1fSApple OSS Distributions * @abstract 473*e3723e1fSApple OSS Distributions * This is the CFBundleIdentifier user for the kernel itself. 474*e3723e1fSApple OSS Distributions */ 475*e3723e1fSApple OSS Distributions #define kOSKextKernelIdentifier "__kernel__" 476*e3723e1fSApple OSS Distributions 477*e3723e1fSApple OSS Distributions #if CONFIG_SPTM && PRIVATE 478*e3723e1fSApple OSS Distributions /*! 479*e3723e1fSApple OSS Distributions * @define kOSKextSPTMIdentifier 480*e3723e1fSApple OSS Distributions * @abstract 481*e3723e1fSApple OSS Distributions * This is the CFBundleIdentifier used by the Secure Page Table Monitor (SPTM). 482*e3723e1fSApple OSS Distributions */ 483*e3723e1fSApple OSS Distributions #define kOSKextSPTMIdentifier "com.apple.sptm" 484*e3723e1fSApple OSS Distributions 485*e3723e1fSApple OSS Distributions /*! 486*e3723e1fSApple OSS Distributions * @define kOSKextTXMIdentifier 487*e3723e1fSApple OSS Distributions * @abstract 488*e3723e1fSApple OSS Distributions * This is the CFBundleIdentifier used by the Trusted Execution Monitor (TXM). 489*e3723e1fSApple OSS Distributions */ 490*e3723e1fSApple OSS Distributions #define kOSKextTXMIdentifier "com.apple.txm" 491*e3723e1fSApple OSS Distributions #endif /* CONFIG_SPTM */ 492*e3723e1fSApple OSS Distributions 493*e3723e1fSApple OSS Distributions /*! 494*e3723e1fSApple OSS Distributions * @define kOSKextBundlePackageTypeKext 495*e3723e1fSApple OSS Distributions * @abstract 496*e3723e1fSApple OSS Distributions * The bundle type value for Kernel Extensions. 497*e3723e1fSApple OSS Distributions */ 498*e3723e1fSApple OSS Distributions #define kOSKextBundlePackageTypeKext "KEXT" 499*e3723e1fSApple OSS Distributions 500*e3723e1fSApple OSS Distributions /*! 501*e3723e1fSApple OSS Distributions * @define kOSKextBundlePackageTypeDriverKit 502*e3723e1fSApple OSS Distributions * @abstract 503*e3723e1fSApple OSS Distributions * The bundle type value for Driver Extensions. 504*e3723e1fSApple OSS Distributions */ 505*e3723e1fSApple OSS Distributions #define kOSKextBundlePackageTypeDriverKit "DEXT" 506*e3723e1fSApple OSS Distributions 507*e3723e1fSApple OSS Distributions /*! 508*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredRoot 509*e3723e1fSApple OSS Distributions * @abstract 510*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 511*e3723e1fSApple OSS Distributions * value indicates that the kext may be needed to mount the root filesystem 512*e3723e1fSApple OSS Distributions * whether starting from a local or a network volume. 513*e3723e1fSApple OSS Distributions */ 514*e3723e1fSApple OSS Distributions #define kOSBundleRequiredRoot "Root" 515*e3723e1fSApple OSS Distributions 516*e3723e1fSApple OSS Distributions /*! 517*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredLocalRoot 518*e3723e1fSApple OSS Distributions * @abstract 519*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 520*e3723e1fSApple OSS Distributions * value indicates that the kext may be needed to mount the root filesystem 521*e3723e1fSApple OSS Distributions * when starting from a local disk. 522*e3723e1fSApple OSS Distributions */ 523*e3723e1fSApple OSS Distributions #define kOSBundleRequiredLocalRoot "Local-Root" 524*e3723e1fSApple OSS Distributions 525*e3723e1fSApple OSS Distributions /*! 526*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredNetworkRoot 527*e3723e1fSApple OSS Distributions * @abstract 528*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 529*e3723e1fSApple OSS Distributions * value indicates that the kext may be needed to mount the root filesystem 530*e3723e1fSApple OSS Distributions * when starting over a network connection. 531*e3723e1fSApple OSS Distributions */ 532*e3723e1fSApple OSS Distributions #define kOSBundleRequiredNetworkRoot "Network-Root" 533*e3723e1fSApple OSS Distributions 534*e3723e1fSApple OSS Distributions /*! 535*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredSafeBoot 536*e3723e1fSApple OSS Distributions * @abstract 537*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 538*e3723e1fSApple OSS Distributions * value indicates that the kext can be loaded during a safe startup. 539*e3723e1fSApple OSS Distributions * This value does not normally cause the kext to be read by the booter 540*e3723e1fSApple OSS Distributions * or included in startup kext caches. 541*e3723e1fSApple OSS Distributions */ 542*e3723e1fSApple OSS Distributions #define kOSBundleRequiredSafeBoot "Safe Boot" 543*e3723e1fSApple OSS Distributions 544*e3723e1fSApple OSS Distributions /*! 545*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredConsole 546*e3723e1fSApple OSS Distributions * @abstract 547*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 548*e3723e1fSApple OSS Distributions * value indicates that the kext may be needed for console access 549*e3723e1fSApple OSS Distributions * (specifically in a single-user startup when 550*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>. 551*e3723e1fSApple OSS Distributions * does not run) 552*e3723e1fSApple OSS Distributions * and should be loaded during early startup. 553*e3723e1fSApple OSS Distributions */ 554*e3723e1fSApple OSS Distributions #define kOSBundleRequiredConsole "Console" 555*e3723e1fSApple OSS Distributions 556*e3723e1fSApple OSS Distributions /*! 557*e3723e1fSApple OSS Distributions * @define kOSBundleRequiredDriverKit 558*e3723e1fSApple OSS Distributions * @abstract 559*e3723e1fSApple OSS Distributions * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code> 560*e3723e1fSApple OSS Distributions * value indicates that the driver extension's (DriverKit driver's) 561*e3723e1fSApple OSS Distributions * personalities must be present in the kernel at early boot (specifically 562*e3723e1fSApple OSS Distributions * before <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code> starts) 563*e3723e1fSApple OSS Distributions * in order to compete with kexts built into the prelinkedkernel. Note that 564*e3723e1fSApple OSS Distributions * kextd is still required to launch the user space driver binary. The IOKit 565*e3723e1fSApple OSS Distributions * matching will happen during early boot, and the actual driver launch 566*e3723e1fSApple OSS Distributions * will happen after kextd starts. 567*e3723e1fSApple OSS Distributions */ 568*e3723e1fSApple OSS Distributions #define kOSBundleRequiredDriverKit "DriverKit" 569*e3723e1fSApple OSS Distributions 570*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 571*e3723e1fSApple OSS Distributions #pragma mark - 572*e3723e1fSApple OSS Distributions /********************************************************************/ 573*e3723e1fSApple OSS Distributions #pragma mark Kext Information 574*e3723e1fSApple OSS Distributions /********************************************************************/ 575*e3723e1fSApple OSS Distributions #endif 576*e3723e1fSApple OSS Distributions /*! 577*e3723e1fSApple OSS Distributions * @group Kext Information 578*e3723e1fSApple OSS Distributions * Types, constants, and macros providing a kext with information 579*e3723e1fSApple OSS Distributions * about itself. 580*e3723e1fSApple OSS Distributions */ 581*e3723e1fSApple OSS Distributions 582*e3723e1fSApple OSS Distributions #ifdef KERNEL 583*e3723e1fSApple OSS Distributions /*! 584*e3723e1fSApple OSS Distributions * @typedef OSKextLoadTag 585*e3723e1fSApple OSS Distributions * 586*e3723e1fSApple OSS Distributions * @abstract 587*e3723e1fSApple OSS Distributions * A unique identifier assigned to a loaded instanace of a kext. 588*e3723e1fSApple OSS Distributions * 589*e3723e1fSApple OSS Distributions * @discussion 590*e3723e1fSApple OSS Distributions * If a kext is unloaded and later reloaded, the new instance 591*e3723e1fSApple OSS Distributions * has a different load tag. 592*e3723e1fSApple OSS Distributions * 593*e3723e1fSApple OSS Distributions * A kext can get its own load tag in the <code>kmod_info_t</code> 594*e3723e1fSApple OSS Distributions * structure passed into its module start routine, as the 595*e3723e1fSApple OSS Distributions * <code>id</code> field (cast to this type). 596*e3723e1fSApple OSS Distributions * You can use the load tag with the functions 597*e3723e1fSApple OSS Distributions * <code>@link OSKextRetainKextWithLoadTag 598*e3723e1fSApple OSS Distributions * OSKextRetainKextWithLoadTag@/link</code> and 599*e3723e1fSApple OSS Distributions * <code>@link OSKextReleaseKextWithLoadTag 600*e3723e1fSApple OSS Distributions * OSKextReleaseKextWithLoadTag@/link</code>. 601*e3723e1fSApple OSS Distributions */ 602*e3723e1fSApple OSS Distributions #else 603*e3723e1fSApple OSS Distributions /*! 604*e3723e1fSApple OSS Distributions * @typedef OSKextLoadTag 605*e3723e1fSApple OSS Distributions * 606*e3723e1fSApple OSS Distributions * @abstract 607*e3723e1fSApple OSS Distributions * A unique identifier assigned to a loaded instanace of a kext. 608*e3723e1fSApple OSS Distributions * 609*e3723e1fSApple OSS Distributions * @discussion 610*e3723e1fSApple OSS Distributions * If a kext is unloaded and later reloaded, the new instance 611*e3723e1fSApple OSS Distributions * has a different load tag. 612*e3723e1fSApple OSS Distributions * 613*e3723e1fSApple OSS Distributions * A kext can get its own load tag in the <code>kmod_info_t</code> 614*e3723e1fSApple OSS Distributions * structure passed into its module start routine, as the 615*e3723e1fSApple OSS Distributions * <code>id</code> field (cast to this type). 616*e3723e1fSApple OSS Distributions */ 617*e3723e1fSApple OSS Distributions #endif 618*e3723e1fSApple OSS Distributions typedef uint32_t OSKextLoadTag; 619*e3723e1fSApple OSS Distributions 620*e3723e1fSApple OSS Distributions /*! 621*e3723e1fSApple OSS Distributions * @define kOSKextInvalidLoadTag 622*e3723e1fSApple OSS Distributions * 623*e3723e1fSApple OSS Distributions * @abstract 624*e3723e1fSApple OSS Distributions * A load tag value that will never be used for a loaded kext; 625*e3723e1fSApple OSS Distributions * indicates kext not found. 626*e3723e1fSApple OSS Distributions */ 627*e3723e1fSApple OSS Distributions #define kOSKextInvalidLoadTag ((OSKextLoadTag)(-1)) 628*e3723e1fSApple OSS Distributions 629*e3723e1fSApple OSS Distributions #ifdef KERNEL 630*e3723e1fSApple OSS Distributions 631*e3723e1fSApple OSS Distributions /* Make these visible to kexts only and *not* the kernel. 632*e3723e1fSApple OSS Distributions */ 633*e3723e1fSApple OSS Distributions #if !XNU_KERNEL_PRIVATE 634*e3723e1fSApple OSS Distributions 635*e3723e1fSApple OSS Distributions /*! 636*e3723e1fSApple OSS Distributions * @function OSKextGetCurrentLoadTag 637*e3723e1fSApple OSS Distributions * 638*e3723e1fSApple OSS Distributions * @abstract 639*e3723e1fSApple OSS Distributions * Returns the run-time load tag for the calling kext as an 640*e3723e1fSApple OSS Distributions * <code>@link OSKextLoadTag OSKextLoadTag@/link</code>. 641*e3723e1fSApple OSS Distributions * 642*e3723e1fSApple OSS Distributions * @result 643*e3723e1fSApple OSS Distributions * The run-time load tag for the calling kext as an 644*e3723e1fSApple OSS Distributions * <code>@link OSKextLoadTag@/link</code>. 645*e3723e1fSApple OSS Distributions * 646*e3723e1fSApple OSS Distributions * @discussion 647*e3723e1fSApple OSS Distributions * The load tag identifies this loaded instance of the kext to the kernel 648*e3723e1fSApple OSS Distributions * and to kernel functions that operate on kexts. 649*e3723e1fSApple OSS Distributions */ 650*e3723e1fSApple OSS Distributions OSKextLoadTag OSKextGetCurrentLoadTag(void); 651*e3723e1fSApple OSS Distributions 652*e3723e1fSApple OSS Distributions /*! 653*e3723e1fSApple OSS Distributions * @function OSKextGetCurrentIdentifier 654*e3723e1fSApple OSS Distributions * 655*e3723e1fSApple OSS Distributions * @abstract 656*e3723e1fSApple OSS Distributions * Returns the CFBundleIdentifier for the calling kext as a C string. 657*e3723e1fSApple OSS Distributions * 658*e3723e1fSApple OSS Distributions * @result 659*e3723e1fSApple OSS Distributions * The CFBundleIdentifier for the calling kext as a C string. 660*e3723e1fSApple OSS Distributions */ 661*e3723e1fSApple OSS Distributions const char * OSKextGetCurrentIdentifier(void); 662*e3723e1fSApple OSS Distributions 663*e3723e1fSApple OSS Distributions /*! 664*e3723e1fSApple OSS Distributions * @function OSKextGetCurrentVersionString 665*e3723e1fSApple OSS Distributions * 666*e3723e1fSApple OSS Distributions * @abstract 667*e3723e1fSApple OSS Distributions * Returns the CFBundleVersion for the calling kext as a C string. 668*e3723e1fSApple OSS Distributions * 669*e3723e1fSApple OSS Distributions * @result 670*e3723e1fSApple OSS Distributions * The CFBundleVersion for the calling kext as a C string. 671*e3723e1fSApple OSS Distributions */ 672*e3723e1fSApple OSS Distributions const char * OSKextGetCurrentVersionString(void); 673*e3723e1fSApple OSS Distributions 674*e3723e1fSApple OSS Distributions #endif /* !XNU_KERNEL_PRIVATE */ 675*e3723e1fSApple OSS Distributions 676*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 677*e3723e1fSApple OSS Distributions #pragma mark - 678*e3723e1fSApple OSS Distributions /********************************************************************/ 679*e3723e1fSApple OSS Distributions #pragma mark Kext Loading C Functions 680*e3723e1fSApple OSS Distributions /********************************************************************/ 681*e3723e1fSApple OSS Distributions #endif 682*e3723e1fSApple OSS Distributions /*! 683*e3723e1fSApple OSS Distributions * @group Kext Loading C Functions 684*e3723e1fSApple OSS Distributions * Functions for loading and tracking kexts in the kernel. 685*e3723e1fSApple OSS Distributions */ 686*e3723e1fSApple OSS Distributions 687*e3723e1fSApple OSS Distributions /*! 688*e3723e1fSApple OSS Distributions * @function OSKextLoadKextWithIdentifier 689*e3723e1fSApple OSS Distributions * 690*e3723e1fSApple OSS Distributions * @abstract 691*e3723e1fSApple OSS Distributions * Request that a kext be loaded. 692*e3723e1fSApple OSS Distributions * 693*e3723e1fSApple OSS Distributions * @param kextIdentifier The bundle identifier of the kext to be loaded. 694*e3723e1fSApple OSS Distributions * 695*e3723e1fSApple OSS Distributions * @result 696*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code> 697*e3723e1fSApple OSS Distributions * if the kext was loaded (or was already loaded). 698*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSKextReturnDeferred kOSKextReturnDeferred@/link</code> 699*e3723e1fSApple OSS Distributions * if the kext was not found and a request 700*e3723e1fSApple OSS Distributions * was queued to <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>. 701*e3723e1fSApple OSS Distributions * Other return values indicate a failure to load the kext. 702*e3723e1fSApple OSS Distributions * 703*e3723e1fSApple OSS Distributions * @discussion 704*e3723e1fSApple OSS Distributions * If a kext is already in the kernel but not loaded, it is loaded immediately. 705*e3723e1fSApple OSS Distributions * If it isn't found, an asynchronous load request is 706*e3723e1fSApple OSS Distributions * made to <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code> 707*e3723e1fSApple OSS Distributions * and <code>@link //apple_ref/c/macro/kOSKextReturnDeferred kOSKextReturnDeferred@/link</code> is returned. 708*e3723e1fSApple OSS Distributions * There is no general notification or callback mechanism for load requests. 709*e3723e1fSApple OSS Distributions */ 710*e3723e1fSApple OSS Distributions OSReturn OSKextLoadKextWithIdentifier(const char * kextIdentifier); 711*e3723e1fSApple OSS Distributions 712*e3723e1fSApple OSS Distributions 713*e3723e1fSApple OSS Distributions /*! 714*e3723e1fSApple OSS Distributions * @function OSKextRetainKextWithLoadTag 715*e3723e1fSApple OSS Distributions * 716*e3723e1fSApple OSS Distributions * @abstract 717*e3723e1fSApple OSS Distributions * Retain a loaded kext based on its load tag, 718*e3723e1fSApple OSS Distributions * and enable autounload for that kext. 719*e3723e1fSApple OSS Distributions * 720*e3723e1fSApple OSS Distributions * @param loadTag The load tag of the kext to be retained. 721*e3723e1fSApple OSS Distributions * See <code>@link OSKextGetCurrentLoadTag@/link</code>. 722*e3723e1fSApple OSS Distributions * 723*e3723e1fSApple OSS Distributions * @result 724*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code> 725*e3723e1fSApple OSS Distributions * if the kext was retained. 726*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound kOSKextReturnNotFound@/link</code> 727*e3723e1fSApple OSS Distributions * if the kext was not found. 728*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSKextReturnInvalidArgument 729*e3723e1fSApple OSS Distributions * kOSKextReturnInvalidArgument@/link</code> 730*e3723e1fSApple OSS Distributions * if <code>loadTag</code> is 731*e3723e1fSApple OSS Distributions * <code>@link kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>. 732*e3723e1fSApple OSS Distributions * 733*e3723e1fSApple OSS Distributions * @discussion 734*e3723e1fSApple OSS Distributions * Retaining a kext prevents it from being unloaded, 735*e3723e1fSApple OSS Distributions * either explicitly or automatically, and enables autounload for the kext. 736*e3723e1fSApple OSS Distributions * When autounload is enabled, then shortly after the kext's last reference 737*e3723e1fSApple OSS Distributions * is dropped, it will be unloaded if there are no outstanding references to it 738*e3723e1fSApple OSS Distributions * and there are no instances of its Libkern C++ subclasses (if any). 739*e3723e1fSApple OSS Distributions * 740*e3723e1fSApple OSS Distributions * Kexts that define subclasses of 741*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/class/IOService IOService@/link</code> 742*e3723e1fSApple OSS Distributions * have autounload enabled automatically. 743*e3723e1fSApple OSS Distributions * Other kexts can use the reference count to manage automatic unload 744*e3723e1fSApple OSS Distributions * without having to define and create Libkern C++ objects. 745*e3723e1fSApple OSS Distributions * For example, a filesystem kext can retain itself whenever a new mount 746*e3723e1fSApple OSS Distributions * is created, and release itself when a mount is removed. 747*e3723e1fSApple OSS Distributions * When the last mount is removed, the kext will be unloaded after a brief delay. 748*e3723e1fSApple OSS Distributions * 749*e3723e1fSApple OSS Distributions * A kext can get its own load tag using the 750*e3723e1fSApple OSS Distributions * <code>@link OSKextGetCurrentLoadTag@/link</code>. 751*e3723e1fSApple OSS Distributions * 752*e3723e1fSApple OSS Distributions * Kexts should not retain and release other kexts; linkage references 753*e3723e1fSApple OSS Distributions * are accounted for internally. 754*e3723e1fSApple OSS Distributions */ 755*e3723e1fSApple OSS Distributions OSReturn OSKextRetainKextWithLoadTag(OSKextLoadTag loadTag); 756*e3723e1fSApple OSS Distributions 757*e3723e1fSApple OSS Distributions 758*e3723e1fSApple OSS Distributions /*! 759*e3723e1fSApple OSS Distributions * @function OSKextReleaseKextWithLoadTag 760*e3723e1fSApple OSS Distributions * 761*e3723e1fSApple OSS Distributions * @abstract 762*e3723e1fSApple OSS Distributions * Release a loaded kext based on its load tag. 763*e3723e1fSApple OSS Distributions * 764*e3723e1fSApple OSS Distributions * @param loadTag The load tag of the kext to be released. 765*e3723e1fSApple OSS Distributions * See <code>@link OSKextGetCurrentLoadTag@/link</code>. 766*e3723e1fSApple OSS Distributions * 767*e3723e1fSApple OSS Distributions * @result 768*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code> 769*e3723e1fSApple OSS Distributions * if the kext was released. 770*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound 771*e3723e1fSApple OSS Distributions * kOSKextReturnNotFound@/link</code> 772*e3723e1fSApple OSS Distributions * if the kext was not found. 773*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/c/macro/kOSKextReturnInvalidArgument 774*e3723e1fSApple OSS Distributions * kOSKextReturnInvalidArgument@/link</code> 775*e3723e1fSApple OSS Distributions * if <code>loadTag</code> is 776*e3723e1fSApple OSS Distributions * <code>@link kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>. 777*e3723e1fSApple OSS Distributions * 778*e3723e1fSApple OSS Distributions * @discussion 779*e3723e1fSApple OSS Distributions * The kext should have been retained previously via 780*e3723e1fSApple OSS Distributions * <code>@link OSKextRetainKextWithLoadTag@/link</code>. 781*e3723e1fSApple OSS Distributions * 782*e3723e1fSApple OSS Distributions * This function schedules an autounload scan for all kexts. 783*e3723e1fSApple OSS Distributions * When that scan occurs, if a kext has autounload enabled, 784*e3723e1fSApple OSS Distributions * it will be unloaded if there are no outstanding references to it 785*e3723e1fSApple OSS Distributions * and there are no instances of its Libkern C++ classes (if any). 786*e3723e1fSApple OSS Distributions * 787*e3723e1fSApple OSS Distributions * Kexts that define subclasses of 788*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/class/IOService IOService@/link</code> 789*e3723e1fSApple OSS Distributions * have autounload enabled automatically. 790*e3723e1fSApple OSS Distributions * Other kexts can use the reference count to manage automatic unload 791*e3723e1fSApple OSS Distributions * without having to define and create Libkern C++ objects. 792*e3723e1fSApple OSS Distributions * For example, a filesystem kext can be retained whenever a new mount 793*e3723e1fSApple OSS Distributions * is created, and released when a mount is removed. 794*e3723e1fSApple OSS Distributions * When the last mount is removed, the kext will be unloaded after a brief delay. 795*e3723e1fSApple OSS Distributions * 796*e3723e1fSApple OSS Distributions * While the autounload scan takes place after a delay of at least a minute, 797*e3723e1fSApple OSS Distributions * a kext that manages its own reference counts for autounload should 798*e3723e1fSApple OSS Distributions * be prepared to have its module stop function called even while the function 799*e3723e1fSApple OSS Distributions * calling this function is still running. 800*e3723e1fSApple OSS Distributions * 801*e3723e1fSApple OSS Distributions * A kext can get its own load tag using the 802*e3723e1fSApple OSS Distributions * <code>@link OSKextGetCurrentLoadTag@/link</code>. 803*e3723e1fSApple OSS Distributions * 804*e3723e1fSApple OSS Distributions * Kexts should not retain and release other kexts; linkage references 805*e3723e1fSApple OSS Distributions * are accounted for internally. 806*e3723e1fSApple OSS Distributions */ 807*e3723e1fSApple OSS Distributions OSReturn OSKextReleaseKextWithLoadTag(OSKextLoadTag loadTag); 808*e3723e1fSApple OSS Distributions 809*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 810*e3723e1fSApple OSS Distributions /********************************************************************/ 811*e3723e1fSApple OSS Distributions #pragma mark - 812*e3723e1fSApple OSS Distributions #pragma mark Kext Requests 813*e3723e1fSApple OSS Distributions /********************************************************************/ 814*e3723e1fSApple OSS Distributions #endif 815*e3723e1fSApple OSS Distributions /*! 816*e3723e1fSApple OSS Distributions * @group Kext Requests to User Space 817*e3723e1fSApple OSS Distributions * Functions for making requests to kextd in user space. 818*e3723e1fSApple OSS Distributions */ 819*e3723e1fSApple OSS Distributions 820*e3723e1fSApple OSS Distributions /*! 821*e3723e1fSApple OSS Distributions * @typedef OSKextRequestTag 822*e3723e1fSApple OSS Distributions * 823*e3723e1fSApple OSS Distributions * @abstract 824*e3723e1fSApple OSS Distributions * Identifies a kext request made to user space. 825*e3723e1fSApple OSS Distributions */ 826*e3723e1fSApple OSS Distributions typedef uint32_t OSKextRequestTag; 827*e3723e1fSApple OSS Distributions 828*e3723e1fSApple OSS Distributions /*! 829*e3723e1fSApple OSS Distributions * @define kOSKextRequestTagInvalid 830*e3723e1fSApple OSS Distributions * 831*e3723e1fSApple OSS Distributions * @abstract 832*e3723e1fSApple OSS Distributions * A request tag value that will never be used for a kext request; 833*e3723e1fSApple OSS Distributions * indicates failure to create/queue the request. 834*e3723e1fSApple OSS Distributions */ 835*e3723e1fSApple OSS Distributions #define kOSKextRequestTagInvalid ((OSKextRequestTag)-1) 836*e3723e1fSApple OSS Distributions 837*e3723e1fSApple OSS Distributions /*! 838*e3723e1fSApple OSS Distributions * @typedef OSKextRequestResourceCallback 839*e3723e1fSApple OSS Distributions * 840*e3723e1fSApple OSS Distributions * @abstract 841*e3723e1fSApple OSS Distributions * Invoked to provide results for a kext resource request. 842*e3723e1fSApple OSS Distributions * 843*e3723e1fSApple OSS Distributions * @param requestTag The tag of the request that the callback pertains to. 844*e3723e1fSApple OSS Distributions * @param result The result of the request: 845*e3723e1fSApple OSS Distributions * <code>@link kOSReturnSuccess 846*e3723e1fSApple OSS Distributions * kOSReturnSuccess@/link</code> 847*e3723e1fSApple OSS Distributions * if the request was fulfilled; 848*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnTimeout 849*e3723e1fSApple OSS Distributions * kOSKextReturnTimeout@/link</code> 850*e3723e1fSApple OSS Distributions * if the request has timed out; 851*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnStopping 852*e3723e1fSApple OSS Distributions * kOSKextReturnStopping@/link</code> 853*e3723e1fSApple OSS Distributions * if the kext containing the callback 854*e3723e1fSApple OSS Distributions * address for the kext is being unloaded; 855*e3723e1fSApple OSS Distributions * or other values on error. 856*e3723e1fSApple OSS Distributions * @param resourceData A pointer to the requested resource data. 857*e3723e1fSApple OSS Distributions * Owned by the system; the kext should make a copy 858*e3723e1fSApple OSS Distributions * if it needs to keep the data past the callback. 859*e3723e1fSApple OSS Distributions * @param resourceDataLength The length of <code>resourceData</code>. 860*e3723e1fSApple OSS Distributions * @param context The context pointer originally passed to 861*e3723e1fSApple OSS Distributions * <code>@link OSKextRequestResource 862*e3723e1fSApple OSS Distributions * OSKextRequestResource@/link</code>. 863*e3723e1fSApple OSS Distributions */ 864*e3723e1fSApple OSS Distributions typedef void (* OSKextRequestResourceCallback)( 865*e3723e1fSApple OSS Distributions OSKextRequestTag requestTag, 866*e3723e1fSApple OSS Distributions OSReturn result, 867*e3723e1fSApple OSS Distributions const void * resourceData, 868*e3723e1fSApple OSS Distributions uint32_t resourceDataLength, 869*e3723e1fSApple OSS Distributions void * context); 870*e3723e1fSApple OSS Distributions 871*e3723e1fSApple OSS Distributions /*! 872*e3723e1fSApple OSS Distributions * @function OSKextRequestResource 873*e3723e1fSApple OSS Distributions * 874*e3723e1fSApple OSS Distributions * @abstract 875*e3723e1fSApple OSS Distributions * Requests data from a nonlocalized resource file in a kext bundle on disk. 876*e3723e1fSApple OSS Distributions * 877*e3723e1fSApple OSS Distributions * @param kextIdentifier The CFBundleIdentifier of the kext 878*e3723e1fSApple OSS Distributions * from which to read the file. 879*e3723e1fSApple OSS Distributions * @param resourceName The name of the resource file to read. 880*e3723e1fSApple OSS Distributions * @param callback A pointer to a callback function; the address 881*e3723e1fSApple OSS Distributions * must be within a currently-loaded kext. 882*e3723e1fSApple OSS Distributions * @param context A pointer to arbitrary run-time data 883*e3723e1fSApple OSS Distributions * that will be passed to the callback 884*e3723e1fSApple OSS Distributions * when it is invoked. May be <code>NULL</code>. 885*e3723e1fSApple OSS Distributions * @param requestTagOut If non-<code>NULL</code>, 886*e3723e1fSApple OSS Distributions * filled on success with a tag identifying the 887*e3723e1fSApple OSS Distributions * pending request 888*e3723e1fSApple OSS Distributions * (or on failure with <code>@link kOSKextRequestTagInvalid 889*e3723e1fSApple OSS Distributions * kOSKextRequestTagInvalid@/link</code>; 890*e3723e1fSApple OSS Distributions * can be used with 891*e3723e1fSApple OSS Distributions * <code>@link OSKextCancelRequest 892*e3723e1fSApple OSS Distributions * OSKextCancelRequest@/link</code>. 893*e3723e1fSApple OSS Distributions * 894*e3723e1fSApple OSS Distributions * @result 895*e3723e1fSApple OSS Distributions * <code>@link kOSReturnSuccess kOSReturnSuccess@/link</code> 896*e3723e1fSApple OSS Distributions * if the request is successfully queued. 897*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnInvalidArgument kOSKextReturnInvalidArgument@/link</code> 898*e3723e1fSApple OSS Distributions * if <code>kextIdentifier</code> or <code>resourceName</code> or if 899*e3723e1fSApple OSS Distributions * <code>callback</code> is not an address within a loaded kext executable. 900*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnStopping kOSKextReturnStopping@/link</code> 901*e3723e1fSApple OSS Distributions * if an unload attempt is being made 902*e3723e1fSApple OSS Distributions * on the kext containing <code>callback</code>. 903*e3723e1fSApple OSS Distributions * Other <code>OSKextReturn...</code> errors are possible. 904*e3723e1fSApple OSS Distributions * 905*e3723e1fSApple OSS Distributions * @discussion 906*e3723e1fSApple OSS Distributions * This function queues an asynchronous request to the user-space kext daemon 907*e3723e1fSApple OSS Distributions * <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>; 908*e3723e1fSApple OSS Distributions * requests for resources early in system startup 909*e3723e1fSApple OSS Distributions * will not be fulfilled until that daemon starts. 910*e3723e1fSApple OSS Distributions * Requests made by a kext while that kext is loading 911*e3723e1fSApple OSS Distributions * (specifically in the kext's module start routine) 912*e3723e1fSApple OSS Distributions * will not be fulfilled until after the start routine returns and 913*e3723e1fSApple OSS Distributions * the kext is completely loaded. 914*e3723e1fSApple OSS Distributions * Kexts requesting resources should be sure to perform appropriate locking 915*e3723e1fSApple OSS Distributions * in the callback function. 916*e3723e1fSApple OSS Distributions * 917*e3723e1fSApple OSS Distributions * Kext resources are stored in the kext's on-disk bundle under the 918*e3723e1fSApple OSS Distributions * Resources subdirectory. 919*e3723e1fSApple OSS Distributions * See {@linkdoc //apple_ref/doc/uid/10000123i Bundle Programming Guide} 920*e3723e1fSApple OSS Distributions * for an overview of bundle structure. 921*e3723e1fSApple OSS Distributions * The localization context of the kext daemon 922*e3723e1fSApple OSS Distributions * (namely that of the superuser) 923*e3723e1fSApple OSS Distributions * will be used in retrieving resources; 924*e3723e1fSApple OSS Distributions * kext resources intended for use in the kernel 925*e3723e1fSApple OSS Distributions * should generally not be localized. 926*e3723e1fSApple OSS Distributions * 927*e3723e1fSApple OSS Distributions * <code>callback</code> is guaranteed to be invoked except when: 928*e3723e1fSApple OSS Distributions * <ul> 929*e3723e1fSApple OSS Distributions * <li>@link OSKextCancelRequest <code>OSKextCancelRequest</code>@/link 930*e3723e1fSApple OSS Distributions * is used to cancel the request. 931*e3723e1fSApple OSS Distributions * In this case the kext gets the <code>context</code> pointer 932*e3723e1fSApple OSS Distributions * and can clean it up.</li> 933*e3723e1fSApple OSS Distributions * <li>The request is made during a kext's module start routine 934*e3723e1fSApple OSS Distributions * and the start routine returns an error. 935*e3723e1fSApple OSS Distributions * In this case, callbacks cannot be safely invoked, so 936*e3723e1fSApple OSS Distributions * the kext should clean up all request contexts 937*e3723e1fSApple OSS Distributions * when returning the error from the start routine.</li> 938*e3723e1fSApple OSS Distributions * </ul> 939*e3723e1fSApple OSS Distributions * 940*e3723e1fSApple OSS Distributions * Kexts with pending requests are not subject to autounload, 941*e3723e1fSApple OSS Distributions * but requests are subject to timeout after a few minutes. 942*e3723e1fSApple OSS Distributions * If that amount of time passes with no response from user space, 943*e3723e1fSApple OSS Distributions * <code>callback</code> is invoked with a result of. 944*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnTimeout kOSKextReturnTimeout@/link</code>. 945*e3723e1fSApple OSS Distributions * 946*e3723e1fSApple OSS Distributions * Kexts that are explicitly unloaded have all pending request callbacks 947*e3723e1fSApple OSS Distributions * invoked with a result of 948*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnStopping kOSKextReturnStopping@/link</code>. 949*e3723e1fSApple OSS Distributions * The kext must handle these callbacks, 950*e3723e1fSApple OSS Distributions * even if its stop routine will prevent unloading. 951*e3723e1fSApple OSS Distributions * If the kext does prevent unloading, it can reissue resource requests 952*e3723e1fSApple OSS Distributions * outside of the stop function. 953*e3723e1fSApple OSS Distributions */ 954*e3723e1fSApple OSS Distributions OSReturn OSKextRequestResource( 955*e3723e1fSApple OSS Distributions const char * kextIdentifier, 956*e3723e1fSApple OSS Distributions const char * resourceName, 957*e3723e1fSApple OSS Distributions OSKextRequestResourceCallback callback, 958*e3723e1fSApple OSS Distributions void * context, 959*e3723e1fSApple OSS Distributions OSKextRequestTag * requestTagOut); 960*e3723e1fSApple OSS Distributions 961*e3723e1fSApple OSS Distributions /*! 962*e3723e1fSApple OSS Distributions * @function OSKextCancelRequest 963*e3723e1fSApple OSS Distributions * 964*e3723e1fSApple OSS Distributions * @abstract 965*e3723e1fSApple OSS Distributions * Cancels a pending user-space kext request without invoking the callback. 966*e3723e1fSApple OSS Distributions * 967*e3723e1fSApple OSS Distributions * @param requestTag A tag identifying a pending request. 968*e3723e1fSApple OSS Distributions * @param contextOut If non-<code>NULL</code>, filled with the context pointer 969*e3723e1fSApple OSS Distributions * originally passed with the request. 970*e3723e1fSApple OSS Distributions * 971*e3723e1fSApple OSS Distributions * @result 972*e3723e1fSApple OSS Distributions * <code>@link kOSReturnSuccess kOSReturnSuccess@/link</code> 973*e3723e1fSApple OSS Distributions * if the request is successfully canceled. 974*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnNotFound kOSKextReturnNotFound@/link</code> 975*e3723e1fSApple OSS Distributions * if <code>requestTag</code> does not identify any pending request. 976*e3723e1fSApple OSS Distributions * Other <code>OSKextReturn...</code> errors are possible. 977*e3723e1fSApple OSS Distributions * 978*e3723e1fSApple OSS Distributions * @discussion 979*e3723e1fSApple OSS Distributions * This function cancels a pending request if it exists, 980*e3723e1fSApple OSS Distributions * so that its callback will not be invoked. 981*e3723e1fSApple OSS Distributions * It returns in <code>contextOut</code> 982*e3723e1fSApple OSS Distributions * the context pointer used to create the request 983*e3723e1fSApple OSS Distributions * so that any resources allocated for the request can be cleaned up. 984*e3723e1fSApple OSS Distributions * 985*e3723e1fSApple OSS Distributions * Kexts do not need to cancel outstanding requests 986*e3723e1fSApple OSS Distributions * in their module stop functions; 987*e3723e1fSApple OSS Distributions * when a kext is unloaded, all pending request callbacks 988*e3723e1fSApple OSS Distributions * are invoked with a result of 989*e3723e1fSApple OSS Distributions * <code>@link kOSKextReturnTimeout kOSKextReturnTimeout@/link</code> 990*e3723e1fSApple OSS Distributions * before the stop function is called. 991*e3723e1fSApple OSS Distributions */ 992*e3723e1fSApple OSS Distributions OSReturn OSKextCancelRequest( 993*e3723e1fSApple OSS Distributions OSKextRequestTag requestTag, 994*e3723e1fSApple OSS Distributions void ** contextOut); 995*e3723e1fSApple OSS Distributions 996*e3723e1fSApple OSS Distributions 997*e3723e1fSApple OSS Distributions /*! 998*e3723e1fSApple OSS Distributions * @function OSKextGrabPgoData 999*e3723e1fSApple OSS Distributions * 1000*e3723e1fSApple OSS Distributions * @abstract 1001*e3723e1fSApple OSS Distributions * Grab a LLVM profile data buffer from a loaded kext. 1002*e3723e1fSApple OSS Distributions * 1003*e3723e1fSApple OSS Distributions * @param uuid the uuid identifying the kext to retrieve data from 1004*e3723e1fSApple OSS Distributions * @param pSize pointer of where to store the size of the buffer. May be NULL. 1005*e3723e1fSApple OSS Distributions * @param pBuffer pointer to the output buffer. May be NULL. 1006*e3723e1fSApple OSS Distributions * @param bufferSize size of the buffer pointed to by pBuffer 1007*e3723e1fSApple OSS Distributions * @param wait_for_unload (boolean) sleep until the kext is unloaded 1008*e3723e1fSApple OSS Distributions * @param metadata (boolean) include metadata footer 1009*e3723e1fSApple OSS Distributions * 1010*e3723e1fSApple OSS Distributions * @result 1011*e3723e1fSApple OSS Distributions * 0 on success 1012*e3723e1fSApple OSS Distributions * ENOTSUP if the kext does not have profile data to retrieve. 1013*e3723e1fSApple OSS Distributions * ENOTSUP if no kext with the given UUID is found 1014*e3723e1fSApple OSS Distributions * ERRORS if the provided buffer is too small 1015*e3723e1fSApple OSS Distributions * EIO internal error, such as if __llvm_profile_write_buffer_internal fails 1016*e3723e1fSApple OSS Distributions */ 1017*e3723e1fSApple OSS Distributions int 1018*e3723e1fSApple OSS Distributions OSKextGrabPgoData(uuid_t uuid, 1019*e3723e1fSApple OSS Distributions uint64_t *pSize, 1020*e3723e1fSApple OSS Distributions char *pBuffer, 1021*e3723e1fSApple OSS Distributions uint64_t bufferSize, 1022*e3723e1fSApple OSS Distributions int wait_for_unload, 1023*e3723e1fSApple OSS Distributions int metadata); 1024*e3723e1fSApple OSS Distributions 1025*e3723e1fSApple OSS Distributions /*! 1026*e3723e1fSApple OSS Distributions * @function OSKextResetPgoCountersLock 1027*e3723e1fSApple OSS Distributions * 1028*e3723e1fSApple OSS Distributions * @abstract 1029*e3723e1fSApple OSS Distributions * Call this function before trapping into the debugger to call OSKextResetPgoCounters. 1030*e3723e1fSApple OSS Distributions */ 1031*e3723e1fSApple OSS Distributions void 1032*e3723e1fSApple OSS Distributions OSKextResetPgoCountersLock(void); 1033*e3723e1fSApple OSS Distributions 1034*e3723e1fSApple OSS Distributions /*! 1035*e3723e1fSApple OSS Distributions * @function OSKextResetPgoCountersUnlock 1036*e3723e1fSApple OSS Distributions * 1037*e3723e1fSApple OSS Distributions * @abstract 1038*e3723e1fSApple OSS Distributions * Call this function after trapping into the debugger to call OSKextResetPgoCounters. 1039*e3723e1fSApple OSS Distributions */ 1040*e3723e1fSApple OSS Distributions void 1041*e3723e1fSApple OSS Distributions OSKextResetPgoCountersUnlock(void); 1042*e3723e1fSApple OSS Distributions 1043*e3723e1fSApple OSS Distributions /*! 1044*e3723e1fSApple OSS Distributions * @function OSKextResetPgoCounters 1045*e3723e1fSApple OSS Distributions * 1046*e3723e1fSApple OSS Distributions * @abstract Reset the PGO counters for all kexts. Call only from debugger 1047*e3723e1fSApple OSS Distributions * context, while holding OSKextResetPgoCountersLock(). 1048*e3723e1fSApple OSS Distributions */ 1049*e3723e1fSApple OSS Distributions void 1050*e3723e1fSApple OSS Distributions OSKextResetPgoCounters(void); 1051*e3723e1fSApple OSS Distributions 1052*e3723e1fSApple OSS Distributions 1053*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 1054*e3723e1fSApple OSS Distributions #pragma mark - 1055*e3723e1fSApple OSS Distributions /********************************************************************/ 1056*e3723e1fSApple OSS Distributions #pragma mark Weak linking 1057*e3723e1fSApple OSS Distributions /********************************************************************/ 1058*e3723e1fSApple OSS Distributions #endif 1059*e3723e1fSApple OSS Distributions /*! 1060*e3723e1fSApple OSS Distributions * @group Weak Linking 1061*e3723e1fSApple OSS Distributions * Support for weak references to symbols in kexts. 1062*e3723e1fSApple OSS Distributions */ 1063*e3723e1fSApple OSS Distributions 1064*e3723e1fSApple OSS Distributions /*! 1065*e3723e1fSApple OSS Distributions * @var gOSKextUnresolved 1066*e3723e1fSApple OSS Distributions * 1067*e3723e1fSApple OSS Distributions * @abstract 1068*e3723e1fSApple OSS Distributions * The value to which a kext's unresolved, weakly-referenced symbols are bound. 1069*e3723e1fSApple OSS Distributions * 1070*e3723e1fSApple OSS Distributions * @discussion 1071*e3723e1fSApple OSS Distributions * A kext must test a weak symbol before using it. A weak symbol 1072*e3723e1fSApple OSS Distributions * is only safe to use if it is not equal to <code>gOSKextUnresolved</code>. 1073*e3723e1fSApple OSS Distributions * 1074*e3723e1fSApple OSS Distributions * Example for a weak symbol named <code>foo</code>: 1075*e3723e1fSApple OSS Distributions * <pre> 1076*e3723e1fSApple OSS Distributions * @textblock 1077*e3723e1fSApple OSS Distributions * if (&foo != gOSKextUnresolved) { 1078*e3723e1fSApple OSS Distributions * foo(); 1079*e3723e1fSApple OSS Distributions * } else { 1080*e3723e1fSApple OSS Distributions * printf("foo() is not supported\n"); 1081*e3723e1fSApple OSS Distributions * } 1082*e3723e1fSApple OSS Distributions * @/textblock 1083*e3723e1fSApple OSS Distributions * </pre> 1084*e3723e1fSApple OSS Distributions */ 1085*e3723e1fSApple OSS Distributions extern const void * const gOSKextUnresolved; 1086*e3723e1fSApple OSS Distributions 1087*e3723e1fSApple OSS Distributions /*! 1088*e3723e1fSApple OSS Distributions * @define OSKextSymbolIsResolved 1089*e3723e1fSApple OSS Distributions * 1090*e3723e1fSApple OSS Distributions * @abstract 1091*e3723e1fSApple OSS Distributions * Checks whether a weakly-referenced symbol has been resolved. 1092*e3723e1fSApple OSS Distributions * 1093*e3723e1fSApple OSS Distributions * @param weak_sym The weak symbol to be tested for resolution. 1094*e3723e1fSApple OSS Distributions * 1095*e3723e1fSApple OSS Distributions * @result 1096*e3723e1fSApple OSS Distributions * <code>TRUE</code> if weak_sym is resolved, or <code>FALSE</code> 1097*e3723e1fSApple OSS Distributions * if weak_sym is unresolved. 1098*e3723e1fSApple OSS Distributions * 1099*e3723e1fSApple OSS Distributions * @discussion 1100*e3723e1fSApple OSS Distributions * This is a convenience macro for testing if weak symbols are resolved. 1101*e3723e1fSApple OSS Distributions * 1102*e3723e1fSApple OSS Distributions * Example for a weak symbol named <code>foo</code>: 1103*e3723e1fSApple OSS Distributions * <pre> 1104*e3723e1fSApple OSS Distributions * @textblock 1105*e3723e1fSApple OSS Distributions * if (OSKextSymbolIsResolved(foo)) { 1106*e3723e1fSApple OSS Distributions * foo(); 1107*e3723e1fSApple OSS Distributions * } else { 1108*e3723e1fSApple OSS Distributions * printf("foo() is not resolved\n"); 1109*e3723e1fSApple OSS Distributions * } 1110*e3723e1fSApple OSS Distributions * @/textblock 1111*e3723e1fSApple OSS Distributions * </pre> 1112*e3723e1fSApple OSS Distributions */ 1113*e3723e1fSApple OSS Distributions #define OSKextSymbolIsResolved(weak_sym) \ 1114*e3723e1fSApple OSS Distributions (&(weak_sym) != gOSKextUnresolved) 1115*e3723e1fSApple OSS Distributions 1116*e3723e1fSApple OSS Distributions 1117*e3723e1fSApple OSS Distributions #if CONFIG_KEC_FIPS 1118*e3723e1fSApple OSS Distributions 1119*e3723e1fSApple OSS Distributions #if PRAGMA_MARK 1120*e3723e1fSApple OSS Distributions #pragma mark - 1121*e3723e1fSApple OSS Distributions /********************************************************************/ 1122*e3723e1fSApple OSS Distributions #pragma mark Kernel External Components for FIPS compliance 1123*e3723e1fSApple OSS Distributions /********************************************************************/ 1124*e3723e1fSApple OSS Distributions #endif 1125*e3723e1fSApple OSS Distributions 1126*e3723e1fSApple OSS Distributions // Kernel External Components for FIPS compliance (KEC_FIPS) 1127*e3723e1fSApple OSS Distributions // WARNING - ath_hash is owned by the kernel, do not free 1128*e3723e1fSApple OSS Distributions typedef struct AppleTEXTHash { 1129*e3723e1fSApple OSS Distributions int ath_version;// version of this structure (value is 1 or 2) 1130*e3723e1fSApple OSS Distributions int ath_length; // length of hash data 1131*e3723e1fSApple OSS Distributions void * ath_hash; // hash extracted from AppleTextHashes dict 1132*e3723e1fSApple OSS Distributions } AppleTEXTHash_t; 1133*e3723e1fSApple OSS Distributions #endif // CONFIG_KEC_FIPS 1134*e3723e1fSApple OSS Distributions 1135*e3723e1fSApple OSS Distributions #endif /* KERNEL */ 1136*e3723e1fSApple OSS Distributions 1137*e3723e1fSApple OSS Distributions __END_DECLS 1138*e3723e1fSApple OSS Distributions 1139*e3723e1fSApple OSS Distributions #endif /* _LIBKERN_OSKEXTLIB_H */ 1140