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
33 #include <sys/cdefs.h>
34 #include <uuid/uuid.h>
38 #include <libkern/OSTypes.h>
39 #include <mach/kmod.h>
40 #include <mach/vm_types.h>
42 #include <CoreFoundation/CoreFoundation.h>
43 #include <mach/kmod.h>
47 #include <libkern/OSReturn.h>
53 /********************************************************************/
54 #pragma mark Misc Constants
55 /********************************************************************/
58 typedef uint8_t OSKextExcludeLevel
;
59 #define kOSKextExcludeNone (0)
60 #define kOSKextExcludeKext (1)
61 #define kOSKextExcludeAll (2)
65 /********************************************************************/
66 #pragma mark Kext/OSBundle Property List Keys
67 /********************************************************************/
71 * @define kOSBundleHelperKey
72 * @abstract Used by loginwindow.
74 #define kOSBundleHelperKey "OSBundleHelper"
77 * @define kOSBundleDeveloperOnlyKey
78 * @abstract A boolean value indicating whether the kext should only load on
81 #define kOSBundleDeveloperOnlyKey "OSBundleDeveloperOnly"
84 * @define kOSBundleRamDiskOnlyKey
85 * @abstract A boolean value indicating whether the kext should only load when
86 * booted from a ram disk.
88 #define kOSBundleRamDiskOnlyKey "OSBundleRamDiskOnly"
92 * @define kAppleSecurityExtensionKey
93 * @abstract A boolean value indicating whether the kext registers
96 #define kAppleSecurityExtensionKey "AppleSecurityExtension"
99 * @define kAppleKernelExternalComponentKey
100 * @abstract A boolean value indicating whether the kext is vending kernel
101 * KPI, and needs special loading behavior.
103 #define kAppleKernelExternalComponentKey "AppleKernelExternalComponent"
105 // properties found in the registry root
106 #define kOSKernelCPUTypeKey "OSKernelCPUType"
107 #define kOSKernelCPUSubtypeKey "OSKernelCPUSubtype"
108 #define kOSStartupMkextCRC "OSStartupMkextCRC" /* value is 32-bit OSData */
109 #define kOSPrelinkKextCountKey "OSPrelinkKextCount" /* value is 32-bit OSNumber */
110 #define kOSPrelinkPersonalityCountKey "OSPrelinkPersonalityCount" /* value is 32-bit OSNumber */
114 /********************************************************************/
115 #pragma mark Load Info Keys
116 /********************************************************************/
118 /*********************************************************************
119 * In addition to the keys defined here, you will find:
120 * kCFBundleIdentifierKey
121 * kCFBundleVersionKey
122 * kOSBundleCompatibleVersionKey
123 * kOSBundleIsInterfaceKey
124 * kOSKernelResourceKey
125 *********************************************************************/
126 #define kOSBundleMachOHeadersKey "OSBundleMachOHeaders"
127 #define kOSBundleLogStringsKey "OSBundleLogStrings"
128 #define kOSBundleCPUTypeKey "OSBundleCPUType"
129 #define kOSBundleCPUSubtypeKey "OSBundleCPUSubtype"
130 #define kOSBundlePathKey "OSBundlePath"
131 #define kOSBundleExecutablePathKey "OSBundleExecutablePath"
132 #define kOSBundleUUIDKey "OSBundleUUID"
133 #define kOSBundleStartedKey "OSBundleStarted"
134 #define kOSBundlePrelinkedKey "OSBundlePrelinked"
135 #define kOSBundleLoadTagKey "OSBundleLoadTag"
136 #define kOSBundleLoadAddressKey "OSBundleLoadAddress"
137 #define kOSBundleLoadSizeKey "OSBundleLoadSize"
138 #define kOSBundleExecLoadAddressKey "OSBundleExecLoadAddress"
139 #define kOSBundleExecLoadSizeKey "OSBundleExecLoadSize"
140 #define kOSBundleWiredSizeKey "OSBundleWiredSize"
141 #define kOSBundleDependenciesKey "OSBundleDependencies"
142 #define kOSBundleRetainCountKey "OSBundleRetainCount"
144 /* Dictionary of metaclass info keyed by classname.
146 #define kOSBundleClassesKey "OSBundleClasses"
148 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
149 * may be absent (for the root class).
151 #define kOSMetaClassNameKey "OSMetaClassName"
152 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
153 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
157 /********************************************************************/
158 #pragma mark Kext Log Specification
159 /********************************************************************/
162 * @group Kext Log Specification
163 * Logging levels & flags for kernel extensions.
164 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
169 * @typedef OSKextLogSpec
170 * @abstract Describes what a log message applies to,
171 * or a filter that determines which log messages are displayed.
174 * A kext log specification is a 32-bit value used as a desription of
175 * what a given log message applies to, or as a filter
176 * indicating which log messages are desired and which are not.
177 * A log specification has three parts (described in detail shortly):
179 * <li>A <b>level</b> from 0-7 in the lowest-order nibble (0x7).</li>
180 * <li>A flag bit in the lowest-order nibble (0x8) indicating whether
181 * log messages tied to individual kexts are always printed (1)
182 * or printed only if the kext has an
183 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
184 * OSBundleEnableKextLogging@/link set to <code>true</code>.
185 * <li>A set of <b>activity flags</b> in the remaining nibbles (0xFFFFFFF0),
186 * which describe areas of activity related to kernel extensions.</li>
189 * You can specify a log spec to most of the kext tools with the -v option
190 * and a hex number (rather than the escalating decimal levels 0-6).
191 * You can also specify a log spec to the kernel with the "kextlog" boot arg
192 * or "debug.kextlog" sysctl.
196 * The log level spans a range from silent (no log messages)
197 * to debuging information:
200 * <li>Silent - Not applicable to messages; as a filter, do not print any log messages.</li>
201 * <li>Errors - Log message is an error.
202 * <li>Warnings - Log message is a warning.
203 * <li>Basic information - Log message is basic success/failure.</li>
204 * <li>Progress - Provides high-level information about stages in processing.</li>
205 * <li>Step - Provides low-level information about complex operations,
206 * typically about individual kexts.</li>
207 * <li>Detail - Provides very low-level information about parts of kexts,
208 * including individual Libkern classes and operations on bundle files.</li>
209 * <li>Debug - Very verbose logging about internal activities.</li>
213 * <code>@link kOSKextLogErrorLevel kOSKextLogErrorLevel@/link</code> or
214 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
215 * ignore activity flags and the
216 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
217 * OSBundleEnableKextLogging@/link property;
218 * that is, only the filter level is checked for messages at these levels.
219 * Log messages at levels above
220 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
221 * are filtered according both to the activity flags in the current filter
222 * and to whether the log message is associated with a kext or not.
223 * Normally log messages associated with kexts are not printed
224 * unless the kext has a
225 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
226 * OSBundleEnableKextLogging@/link property set to <code>true</code>.
227 * If you set the high-order bit of the log level (that is, add 8 to the level),
228 * then all kext-specific log messages matching the activity flags are printed.
229 * This can be very verbose.
231 * <b>Activity Flags</b>
233 * Each flag governs a category of activity,
234 * such as loading, IPC, or archives; by combining them with bitwise OR,
235 * you can choose which messages you wish to see (or when logging messages,
236 * which bit flags select your message).
238 * <b>Byte 1:</b> <code>0xF0</code> - Basic activities
239 * (<code>@link kOSKextLogGeneralFlag kOSKextLogGeneralFlag@/link</code>,
240 * <code>@link kOSKextLogLoadFlag kOSKextLogLoadFlag@/link</code>, and
241 * <code>@link kOSKextLogArchiveFlag kOSKextLogArchiveFlag@/link</code>).
243 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
245 * <b>Byte 4:</b> <code>0xF000</code> - Kext diagnostics
246 * (<code>@link kOSKextLogValidationFlag kOSKextLogValidationFlag@/link</code>,
247 * <code>@link kOSKextLogAuthenticationFlag kOSKextLogAuthenticationFlag@/link</code>, and
248 * <code>@link kOSKextLogDependenciesFlag kOSKextLogDependenciesFlag@/link</code>).
250 * <b>Byte 5:</b> <code>0xF00000</code> - Kext access & bookkeeping
251 * (<code>@link kOSKextLogDirectoryScanFlag kOSKextLogDirectoryScanFlag@/link</code>,
252 * <code>@link kOSKextLogFileAccessFlag kOSKextLogFileAccessFlag@/link</code>,
253 * <code>@link kOSKextLogKextBookkeepingFlag kOSKextLogKextBookkeepingFlag@/link </code>).
255 * <b>Byte 6:</b> <code>0xF000000</code> - Linking & patching
256 * (<code>@link kOSKextLogLinkFlag kOSKextLogLinkFlag@/link</code> and
257 * <code>@link kOSKextLogPatchFlag kOSKextLogPatchFlag@/link</code>).
259 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
261 typedef uint32_t OSKextLogSpec
;
264 /********************************************************************/
266 /********************************************************************/
269 * @define kOSKextLogLevelMask
270 * @abstract Masks the bottom 3 bits of an
271 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
274 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
277 * @define kOSKextLogKextOrGlobalMask
278 * @abstract Determines whether per-kext log messages are output.
281 * In filter specifications, if unset (the usual default),
282 * then log messages associated with a kext are only output
284 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
285 * OSBundleEnableKextLogging@/link
286 * property set to <code>true</code>.
287 * If set, then all log messages associated with kexts
290 * In message specifications, if set it indicates that the message is either
291 * not associated with a kext, or is associated with a kext that has an
292 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
293 * OSBundleEnableKextLogging@/link
294 * property set to <code>true</code>.
296 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
300 * @define kOSKextLogFlagsMask
301 * @abstract Masks the flag bits of an
302 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
304 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
307 * @define kOSKextLogFlagsMask
308 * @abstract Masks the flag bits of an
309 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>
310 * to which command-line <code>-v</code> levels apply.
312 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
315 * @define kOSKextLogConfigMask
316 * @abstract Masks the config bits of an
317 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
319 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
322 /********************************************************************/
323 #pragma mark 0xF - Log Level
324 /********************************************************************/
328 * @define kOSKextLogExplicitLevel
329 * @abstract Used when logging a message to overrides the current log filter,
330 * even if it's set to silent for log messages.
331 * This is essentially a pass-through for
332 * unconditional print messages to go
333 * through the logging engine.
335 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
338 * @define kOSKextLogErrorLevel
339 * @abstract Log messages concerning error conditions in any category.
341 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
345 * @define kOSKextLogWarningLevel
346 * @abstract Log messages concerning warning conditions in any category,
347 * which indicate potential error conditions,
348 * and notices, which may explain unexpected but correct behavior.
350 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
354 * @define kOSKextLogBasicLevel
355 * @abstract Log messages concerning top-level outcome in any category
356 * (kext load/unload, kext cache creation/extration w/# kexts).
358 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
362 * @define kOSKextLogProgressLevel
363 * @abstract Log messages concerning high-level progress in any category,
364 * such as sending a load request to the kernel,
365 * allocation/link/map/start (load operation),
366 * stop/unmap (unload operation), kext added/extracted (archive).
368 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
372 * @define kOSKextLogStepLevel
373 * @abstract Log messages concerning major steps in any category,
374 * such as sending personalities to the IOCatalogue when loading,
375 * detailed IPC with the kernel, or filtering of kexts for an archive.
377 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
381 * @define kOSKextLogDetailLevel
382 * @abstract Log messages concerning specific details in any category,
383 * such as classes being registered/unregistered or
384 * operations on indivdual files in a kext.
386 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
390 * @define kOSKextLogDebugLevel
391 * @abstract Log messages concerning very low-level actions that are
392 * useful mainly for debugging the kext system itself.
394 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
398 /********************************************************************/
399 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
400 /********************************************************************/
404 * @define kOSKextLogGeneralFlag
405 * @abstract Log messages about general activity in the kext system.
407 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
410 * @define kOSKextLogLoadFlag
411 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
414 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
417 * @define kOSKextLogIPCFlag
418 * @abstract Log messages about any interaction between kernel and user space
419 * regarding kernel extensions.
421 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
424 * @define kOSKextLogArchiveFlag
425 * @abstract Log messages about creating or processing a kext startup cache file
426 * (mkext or prelinked kernel).
428 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
432 /********************************************************************/
433 #pragma mark 0xF00 - Reserved Verbose Area
434 /********************************************************************/
436 // reserved slot for group ((OSKextLogSpec) 0x100)
437 // reserved slot for group ((OSKextLogSpec) 0x200)
438 // reserved slot for group ((OSKextLogSpec) 0x400)
439 // reserved slot for group ((OSKextLogSpec) 0x800)
442 /********************************************************************/
443 #pragma mark 0xF000 - Kext diagnostic activity
444 /********************************************************************/
448 * @define kOSKextLogValidationFlag
449 * @abstract Log messages when validating kernel extensions.
451 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
454 * @define kOSKextLogAuthenticationFlag
455 * @abstract Log messages when autnenticating kernel extension files.
456 * Irrelevant in the kernel.
458 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
461 * @define kOSKextLogDependenciesFlag
462 * @abstract Log messages when resolving dependencies for a kernel extension.
464 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
466 // reserved slot for group ((OSKextLogSpec) 0x8000)
469 /********************************************************************/
470 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
471 /********************************************************************/
475 * @define kOSKextLogDirectoryScanFlag
476 * @abstract Log messages when scanning directories for kernel extensions.
477 * In the kernel logs every booter kext entry processed.
479 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
482 * @define kOSKextLogFileAccessFlag
483 * @abstract Log messages when performing any filesystem access (very verbose).
484 * Irrelevant in the kernel.
486 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
489 * @define kOSKextLogKextBookkeepingFlag
490 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
492 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
494 // reserved slot for group ((OSKextLogSpec) 0x80000)
497 /********************************************************************/
498 #pragma mark 0xF00000 - Linking & Patching
499 /********************************************************************/
503 * @define kOSKextLogLinkFlag
504 * @abstract Log messages about linking.
506 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
509 * @define kOSKextLogPatchFlag
510 * @abstract Log messages about patching.
512 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
514 // reserved slot for group ((OSKextLogSpec) 0x400000)
515 // reserved slot for group ((OSKextLogSpec) 0x800000)
518 /********************************************************************/
519 #pragma mark 0xF000000 - Reserved
520 /********************************************************************/
523 // reserved slot for grouping ((OSKextLogSpec) 0x1000000)
524 // reserved slot for grouping ((OSKextLogSpec) 0x2000000)
525 // reserved slot for grouping ((OSKextLogSpec) 0x4000000)
526 // reserved slot for grouping ((OSKextLogSpec) 0x8000000)
530 /********************************************************************/
531 #pragma mark 0xF0000000 - Config Flags
532 /********************************************************************/
535 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
536 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
537 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
540 /********************************************************************/
541 #pragma mark Predefined Specifications
542 /********************************************************************/
546 * @define kOSKextLogSilentFilter
547 * @abstract For use in filter specs:
548 * Ignore all log messages with a log level greater than
549 * <code>@link kOSKextLogExplicitLevel kOSKextLogExplicitLevel@/link</code>.
551 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
554 * @define kOSKextLogShowAllFilter
555 * @abstract For use in filter specs:
556 * Print all log messages not associated with a kext or
557 * associated with a kext that has
558 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
559 * OSBundleEnableKextLogging@/link
560 * set to <code>true</code>.
562 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
565 * @define kOSKextLogShowAllKextsFilter
566 * @abstract For use in filter specs:
567 * Print all log messages has
568 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
569 * OSBundleEnableKextLogging@/link
570 * set to <code>true</code>.
572 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
573 (kOSKextLogShowAllFilter | \
574 kOSKextLogKextOrGlobalMask))
578 /********************************************************************/
579 #pragma mark Kext Version String Processing
580 /********************************************************************/
583 * @group Kext Version String Processing
584 * Functions for working with kext versions and compatible versions.
588 * @typedef OSKextVersion
589 * @abstract An encoded kext version that can be compared arithmetically.
592 * A value of zero (<code>@link kOSKextVersionUndefined kOSKextVersionUndefined@/link</code>)
593 * is <i>not</i> equivalent to a version string of "0.0",
594 * and typically means there is no version specified
595 * (for example, that there is no CFBundleVersion property at all).
596 * Values below zero are invalid.
598 * The encoding used is subject to change,
599 * and should never be saved to permanent storage.
600 * Always use proper version strings in files and interprocess communication.
602 typedef int64_t OSKextVersion
;
605 * @define kOSKextVersionMaxLength
606 * @abstract The length of a string buffer
607 * guaranteed to be able to hold a kext version.
610 * Kext versions use an extended Mac OS 'vers' format with double the number
611 * of digits before the build stage: ####.##.##s{1-255} where 's'
612 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
614 #define kOSKextVersionMaxLength (20)
615 // with a few bytes to spare including a nul byte
616 // xx-review: Should we make this much bigger in case we ever need longer strings?
619 * @define kOSKextVersionUndefined
620 * @abstract The undefined version.
623 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
625 * (for example, that there is no CFBundleVersion property at all).
627 #define kOSKextVersionUndefined (0)
630 * @function OSKextParseVersionString
633 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
635 * @param versionString The kext version string to parse.
638 * An encoded kext version that can be compared numerically
639 * against other encoded kext versions,
640 * <0 if <code>versionString</code> is <code>NULL</code>, empty,
641 * or cannot be parsed.
644 * Kext versions use an extended Mac OS 'vers' format with double the number
645 * of digits before the build stage: ####.##.##s{1-255} where 's'
646 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
648 OSKextVersion
OSKextParseVersionString(const char * versionString
);
652 * @function OSKextVersionGetString
655 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
659 * The encoded version to format.
661 * A C string buffer of at least
662 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code> bytes.
663 * @param bufferSize The size in bytes of <code>buffer</code>.
666 * <code>TRUE</code> if the encoded version is formatted successfully.
667 * <code>FALSE</code> if <code>buffer</code> is <code>NULL</code> or
668 * <code>bufferSize</code> is less than
669 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code>.
672 * The return value strictly indicates whether <code>buffer</code>
673 * is large enough to hold the result.
674 * If <code>aVersion</code> is 0, the resulting string is "(missing)".
675 * If <code>aVersion</code> is less than 0
676 * or is not a valid kext version encoding,
677 * the resulting string is "(invalid)".
679 Boolean
OSKextVersionGetString(
680 OSKextVersion aVersion
,
682 uint32_t bufferSize
);
689 /********************************************************************/
691 #pragma mark Weak linking
692 /********************************************************************/
694 #ifdef XNU_KERNEL_PRIVATE
695 void kext_weak_symbol_referenced(void);
696 #endif /* XNU_KERNEL_PRIVATE */
700 /********************************************************************/
701 #pragma mark Miscellaneous Kernel-Only Kext Functions
702 /********************************************************************/
706 * @function kext_get_vm_map
707 * @abstract Returns the vm_map from which the kext was allocated.
709 * @param info The kmod_info_t structure of the kext.
710 * @result The vm_map from which the kext was allocated. This function
711 * cannot return <code>NULL</code>.
713 vm_map_t
kext_get_vm_map(kmod_info_t
* info
);
715 #ifdef XNU_KERNEL_PRIVATE
719 * @function OSKextRegisterKextsWithDTrace
721 * DTrace calls this once when it has started up so that the kext system
722 * will register any already-loaded kexts with it.
724 void OSKextRegisterKextsWithDTrace(void);
726 #endif /* CONFIG_DTRACE */
729 * @function kext_dump_panic_lists
730 * @abstract Prints compacted lists of last unloaded & all loaded kexts
733 * @param printf_func The printf-style function to use for output.
735 void kext_dump_panic_lists(int (*printf_func
)(const char *fmt
, ...));
737 #endif /* XNU_KERNEL_PRIVATE */
739 #ifdef XNU_KERNEL_PRIVATE
743 /********************************************************************/
744 #pragma mark Kext Loading C Functions
745 /********************************************************************/
748 * @function OSKextGetLoadTagForBundleIdentifier
749 * @abstract Look up the load tag for a kext.
751 * @param kextIdentifier The bundle identifier of the kext to look up.
753 * The load tag of the requested kext, or
754 * <code>@link //apple_ref/c/macro/kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>
755 * if the kext was not found.
758 * A load tag uniquely identifies a loaded kext.
759 * It can be found as the <code>id</code> field of a loaded kext's
760 * <code>kmod_info_t</code> struct.
762 * Note that a load tag represents a specific loaded instance of a kext.
763 * If that kext is unloaded, the load tag is no longer a valid reference.
764 * If the same kext is later reloaded, it will have a new load tag.
766 * You can use the load tag to adjust a kext's reference count
768 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
769 * OSKextRetainKextWithLoadTag@/link</code>
771 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
772 * OSKextReleaseKextWithLoadTag@/link</code>,
773 * so that the kext is automatically unloaded when no references remain,
774 * or to unload the kext immediately
775 * with <code>@link //apple_ref/c/func/OSKextUnloadKextWithLoadTag OSKextUnloadKextWithLoadTag@/link</code>.
777 * Those functions are intended for use with non-IOKit kexts
778 * (specifically, kexts that define no subclasses of
779 * <code>@link //apple_ref/doc/class/IOServiceIOService@/link</code>).
780 * Pure IOKit kexts are managed via instance counts
781 * of their libkern C++ object classes;
782 * using those functions on them will only interfere with that mechanism.
783 * If you have a hybrid kext with both IOService subclasses and non-IOKit code,
784 * however, you may want to use reference counting for the non-IOKit portions:
785 * that way the kext will only unload automaticaly
786 * when there are no C++ objects and the kext reference count is zero.
788 uint32_t OSKextGetLoadTagForBundleIdentifier(
789 const char * kextIdentifier
);
793 * @function OSKextUnloadKextWithLoadTag
794 * @abstract Stop and unload a kext based on its load tag.
796 * @param loadTag The load tag of the kext to unload.
798 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
799 * if the kext was found and unloaded.
800 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
801 * kOSKextReturnNotFound@/link</code>
802 * if the kext was not found.
803 * <code>@link //apple_ref/c/macro/kOSKextReturnInUse
804 * kOSKextReturnInUse@/link</code>
805 * if the kext has outstanding references
806 * or if there are instances of its libkern C++ subclasses.
807 * Other return values indicate a failure to unload the kext,
808 * typically because the module stop routine failed.
811 * A panic will occur if a kext calls this function to unload itself.
812 * The safest way for a kext to unload itself is to call
813 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
814 * OSKextRetainKextWithLoadTag@/link</code>
815 * with its own load tag
816 * (the <code>id</code> field of its <code>kmod_info_t</code> struct),
818 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
819 * OSKextReleaseKextWithLoadTag@/link</code>;
820 * this will schedule the kext for unload on a separate thread.
822 * This function can be used when reference-based autounloading is not
824 * If a kernel system or kext is already monitoring
825 * the need for a kext,
826 * it can simply call this function when it's known that the kext is not needed.
828 OSReturn
OSKextUnloadKextWithLoadTag(uint32_t loadTag
);
830 #endif /* XNU_KERNEL_PRIVATE */
836 /********************************************************************/
837 #pragma mark Loaded Kext Summary
838 /********************************************************************/
842 * @define kOSKextLoadedKextSummaryVersion
843 * @abstract The current version of the loaded kext summary headers.
845 #define kOSKextLoadedKextSummaryVersion 2
848 * @typedef OSKextLoadedKextSummary
849 * @abstract A structure that describes a loaded kext.
851 * @field name The kext's bundle identifier.
852 * @field uuid The kext's UUID;
853 * @field address The kext's load address.
854 * @field size The kext's load size.
855 * @field version The binary format (OSKextVersion) version of the kext.
856 * @field loadTag The kext's load tag.
857 * @field flags Internal tracking flags.
858 * @field reference_list who this refs (links on).
861 * The OSKextLoadedKextSummary structure contains a basic set of information
862 * about the kext to facilitate kext debugging and panic debug log output.
864 typedef struct _loaded_kext_summary
{
865 char name
[KMOD_MAX_NAME
];
872 uint64_t reference_list
;
873 } OSKextLoadedKextSummary
;
876 * @typedef OSKextLoadedKextSummaryHeader
877 * @abstract A structure that describes the set of loaded kext summaries.
879 * @field version The version of the loaded kext summary structures.
880 * @field entry_size The size of each entry in summaries.
881 * @field numSummaries The number of OSKextLoadedKextSummary structures
882 * following the header.
883 * @field summaries A convenience pointer to the array of summaries following
887 * The OSKextLoadedKextSummaryHeader describes the set of loaded kext summaries
888 * available for use by the debugger or panic log routine.
889 * The array of summaries contains one OSKextLoadedKextSummary for every kext
890 * that declares an executable and is not an interface to the kernel.
892 typedef struct _loaded_kext_summary_header
{
895 uint32_t numSummaries
;
896 uint32_t reserved
; /* explicit alignment for gdb */
897 OSKextLoadedKextSummary summaries
[0];
898 } OSKextLoadedKextSummaryHeader
;
901 * @var gLoadedKextSummaries
902 * @abstract The global pointer to the current set of loaded kext summaries.
904 extern OSKextLoadedKextSummaryHeader
* gLoadedKextSummaries
;
907 * @var gLoadedKextSummariesTimestamp
909 * @abstract This will be set to mach_absolute_time() around updates to
910 * gLoadedKextSummaries. Ie. immediately before gLoadedKextSummaries is set to
911 * zero, and immediately after it is set to a new value.
913 extern uint64_t gLoadedKextSummariesTimestamp
;
916 * @function OSKextLoadedKextSummariesUpdated
917 * @abstract Called when gLoadedKextSummaries has been updated.
920 * gLoadedKextSummaries is updated when a kext is loaded or unloaded.
921 * When the update is complete, OSKextLoadedKextSummariesUpdated is called.
922 * gdb can set a breakpoint on this function to detect kext loads and unloads.
924 void OSKextLoadedKextSummariesUpdated(void);
926 #ifdef XNU_KERNEL_PRIVATE
928 extern const vm_allocation_site_t
* OSKextGetAllocationSiteForCaller(uintptr_t address
);
929 extern uint32_t OSKextGetKmodIDForSite(vm_allocation_site_t
* site
,
930 char * name
, vm_size_t namelen
);
931 extern void OSKextFreeSite(vm_allocation_site_t
* site
);
934 extern int OSKextGetUUIDForName(const char *, uuid_t
);
937 #endif /* XNU_KERNEL_PRIVATE */
941 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */