2 * Copyright (c) 1998-2000 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_OSKEXTLIBPRIVATE_H
30 #define _LIBKERN_OSKEXTLIBPRIVATE_H
32 #include <sys/cdefs.h>
33 #include <uuid/uuid.h>
37 #include <libkern/OSTypes.h>
38 #include <mach/kmod.h>
39 #include <mach/vm_types.h>
41 #include <CoreFoundation/CoreFoundation.h>
42 #include <System/mach/kmod.h>
46 #include <libkern/OSReturn.h>
52 /********************************************************************/
53 #pragma mark Misc Constants
54 /********************************************************************/
57 typedef uint8_t OSKextExcludeLevel
;
58 #define kOSKextExcludeNone (0)
59 #define kOSKextExcludeKext (1)
60 #define kOSKextExcludeAll (2)
64 /********************************************************************/
65 #pragma mark Kext/OSBundle Property List Keys
66 /********************************************************************/
70 * @define kOSBundleHelperKey
71 * @abstract Used by loginwindow.
73 #define kOSBundleHelperKey "OSBundleHelper"
76 * @define kOSBundleDeveloperOnlyKey
77 * @abstract A boolean value indicating whether the kext should only load on
80 #define kOSBundleDeveloperOnlyKey "OSBundleDeveloperOnly"
84 * @define kAppleSecurityExtensionKey
85 * @abstract A boolean value indicating whether the kext registers
88 #define kAppleSecurityExtensionKey "AppleSecurityExtension"
91 * @define kAppleKernelExternalComponentKey
92 * @abstract A boolean value indicating whether the kext is vending kernel
93 * KPI, and needs special loading behavior.
95 #define kAppleKernelExternalComponentKey "AppleKernelExternalComponent"
97 // properties found in the registry root
98 #define kOSKernelCPUTypeKey "OSKernelCPUType"
99 #define kOSKernelCPUSubtypeKey "OSKernelCPUSubtype"
100 #define kOSStartupMkextCRC "OSStartupMkextCRC" /* value is 32-bit OSData */
101 #define kOSPrelinkKextCountKey "OSPrelinkKextCount" /* value is 32-bit OSNumber */
102 #define kOSPrelinkPersonalityCountKey "OSPrelinkPersonalityCount" /* value is 32-bit OSNumber */
106 /********************************************************************/
107 #pragma mark Load Info Keys
108 /********************************************************************/
110 /*********************************************************************
111 * In addition to the keys defined here, you will find:
112 * kCFBundleIdentifierKey
113 * kCFBundleVersionKey
114 * kOSBundleCompatibleVersionKey
115 * kOSBundleIsInterfaceKey
116 * kOSKernelResourceKey
117 *********************************************************************/
118 #define kOSBundleMachOHeadersKey "OSBundleMachOHeaders"
119 #define kOSBundleCPUTypeKey "OSBundleCPUType"
120 #define kOSBundleCPUSubtypeKey "OSBundleCPUSubtype"
121 #define kOSBundlePathKey "OSBundlePath"
122 #define kOSBundleExecutablePathKey "OSBundleExecutablePath"
123 #define kOSBundleUUIDKey "OSBundleUUID"
124 #define kOSBundleStartedKey "OSBundleStarted"
125 #define kOSBundlePrelinkedKey "OSBundlePrelinked"
126 #define kOSBundleLoadTagKey "OSBundleLoadTag"
127 #define kOSBundleLoadAddressKey "OSBundleLoadAddress"
128 #define kOSBundleLoadSizeKey "OSBundleLoadSize"
129 #define kOSBundleWiredSizeKey "OSBundleWiredSize"
130 #define kOSBundleDependenciesKey "OSBundleDependencies"
131 #define kOSBundleRetainCountKey "OSBundleRetainCount"
133 /* Dictionary of metaclass info keyed by classname.
135 #define kOSBundleClassesKey "OSBundleClasses"
137 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
138 * may be absent (for the root class).
140 #define kOSMetaClassNameKey "OSMetaClassName"
141 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
142 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
146 /********************************************************************/
147 #pragma mark Kext Log Specification
148 /********************************************************************/
151 * @group Kext Log Specification
152 * Logging levels & flags for kernel extensions.
153 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
158 * @typedef OSKextLogSpec
159 * @abstract Describes what a log message applies to,
160 * or a filter that determines which log messages are displayed.
163 * A kext log specification is a 32-bit value used as a desription of
164 * what a given log message applies to, or as a filter
165 * indicating which log messages are desired and which are not.
166 * A log specification has three parts (described in detail shortly):
168 * <li>A <b>level</b> from 0-7 in the lowest-order nibble (0x7).</li>
169 * <li>A flag bit in the lowest-order nibble (0x8) indicating whether
170 * log messages tied to individual kexts are always printed (1)
171 * or printed only if the kext has an
172 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
173 * OSBundleEnableKextLogging@/link set to <code>true</code>.
174 * <li>A set of <b>activity flags</b> in the remaining nibbles (0xFFFFFFF0),
175 * which describe areas of activity related to kernel extensions.</li>
178 * You can specify a log spec to most of the kext tools with the -v option
179 * and a hex number (rather than the escalating decimal levels 0-6).
180 * You can also specify a log spec to the kernel with the "kextlog" boot arg
181 * or "debug.kextlog" sysctl.
185 * The log level spans a range from silent (no log messages)
186 * to debuging information:
189 * <li>Silent - Not applicable to messages; as a filter, do not print any log messages.</li>
190 * <li>Errors - Log message is an error.
191 * <li>Warnings - Log message is a warning.
192 * <li>Basic information - Log message is basic success/failure.</li>
193 * <li>Progress - Provides high-level information about stages in processing.</li>
194 * <li>Step - Provides low-level information about complex operations,
195 * typically about individual kexts.</li>
196 * <li>Detail - Provides very low-level information about parts of kexts,
197 * including individual Libkern classes and operations on bundle files.</li>
198 * <li>Debug - Very verbose logging about internal activities.</li>
202 * <code>@link kOSKextLogErrorLevel kOSKextLogErrorLevel@/link</code> or
203 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
204 * ignore activity flags and the
205 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
206 * OSBundleEnableKextLogging@/link property;
207 * that is, only the filter level is checked for messages at these levels.
208 * Log messages at levels above
209 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
210 * are filtered according both to the activity flags in the current filter
211 * and to whether the log message is associated with a kext or not.
212 * Normally log messages associated with kexts are not printed
213 * unless the kext has a
214 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
215 * OSBundleEnableKextLogging@/link property set to <code>true</code>.
216 * If you set the high-order bit of the log level (that is, add 8 to the level),
217 * then all kext-specific log messages matching the activity flags are printed.
218 * This can be very verbose.
220 * <b>Activity Flags</b>
222 * Each flag governs a category of activity,
223 * such as loading, IPC, or archives; by combining them with bitwise OR,
224 * you can choose which messages you wish to see (or when logging messages,
225 * which bit flags select your message).
227 * <b>Byte 1:</b> <code>0xF0</code> - Basic activities
228 * (<code>@link kOSKextLogGeneralFlag kOSKextLogGeneralFlag@/link</code>,
229 * <code>@link kOSKextLogLoadFlag kOSKextLogLoadFlag@/link</code>, and
230 * <code>@link kOSKextLogArchiveFlag kOSKextLogArchiveFlag@/link</code>).
232 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
234 * <b>Byte 4:</b> <code>0xF000</code> - Kext diagnostics
235 * (<code>@link kOSKextLogValidationFlag kOSKextLogValidationFlag@/link</code>,
236 * <code>@link kOSKextLogAuthenticationFlag kOSKextLogAuthenticationFlag@/link</code>, and
237 * <code>@link kOSKextLogDependenciesFlag kOSKextLogDependenciesFlag@/link</code>).
239 * <b>Byte 5:</b> <code>0xF00000</code> - Kext access & bookkeeping
240 * (<code>@link kOSKextLogDirectoryScanFlag kOSKextLogDirectoryScanFlag@/link</code>,
241 * <code>@link kOSKextLogFileAccessFlag kOSKextLogFileAccessFlag@/link</code>,
242 * <code>@link kOSKextLogKextBookkeepingFlag kOSKextLogKextBookkeepingFlag@/link </code>).
244 * <b>Byte 6:</b> <code>0xF000000</code> - Linking & patching
245 * (<code>@link kOSKextLogLinkFlag kOSKextLogLinkFlag@/link</code> and
246 * <code>@link kOSKextLogPatchFlag kOSKextLogPatchFlag@/link</code>).
248 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
250 typedef uint32_t OSKextLogSpec
;
253 /********************************************************************/
255 /********************************************************************/
258 * @define kOSKextLogLevelMask
259 * @abstract Masks the bottom 3 bits of an
260 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
263 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
266 * @define kOSKextLogKextOrGlobalMask
267 * @abstract Determines whether per-kext log messages are output.
270 * In filter specifications, if unset (the usual default),
271 * then log messages associated with a kext are only output
273 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
274 * OSBundleEnableKextLogging@/link
275 * property set to <code>true</code>.
276 * If set, then all log messages associated with kexts
279 * In message specifications, if set it indicates that the message is either
280 * not associated with a kext, or is associated with a kext that has an
281 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
282 * OSBundleEnableKextLogging@/link
283 * property set to <code>true</code>.
285 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
289 * @define kOSKextLogFlagsMask
290 * @abstract Masks the flag bits of an
291 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
293 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
296 * @define kOSKextLogFlagsMask
297 * @abstract Masks the flag bits of an
298 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>
299 * to which command-line <code>-v</code> levels apply.
301 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
304 * @define kOSKextLogConfigMask
305 * @abstract Masks the config bits of an
306 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
308 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
311 /********************************************************************/
312 #pragma mark 0xF - Log Level
313 /********************************************************************/
317 * @define kOSKextLogExplicitLevel
318 * @abstract Used when logging a message to overrides the current log filter,
319 * even if it's set to silent for log messages.
320 * This is essentially a pass-through for
321 * unconditional print messages to go
322 * through the logging engine.
324 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
327 * @define kOSKextLogErrorLevel
328 * @abstract Log messages concerning error conditions in any category.
330 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
334 * @define kOSKextLogWarningLevel
335 * @abstract Log messages concerning warning conditions in any category,
336 * which indicate potential error conditions,
337 * and notices, which may explain unexpected but correct behavior.
339 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
343 * @define kOSKextLogBasicLevel
344 * @abstract Log messages concerning top-level outcome in any category
345 * (kext load/unload, kext cache creation/extration w/# kexts).
347 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
351 * @define kOSKextLogProgressLevel
352 * @abstract Log messages concerning high-level progress in any category,
353 * such as sending a load request to the kernel,
354 * allocation/link/map/start (load operation),
355 * stop/unmap (unload operation), kext added/extracted (archive).
357 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
361 * @define kOSKextLogStepLevel
362 * @abstract Log messages concerning major steps in any category,
363 * such as sending personalities to the IOCatalogue when loading,
364 * detailed IPC with the kernel, or filtering of kexts for an archive.
366 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
370 * @define kOSKextLogDetailLevel
371 * @abstract Log messages concerning specific details in any category,
372 * such as classes being registered/unregistered or
373 * operations on indivdual files in a kext.
375 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
379 * @define kOSKextLogDebugLevel
380 * @abstract Log messages concerning very low-level actions that are
381 * useful mainly for debugging the kext system itself.
383 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
387 /********************************************************************/
388 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
389 /********************************************************************/
393 * @define kOSKextLogGeneralFlag
394 * @abstract Log messages about general activity in the kext system.
396 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
399 * @define kOSKextLogLoadFlag
400 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
403 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
406 * @define kOSKextLogIPCFlag
407 * @abstract Log messages about any interaction between kernel and user space
408 * regarding kernel extensions.
410 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
413 * @define kOSKextLogArchiveFlag
414 * @abstract Log messages about creating or processing a kext startup cache file
415 * (mkext or prelinked kernel).
417 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
421 /********************************************************************/
422 #pragma mark 0xF00 - Reserved Verbose Area
423 /********************************************************************/
425 // reserved slot for group ((OSKextLogSpec) 0x100)
426 // reserved slot for group ((OSKextLogSpec) 0x200)
427 // reserved slot for group ((OSKextLogSpec) 0x400)
428 // reserved slot for group ((OSKextLogSpec) 0x800)
431 /********************************************************************/
432 #pragma mark 0xF000 - Kext diagnostic activity
433 /********************************************************************/
437 * @define kOSKextLogValidationFlag
438 * @abstract Log messages when validating kernel extensions.
440 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
443 * @define kOSKextLogAuthenticationFlag
444 * @abstract Log messages when autnenticating kernel extension files.
445 * Irrelevant in the kernel.
447 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
450 * @define kOSKextLogDependenciesFlag
451 * @abstract Log messages when resolving dependencies for a kernel extension.
453 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
455 // reserved slot for group ((OSKextLogSpec) 0x8000)
458 /********************************************************************/
459 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
460 /********************************************************************/
464 * @define kOSKextLogDirectoryScanFlag
465 * @abstract Log messages when scanning directories for kernel extensions.
466 * In the kernel logs every booter kext entry processed.
468 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
471 * @define kOSKextLogFileAccessFlag
472 * @abstract Log messages when performing any filesystem access (very verbose).
473 * Irrelevant in the kernel.
475 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
478 * @define kOSKextLogKextBookkeepingFlag
479 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
481 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
483 // reserved slot for group ((OSKextLogSpec) 0x80000)
486 /********************************************************************/
487 #pragma mark 0xF00000 - Linking & Patching
488 /********************************************************************/
492 * @define kOSKextLogLinkFlag
493 * @abstract Log messages about linking.
495 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
498 * @define kOSKextLogPatchFlag
499 * @abstract Log messages about patching.
501 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
503 // reserved slot for group ((OSKextLogSpec) 0x400000)
504 // reserved slot for group ((OSKextLogSpec) 0x800000)
507 /********************************************************************/
508 #pragma mark 0xF000000 - Reserved
509 /********************************************************************/
512 // reserved slot for grouping ((OSKextLogSpec) 0x1000000)
513 // reserved slot for grouping ((OSKextLogSpec) 0x2000000)
514 // reserved slot for grouping ((OSKextLogSpec) 0x4000000)
515 // reserved slot for grouping ((OSKextLogSpec) 0x8000000)
519 /********************************************************************/
520 #pragma mark 0xF0000000 - Config Flags
521 /********************************************************************/
524 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
525 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
526 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
529 /********************************************************************/
530 #pragma mark Predefined Specifications
531 /********************************************************************/
535 * @define kOSKextLogSilentFilter
536 * @abstract For use in filter specs:
537 * Ignore all log messages with a log level greater than
538 * <code>@link kOSKextLogExplicitLevel kOSKextLogExplicitLevel@/link</code>.
540 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
543 * @define kOSKextLogShowAllFilter
544 * @abstract For use in filter specs:
545 * Print all log messages not associated with a kext or
546 * associated with a kext that has
547 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
548 * OSBundleEnableKextLogging@/link
549 * set to <code>true</code>.
551 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
554 * @define kOSKextLogShowAllKextsFilter
555 * @abstract For use in filter specs:
556 * Print all log messages has
557 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
558 * OSBundleEnableKextLogging@/link
559 * set to <code>true</code>.
561 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
562 (kOSKextLogShowAllFilter | \
563 kOSKextLogKextOrGlobalMask))
567 /********************************************************************/
568 #pragma mark Kext Version String Processing
569 /********************************************************************/
572 * @group Kext Version String Processing
573 * Functions for working with kext versions and compatible versions.
577 * @typedef OSKextVersion
578 * @abstract An encoded kext version that can be compared arithmetically.
581 * A value of zero (<code>@link kOSKextVersionUndefined kOSKextVersionUndefined@/link</code>)
582 * is <i>not</i> equivalent to a version string of "0.0",
583 * and typically means there is no version specified
584 * (for example, that there is no CFBundleVersion property at all).
585 * Values below zero are invalid.
587 * The encoding used is subject to change,
588 * and should never be saved to permanent storage.
589 * Always use proper version strings in files and interprocess communication.
591 typedef int64_t OSKextVersion
;
594 * @define kOSKextVersionMaxLength
595 * @abstract The length of a string buffer
596 * guaranteed to be able to hold a kext version.
599 * Kext versions use an extended Mac OS 'vers' format with double the number
600 * of digits before the build stage: ####.##.##s{1-255} where 's'
601 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
603 #define kOSKextVersionMaxLength (20)
604 // with a few bytes to spare including a nul byte
605 // xx-review: Should we make this much bigger in case we ever need longer strings?
608 * @define kOSKextVersionUndefined
609 * @abstract The undefined version.
612 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
614 * (for example, that there is no CFBundleVersion property at all).
616 #define kOSKextVersionUndefined (0)
619 * @function OSKextParseVersionString
622 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
624 * @param versionString The kext version string to parse.
627 * An encoded kext version that can be compared numerically
628 * against other encoded kext versions,
629 * <0 if <code>versionString</code> is <code>NULL</code>, empty,
630 * or cannot be parsed.
633 * Kext versions use an extended Mac OS 'vers' format with double the number
634 * of digits before the build stage: ####.##.##s{1-255} where 's'
635 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
637 OSKextVersion
OSKextParseVersionString(const char * versionString
);
641 * @function OSKextVersionGetString
644 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
648 * The encoded version to format.
650 * A C string buffer of at least
651 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code> bytes.
652 * @param bufferSize The size in bytes of <code>buffer</code>.
655 * <code>TRUE</code> if the encoded version is formatted successfully.
656 * <code>FALSE</code> if <code>buffer</code> is <code>NULL</code> or
657 * <code>bufferSize</code> is less than
658 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code>.
661 * The return value strictly indicates whether <code>buffer</code>
662 * is large enough to hold the result.
663 * If <code>aVersion</code> is 0, the resulting string is "(missing)".
664 * If <code>aVersion</code> is less than 0
665 * or is not a valid kext version encoding,
666 * the resulting string is "(invalid)".
668 Boolean
OSKextVersionGetString(
669 OSKextVersion aVersion
,
671 uint32_t bufferSize
);
678 /********************************************************************/
680 #pragma mark Weak linking
681 /********************************************************************/
683 #ifdef XNU_KERNEL_PRIVATE
684 void kext_weak_symbol_referenced(void);
685 #endif /* XNU_KERNEL_PRIVATE */
689 /********************************************************************/
690 #pragma mark Miscellaneous Kernel-Only Kext Functions
691 /********************************************************************/
695 * @function kext_get_vm_map
696 * @abstract Returns the vm_map from which the kext was allocated.
698 * @param info The kmod_info_t structure of the kext.
699 * @result The vm_map from which the kext was allocated. This function
700 * cannot return <code>NULL</code>.
702 vm_map_t
kext_get_vm_map(kmod_info_t
* info
);
704 #ifdef XNU_KERNEL_PRIVATE
708 * @function OSKextRegisterKextsWithDTrace
710 * DTrace calls this once when it has started up so that the kext system
711 * will register any already-loaded kexts with it.
713 void OSKextRegisterKextsWithDTrace(void);
715 #endif /* CONFIG_DTRACE */
718 * @function kext_dump_panic_lists
719 * @abstract Prints compacted lists of last unloaded & all loaded kexts
722 * @param printf_func The printf-style function to use for output.
724 void kext_dump_panic_lists(int (*printf_func
)(const char *fmt
, ...));
726 #endif /* XNU_KERNEL_PRIVATE */
728 #ifdef XNU_KERNEL_PRIVATE
732 /********************************************************************/
733 #pragma mark Kext Loading C Functions
734 /********************************************************************/
737 * @function OSKextGetLoadTagForBundleIdentifier
738 * @abstract Look up the load tag for a kext.
740 * @param kextIdentifier The bundle identifier of the kext to look up.
742 * The load tag of the requested kext, or
743 * <code>@link //apple_ref/c/macro/kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>
744 * if the kext was not found.
747 * A load tag uniquely identifies a loaded kext.
748 * It can be found as the <code>id</code> field of a loaded kext's
749 * <code>kmod_info_t</code> struct.
751 * Note that a load tag represents a specific loaded instance of a kext.
752 * If that kext is unloaded, the load tag is no longer a valid reference.
753 * If the same kext is later reloaded, it will have a new load tag.
755 * You can use the load tag to adjust a kext's reference count
757 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
758 * OSKextRetainKextWithLoadTag@/link</code>
760 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
761 * OSKextReleaseKextWithLoadTag@/link</code>,
762 * so that the kext is automatically unloaded when no references remain,
763 * or to unload the kext immediately
764 * with <code>@link //apple_ref/c/func/OSKextUnloadKextWithLoadTag OSKextUnloadKextWithLoadTag@/link</code>.
766 * Those functions are intended for use with non-IOKit kexts
767 * (specifically, kexts that define no subclasses of
768 * <code>@link //apple_ref/doc/class/IOServiceIOService@/link</code>).
769 * Pure IOKit kexts are managed via instance counts
770 * of their libkern C++ object classes;
771 * using those functions on them will only interfere with that mechanism.
772 * If you have a hybrid kext with both IOService subclasses and non-IOKit code,
773 * however, you may want to use reference counting for the non-IOKit portions:
774 * that way the kext will only unload automaticaly
775 * when there are no C++ objects and the kext reference count is zero.
777 uint32_t OSKextGetLoadTagForBundleIdentifier(
778 const char * kextIdentifier
);
782 * @function OSKextUnloadKextWithLoadTag
783 * @abstract Stop and unload a kext based on its load tag.
785 * @param loadTag The load tag of the kext to unload.
787 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
788 * if the kext was found and unloaded.
789 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
790 * kOSKextReturnNotFound@/link</code>
791 * if the kext was not found.
792 * <code>@link //apple_ref/c/macro/kOSKextReturnInUse
793 * kOSKextReturnInUse@/link</code>
794 * if the kext has outstanding references
795 * or if there are instances of its libkern C++ subclasses.
796 * Other return values indicate a failure to unload the kext,
797 * typically because the module stop routine failed.
800 * A panic will occur if a kext calls this function to unload itself.
801 * The safest way for a kext to unload itself is to call
802 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
803 * OSKextRetainKextWithLoadTag@/link</code>
804 * with its own load tag
805 * (the <code>id</code> field of its <code>kmod_info_t</code> struct),
807 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
808 * OSKextReleaseKextWithLoadTag@/link</code>;
809 * this will schedule the kext for unload on a separate thread.
811 * This function can be used when reference-based autounloading is not
813 * If a kernel system or kext is already monitoring
814 * the need for a kext,
815 * it can simply call this function when it's known that the kext is not needed.
817 OSReturn
OSKextUnloadKextWithLoadTag(uint32_t loadTag
);
819 #endif /* XNU_KERNEL_PRIVATE */
825 /********************************************************************/
826 #pragma mark Loaded Kext Summary
827 /********************************************************************/
831 * @define kOSKextLoadedKextSummaryVersion
832 * @abstract The current version of the loaded kext summary headers.
834 #define kOSKextLoadedKextSummaryVersion 2
837 * @typedef OSKextLoadedKextSummary
838 * @abstract A structure that describes a loaded kext.
840 * @field name The kext's bundle identifier.
841 * @field uuid The kext's UUID;
842 * @field address The kext's load address.
843 * @field size The kext's load size.
844 * @field version The binary format (OSKextVersion) version of the kext.
845 * @field loadTag The kext's load tag.
846 * @field flags Internal tracking flags.
847 * @field reference_list who this refs (links on).
850 * The OSKextLoadedKextSummary structure contains a basic set of information
851 * about the kext to facilitate kext debugging and panic debug log output.
853 typedef struct _loaded_kext_summary
{
854 char name
[KMOD_MAX_NAME
];
861 uint64_t reference_list
;
862 } OSKextLoadedKextSummary
;
865 * @typedef OSKextLoadedKextSummaryHeader
866 * @abstract A structure that describes the set of loaded kext summaries.
868 * @field version The version of the loaded kext summary structures.
869 * @field entry_size The size of each entry in summaries.
870 * @field numSummaries The number of OSKextLoadedKextSummary structures
871 * following the header.
872 * @field summaries A convenience pointer to the array of summaries following
876 * The OSKextLoadedKextSummaryHeader describes the set of loaded kext summaries
877 * available for use by the debugger or panic log routine.
878 * The array of summaries contains one OSKextLoadedKextSummary for every kext
879 * that declares an executable and is not an interface to the kernel.
881 typedef struct _loaded_kext_summary_header
{
884 uint32_t numSummaries
;
885 uint32_t reserved
; /* explicit alignment for gdb */
886 OSKextLoadedKextSummary summaries
[0];
887 } OSKextLoadedKextSummaryHeader
;
890 * @var gLoadedKextSummaries
891 * @abstract The global pointer to the current set of loaded kext summaries.
893 extern OSKextLoadedKextSummaryHeader
* gLoadedKextSummaries
;
896 * @function OSKextLoadedKextSummariesUpdated
897 * @abstract Called when gLoadedKextSummaries has been updated.
900 * gLoadedKextSummaries is updated when a kext is loaded or unloaded.
901 * When the update is complete, OSKextLoadedKextSummariesUpdated is called.
902 * gdb can set a breakpoint on this function to detect kext loads and unloads.
904 void OSKextLoadedKextSummariesUpdated(void);
908 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */