]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/OSKextLibPrivate.h
2557007ea707c404132096c619ae944e24c2e1e5
[apple/xnu.git] / libkern / libkern / OSKextLibPrivate.h
1 /*
2 * Copyright (c) 1998-2000 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef _LIBKERN_OSKEXTLIBPRIVATE_H
30 #define _LIBKERN_OSKEXTLIBPRIVATE_H
31
32
33 #include <sys/cdefs.h>
34 #include <uuid/uuid.h>
35
36 __BEGIN_DECLS
37 #ifdef KERNEL
38 #include <libkern/OSTypes.h>
39 #include <mach/kmod.h>
40 #include <mach/vm_types.h>
41 #else
42 #include <CoreFoundation/CoreFoundation.h>
43 #include <mach/kmod.h>
44 #endif /* KERNEL */
45 __END_DECLS
46
47 #include <libkern/OSReturn.h>
48
49 __BEGIN_DECLS
50
51 #if PRAGMA_MARK
52 #pragma mark -
53 /********************************************************************/
54 #pragma mark Misc Constants
55 /********************************************************************/
56 #endif
57
58 typedef uint8_t OSKextExcludeLevel;
59 #define kOSKextExcludeNone (0)
60 #define kOSKextExcludeKext (1)
61 #define kOSKextExcludeAll (2)
62
63 #if PRAGMA_MARK
64 #pragma mark -
65 /********************************************************************/
66 #pragma mark Kext/OSBundle Property List Keys
67 /********************************************************************/
68 #endif
69
70 /*!
71 * @define kOSBundleHelperKey
72 * @abstract Used by loginwindow.
73 */
74 #define kOSBundleHelperKey "OSBundleHelper"
75
76 /*!
77 * @define kOSBundleDeveloperOnlyKey
78 * @abstract A boolean value indicating whether the kext should only load on
79 * Developer devices.
80 */
81 #define kOSBundleDeveloperOnlyKey "OSBundleDeveloperOnly"
82
83 /*!
84 * @define kOSBundleRamDiskOnlyKey
85 * @abstract A boolean value indicating whether the kext should only load when
86 * booted from a ram disk.
87 */
88 #define kOSBundleRamDiskOnlyKey "OSBundleRamDiskOnly"
89
90
91 /*!
92 * @define kAppleSecurityExtensionKey
93 * @abstract A boolean value indicating whether the kext registers
94 * MACF hooks.
95 */
96 #define kAppleSecurityExtensionKey "AppleSecurityExtension"
97
98 /*!
99 * @define kAppleKernelExternalComponentKey
100 * @abstract A boolean value indicating whether the kext is vending kernel
101 * KPI, and needs special loading behavior.
102 */
103 #define kAppleKernelExternalComponentKey "AppleKernelExternalComponent"
104
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 */
111
112 #if PRAGMA_MARK
113 #pragma mark -
114 /********************************************************************/
115 #pragma mark Load Info Keys
116 /********************************************************************/
117 #endif
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"
143
144 /* Dictionary of metaclass info keyed by classname.
145 */
146 #define kOSBundleClassesKey "OSBundleClasses"
147
148 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
149 * may be absent (for the root class).
150 */
151 #define kOSMetaClassNameKey "OSMetaClassName"
152 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
153 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
154
155 #if PRAGMA_MARK
156 #pragma mark -
157 /********************************************************************/
158 #pragma mark Kext Log Specification
159 /********************************************************************/
160 #endif
161 /*!
162 * @group Kext Log Specification
163 * Logging levels & flags for kernel extensions.
164 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
165 * for an overview.
166 */
167
168 /*!
169 * @typedef OSKextLogSpec
170 * @abstract Describes what a log message applies to,
171 * or a filter that determines which log messages are displayed.
172 *
173 * @discussion
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):
178 * <ul>
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>
187 * </ul>
188 *
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.
193 *
194 * <b>Log Levels</b>
195 *
196 * The log level spans a range from silent (no log messages)
197 * to debuging information:
198 *
199 * <ol start="0">
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>
210 * </ol>
211 *
212 * Log messages at
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.
230 *
231 * <b>Activity Flags</b>
232 *
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).
237 *
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>).
242 *
243 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
244 *
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>).
249 *
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>).
254 *
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>).
258 *
259 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
260 */
261 typedef uint32_t OSKextLogSpec;
262
263 #if PRAGMA_MARK
264 /********************************************************************/
265 #pragma mark Masks
266 /********************************************************************/
267 #endif
268 /*!
269 * @define kOSKextLogLevelMask
270 * @abstract Masks the bottom 3 bits of an
271 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
272 * the raw level.
273 */
274 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
275
276 /*!
277 * @define kOSKextLogKextOrGlobalMask
278 * @abstract Determines whether per-kext log messages are output.
279 *
280 * @discussion
281 * In filter specifications, if unset (the usual default),
282 * then log messages associated with a kext are only output
283 * if the kext has an
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
288 * are output.
289 *
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>.
295 */
296 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
297
298
299 /*!
300 * @define kOSKextLogFlagsMask
301 * @abstract Masks the flag bits of an
302 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
303 */
304 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
305
306 /*!
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.
311 */
312 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
313
314 /*!
315 * @define kOSKextLogConfigMask
316 * @abstract Masks the config bits of an
317 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
318 */
319 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
320
321 #if PRAGMA_MARK
322 /********************************************************************/
323 #pragma mark 0xF - Log Level
324 /********************************************************************/
325 #endif
326
327 /*!
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.
334 */
335 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
336
337 /*!
338 * @define kOSKextLogErrorLevel
339 * @abstract Log messages concerning error conditions in any category.
340 */
341 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
342
343
344 /*!
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.
349 */
350 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
351
352
353 /*!
354 * @define kOSKextLogBasicLevel
355 * @abstract Log messages concerning top-level outcome in any category
356 * (kext load/unload, kext cache creation/extration w/# kexts).
357 */
358 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
359
360
361 /*!
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).
367 */
368 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
369
370
371 /*!
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.
376 */
377 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
378
379
380 /*!
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.
385 */
386 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
387
388
389 /*!
390 * @define kOSKextLogDebugLevel
391 * @abstract Log messages concerning very low-level actions that are
392 * useful mainly for debugging the kext system itself.
393 */
394 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
395
396
397 #if PRAGMA_MARK
398 /********************************************************************/
399 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
400 /********************************************************************/
401 #endif
402
403 /*!
404 * @define kOSKextLogGeneralFlag
405 * @abstract Log messages about general activity in the kext system.
406 */
407 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
408
409 /*!
410 * @define kOSKextLogLoadFlag
411 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
412 * in the kernel.
413 */
414 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
415
416 /*!
417 * @define kOSKextLogIPCFlag
418 * @abstract Log messages about any interaction between kernel and user space
419 * regarding kernel extensions.
420 */
421 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
422
423 /*!
424 * @define kOSKextLogArchiveFlag
425 * @abstract Log messages about creating or processing a kext startup cache file
426 * (mkext or prelinked kernel).
427 */
428 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
429
430
431 #if PRAGMA_MARK
432 /********************************************************************/
433 #pragma mark 0xF00 - Reserved Verbose Area
434 /********************************************************************/
435 #endif
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)
440
441 #if PRAGMA_MARK
442 /********************************************************************/
443 #pragma mark 0xF000 - Kext diagnostic activity
444 /********************************************************************/
445 #endif
446
447 /*!
448 * @define kOSKextLogValidationFlag
449 * @abstract Log messages when validating kernel extensions.
450 */
451 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
452
453 /*!
454 * @define kOSKextLogAuthenticationFlag
455 * @abstract Log messages when autnenticating kernel extension files.
456 * Irrelevant in the kernel.
457 */
458 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
459
460 /*!
461 * @define kOSKextLogDependenciesFlag
462 * @abstract Log messages when resolving dependencies for a kernel extension.
463 */
464 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
465
466 // reserved slot for group ((OSKextLogSpec) 0x8000)
467
468 #if PRAGMA_MARK
469 /********************************************************************/
470 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
471 /********************************************************************/
472 #endif
473
474 /*!
475 * @define kOSKextLogDirectoryScanFlag
476 * @abstract Log messages when scanning directories for kernel extensions.
477 * In the kernel logs every booter kext entry processed.
478 */
479 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
480
481 /*!
482 * @define kOSKextLogFileAccessFlag
483 * @abstract Log messages when performing any filesystem access (very verbose).
484 * Irrelevant in the kernel.
485 */
486 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
487
488 /*!
489 * @define kOSKextLogKextBookkeepingFlag
490 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
491 */
492 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
493
494 // reserved slot for group ((OSKextLogSpec) 0x80000)
495
496 #if PRAGMA_MARK
497 /********************************************************************/
498 #pragma mark 0xF00000 - Linking & Patching
499 /********************************************************************/
500 #endif
501
502 /*!
503 * @define kOSKextLogLinkFlag
504 * @abstract Log messages about linking.
505 */
506 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
507
508 /*!
509 * @define kOSKextLogPatchFlag
510 * @abstract Log messages about patching.
511 */
512 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
513
514 // reserved slot for group ((OSKextLogSpec) 0x400000)
515 // reserved slot for group ((OSKextLogSpec) 0x800000)
516
517 #if PRAGMA_MARK
518 /********************************************************************/
519 #pragma mark 0xF000000 - Reserved
520 /********************************************************************/
521 #endif
522
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)
527
528
529 #if PRAGMA_MARK
530 /********************************************************************/
531 #pragma mark 0xF0000000 - Config Flags
532 /********************************************************************/
533 #endif
534
535 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
536 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
537 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
538
539 #if PRAGMA_MARK
540 /********************************************************************/
541 #pragma mark Predefined Specifications
542 /********************************************************************/
543 #endif
544
545 /*!
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>.
550 */
551 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
552
553 /*!
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>.
561 */
562 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
563
564 /*!
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>.
571 */
572 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
573 (kOSKextLogShowAllFilter | \
574 kOSKextLogKextOrGlobalMask))
575
576 #if PRAGMA_MARK
577 #pragma mark -
578 /********************************************************************/
579 #pragma mark Kext Version String Processing
580 /********************************************************************/
581 #endif
582 /*!
583 * @group Kext Version String Processing
584 * Functions for working with kext versions and compatible versions.
585 */
586
587 /*!
588 * @typedef OSKextVersion
589 * @abstract An encoded kext version that can be compared arithmetically.
590 *
591 * @discussion
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.
597 *
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.
601 */
602 typedef int64_t OSKextVersion;
603
604 /*!
605 * @define kOSKextVersionMaxLength
606 * @abstract The length of a string buffer
607 * guaranteed to be able to hold a kext version.
608 *
609 * @discussion
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'.
613 */
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?
617
618 /*!
619 * @define kOSKextVersionUndefined
620 * @abstract The undefined version.
621 *
622 * @discussion
623 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
624 * lack of a version
625 * (for example, that there is no CFBundleVersion property at all).
626 */
627 #define kOSKextVersionUndefined (0)
628
629 /*!
630 * @function OSKextParseVersionString
631 *
632 * @abstract
633 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
634 *
635 * @param versionString The kext version string to parse.
636 *
637 * @result
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.
642 *
643 * @discussion
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'.
647 */
648 OSKextVersion OSKextParseVersionString(const char * versionString);
649
650
651 /*!
652 * @function OSKextVersionGetString
653 *
654 * @abstract
655 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
656 * representation.
657 *
658 * @param aVersion
659 * The encoded version to format.
660 * @param buffer
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>.
664 *
665 * @result
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>.
670 *
671 * @discussion
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)".
678 */
679 Boolean OSKextVersionGetString(
680 OSKextVersion aVersion,
681 char * buffer,
682 uint32_t bufferSize);
683
684
685 #ifdef KERNEL
686
687
688 #if PRAGMA_MARK
689 /********************************************************************/
690 #pragma mark -
691 #pragma mark Weak linking
692 /********************************************************************/
693 #endif
694 #ifdef XNU_KERNEL_PRIVATE
695 void kext_weak_symbol_referenced(void);
696 #endif /* XNU_KERNEL_PRIVATE */
697
698 #if PRAGMA_MARK
699 #pragma mark -
700 /********************************************************************/
701 #pragma mark Miscellaneous Kernel-Only Kext Functions
702 /********************************************************************/
703 #endif
704
705 /*!
706 * @function kext_get_vm_map
707 * @abstract Returns the vm_map from which the kext was allocated.
708 *
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>.
712 */
713 vm_map_t kext_get_vm_map(kmod_info_t * info);
714
715 #ifdef XNU_KERNEL_PRIVATE
716
717 #if CONFIG_DTRACE
718 /*!
719 * @function OSKextRegisterKextsWithDTrace
720 * @abstract
721 * DTrace calls this once when it has started up so that the kext system
722 * will register any already-loaded kexts with it.
723 */
724 void OSKextRegisterKextsWithDTrace(void);
725
726 #endif /* CONFIG_DTRACE */
727
728 /*!
729 * @function kext_dump_panic_lists
730 * @abstract Prints compacted lists of last unloaded & all loaded kexts
731 * during a panic.
732 *
733 * @param printf_func The printf-style function to use for output.
734 */
735 void kext_dump_panic_lists(int (*printf_func)(const char *fmt, ...));
736
737 #endif /* XNU_KERNEL_PRIVATE */
738
739 #ifdef XNU_KERNEL_PRIVATE
740
741 #if PRAGMA_MARK
742 #pragma mark -
743 /********************************************************************/
744 #pragma mark Kext Loading C Functions
745 /********************************************************************/
746 #endif
747 /*!
748 * @function OSKextGetLoadTagForBundleIdentifier
749 * @abstract Look up the load tag for a kext.
750 *
751 * @param kextIdentifier The bundle identifier of the kext to look up.
752 * @result
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.
756 *
757 * @discussion
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.
761 *
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.
765 *
766 * You can use the load tag to adjust a kext's reference count
767 * via
768 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
769 * OSKextRetainKextWithLoadTag@/link</code>
770 * and
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>.
776 *
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.
787 */
788 uint32_t OSKextGetLoadTagForBundleIdentifier(
789 const char * kextIdentifier);
790
791
792 /*!
793 * @function OSKextUnloadKextWithLoadTag
794 * @abstract Stop and unload a kext based on its load tag.
795 *
796 * @param loadTag The load tag of the kext to unload.
797 * @result
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.
809 *
810 * @discussion
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),
817 * followed by
818 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
819 * OSKextReleaseKextWithLoadTag@/link</code>;
820 * this will schedule the kext for unload on a separate thread.
821 *
822 * This function can be used when reference-based autounloading is not
823 * appropriate.
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.
827 */
828 OSReturn OSKextUnloadKextWithLoadTag(uint32_t loadTag);
829
830 #endif /* XNU_KERNEL_PRIVATE */
831
832 #endif /* KERNEL */
833
834 #if PRAGMA_MARK
835 #pragma mark -
836 /********************************************************************/
837 #pragma mark Loaded Kext Summary
838 /********************************************************************/
839 #endif
840
841 /*!
842 * @define kOSKextLoadedKextSummaryVersion
843 * @abstract The current version of the loaded kext summary headers.
844 */
845 #define kOSKextLoadedKextSummaryVersion 2
846
847 /*!
848 * @typedef OSKextLoadedKextSummary
849 * @abstract A structure that describes a loaded kext.
850 *
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).
859 *
860 * @discussion
861 * The OSKextLoadedKextSummary structure contains a basic set of information
862 * about the kext to facilitate kext debugging and panic debug log output.
863 */
864 typedef struct _loaded_kext_summary {
865 char name[KMOD_MAX_NAME];
866 uuid_t uuid;
867 uint64_t address;
868 uint64_t size;
869 uint64_t version;
870 uint32_t loadTag;
871 uint32_t flags;
872 uint64_t reference_list;
873 } OSKextLoadedKextSummary;
874
875 /*!
876 * @typedef OSKextLoadedKextSummaryHeader
877 * @abstract A structure that describes the set of loaded kext summaries.
878 *
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
884 * the header.
885 *
886 * @discussion
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.
891 */
892 typedef struct _loaded_kext_summary_header {
893 uint32_t version;
894 uint32_t entry_size;
895 uint32_t numSummaries;
896 uint32_t reserved; /* explicit alignment for gdb */
897 OSKextLoadedKextSummary summaries[0];
898 } OSKextLoadedKextSummaryHeader;
899
900 /*!
901 * @var gLoadedKextSummaries
902 * @abstract The global pointer to the current set of loaded kext summaries.
903 */
904 extern OSKextLoadedKextSummaryHeader * gLoadedKextSummaries;
905
906 /*!
907 * @var gLoadedKextSummariesTimestamp
908 *
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.
912 */
913 extern uint64_t gLoadedKextSummariesTimestamp;
914
915 /*!
916 * @function OSKextLoadedKextSummariesUpdated
917 * @abstract Called when gLoadedKextSummaries has been updated.
918 *
919 * @discussion
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.
923 */
924 void OSKextLoadedKextSummariesUpdated(void);
925
926 #ifdef XNU_KERNEL_PRIVATE
927
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);
932
933 #if CONFIG_IMAGEBOOT
934 extern int OSKextGetUUIDForName(const char *, uuid_t);
935 #endif
936
937 #endif /* XNU_KERNEL_PRIVATE */
938
939 __END_DECLS
940
941 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */