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)
63 #define kIOCatalogManagementEntitlement "com.apple.private.security.iocatalog-management"
64 #define kOSKextCollectionManagementEntitlement "com.apple.private.security.kext-collection-management"
65 #define kOSKextOnlyBootKCManagementEntitlement "com.apple.private.security.only-bootkc-management"
67 #define kOSKextCodelessKextLoadAddr (0x7FFFFFFFFFFFFFFFULL)
69 #define kIOKitDaemonName "kernelmanagerd"
73 /********************************************************************/
74 #pragma mark Kext/OSBundle Property List Keys
75 /********************************************************************/
79 * @define kOSBundleHelperKey
80 * @abstract Used by loginwindow.
82 #define kOSBundleHelperKey "OSBundleHelper"
85 * @define kOSBundleDeveloperOnlyKey
86 * @abstract A boolean value indicating whether the kext should only load on
89 #define kOSBundleDeveloperOnlyKey "OSBundleDeveloperOnly"
92 * @define kOSBundleRamDiskOnlyKey
93 * @abstract A boolean value indicating whether the kext should only load when
94 * booted from a ram disk.
96 #define kOSBundleRamDiskOnlyKey "OSBundleRamDiskOnly"
100 * @define kAppleSecurityExtensionKey
101 * @abstract A boolean value indicating whether the kext registers
104 #define kAppleSecurityExtensionKey "AppleSecurityExtension"
107 * @define kAppleKernelExternalComponentKey
108 * @abstract A boolean value indicating whether the kext is vending kernel
109 * KPI, and needs special loading behavior.
111 #define kAppleKernelExternalComponentKey "AppleKernelExternalComponent"
114 * @define kOSKextInfoPlistDigestKey
115 * @abstract SHA-256 data of the kext's Info.plist
117 #define kOSKextInfoPlistDigestKey "_InfoPlistDigest"
120 * @define kOSKextBundleCollectionTypeKey
121 * @abstract The type of collection in which a kext is linked. Possible
122 * values: kKCTypePrimary, kKCTypeSystem, kKCTypeAuxiliary,
125 #define kOSKextBundleCollectionTypeKey "_BundleCollectionType"
128 * @define kOSKextAuxKCAvailabilityKey
129 * @abstract boolean value: false if the kext is in the AuxKC and
130 * is not loadable; true otherwise.
132 #define kOSKextAuxKCAvailabilityKey "_AuxKCAvailability"
135 // properties found in the registry root
136 #define kOSKernelCPUTypeKey "OSKernelCPUType"
137 #define kOSKernelCPUSubtypeKey "OSKernelCPUSubtype"
138 #define kOSStartupMkextCRC "OSStartupMkextCRC" /* value is 32-bit OSData */
139 #define kOSPrelinkKextCountKey "OSPrelinkKextCount" /* value is 32-bit OSNumber */
140 #define kOSPrelinkPersonalityCountKey "OSPrelinkPersonalityCount" /* value is 32-bit OSNumber */
144 /********************************************************************/
145 #pragma mark Load Info Keys
146 /********************************************************************/
148 /*********************************************************************
149 * In addition to the keys defined here, you will find:
150 * kCFBundleIdentifierKey
151 * kCFBundleVersionKey
152 * kOSBundleCompatibleVersionKey
153 * kOSBundleIsInterfaceKey
154 * kOSKernelResourceKey
155 *********************************************************************/
156 #define kOSBundleMachOHeadersKey "OSBundleMachOHeaders"
157 #define kOSBundleLogStringsKey "OSBundleLogStrings"
158 #define kOSBundleCPUTypeKey "OSBundleCPUType"
159 #define kOSBundleCPUSubtypeKey "OSBundleCPUSubtype"
160 #define kOSBundlePathKey "OSBundlePath"
161 #define kOSBundleExecutablePathKey "OSBundleExecutablePath"
162 #define kOSBundleUUIDKey "OSBundleUUID"
163 #define kOSBundleTextUUIDKey "OSBundleTextUUID"
164 #define kOSBundleStartedKey "OSBundleStarted"
165 #define kOSBundlePrelinkedKey "OSBundlePrelinked"
166 #define kOSBundleLoadTagKey "OSBundleLoadTag"
167 #define kOSBundleLoadAddressKey "OSBundleLoadAddress"
168 #define kOSBundleLoadSizeKey "OSBundleLoadSize"
169 #define kOSBundleExecLoadAddressKey "OSBundleExecLoadAddress"
170 #define kOSBundleExecLoadSizeKey "OSBundleExecLoadSize"
171 #define kOSBundleWiredSizeKey "OSBundleWiredSize"
172 #define kOSBundleDependenciesKey "OSBundleDependencies"
173 #define kOSBundleRetainCountKey "OSBundleRetainCount"
174 #define kOSBundleCacheLoadAddressKey "OSBundleCacheLoadAddress"
175 // Kernel TEXT encompasses kexts
176 #define kOSBundleKextsInKernelTextKey "OSBundleKextsInKernelText"
177 // OSKextCopyLoadedKextInfo includes non-started kexts when present:
178 #define kOSBundleAllPrelinkedKey "OSBundleAllPrelinked"
180 /* Dictionary of metaclass info keyed by classname.
182 #define kOSBundleClassesKey "OSBundleClasses"
184 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
185 * may be absent (for the root class).
187 #define kOSMetaClassNameKey "OSMetaClassName"
188 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
189 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
193 /********************************************************************/
194 #pragma mark Kext Collection Type Keys
195 /********************************************************************/
197 #define kKCTypePrimary "Primary"
198 #define kKCTypeSystem "System"
199 #define kKCTypeAuxiliary "Auxiliary"
200 #define kKCTypeCodeless "Codeless"
201 #define kKCTypeAny "Any"
205 /********************************************************************/
206 #pragma mark Kext Log Specification
207 /********************************************************************/
210 * @group Kext Log Specification
211 * Logging levels & flags for kernel extensions.
212 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
217 * @typedef OSKextLogSpec
218 * @abstract Describes what a log message applies to,
219 * or a filter that determines which log messages are displayed.
222 * A kext log specification is a 32-bit value used as a desription of
223 * what a given log message applies to, or as a filter
224 * indicating which log messages are desired and which are not.
225 * A log specification has three parts (described in detail shortly):
227 * <li>A <b>level</b> from 0-7 in the lowest-order nibble (0x7).</li>
228 * <li>A flag bit in the lowest-order nibble (0x8) indicating whether
229 * log messages tied to individual kexts are always printed (1)
230 * or printed only if the kext has an
231 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
232 * OSBundleEnableKextLogging@/link set to <code>true</code>.
233 * <li>A set of <b>activity flags</b> in the remaining nibbles (0xFFFFFFF0),
234 * which describe areas of activity related to kernel extensions.</li>
237 * You can specify a log spec to most of the kext tools with the -v option
238 * and a hex number (rather than the escalating decimal levels 0-6).
239 * You can also specify a log spec to the kernel with the "kextlog" boot arg
240 * or "debug.kextlog" sysctl.
244 * The log level spans a range from silent (no log messages)
245 * to debuging information:
248 * <li>Silent - Not applicable to messages; as a filter, do not print any log messages.</li>
249 * <li>Errors - Log message is an error.
250 * <li>Warnings - Log message is a warning.
251 * <li>Basic information - Log message is basic success/failure.</li>
252 * <li>Progress - Provides high-level information about stages in processing.</li>
253 * <li>Step - Provides low-level information about complex operations,
254 * typically about individual kexts.</li>
255 * <li>Detail - Provides very low-level information about parts of kexts,
256 * including individual Libkern classes and operations on bundle files.</li>
257 * <li>Debug - Very verbose logging about internal activities.</li>
261 * <code>@link kOSKextLogErrorLevel kOSKextLogErrorLevel@/link</code> or
262 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
263 * ignore activity flags and the
264 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
265 * OSBundleEnableKextLogging@/link property;
266 * that is, only the filter level is checked for messages at these levels.
267 * Log messages at levels above
268 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
269 * are filtered according both to the activity flags in the current filter
270 * and to whether the log message is associated with a kext or not.
271 * Normally log messages associated with kexts are not printed
272 * unless the kext has a
273 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
274 * OSBundleEnableKextLogging@/link property set to <code>true</code>.
275 * If you set the high-order bit of the log level (that is, add 8 to the level),
276 * then all kext-specific log messages matching the activity flags are printed.
277 * This can be very verbose.
279 * <b>Activity Flags</b>
281 * Each flag governs a category of activity,
282 * such as loading, IPC, or archives; by combining them with bitwise OR,
283 * you can choose which messages you wish to see (or when logging messages,
284 * which bit flags select your message).
286 * <b>Byte 1:</b> <code>0xF0</code> - Basic activities
287 * (<code>@link kOSKextLogGeneralFlag kOSKextLogGeneralFlag@/link</code>,
288 * <code>@link kOSKextLogLoadFlag kOSKextLogLoadFlag@/link</code>, and
289 * <code>@link kOSKextLogArchiveFlag kOSKextLogArchiveFlag@/link</code>).
291 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
293 * <b>Byte 4:</b> <code>0xF000</code> - Kext diagnostics
294 * (<code>@link kOSKextLogValidationFlag kOSKextLogValidationFlag@/link</code>,
295 * <code>@link kOSKextLogAuthenticationFlag kOSKextLogAuthenticationFlag@/link</code>, and
296 * <code>@link kOSKextLogDependenciesFlag kOSKextLogDependenciesFlag@/link</code>).
298 * <b>Byte 5:</b> <code>0xF00000</code> - Kext access & bookkeeping
299 * (<code>@link kOSKextLogDirectoryScanFlag kOSKextLogDirectoryScanFlag@/link</code>,
300 * <code>@link kOSKextLogFileAccessFlag kOSKextLogFileAccessFlag@/link</code>,
301 * <code>@link kOSKextLogKextBookkeepingFlag kOSKextLogKextBookkeepingFlag@/link </code>).
303 * <b>Byte 6:</b> <code>0xF000000</code> - Linking & patching
304 * (<code>@link kOSKextLogLinkFlag kOSKextLogLinkFlag@/link</code> and
305 * <code>@link kOSKextLogPatchFlag kOSKextLogPatchFlag@/link</code>).
307 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
309 typedef uint32_t OSKextLogSpec
;
312 /********************************************************************/
314 /********************************************************************/
317 * @define kOSKextLogLevelMask
318 * @abstract Masks the bottom 3 bits of an
319 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
322 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
325 * @define kOSKextLogKextOrGlobalMask
326 * @abstract Determines whether per-kext log messages are output.
329 * In filter specifications, if unset (the usual default),
330 * then log messages associated with a kext are only output
332 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
333 * OSBundleEnableKextLogging@/link
334 * property set to <code>true</code>.
335 * If set, then all log messages associated with kexts
338 * In message specifications, if set it indicates that the message is either
339 * not associated with a kext, or is associated with a kext that has an
340 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
341 * OSBundleEnableKextLogging@/link
342 * property set to <code>true</code>.
344 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
348 * @define kOSKextLogFlagsMask
349 * @abstract Masks the flag bits of an
350 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
352 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
355 * @define kOSKextLogFlagsMask
356 * @abstract Masks the flag bits of an
357 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>
358 * to which command-line <code>-v</code> levels apply.
360 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
363 * @define kOSKextLogConfigMask
364 * @abstract Masks the config bits of an
365 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
367 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
370 /********************************************************************/
371 #pragma mark 0xF - Log Level
372 /********************************************************************/
376 * @define kOSKextLogExplicitLevel
377 * @abstract Used when logging a message to overrides the current log filter,
378 * even if it's set to silent for log messages.
379 * This is essentially a pass-through for
380 * unconditional print messages to go
381 * through the logging engine.
383 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
386 * @define kOSKextLogErrorLevel
387 * @abstract Log messages concerning error conditions in any category.
389 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
393 * @define kOSKextLogWarningLevel
394 * @abstract Log messages concerning warning conditions in any category,
395 * which indicate potential error conditions,
396 * and notices, which may explain unexpected but correct behavior.
398 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
402 * @define kOSKextLogBasicLevel
403 * @abstract Log messages concerning top-level outcome in any category
404 * (kext load/unload, kext cache creation/extration w/# kexts).
406 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
410 * @define kOSKextLogProgressLevel
411 * @abstract Log messages concerning high-level progress in any category,
412 * such as sending a load request to the kernel,
413 * allocation/link/map/start (load operation),
414 * stop/unmap (unload operation), kext added/extracted (archive).
416 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
420 * @define kOSKextLogStepLevel
421 * @abstract Log messages concerning major steps in any category,
422 * such as sending personalities to the IOCatalogue when loading,
423 * detailed IPC with the kernel, or filtering of kexts for an archive.
425 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
429 * @define kOSKextLogDetailLevel
430 * @abstract Log messages concerning specific details in any category,
431 * such as classes being registered/unregistered or
432 * operations on indivdual files in a kext.
434 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
438 * @define kOSKextLogDebugLevel
439 * @abstract Log messages concerning very low-level actions that are
440 * useful mainly for debugging the kext system itself.
442 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
446 /********************************************************************/
447 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
448 /********************************************************************/
452 * @define kOSKextLogGeneralFlag
453 * @abstract Log messages about general activity in the kext system.
455 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
458 * @define kOSKextLogLoadFlag
459 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
462 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
465 * @define kOSKextLogIPCFlag
466 * @abstract Log messages about any interaction between kernel and user space
467 * regarding kernel extensions.
469 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
472 * @define kOSKextLogArchiveFlag
473 * @abstract Log messages about creating or processing a kext startup cache file
474 * (mkext or prelinked kernel).
476 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
480 /********************************************************************/
481 #pragma mark 0xF00 - Reserved Verbose Area
482 /********************************************************************/
484 // reserved slot for group ((OSKextLogSpec) 0x100)
485 // reserved slot for group ((OSKextLogSpec) 0x200)
486 // reserved slot for group ((OSKextLogSpec) 0x400)
487 // reserved slot for group ((OSKextLogSpec) 0x800)
490 /********************************************************************/
491 #pragma mark 0xF000 - Kext diagnostic activity
492 /********************************************************************/
496 * @define kOSKextLogValidationFlag
497 * @abstract Log messages when validating kernel extensions.
499 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
502 * @define kOSKextLogAuthenticationFlag
503 * @abstract Log messages when autnenticating kernel extension files.
504 * Irrelevant in the kernel.
506 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
509 * @define kOSKextLogDependenciesFlag
510 * @abstract Log messages when resolving dependencies for a kernel extension.
512 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
514 // reserved slot for group ((OSKextLogSpec) 0x8000)
517 /********************************************************************/
518 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
519 /********************************************************************/
523 * @define kOSKextLogDirectoryScanFlag
524 * @abstract Log messages when scanning directories for kernel extensions.
525 * In the kernel logs every booter kext entry processed.
527 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
530 * @define kOSKextLogFileAccessFlag
531 * @abstract Log messages when performing any filesystem access (very verbose).
532 * Irrelevant in the kernel.
534 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
537 * @define kOSKextLogKextBookkeepingFlag
538 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
540 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
542 // reserved slot for group ((OSKextLogSpec) 0x80000)
545 /********************************************************************/
546 #pragma mark 0xF00000 - Linking & Patching
547 /********************************************************************/
551 * @define kOSKextLogLinkFlag
552 * @abstract Log messages about linking.
554 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
557 * @define kOSKextLogPatchFlag
558 * @abstract Log messages about patching.
560 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
562 // reserved slot for group ((OSKextLogSpec) 0x400000)
563 // reserved slot for group ((OSKextLogSpec) 0x800000)
566 /********************************************************************/
567 #pragma mark 0xF000000 - Reserved
568 /********************************************************************/
571 // reserved slot for grouping ((OSKextLogSpec) 0x1000000)
572 // reserved slot for grouping ((OSKextLogSpec) 0x2000000)
573 // reserved slot for grouping ((OSKextLogSpec) 0x4000000)
574 // reserved slot for grouping ((OSKextLogSpec) 0x8000000)
578 /********************************************************************/
579 #pragma mark 0xF0000000 - Config Flags
580 /********************************************************************/
583 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
584 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
585 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
588 /********************************************************************/
589 #pragma mark Predefined Specifications
590 /********************************************************************/
594 * @define kOSKextLogSilentFilter
595 * @abstract For use in filter specs:
596 * Ignore all log messages with a log level greater than
597 * <code>@link kOSKextLogExplicitLevel kOSKextLogExplicitLevel@/link</code>.
599 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
602 * @define kOSKextLogShowAllFilter
603 * @abstract For use in filter specs:
604 * Print all log messages not associated with a kext or
605 * associated with a kext that has
606 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
607 * OSBundleEnableKextLogging@/link
608 * set to <code>true</code>.
610 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
613 * @define kOSKextLogShowAllKextsFilter
614 * @abstract For use in filter specs:
615 * Print all log messages has
616 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
617 * OSBundleEnableKextLogging@/link
618 * set to <code>true</code>.
620 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
621 (kOSKextLogShowAllFilter | \
622 kOSKextLogKextOrGlobalMask))
626 /********************************************************************/
627 #pragma mark Kext Version String Processing
628 /********************************************************************/
631 * @group Kext Version String Processing
632 * Functions for working with kext versions and compatible versions.
636 * @typedef OSKextVersion
637 * @abstract An encoded kext version that can be compared arithmetically.
640 * A value of zero (<code>@link kOSKextVersionUndefined kOSKextVersionUndefined@/link</code>)
641 * is <i>not</i> equivalent to a version string of "0.0",
642 * and typically means there is no version specified
643 * (for example, that there is no CFBundleVersion property at all).
644 * Values below zero are invalid.
646 * The encoding used is subject to change,
647 * and should never be saved to permanent storage.
648 * Always use proper version strings in files and interprocess communication.
650 typedef int64_t OSKextVersion
;
653 * @define kOSKextVersionMaxLength
654 * @abstract The length of a string buffer
655 * guaranteed to be able to hold a kext version.
658 * Kext versions use an extended Mac OS 'vers' format with double the number
659 * of digits before the build stage: ####.##.##s{1-255} where 's'
660 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
662 #define kOSKextVersionMaxLength (20)
663 // with a few bytes to spare including a nul byte
664 // xx-review: Should we make this much bigger in case we ever need longer strings?
667 * @define kOSKextVersionUndefined
668 * @abstract The undefined version.
671 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
673 * (for example, that there is no CFBundleVersion property at all).
675 #define kOSKextVersionUndefined (0)
678 * @function OSKextParseVersionString
681 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
683 * @param versionString The kext version string to parse.
686 * An encoded kext version that can be compared numerically
687 * against other encoded kext versions,
688 * <0 if <code>versionString</code> is <code>NULL</code>, empty,
689 * or cannot be parsed.
692 * Kext versions use an extended Mac OS 'vers' format with double the number
693 * of digits before the build stage: ####.##.##s{1-255} where 's'
694 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
696 OSKextVersion
OSKextParseVersionString(const char * versionString
);
700 * @function OSKextVersionGetString
703 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
707 * The encoded version to format.
709 * A C string buffer of at least
710 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code> bytes.
711 * @param bufferSize The size in bytes of <code>buffer</code>.
714 * <code>TRUE</code> if the encoded version is formatted successfully.
715 * <code>FALSE</code> if <code>buffer</code> is <code>NULL</code> or
716 * <code>bufferSize</code> is less than
717 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code>.
720 * The return value strictly indicates whether <code>buffer</code>
721 * is large enough to hold the result.
722 * If <code>aVersion</code> is 0, the resulting string is "(missing)".
723 * If <code>aVersion</code> is less than 0
724 * or is not a valid kext version encoding,
725 * the resulting string is "(invalid)".
727 Boolean
OSKextVersionGetString(
728 OSKextVersion aVersion
,
730 uint32_t bufferSize
);
737 /********************************************************************/
739 #pragma mark Weak linking
740 /********************************************************************/
742 #ifdef XNU_KERNEL_PRIVATE
743 void kext_weak_symbol_referenced(void) __abortlike
;
744 #endif /* XNU_KERNEL_PRIVATE */
748 /********************************************************************/
749 #pragma mark Miscellaneous Kernel-Only Kext Functions
750 /********************************************************************/
754 * @function kext_get_vm_map
755 * @abstract Returns the vm_map from which the kext was allocated.
757 * @param info The kmod_info_t structure of the kext.
758 * @result The vm_map from which the kext was allocated. This function
759 * cannot return <code>NULL</code>.
761 vm_map_t
kext_get_vm_map(kmod_info_t
* info
);
763 #ifdef XNU_KERNEL_PRIVATE
767 * @function OSKextRegisterKextsWithDTrace
769 * DTrace calls this once when it has started up so that the kext system
770 * will register any already-loaded kexts with it.
772 void OSKextRegisterKextsWithDTrace(void);
774 #endif /* CONFIG_DTRACE */
777 * @function kext_dump_panic_lists
778 * @abstract Prints compacted lists of last unloaded & all loaded kexts
781 * @param printf_func The printf-style function to use for output.
783 void kext_dump_panic_lists(int (*printf_func
)(const char *fmt
, ...));
785 #endif /* XNU_KERNEL_PRIVATE */
787 #ifdef XNU_KERNEL_PRIVATE
791 /********************************************************************/
792 #pragma mark Kext Loading C Functions
793 /********************************************************************/
796 * @function OSKextGetLoadTagForBundleIdentifier
797 * @abstract Look up the load tag for a kext.
799 * @param kextIdentifier The bundle identifier of the kext to look up.
801 * The load tag of the requested kext, or
802 * <code>@link //apple_ref/c/macro/kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>
803 * if the kext was not found.
806 * A load tag uniquely identifies a loaded kext.
807 * It can be found as the <code>id</code> field of a loaded kext's
808 * <code>kmod_info_t</code> struct.
810 * Note that a load tag represents a specific loaded instance of a kext.
811 * If that kext is unloaded, the load tag is no longer a valid reference.
812 * If the same kext is later reloaded, it will have a new load tag.
814 * You can use the load tag to adjust a kext's reference count
816 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
817 * OSKextRetainKextWithLoadTag@/link</code>
819 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
820 * OSKextReleaseKextWithLoadTag@/link</code>,
821 * so that the kext is automatically unloaded when no references remain,
822 * or to unload the kext immediately
823 * with <code>@link //apple_ref/c/func/OSKextUnloadKextWithLoadTag OSKextUnloadKextWithLoadTag@/link</code>.
825 * Those functions are intended for use with non-IOKit kexts
826 * (specifically, kexts that define no subclasses of
827 * <code>@link //apple_ref/doc/class/IOServiceIOService@/link</code>).
828 * Pure IOKit kexts are managed via instance counts
829 * of their libkern C++ object classes;
830 * using those functions on them will only interfere with that mechanism.
831 * If you have a hybrid kext with both IOService subclasses and non-IOKit code,
832 * however, you may want to use reference counting for the non-IOKit portions:
833 * that way the kext will only unload automaticaly
834 * when there are no C++ objects and the kext reference count is zero.
836 uint32_t OSKextGetLoadTagForBundleIdentifier(
837 const char * kextIdentifier
);
841 * @function OSKextUnloadKextWithLoadTag
842 * @abstract Stop and unload a kext based on its load tag.
844 * @param loadTag The load tag of the kext to unload.
846 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
847 * if the kext was found and unloaded.
848 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
849 * kOSKextReturnNotFound@/link</code>
850 * if the kext was not found.
851 * <code>@link //apple_ref/c/macro/kOSKextReturnInUse
852 * kOSKextReturnInUse@/link</code>
853 * if the kext has outstanding references
854 * or if there are instances of its libkern C++ subclasses.
855 * Other return values indicate a failure to unload the kext,
856 * typically because the module stop routine failed.
859 * A panic will occur if a kext calls this function to unload itself.
860 * The safest way for a kext to unload itself is to call
861 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
862 * OSKextRetainKextWithLoadTag@/link</code>
863 * with its own load tag
864 * (the <code>id</code> field of its <code>kmod_info_t</code> struct),
866 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
867 * OSKextReleaseKextWithLoadTag@/link</code>;
868 * this will schedule the kext for unload on a separate thread.
870 * This function can be used when reference-based autounloading is not
872 * If a kernel system or kext is already monitoring
873 * the need for a kext,
874 * it can simply call this function when it's known that the kext is not needed.
876 OSReturn
OSKextUnloadKextWithLoadTag(uint32_t loadTag
);
878 #endif /* XNU_KERNEL_PRIVATE */
884 /********************************************************************/
885 #pragma mark Loaded Kext Summary
886 /********************************************************************/
890 * @define kOSKextLoadedKextSummaryVersion
891 * @abstract The current version of the loaded kext summary headers.
893 #define kOSKextLoadedKextSummaryVersion 2
896 * @typedef OSKextLoadedKextSummary
897 * @abstract A structure that describes a loaded kext.
899 * @field name The kext's bundle identifier.
900 * @field uuid The kext's UUID;
901 * @field address The kext's load address.
902 * @field size The kext's load size.
903 * @field version The binary format (OSKextVersion) version of the kext.
904 * @field loadTag The kext's load tag.
905 * @field flags Internal tracking flags.
906 * @field reference_list who this refs (links on).
907 * @field text_exec_address The address of the __TEXT_EXEC segment (if it exists), otherwise __TEXT
908 * @field text_exec_size The size of the segment pointed to by text_address
911 * The OSKextLoadedKextSummary structure contains a basic set of information
912 * about the kext to facilitate kext debugging and panic debug log output.
914 typedef struct _loaded_kext_summary
{
915 char name
[KMOD_MAX_NAME
];
922 uint64_t reference_list
;
923 uint64_t text_exec_address
;
924 size_t text_exec_size
;
925 } OSKextLoadedKextSummary
;
928 * @typedef OSKextLoadedKextSummaryHeader
929 * @abstract A structure that describes the set of loaded kext summaries.
931 * @field version The version of the loaded kext summary structures.
932 * @field entry_size The size of each entry in summaries.
933 * @field numSummaries The number of OSKextLoadedKextSummary structures
934 * following the header.
935 * @field summaries A convenience pointer to the array of summaries following
939 * The OSKextLoadedKextSummaryHeader describes the set of loaded kext summaries
940 * available for use by the debugger or panic log routine.
941 * The array of summaries contains one OSKextLoadedKextSummary for every kext
942 * that declares an executable and is not an interface to the kernel.
944 typedef struct _loaded_kext_summary_header
{
947 uint32_t numSummaries
;
948 uint32_t reserved
; /* explicit alignment for gdb */
949 OSKextLoadedKextSummary summaries
[0];
950 } OSKextLoadedKextSummaryHeader
;
953 * @var gLoadedKextSummaries
954 * @abstract The global pointer to the current set of loaded kext summaries.
956 extern OSKextLoadedKextSummaryHeader
* gLoadedKextSummaries
;
959 * @var gLoadedKextSummariesTimestamp
961 * @abstract This will be set to mach_absolute_time() around updates to
962 * gLoadedKextSummaries. Ie. immediately before gLoadedKextSummaries is set to
963 * zero, and immediately after it is set to a new value.
965 extern uint64_t gLoadedKextSummariesTimestamp
;
968 * @function OSKextLoadedKextSummariesUpdated
969 * @abstract Called when gLoadedKextSummaries has been updated.
972 * gLoadedKextSummaries is updated when a kext is loaded or unloaded.
973 * When the update is complete, OSKextLoadedKextSummariesUpdated is called.
974 * gdb can set a breakpoint on this function to detect kext loads and unloads.
976 void OSKextLoadedKextSummariesUpdated(void);
978 #ifdef XNU_KERNEL_PRIVATE
980 extern const vm_allocation_site_t
* OSKextGetAllocationSiteForCaller(uintptr_t address
);
981 extern uint32_t OSKextGetKmodIDForSite(const vm_allocation_site_t
* site
,
982 char * name
, vm_size_t namelen
);
983 extern void OSKextFreeSite(vm_allocation_site_t
* site
);
986 extern int OSKextGetUUIDForName(const char *, uuid_t
);
989 extern vm_tag_t gIOSurfaceTag
;
991 extern void *OSKextKextForAddress(const void *addr
);
993 #endif /* XNU_KERNEL_PRIVATE */
997 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */