2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _LIBKERN_OSKEXTLIB_H
30 #define _LIBKERN_OSKEXTLIB_H
32 #include <sys/cdefs.h>
36 #include <mach/kmod.h>
37 #include <mach/vm_types.h>
38 #include <uuid/uuid.h>
41 #include <libkern/OSTypes.h>
42 #include <libkern/OSReturn.h>
44 #include <CoreFoundation/CoreFoundation.h>
45 #include <libkern/OSReturn.h>
51 * Declares functions, basic return values, and other constants
52 * related to kernel extensions (kexts).
57 /********************************************************************/
58 #pragma mark OSReturn Values for Kernel Extensions
59 /********************************************************************/
62 * @group OSReturn Values for Kernel Extensions
63 * Many kext-related functions return these values,
64 * as well as those defined under
65 * <code>@link //apple_ref/c/tdef/OSReturn OSReturn@/link</code>
66 * and other variants of <code>kern_return_t</code>.
69 #ifdef XNU_KERNEL_PRIVATE
70 /*********************************************************************
71 * Check libsyscall/mach/err_libkern.sub when editing or adding
73 *********************************************************************/
74 #endif /* XNU_KERNEL_PRIVATE */
76 #define sub_libkern_kext err_sub(2)
77 #define libkern_kext_err(code) (sys_libkern|sub_libkern_kext|(code))
81 * @define kOSKextReturnInternalError
82 * @abstract An internal error in the kext library.
83 * Contrast with <code>@link //apple_ref/c/econst/OSReturnError
84 * OSReturnError@/link</code>.
86 #define kOSKextReturnInternalError libkern_kext_err(0x1)
89 * @define kOSKextReturnNoMemory
90 * @abstract Memory allocation failed.
92 #define kOSKextReturnNoMemory libkern_kext_err(0x2)
95 * @define kOSKextReturnNoResources
96 * @abstract Some resource other than memory (such as available load tags)
99 #define kOSKextReturnNoResources libkern_kext_err(0x3)
102 * @define kOSKextReturnNotPrivileged
103 * @abstract The caller lacks privileges to perform the requested operation.
105 #define kOSKextReturnNotPrivileged libkern_kext_err(0x4)
108 * @define kOSKextReturnInvalidArgument
109 * @abstract Invalid argument.
111 #define kOSKextReturnInvalidArgument libkern_kext_err(0x5)
114 * @define kOSKextReturnNotFound
115 * @abstract Search item not found.
117 #define kOSKextReturnNotFound libkern_kext_err(0x6)
120 * @define kOSKextReturnBadData
121 * @abstract Malformed data (not used for XML).
123 #define kOSKextReturnBadData libkern_kext_err(0x7)
126 * @define kOSKextReturnSerialization
127 * @abstract Error converting or (un)serializing URL, string, or XML.
129 #define kOSKextReturnSerialization libkern_kext_err(0x8)
132 * @define kOSKextReturnUnsupported
133 * @abstract Operation is no longer or not yet supported.
135 #define kOSKextReturnUnsupported libkern_kext_err(0x9)
138 * @define kOSKextReturnDisabled
139 * @abstract Operation is currently disabled.
141 #define kOSKextReturnDisabled libkern_kext_err(0xa)
144 * @define kOSKextReturnNotAKext
145 * @abstract Bundle is not a kernel extension.
147 #define kOSKextReturnNotAKext libkern_kext_err(0xb)
150 * @define kOSKextReturnValidation
151 * @abstract Validation failures encountered; check diagnostics for details.
153 #define kOSKextReturnValidation libkern_kext_err(0xc)
156 * @define kOSKextReturnAuthentication
157 * @abstract Authetication failures encountered; check diagnostics for details.
159 #define kOSKextReturnAuthentication libkern_kext_err(0xd)
162 * @define kOSKextReturnDependencies
163 * @abstract Dependency resolution failures encountered; check diagnostics for details.
165 #define kOSKextReturnDependencies libkern_kext_err(0xe)
168 * @define kOSKextReturnArchNotFound
169 * @abstract Kext does not contain code for the requested architecture.
171 #define kOSKextReturnArchNotFound libkern_kext_err(0xf)
174 * @define kOSKextReturnCache
175 * @abstract An error occurred processing a system kext cache.
177 #define kOSKextReturnCache libkern_kext_err(0x10)
180 * @define kOSKextReturnDeferred
181 * @abstract Operation has been posted asynchronously to user space (kernel only).
183 #define kOSKextReturnDeferred libkern_kext_err(0x11)
186 * @define kOSKextReturnBootLevel
187 * @abstract Kext not loadable or operation not allowed at current boot level.
189 #define kOSKextReturnBootLevel libkern_kext_err(0x12)
192 * @define kOSKextReturnNotLoadable
193 * @abstract Kext cannot be loaded; check diagnostics for details.
195 #define kOSKextReturnNotLoadable libkern_kext_err(0x13)
198 * @define kOSKextReturnLoadedVersionDiffers
199 * @abstract A different version (or executable UUID, or executable by checksum)
200 * of the requested kext is already loaded.
202 #define kOSKextReturnLoadedVersionDiffers libkern_kext_err(0x14)
205 * @define kOSKextReturnDependencyLoadError
206 * @abstract A load error occurred on a dependency of the kext being loaded.
208 #define kOSKextReturnDependencyLoadError libkern_kext_err(0x15)
211 * @define kOSKextReturnLinkError
212 * @abstract A link failure occured with this kext or a dependency.
214 #define kOSKextReturnLinkError libkern_kext_err(0x16)
217 * @define kOSKextReturnStartStopError
218 * @abstract The kext start or stop routine returned an error.
220 #define kOSKextReturnStartStopError libkern_kext_err(0x17)
223 * @define kOSKextReturnInUse
224 * @abstract The kext is currently in use or has outstanding references,
225 * and cannot be unloaded.
227 #define kOSKextReturnInUse libkern_kext_err(0x18)
230 * @define kOSKextReturnTimeout
231 * @abstract A kext request has timed out.
233 #define kOSKextReturnTimeout libkern_kext_err(0x19)
236 * @define kOSKextReturnStopping
237 * @abstract The kext is in the process of stopping; requests cannot be made.
239 #define kOSKextReturnStopping libkern_kext_err(0x1a)
243 /********************************************************************/
244 #pragma mark Kext/OSBundle Property List Keys
245 /********************************************************************/
248 * @group Kext Property List Keys
249 * These constants cover CFBundle properties defined for kernel extensions.
250 * Because they are used in the kernel, if you want to use one with
251 * CFBundle APIs you'll need to wrap it in a <code>CFSTR()</code> macro.
255 /* Define C-string versions of the CFBundle keys for use in the kernel.
257 #define kCFBundleIdentifierKey "CFBundleIdentifier"
258 #define kCFBundleVersionKey "CFBundleVersion"
259 #define kCFBundleNameKey "CFBundleName"
260 #define kCFBundleExecutableKey "CFBundleExecutable"
264 * @define kOSBundleCompatibleVersionKey
265 * @abstract A string giving the backwards-compatible version of a library kext
266 * in extended Mac OS 'vers' format (####.##.##s{1-255} where 's'
267 * is a build stage 'd', 'a', 'b', 'f' or 'fc').
269 #define kOSBundleCompatibleVersionKey "OSBundleCompatibleVersion"
272 * @define kOSBundleEnableKextLoggingKey
273 * @abstract Set to true to have the kernel kext logging spec applied
275 * See <code>@link //apple_ref/c/econst/OSKextLogSpec
276 * OSKextLogSpec@/link</code>.
278 #define kOSBundleEnableKextLoggingKey "OSBundleEnableKextLogging"
281 * @define kOSBundleIsInterfaceKey
282 * @abstract A boolean value indicating whether the kext executable
283 * contains only symbol references.
285 #define kOSBundleIsInterfaceKey "OSBundleIsInterface"
288 * @define kOSBundleLibrariesKey
289 * @abstract A dictionary listing link dependencies for this kext.
290 * Keys are bundle identifiers, values are version strings.
292 #define kOSBundleLibrariesKey "OSBundleLibraries"
295 * @define kOSBundleRequiredKey
296 * @abstract A string indicating in which kinds of startup this kext
297 * may need to load during early startup (before
298 * <code>@link //apple_ref/doc/man/8/kextd kextcache(8)@/link</code>).
300 * The value is one of:
302 * <li>@link kOSBundleRequiredRoot "OSBundleRequiredRoot"@/link</li>
303 * <li>@link kOSBundleRequiredLocalRoot "OSBundleRequiredLocalRoot"@/link</li>
304 * <li>@link kOSBundleRequiredNetworkRoot "OSBundleRequiredNetworkRoot"@/link</li>
305 * <li>@link kOSBundleRequiredSafeBoot "OSBundleRequiredSafeBoot"@/link</li>
306 * <li>@link kOSBundleRequiredConsole "OSBundleRequiredConsole"@/link</li>
309 * Use this property judiciously.
310 * Every kext that declares a value other than "OSBundleRequiredSafeBoot"
311 * increases startup time, as the booter must read it into memory,
312 * or startup kext caches must include it.
314 #define kOSBundleRequiredKey "OSBundleRequired"
317 * @define kOSBundleAllowUserLoadKey
318 * @abstract A boolean value indicating whether
319 * <code>@link //apple_ref/doc/man/8/kextd kextcache(8)@/link</code>
320 * will honor a non-root process's request to load a kext.
322 * See <code>@link //apple_ref/doc/compositePage/c/func/KextManagerLoadKextWithURL
323 * KextManagerLoadKextWithURL@/link</code>
324 * and <code>@link //apple_ref/doc/compositePage/c/func/KextManagerLoadKextWithIdentifier
325 * KextManagerLoadKextWithIdentifier@/link</code>.
327 #define kOSBundleAllowUserLoadKey "OSBundleAllowUserLoad"
330 * @define kOSKernelResourceKey
331 * @abstract A boolean value indicating whether the kext represents a built-in
332 * component of the kernel.
334 #define kOSKernelResourceKey "OSKernelResource"
337 * @define kIOKitPersonalitiesKey
338 * @abstract A dictionary of dictionaries used in matching for I/O Kit drivers.
340 #define kIOKitPersonalitiesKey "IOKitPersonalities"
343 * @define kIOPersonalityPublisherKey
344 * @abstract Used in personalities sent to the I/O Kit,
345 * contains the CFBundleIdentifier of the kext
346 * that the personality originated in.
348 #define kIOPersonalityPublisherKey "IOPersonalityPublisher"
352 * @define kAppleTextHashesKey
353 * @abstract A dictionary conataining hashes for corecrypto kext.
355 #define kAppleTextHashesKey "AppleTextHashes"
361 /********************************************************************/
362 #pragma mark Kext/OSBundle Property Deprecated Keys
363 /********************************************************************/
366 * @define kOSBundleDebugLevelKey
368 * Deprecated (used on some releases of Mac OS X prior to 10.6 Snow Leopard).
369 * Value is an integer from 1-6, corresponding to the verbose levels
370 * of kext tools on those releases.
371 * On 10.6 Snow Leopard, use <code>@link OSKextEnableKextLogging
372 * OSKextEnableKextLogging@/link</code>.
374 #define kOSBundleDebugLevelKey "OSBundleDebugLevel"
377 * @define kOSBundleSharedExecutableIdentifierKey
378 * @abstract Deprecated (used on some releases of Mac OS X
379 * prior to 10.6 Snow Leopard).
380 * Value is the bundle identifier of the pseudokext
381 * that contains an executable shared by this kext.
383 #define kOSBundleSharedExecutableIdentifierKey "OSBundleSharedExecutableIdentifier"
387 /********************************************************************/
388 #pragma mark Kext/OSBundle Property List Values
389 /********************************************************************/
393 * @group Kext Property List Values
394 * These constants encompass established values
395 * for kernel extension bundle properties.
399 * @define kOSKextKernelIdentifier
401 * This is the CFBundleIdentifier user for the kernel itself.
403 #define kOSKextKernelIdentifier "__kernel__"
406 * @define kOSBundleRequiredRoot
408 * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code>
409 * value indicates that the kext may be needed to mount the root filesystem
410 * whether starting from a local or a network volume.
412 #define kOSBundleRequiredRoot "Root"
415 * @define kOSBundleRequiredLocalRoot
417 * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code>
418 * value indicates that the kext may be needed to mount the root filesystem
419 * when starting from a local disk.
421 #define kOSBundleRequiredLocalRoot "Local-Root"
424 * @define kOSBundleRequiredNetworkRoot
426 * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code>
427 * value indicates that the kext may be needed to mount the root filesystem
428 * when starting over a network connection.
430 #define kOSBundleRequiredNetworkRoot "Network-Root"
433 * @define kOSBundleRequiredSafeBoot
435 * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code>
436 * value indicates that the kext can be loaded during a safe startup.
437 * This value does not normally cause the kext to be read by the booter
438 * or included in startup kext caches.
440 #define kOSBundleRequiredSafeBoot "Safe Boot"
443 * @define kOSBundleRequiredConsole
445 * This <code>@link kOSBundleRequiredKey OSBundleRequired@/link</code>
446 * value indicates that the kext may be needed for console access
447 * (specifically in a single-user startup when
448 * <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>.
450 * and should be loaded during early startup.
452 #define kOSBundleRequiredConsole "Console"
457 /********************************************************************/
458 #pragma mark Kext Information
459 /********************************************************************/
462 * @group Kext Information
463 * Types, constants, and macros providing a kext with information
469 * @typedef OSKextLoadTag
472 * A unique identifier assigned to a loaded instanace of a kext.
475 * If a kext is unloaded and later reloaded, the new instance
476 * has a different load tag.
478 * A kext can get its own load tag in the <code>kmod_info_t</code>
479 * structure passed into its module start routine, as the
480 * <code>id</code> field (cast to this type).
481 * You can use the load tag with the functions
482 * <code>@link OSKextRetainKextWithLoadTag
483 * OSKextRetainKextWithLoadTag@/link</code> and
484 * <code>@link OSKextReleaseKextWithLoadTag
485 * OSKextReleaseKextWithLoadTag@/link</code>.
489 * @typedef OSKextLoadTag
492 * A unique identifier assigned to a loaded instanace of a kext.
495 * If a kext is unloaded and later reloaded, the new instance
496 * has a different load tag.
498 * A kext can get its own load tag in the <code>kmod_info_t</code>
499 * structure passed into its module start routine, as the
500 * <code>id</code> field (cast to this type).
503 typedef uint32_t OSKextLoadTag
;
506 * @define kOSKextInvalidLoadTag
509 * A load tag value that will never be used for a loaded kext;
510 * indicates kext not found.
512 #define kOSKextInvalidLoadTag ((OSKextLoadTag)(-1))
516 /* Make these visible to kexts only and *not* the kernel.
518 #if !XNU_KERNEL_PRIVATE
521 * @function OSKextGetCurrentLoadTag
524 * Returns the run-time load tag for the calling kext as an
525 * <code>@link OSKextLoadTag OSKextLoadTag@/link</code>.
528 * The run-time load tag for the calling kext as an
529 * <code>@link OSKextLoadTag@/link</code>.
532 * The load tag identifies this loaded instance of the kext to the kernel
533 * and to kernel functions that operate on kexts.
535 OSKextLoadTag
OSKextGetCurrentLoadTag(void);
538 * @function OSKextGetCurrentIdentifier
541 * Returns the CFBundleIdentifier for the calling kext as a C string.
544 * The CFBundleIdentifier for the calling kext as a C string.
546 const char * OSKextGetCurrentIdentifier(void);
549 * @function OSKextGetCurrentVersionString
552 * Returns the CFBundleVersion for the calling kext as a C string.
555 * The CFBundleVersion for the calling kext as a C string.
557 const char * OSKextGetCurrentVersionString(void);
559 #endif /* !XNU_KERNEL_PRIVATE */
563 /********************************************************************/
564 #pragma mark Kext Loading C Functions
565 /********************************************************************/
568 * @group Kext Loading C Functions
569 * Functions for loading and tracking kexts in the kernel.
573 * @function OSKextLoadKextWithIdentifier
576 * Request that a kext be loaded.
578 * @param kextIdentifier The bundle identifier of the kext to be loaded.
581 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
582 * if the kext was loaded (or was already loaded).
583 * <code>@link //apple_ref/c/macro/kOSKextReturnDeferred kOSKextReturnDeferred@/link</code>
584 * if the kext was not found and a request
585 * was queued to <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>.
586 * Other return values indicate a failure to load the kext.
589 * If a kext is already in the kernel but not loaded, it is loaded immediately.
590 * If it isn't found, an asynchronous load request is
591 * made to <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>
592 * and <code>@link //apple_ref/c/macro/kOSKextReturnDeferred kOSKextReturnDeferred@/link</code> is returned.
593 * There is no general notification or callback mechanism for load requests.
595 OSReturn
OSKextLoadKextWithIdentifier(const char * kextIdentifier
);
599 * @function OSKextRetainKextWithLoadTag
602 * Retain a loaded kext based on its load tag,
603 * and enable autounload for that kext.
605 * @param loadTag The load tag of the kext to be retained.
606 * See <code>@link OSKextGetCurrentLoadTag@/link</code>.
609 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
610 * if the kext was retained.
611 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound kOSKextReturnNotFound@/link</code>
612 * if the kext was not found.
613 * <code>@link //apple_ref/c/macro/kOSKextReturnInvalidArgument
614 * kOSKextReturnInvalidArgument@/link</code>
615 * if <code>loadTag</code> is
616 * <code>@link kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>.
619 * Retaining a kext prevents it from being unloaded,
620 * either explicitly or automatically, and enables autounload for the kext.
621 * When autounload is enabled, then shortly after the kext's last reference
622 * is dropped, it will be unloaded if there are no outstanding references to it
623 * and there are no instances of its Libkern C++ subclasses (if any).
625 * Kexts that define subclasses of
626 * <code>@link //apple_ref/doc/class/IOService IOService@/link</code>
627 * have autounload enabled automatically.
628 * Other kexts can use the reference count to manage automatic unload
629 * without having to define and create Libkern C++ objects.
630 * For example, a filesystem kext can retain itself whenever a new mount
631 * is created, and release itself when a mount is removed.
632 * When the last mount is removed, the kext will be unloaded after a brief delay.
634 * A kext can get its own load tag using the
635 * <code>@link OSKextGetCurrentLoadTag@/link</code>.
637 * Kexts should not retain and release other kexts; linkage references
638 * are accounted for internally.
640 OSReturn
OSKextRetainKextWithLoadTag(OSKextLoadTag loadTag
);
644 * @function OSKextReleaseKextWithLoadTag
647 * Release a loaded kext based on its load tag.
649 * @param loadTag The load tag of the kext to be released.
650 * See <code>@link OSKextGetCurrentLoadTag@/link</code>.
653 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
654 * if the kext was released.
655 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
656 * kOSKextReturnNotFound@/link</code>
657 * if the kext was not found.
658 * <code>@link //apple_ref/c/macro/kOSKextReturnInvalidArgument
659 * kOSKextReturnInvalidArgument@/link</code>
660 * if <code>loadTag</code> is
661 * <code>@link kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>.
664 * The kext should have been retained previously via
665 * <code>@link OSKextRetainKextWithLoadTag@/link</code>.
667 * This function schedules an autounload scan for all kexts.
668 * When that scan occurs, if a kext has autounload enabled,
669 * it will be unloaded if there are no outstanding references to it
670 * and there are no instances of its Libkern C++ classes (if any).
672 * Kexts that define subclasses of
673 * <code>@link //apple_ref/doc/class/IOService IOService@/link</code>
674 * have autounload enabled automatically.
675 * Other kexts can use the reference count to manage automatic unload
676 * without having to define and create Libkern C++ objects.
677 * For example, a filesystem kext can be retained whenever a new mount
678 * is created, and released when a mount is removed.
679 * When the last mount is removed, the kext will be unloaded after a brief delay.
681 * While the autounload scan takes place after a delay of at least a minute,
682 * a kext that manages its own reference counts for autounload should
683 * be prepared to have its module stop function called even while the function
684 * calling this function is still running.
686 * A kext can get its own load tag using the
687 * <code>@link OSKextGetCurrentLoadTag@/link</code>.
689 * Kexts should not retain and release other kexts; linkage references
690 * are accounted for internally.
692 OSReturn
OSKextReleaseKextWithLoadTag(OSKextLoadTag loadTag
);
695 /********************************************************************/
697 #pragma mark Kext Requests
698 /********************************************************************/
701 * @group Kext Requests to User Space
702 * Functions for making requests to kextd in user space.
706 * @typedef OSKextRequestTag
709 * Identifies a kext request made to user space.
711 typedef uint32_t OSKextRequestTag
;
714 * @define kOSKextRequestTagInvalid
717 * A request tag value that will never be used for a kext request;
718 * indicates failure to create/queue the request.
720 #define kOSKextRequestTagInvalid ((OSKextRequestTag)-1)
723 * @typedef OSKextRequestResourceCallback
726 * Invoked to provide results for a kext resource request.
728 * @param requestTag The tag of the request that the callback pertains to.
729 * @param result The result of the request:
730 * <code>@link kOSReturnSuccess
731 * kOSReturnSuccess@/link</code>
732 * if the request was fulfilled;
733 * <code>@link kOSKextReturnTimeout
734 * kOSKextReturnTimeout@/link</code>
735 * if the request has timed out;
736 * <code>@link kOSKextReturnStopping
737 * kOSKextReturnStopping@/link</code>
738 * if the kext containing the callback
739 * address for the kext is being unloaded;
740 * or other values on error.
741 * @param resourceData A pointer to the requested resource data.
742 * Owned by the system; the kext should make a copy
743 * if it needs to keep the data past the callback.
744 * @param resourceDataLength The length of <code>resourceData</code>.
745 * @param context The context pointer originally passed to
746 * <code>@link OSKextRequestResource
747 * OSKextRequestResource@/link</code>.
749 typedef void (* OSKextRequestResourceCallback
)(
750 OSKextRequestTag requestTag
,
752 const void * resourceData
,
753 uint32_t resourceDataLength
,
757 * @function OSKextRequestResource
760 * Requests data from a nonlocalized resource file in a kext bundle on disk.
762 * @param kextIdentifier The CFBundleIdentifier of the kext
763 * from which to read the file.
764 * @param resourceName The name of the resource file to read.
765 * @param callback A pointer to a callback function; the address
766 * must be within a currently-loaded kext.
767 * @param context A pointer to arbitrary run-time data
768 * that will be passed to the callback
769 * when it is invoked. May be <code>NULL</code>.
770 * @param requestTagOut If non-<code>NULL</code>,
771 * filled on success with a tag identifying the
773 * (or on failure with <code>@link kOSKextRequestTagInvalid
774 * kOSKextRequestTagInvalid@/link</code>;
776 * <code>@link OSKextCancelRequest
777 * OSKextCancelRequest@/link</code>.
780 * <code>@link kOSReturnSuccess kOSReturnSuccess@/link</code>
781 * if the request is successfully queued.
782 * <code>@link kOSKextReturnInvalidArgument kOSKextReturnInvalidArgument@/link</code>
783 * if <code>kextIdentifier</code> or <code>resourceName</code> or if
784 * <code>callback</code> is not an address within a loaded kext executable.
785 * <code>@link kOSKextReturnStopping kOSKextReturnStopping@/link</code>
786 * if an unload attempt is being made
787 * on the kext containing <code>callback</code>.
788 * Other <code>OSKextReturn...</code> errors are possible.
791 * This function queues an asynchronous request to the user-space kext daemon
792 * <code>@link //apple_ref/doc/man/8/kextd kextd(8)@/link</code>;
793 * requests for resources early in system startup
794 * will not be fulfilled until that daemon starts.
795 * Requests made by a kext while that kext is loading
796 * (specifically in the kext's module start routine)
797 * will not be fulfilled until after the start routine returns and
798 * the kext is completely loaded.
799 * Kexts requesting resources should be sure to perform appropriate locking
800 * in the callback function.
802 * Kext resources are stored in the kext's on-disk bundle under the
803 * Resources subdirectory.
804 * See {@linkdoc //apple_ref/doc/uid/10000123i Bundle Programming Guide}
805 * for an overview of bundle structure.
806 * The localization context of the kext daemon
807 * (namely that of the superuser)
808 * will be used in retrieving resources;
809 * kext resources intended for use in the kernel
810 * should generally not be localized.
812 * <code>callback</code> is guaranteed to be invoked except when:
814 * <li>@link OSKextCancelRequest <code>OSKextCancelRequest</code>@/link
815 * is used to cancel the request.
816 * In this case the kext gets the <code>context</code> pointer
817 * and can clean it up.</li>
818 * <li>The request is made during a kext's module start routine
819 * and the start routine returns an error.
820 * In this case, callbacks cannot be safely invoked, so
821 * the kext should clean up all request contexts
822 * when returning the error from the start routine.</li>
825 * Kexts with pending requests are not subject to autounload,
826 * but requests are subject to timeout after a few minutes.
827 * If that amount of time passes with no response from user space,
828 * <code>callback</code> is invoked with a result of.
829 * <code>@link kOSKextReturnTimeout kOSKextReturnTimeout@/link</code>.
831 * Kexts that are explicitly unloaded have all pending request callbacks
832 * invoked with a result of
833 * <code>@link kOSKextReturnStopping kOSKextReturnStopping@/link</code>.
834 * The kext must handle these callbacks,
835 * even if its stop routine will prevent unloading.
836 * If the kext does prevent unloading, it can reissue resource requests
837 * outside of the stop function.
839 OSReturn
OSKextRequestResource(
840 const char * kextIdentifier
,
841 const char * resourceName
,
842 OSKextRequestResourceCallback callback
,
844 OSKextRequestTag
* requestTagOut
);
847 * @function OSKextCancelRequest
850 * Cancels a pending user-space kext request without invoking the callback.
852 * @param requestTag A tag identifying a pending request.
853 * @param contextOut If non-<code>NULL</code>, filled with the context pointer
854 * originally passed with the request.
857 * <code>@link kOSReturnSuccess kOSReturnSuccess@/link</code>
858 * if the request is successfully canceled.
859 * <code>@link kOSKextReturnNotFound kOSKextReturnNotFound@/link</code>
860 * if <code>requestTag</code> does not identify any pending request.
861 * Other <code>OSKextReturn...</code> errors are possible.
864 * This function cancels a pending request if it exists,
865 * so that its callback will not be invoked.
866 * It returns in <code>contextOut</code>
867 * the context pointer used to create the request
868 * so that any resources allocated for the request can be cleaned up.
870 * Kexts do not need to cancel outstanding requests
871 * in their module stop functions;
872 * when a kext is unloaded, all pending request callbacks
873 * are invoked with a result of
874 * <code>@link kOSKextReturnTimeout kOSKextReturnTimeout@/link</code>
875 * before the stop function is called.
877 OSReturn
OSKextCancelRequest(
878 OSKextRequestTag requestTag
,
883 * @function OSKextGrabPgoData
886 * Grab a LLVM profile data buffer from a loaded kext.
888 * @param uuid the uuid identifying the kext to retrieve data from
889 * @param pSize pointer of where to store the size of the buffer. May be NULL.
890 * @param pBuffer pointer to the output buffer. May be NULL.
891 * @param bufferSize size of the buffer pointed to by pBuffer
892 * @param wait_for_unload (boolean) sleep until the kext is unloaded
893 * @param metadata (boolean) include metadata footer
897 * ENOTSUP if the kext does not have profile data to retrieve.
898 * ENOTSUP if no kext with the given UUID is found
899 * ERRORS if the provided buffer is too small
900 * EIO internal error, such as if __llvm_profile_write_buffer_internal fails
903 OSKextGrabPgoData(uuid_t uuid
,
914 /********************************************************************/
915 #pragma mark Weak linking
916 /********************************************************************/
919 * @group Weak Linking
920 * Support for weak references to symbols in kexts.
924 * @var gOSKextUnresolved
927 * The value to which a kext's unresolved, weakly-referenced symbols are bound.
930 * A kext must test a weak symbol before using it. A weak symbol
931 * is only safe to use if it is not equal to <code>gOSKextUnresolved</code>.
933 * Example for a weak symbol named <code>foo</code>:
936 * if (&foo != gOSKextUnresolved) {
939 * printf("foo() is not supported\n");
944 extern const void * gOSKextUnresolved
;
947 * @define OSKextSymbolIsResolved
950 * Checks whether a weakly-referenced symbol has been resolved.
952 * @param weak_sym The weak symbol to be tested for resolution.
955 * <code>TRUE</code> if weak_sym is resolved, or <code>FALSE</code>
956 * if weak_sym is unresolved.
959 * This is a convenience macro for testing if weak symbols are resolved.
961 * Example for a weak symbol named <code>foo</code>:
964 * if (OSKextSymbolIsResolved(foo)) {
967 * printf("foo() is not resolved\n");
972 #define OSKextSymbolIsResolved(weak_sym) \
973 (&(weak_sym) != gOSKextUnresolved)
980 /********************************************************************/
981 #pragma mark Kernel External Components for FIPS compliance
982 /********************************************************************/
985 // Kernel External Components for FIPS compliance (KEC_FIPS)
986 // WARNING - ath_hash is owned by the kernel, do not free
987 typedef struct AppleTEXTHash
{
988 const int ath_version
; // version of this structure (value is 1)
989 int ath_length
; // length of hash data
990 void * ath_hash
; // hash extracted from AppleTextHashes dict
992 #endif // CONFIG_KEC_FIPS
998 #endif /* _LIBKERN_OSKEXTLIB_H */