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"
75 // properties found in the registry root
76 #define kOSKernelCPUTypeKey "OSKernelCPUType"
77 #define kOSKernelCPUSubtypeKey "OSKernelCPUSubtype"
78 #define kOSStartupMkextCRC "OSStartupMkextCRC" /* value is 32-bit OSData */
79 #define kOSPrelinkKextCountKey "OSPrelinkKextCount" /* value is 32-bit OSNumber */
80 #define kOSPrelinkPersonalityCountKey "OSPrelinkPersonalityCount" /* value is 32-bit OSNumber */
84 /********************************************************************/
85 #pragma mark Load Info Keys
86 /********************************************************************/
88 /*********************************************************************
89 * In addition to the keys defined here, you will find:
90 * kCFBundleIdentifierKey
92 * kOSBundleCompatibleVersionKey
93 * kOSBundleIsInterfaceKey
94 * kOSKernelResourceKey
95 *********************************************************************/
96 #define kOSBundleMachOHeadersKey "OSBundleMachOHeaders"
97 #define kOSBundleCPUTypeKey "OSBundleCPUType"
98 #define kOSBundleCPUSubtypeKey "OSBundleCPUSubtype"
99 #define kOSBundlePathKey "OSBundlePath"
100 #define kOSBundleExecutablePathKey "OSBundleExecutablePath"
101 #define kOSBundleUUIDKey "OSBundleUUID"
102 #define kOSBundleStartedKey "OSBundleStarted"
103 #define kOSBundlePrelinkedKey "OSBundlePrelinked"
104 #define kOSBundleLoadTagKey "OSBundleLoadTag"
105 #define kOSBundleLoadAddressKey "OSBundleLoadAddress"
106 #define kOSBundleLoadSizeKey "OSBundleLoadSize"
107 #define kOSBundleWiredSizeKey "OSBundleWiredSize"
108 #define kOSBundleDependenciesKey "OSBundleDependencies"
109 #define kOSBundleRetainCountKey "OSBundleRetainCount"
111 /* Dictionary of metaclass info keyed by classname.
113 #define kOSBundleClassesKey "OSBundleClasses"
115 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
116 * may be absent (for the root class).
118 #define kOSMetaClassNameKey "OSMetaClassName"
119 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
120 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
124 /********************************************************************/
125 #pragma mark Kext Log Specification
126 /********************************************************************/
129 * @group Kext Log Specification
130 * Logging levels & flags for kernel extensions.
131 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
136 * @typedef OSKextLogSpec
137 * @abstract Describes what a log message applies to,
138 * or a filter that determines which log messages are displayed.
141 * A kext log specification is a 32-bit value used as a desription of
142 * what a given log message applies to, or as a filter
143 * indicating which log messages are desired and which are not.
144 * A log specification has three parts (described in detail shortly):
146 * <li>A <b>level</b> from 0-7 in the lowest-order nibble (0x7).</li>
147 * <li>A flag bit in the lowest-order nibble (0x8) indicating whether
148 * log messages tied to individual kexts are always printed (1)
149 * or printed only if the kext has an
150 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
151 * OSBundleEnableKextLogging@/link set to <code>true</code>.
152 * <li>A set of <b>activity flags</b> in the remaining nibbles (0xFFFFFFF0),
153 * which describe areas of activity related to kernel extensions.</li>
156 * You can specify a log spec to most of the kext tools with the -v option
157 * and a hex number (rather than the escalating decimal levels 0-6).
158 * You can also specify a log spec to the kernel with the "kextlog" boot arg
159 * or "debug.kextlog" sysctl.
163 * The log level spans a range from silent (no log messages)
164 * to debuging information:
167 * <li>Silent - Not applicable to messages; as a filter, do not print any log messages.</li>
168 * <li>Errors - Log message is an error.
169 * <li>Warnings - Log message is a warning.
170 * <li>Basic information - Log message is basic success/failure.</li>
171 * <li>Progress - Provides high-level information about stages in processing.</li>
172 * <li>Step - Provides low-level information about complex operations,
173 * typically about individual kexts.</li>
174 * <li>Detail - Provides very low-level information about parts of kexts,
175 * including individual Libkern classes and operations on bundle files.</li>
176 * <li>Debug - Very verbose logging about internal activities.</li>
180 * <code>@link kOSKextLogErrorLevel kOSKextLogErrorLevel@/link</code> or
181 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
182 * ignore activity flags and the
183 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
184 * OSBundleEnableKextLogging@/link property;
185 * that is, only the filter level is checked for messages at these levels.
186 * Log messages at levels above
187 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
188 * are filtered according both to the activity flags in the current filter
189 * and to whether the log message is associated with a kext or not.
190 * Normally log messages associated with kexts are not printed
191 * unless the kext has a
192 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
193 * OSBundleEnableKextLogging@/link property set to <code>true</code>.
194 * If you set the high-order bit of the log level (that is, add 8 to the level),
195 * then all kext-specific log messages matching the activity flags are printed.
196 * This can be very verbose.
198 * <b>Activity Flags</b>
200 * Each flag governs a category of activity,
201 * such as loading, IPC, or archives; by combining them with bitwise OR,
202 * you can choose which messages you wish to see (or when logging messages,
203 * which bit flags select your message).
205 * <b>Byte 1:</b> <code>0xF0</code> - Basic activities
206 * (<code>@link kOSKextLogGeneralFlag kOSKextLogGeneralFlag@/link</code>,
207 * <code>@link kOSKextLogLoadFlag kOSKextLogLoadFlag@/link</code>, and
208 * <code>@link kOSKextLogArchiveFlag kOSKextLogArchiveFlag@/link</code>).
210 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
212 * <b>Byte 4:</b> <code>0xF000</code> - Kext diagnostics
213 * (<code>@link kOSKextLogValidationFlag kOSKextLogValidationFlag@/link</code>,
214 * <code>@link kOSKextLogAuthenticationFlag kOSKextLogAuthenticationFlag@/link</code>, and
215 * <code>@link kOSKextLogDependenciesFlag kOSKextLogDependenciesFlag@/link</code>).
217 * <b>Byte 5:</b> <code>0xF00000</code> - Kext access & bookkeeping
218 * (<code>@link kOSKextLogDirectoryScanFlag kOSKextLogDirectoryScanFlag@/link</code>,
219 * <code>@link kOSKextLogFileAccessFlag kOSKextLogFileAccessFlag@/link</code>,
220 * <code>@link kOSKextLogKextBookkeepingFlag kOSKextLogKextBookkeepingFlag@/link </code>).
222 * <b>Byte 6:</b> <code>0xF000000</code> - Linking & patching
223 * (<code>@link kOSKextLogLinkFlag kOSKextLogLinkFlag@/link</code> and
224 * <code>@link kOSKextLogPatchFlag kOSKextLogPatchFlag@/link</code>).
226 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
228 typedef uint32_t OSKextLogSpec
;
231 /********************************************************************/
233 /********************************************************************/
236 * @define kOSKextLogLevelMask
237 * @abstract Masks the bottom 3 bits of an
238 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
241 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
244 * @define kOSKextLogKextOrGlobalMask
245 * @abstract Determines whether per-kext log messages are output.
248 * In filter specifications, if unset (the usual default),
249 * then log messages associated with a kext are only output
251 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
252 * OSBundleEnableKextLogging@/link
253 * property set to <code>true</code>.
254 * If set, then all log messages associated with kexts
257 * In message specifications, if set it indicates that the message is either
258 * not associated with a kext, or is associated with a kext that has an
259 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
260 * OSBundleEnableKextLogging@/link
261 * property set to <code>true</code>.
263 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
267 * @define kOSKextLogFlagsMask
268 * @abstract Masks the flag bits of an
269 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
271 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
274 * @define kOSKextLogFlagsMask
275 * @abstract Masks the flag bits of an
276 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>
277 * to which command-line <code>-v</code> levels apply.
279 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
282 * @define kOSKextLogConfigMask
283 * @abstract Masks the config bits of an
284 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
286 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
289 /********************************************************************/
290 #pragma mark 0xF - Log Level
291 /********************************************************************/
295 * @define kOSKextLogExplicitLevel
296 * @abstract Used when logging a message to overrides the current log filter,
297 * even if it's set to silent for log messages.
298 * This is essentially a pass-through for
299 * unconditional print messages to go
300 * through the logging engine.
302 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
305 * @define kOSKextLogErrorLevel
306 * @abstract Log messages concerning error conditions in any category.
308 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
312 * @define kOSKextLogWarningLevel
313 * @abstract Log messages concerning warning conditions in any category,
314 * which indicate potential error conditions,
315 * and notices, which may explain unexpected but correct behavior.
317 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
321 * @define kOSKextLogBasicLevel
322 * @abstract Log messages concerning top-level outcome in any category
323 * (kext load/unload, kext cache creation/extration w/# kexts).
325 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
329 * @define kOSKextLogProgressLevel
330 * @abstract Log messages concerning high-level progress in any category,
331 * such as sending a load request to the kernel,
332 * allocation/link/map/start (load operation),
333 * stop/unmap (unload operation), kext added/extracted (archive).
335 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
339 * @define kOSKextLogStepLevel
340 * @abstract Log messages concerning major steps in any category,
341 * such as sending personalities to the IOCatalogue when loading,
342 * detailed IPC with the kernel, or filtering of kexts for an archive.
344 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
348 * @define kOSKextLogDetailLevel
349 * @abstract Log messages concerning specific details in any category,
350 * such as classes being registered/unregistered or
351 * operations on indivdual files in a kext.
353 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
357 * @define kOSKextLogDebugLevel
358 * @abstract Log messages concerning very low-level actions that are
359 * useful mainly for debugging the kext system itself.
361 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
365 /********************************************************************/
366 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
367 /********************************************************************/
371 * @define kOSKextLogGeneralFlag
372 * @abstract Log messages about general activity in the kext system.
374 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
377 * @define kOSKextLogLoadFlag
378 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
381 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
384 * @define kOSKextLogIPCFlag
385 * @abstract Log messages about any interaction between kernel and user space
386 * regarding kernel extensions.
388 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
391 * @define kOSKextLogArchiveFlag
392 * @abstract Log messages about creating or processing a kext startup cache file
393 * (mkext or prelinked kernel).
395 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
399 /********************************************************************/
400 #pragma mark 0xF00 - Reserved Verbose Area
401 /********************************************************************/
403 // reserved slot for group ((OSKextLogSpec) 0x100)
404 // reserved slot for group ((OSKextLogSpec) 0x200)
405 // reserved slot for group ((OSKextLogSpec) 0x400)
406 // reserved slot for group ((OSKextLogSpec) 0x800)
409 /********************************************************************/
410 #pragma mark 0xF000 - Kext diagnostic activity
411 /********************************************************************/
415 * @define kOSKextLogValidationFlag
416 * @abstract Log messages when validating kernel extensions.
418 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
421 * @define kOSKextLogAuthenticationFlag
422 * @abstract Log messages when autnenticating kernel extension files.
423 * Irrelevant in the kernel.
425 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
428 * @define kOSKextLogDependenciesFlag
429 * @abstract Log messages when resolving dependencies for a kernel extension.
431 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
433 // reserved slot for group ((OSKextLogSpec) 0x8000)
436 /********************************************************************/
437 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
438 /********************************************************************/
442 * @define kOSKextLogDirectoryScanFlag
443 * @abstract Log messages when scanning directories for kernel extensions.
444 * In the kernel logs every booter kext entry processed.
446 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
449 * @define kOSKextLogFileAccessFlag
450 * @abstract Log messages when performing any filesystem access (very verbose).
451 * Irrelevant in the kernel.
453 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
456 * @define kOSKextLogKextBookkeepingFlag
457 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
459 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
461 // reserved slot for group ((OSKextLogSpec) 0x80000)
464 /********************************************************************/
465 #pragma mark 0xF00000 - Linking & Patching
466 /********************************************************************/
470 * @define kOSKextLogLinkFlag
471 * @abstract Log messages about linking.
473 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
476 * @define kOSKextLogPatchFlag
477 * @abstract Log messages about patching.
479 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
481 // reserved slot for group ((OSKextLogSpec) 0x400000)
482 // reserved slot for group ((OSKextLogSpec) 0x800000)
485 /********************************************************************/
486 #pragma mark 0xF000000 - Reserved
487 /********************************************************************/
490 // reserved slot for grouping ((OSKextLogSpec) 0x1000000)
491 // reserved slot for grouping ((OSKextLogSpec) 0x2000000)
492 // reserved slot for grouping ((OSKextLogSpec) 0x4000000)
493 // reserved slot for grouping ((OSKextLogSpec) 0x8000000)
497 /********************************************************************/
498 #pragma mark 0xF0000000 - Config Flags
499 /********************************************************************/
502 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
503 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
504 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
507 /********************************************************************/
508 #pragma mark Predefined Specifications
509 /********************************************************************/
513 * @define kOSKextLogSilentFilter
514 * @abstract For use in filter specs:
515 * Ignore all log messages with a log level greater than
516 * <code>@link kOSKextLogExplicitLevel kOSKextLogExplicitLevel@/link</code>.
518 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
521 * @define kOSKextLogShowAllFilter
522 * @abstract For use in filter specs:
523 * Print all log messages not associated with a kext or
524 * associated with a kext that has
525 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
526 * OSBundleEnableKextLogging@/link
527 * set to <code>true</code>.
529 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
532 * @define kOSKextLogShowAllKextsFilter
533 * @abstract For use in filter specs:
534 * Print all log messages has
535 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
536 * OSBundleEnableKextLogging@/link
537 * set to <code>true</code>.
539 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
540 (kOSKextLogShowAllFilter | \
541 kOSKextLogKextOrGlobalMask))
545 /********************************************************************/
546 #pragma mark Kext Version String Processing
547 /********************************************************************/
550 * @group Kext Version String Processing
551 * Functions for working with kext versions and compatible versions.
555 * @typedef OSKextVersion
556 * @abstract An encoded kext version that can be compared arithmetically.
559 * A value of zero (<code>@link kOSKextVersionUndefined kOSKextVersionUndefined@/link</code>)
560 * is <i>not</i> equivalent to a version string of "0.0",
561 * and typically means there is no version specified
562 * (for example, that there is no CFBundleVersion property at all).
563 * Values below zero are invalid.
565 * The encoding used is subject to change,
566 * and should never be saved to permanent storage.
567 * Always use proper version strings in files and interprocess communication.
569 typedef int64_t OSKextVersion
;
572 * @define kOSKextVersionMaxLength
573 * @abstract The length of a string buffer
574 * guaranteed to be able to hold a kext version.
577 * Kext versions use an extended Mac OS 'vers' format with double the number
578 * of digits before the build stage: ####.##.##s{1-255} where 's'
579 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
581 #define kOSKextVersionMaxLength (20)
582 // with a few bytes to spare including a nul byte
583 // xx-review: Should we make this much bigger in case we ever need longer strings?
586 * @define kOSKextVersionUndefined
587 * @abstract The undefined version.
590 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
592 * (for example, that there is no CFBundleVersion property at all).
594 #define kOSKextVersionUndefined (0)
597 * @function OSKextParseVersionString
600 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
602 * @param versionString The kext version string to parse.
605 * An encoded kext version that can be compared numerically
606 * against other encoded kext versions,
607 * <0 if <code>versionString</code> is <code>NULL</code>, empty,
608 * or cannot be parsed.
611 * Kext versions use an extended Mac OS 'vers' format with double the number
612 * of digits before the build stage: ####.##.##s{1-255} where 's'
613 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
615 OSKextVersion
OSKextParseVersionString(const char * versionString
);
619 * @function OSKextVersionGetString
622 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
626 * The encoded version to format.
628 * A C string buffer of at least
629 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code> bytes.
630 * @param bufferSize The size in bytes of <code>buffer</code>.
633 * <code>TRUE</code> if the encoded version is formatted successfully.
634 * <code>FALSE</code> if <code>buffer</code> is <code>NULL</code> or
635 * <code>bufferSize</code> is less than
636 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code>.
639 * The return value strictly indicates whether <code>buffer</code>
640 * is large enough to hold the result.
641 * If <code>aVersion</code> is 0, the resulting string is "(missing)".
642 * If <code>aVersion</code> is less than 0
643 * or is not a valid kext version encoding,
644 * the resulting string is "(invalid)".
646 Boolean
OSKextVersionGetString(
647 OSKextVersion aVersion
,
649 uint32_t bufferSize
);
656 /********************************************************************/
658 #pragma mark Weak linking
659 /********************************************************************/
661 #ifdef XNU_KERNEL_PRIVATE
662 void kext_weak_symbol_referenced(void);
663 #endif /* XNU_KERNEL_PRIVATE */
667 /********************************************************************/
668 #pragma mark Miscellaneous Kernel-Only Kext Functions
669 /********************************************************************/
673 * @function kext_get_vm_map
674 * @abstract Returns the vm_map from which the kext was allocated.
676 * @param info The kmod_info_t structure of the kext.
677 * @result The vm_map from which the kext was allocated. This function
678 * cannot return <code>NULL</code>.
680 vm_map_t
kext_get_vm_map(kmod_info_t
* info
);
682 #ifdef XNU_KERNEL_PRIVATE
686 * @function OSKextRegisterKextsWithDTrace
688 * DTrace calls this once when it has started up so that the kext system
689 * will register any already-loaded kexts with it.
691 void OSKextRegisterKextsWithDTrace(void);
693 #endif /* CONFIG_DTRACE */
696 * @function kext_dump_panic_lists
697 * @abstract Prints compacted lists of last unloaded & all loaded kexts
700 * @param printf_func The printf-style function to use for output.
702 void kext_dump_panic_lists(int (*printf_func
)(const char *fmt
, ...));
704 #endif /* XNU_KERNEL_PRIVATE */
706 #ifdef XNU_KERNEL_PRIVATE
710 /********************************************************************/
711 #pragma mark Kext Loading C Functions
712 /********************************************************************/
715 * @function OSKextGetLoadTagForBundleIdentifier
716 * @abstract Look up the load tag for a kext.
718 * @param kextIdentifier The bundle identifier of the kext to look up.
720 * The load tag of the requested kext, or
721 * <code>@link //apple_ref/c/macro/kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>
722 * if the kext was not found.
725 * A load tag uniquely identifies a loaded kext.
726 * It can be found as the <code>id</code> field of a loaded kext's
727 * <code>kmod_info_t</code> struct.
729 * Note that a load tag represents a specific loaded instance of a kext.
730 * If that kext is unloaded, the load tag is no longer a valid reference.
731 * If the same kext is later reloaded, it will have a new load tag.
733 * You can use the load tag to adjust a kext's reference count
735 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
736 * OSKextRetainKextWithLoadTag@/link</code>
738 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
739 * OSKextReleaseKextWithLoadTag@/link</code>,
740 * so that the kext is automatically unloaded when no references remain,
741 * or to unload the kext immediately
742 * with <code>@link //apple_ref/c/func/OSKextUnloadKextWithLoadTag OSKextUnloadKextWithLoadTag@/link</code>.
744 * Those functions are intended for use with non-IOKit kexts
745 * (specifically, kexts that define no subclasses of
746 * <code>@link //apple_ref/doc/class/IOServiceIOService@/link</code>).
747 * Pure IOKit kexts are managed via instance counts
748 * of their libkern C++ object classes;
749 * using those functions on them will only interfere with that mechanism.
750 * If you have a hybrid kext with both IOService subclasses and non-IOKit code,
751 * however, you may want to use reference counting for the non-IOKit portions:
752 * that way the kext will only unload automaticaly
753 * when there are no C++ objects and the kext reference count is zero.
755 uint32_t OSKextGetLoadTagForBundleIdentifier(
756 const char * kextIdentifier
);
760 * @function OSKextUnloadKextWithLoadTag
761 * @abstract Stop and unload a kext based on its load tag.
763 * @param loadTag The load tag of the kext to unload.
765 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
766 * if the kext was found and unloaded.
767 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
768 * kOSKextReturnNotFound@/link</code>
769 * if the kext was not found.
770 * <code>@link //apple_ref/c/macro/kOSKextReturnInUse
771 * kOSKextReturnInUse@/link</code>
772 * if the kext has outstanding references
773 * or if there are instances of its libkern C++ subclasses.
774 * Other return values indicate a failure to unload the kext,
775 * typically because the module stop routine failed.
778 * A panic will occur if a kext calls this function to unload itself.
779 * The safest way for a kext to unload itself is to call
780 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
781 * OSKextRetainKextWithLoadTag@/link</code>
782 * with its own load tag
783 * (the <code>id</code> field of its <code>kmod_info_t</code> struct),
785 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
786 * OSKextReleaseKextWithLoadTag@/link</code>;
787 * this will schedule the kext for unload on a separate thread.
789 * This function can be used when reference-based autounloading is not
791 * If a kernel system or kext is already monitoring
792 * the need for a kext,
793 * it can simply call this function when it's known that the kext is not needed.
795 OSReturn
OSKextUnloadKextWithLoadTag(uint32_t loadTag
);
797 #endif /* XNU_KERNEL_PRIVATE */
803 /********************************************************************/
804 #pragma mark Loaded Kext Summary
805 /********************************************************************/
809 * @define kOSKextLoadedKextSummaryVersion
810 * @abstract The current version of the loaded kext summary headers.
812 #define kOSKextLoadedKextSummaryVersion 2
815 * @typedef OSKextLoadedKextSummary
816 * @abstract A structure that describes a loaded kext.
818 * @field name The kext's bundle identifier.
819 * @field uuid The kext's UUID;
820 * @field address The kext's load address.
821 * @field size The kext's load size.
822 * @field version The binary format (OSKextVersion) version of the kext.
823 * @field loadTag The kext's load tag.
824 * @field flags Internal tracking flags.
825 * @field reference_list who this refs (links on).
828 * The OSKextLoadedKextSummary structure contains a basic set of information
829 * about the kext to facilitate kext debugging and panic debug log output.
831 typedef struct _loaded_kext_summary
{
832 char name
[KMOD_MAX_NAME
];
839 uint64_t reference_list
;
840 } OSKextLoadedKextSummary
;
843 * @typedef OSKextLoadedKextSummaryHeader
844 * @abstract A structure that describes the set of loaded kext summaries.
846 * @field version The version of the loaded kext summary structures.
847 * @field entry_size The size of each entry in summaries.
848 * @field numSummaries The number of OSKextLoadedKextSummary structures
849 * following the header.
850 * @field summaries A convenience pointer to the array of summaries following
854 * The OSKextLoadedKextSummaryHeader describes the set of loaded kext summaries
855 * available for use by the debugger or panic log routine.
856 * The array of summaries contains one OSKextLoadedKextSummary for every kext
857 * that declares an executable and is not an interface to the kernel.
859 typedef struct _loaded_kext_summary_header
{
862 uint32_t numSummaries
;
863 uint32_t reserved
; /* explicit alignment for gdb */
864 OSKextLoadedKextSummary summaries
[0];
865 } OSKextLoadedKextSummaryHeader
;
868 * @var gLoadedKextSummaries
869 * @abstract The global pointer to the current set of loaded kext summaries.
871 extern OSKextLoadedKextSummaryHeader
* gLoadedKextSummaries
;
874 * @function OSKextLoadedKextSummariesUpdated
875 * @abstract Called when gLoadedKextSummaries has been updated.
878 * gLoadedKextSummaries is updated when a kext is loaded or unloaded.
879 * When the update is complete, OSKextLoadedKextSummariesUpdated is called.
880 * gdb can set a breakpoint on this function to detect kext loads and unloads.
882 void OSKextLoadedKextSummariesUpdated(void);
886 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */