]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/OSKextLibPrivate.h
15f85461ddb44787959693e1aaf06ed251bb0389
[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 #include <sys/cdefs.h>
33 #include <uuid/uuid.h>
34
35 __BEGIN_DECLS
36 #ifdef KERNEL
37 #include <libkern/OSTypes.h>
38 #include <mach/kmod.h>
39 #include <mach/vm_types.h>
40 #else
41 #include <CoreFoundation/CoreFoundation.h>
42 #include <System/mach/kmod.h>
43 #endif /* KERNEL */
44 __END_DECLS
45
46 #include <libkern/OSReturn.h>
47
48 __BEGIN_DECLS
49
50 #if PRAGMA_MARK
51 #pragma mark -
52 /********************************************************************/
53 #pragma mark Misc Constants
54 /********************************************************************/
55 #endif
56
57 typedef uint8_t OSKextExcludeLevel;
58 #define kOSKextExcludeNone (0)
59 #define kOSKextExcludeKext (1)
60 #define kOSKextExcludeAll (2)
61
62 #if PRAGMA_MARK
63 #pragma mark -
64 /********************************************************************/
65 #pragma mark Kext/OSBundle Property List Keys
66 /********************************************************************/
67 #endif
68
69 /*!
70 * @define kOSBundleHelperKey
71 * @abstract Used by loginwindow.
72 */
73 #define kOSBundleHelperKey "OSBundleHelper"
74
75 /*!
76 * @define kOSBundleDeveloperOnlyKey
77 * @abstract A boolean value indicating whether the kext should only load on
78 * Developer devices.
79 */
80 #define kOSBundleDeveloperOnlyKey "OSBundleDeveloperOnly"
81
82
83 /*!
84 * @define kAppleSecurityExtensionKey
85 * @abstract A boolean value indicating whether the kext registers
86 * MACF hooks.
87 */
88 #define kAppleSecurityExtensionKey "AppleSecurityExtension"
89
90 /*!
91 * @define kAppleKernelExternalComponentKey
92 * @abstract A boolean value indicating whether the kext is vending kernel
93 * KPI, and needs special loading behavior.
94 */
95 #define kAppleKernelExternalComponentKey "AppleKernelExternalComponent"
96
97 // properties found in the registry root
98 #define kOSKernelCPUTypeKey "OSKernelCPUType"
99 #define kOSKernelCPUSubtypeKey "OSKernelCPUSubtype"
100 #define kOSStartupMkextCRC "OSStartupMkextCRC" /* value is 32-bit OSData */
101 #define kOSPrelinkKextCountKey "OSPrelinkKextCount" /* value is 32-bit OSNumber */
102 #define kOSPrelinkPersonalityCountKey "OSPrelinkPersonalityCount" /* value is 32-bit OSNumber */
103
104 #if PRAGMA_MARK
105 #pragma mark -
106 /********************************************************************/
107 #pragma mark Load Info Keys
108 /********************************************************************/
109 #endif
110 /*********************************************************************
111 * In addition to the keys defined here, you will find:
112 * kCFBundleIdentifierKey
113 * kCFBundleVersionKey
114 * kOSBundleCompatibleVersionKey
115 * kOSBundleIsInterfaceKey
116 * kOSKernelResourceKey
117 *********************************************************************/
118 #define kOSBundleMachOHeadersKey "OSBundleMachOHeaders"
119 #define kOSBundleCPUTypeKey "OSBundleCPUType"
120 #define kOSBundleCPUSubtypeKey "OSBundleCPUSubtype"
121 #define kOSBundlePathKey "OSBundlePath"
122 #define kOSBundleExecutablePathKey "OSBundleExecutablePath"
123 #define kOSBundleUUIDKey "OSBundleUUID"
124 #define kOSBundleStartedKey "OSBundleStarted"
125 #define kOSBundlePrelinkedKey "OSBundlePrelinked"
126 #define kOSBundleLoadTagKey "OSBundleLoadTag"
127 #define kOSBundleLoadAddressKey "OSBundleLoadAddress"
128 #define kOSBundleLoadSizeKey "OSBundleLoadSize"
129 #define kOSBundleWiredSizeKey "OSBundleWiredSize"
130 #define kOSBundleDependenciesKey "OSBundleDependencies"
131 #define kOSBundleRetainCountKey "OSBundleRetainCount"
132
133 /* Dictionary of metaclass info keyed by classname.
134 */
135 #define kOSBundleClassesKey "OSBundleClasses"
136
137 /* These are contained in kOSBundleClassesKey. kOSMetaClassSuperclassNameKey
138 * may be absent (for the root class).
139 */
140 #define kOSMetaClassNameKey "OSMetaClassName"
141 #define kOSMetaClassSuperclassNameKey "OSMetaClassSuperclassName"
142 #define kOSMetaClassTrackingCountKey "OSMetaClassTrackingCount"
143
144 #if PRAGMA_MARK
145 #pragma mark -
146 /********************************************************************/
147 #pragma mark Kext Log Specification
148 /********************************************************************/
149 #endif
150 /*!
151 * @group Kext Log Specification
152 * Logging levels & flags for kernel extensions.
153 * See <code>@link //apple_ref/c/tdef/OSKextLogSpec OSKextLogSpec@/link</code>
154 * for an overview.
155 */
156
157 /*!
158 * @typedef OSKextLogSpec
159 * @abstract Describes what a log message applies to,
160 * or a filter that determines which log messages are displayed.
161 *
162 * @discussion
163 * A kext log specification is a 32-bit value used as a desription of
164 * what a given log message applies to, or as a filter
165 * indicating which log messages are desired and which are not.
166 * A log specification has three parts (described in detail shortly):
167 * <ul>
168 * <li>A <b>level</b> from 0-7 in the lowest-order nibble (0x7).</li>
169 * <li>A flag bit in the lowest-order nibble (0x8) indicating whether
170 * log messages tied to individual kexts are always printed (1)
171 * or printed only if the kext has an
172 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
173 * OSBundleEnableKextLogging@/link set to <code>true</code>.
174 * <li>A set of <b>activity flags</b> in the remaining nibbles (0xFFFFFFF0),
175 * which describe areas of activity related to kernel extensions.</li>
176 * </ul>
177 *
178 * You can specify a log spec to most of the kext tools with the -v option
179 * and a hex number (rather than the escalating decimal levels 0-6).
180 * You can also specify a log spec to the kernel with the "kextlog" boot arg
181 * or "debug.kextlog" sysctl.
182 *
183 * <b>Log Levels</b>
184 *
185 * The log level spans a range from silent (no log messages)
186 * to debuging information:
187 *
188 * <ol start="0">
189 * <li>Silent - Not applicable to messages; as a filter, do not print any log messages.</li>
190 * <li>Errors - Log message is an error.
191 * <li>Warnings - Log message is a warning.
192 * <li>Basic information - Log message is basic success/failure.</li>
193 * <li>Progress - Provides high-level information about stages in processing.</li>
194 * <li>Step - Provides low-level information about complex operations,
195 * typically about individual kexts.</li>
196 * <li>Detail - Provides very low-level information about parts of kexts,
197 * including individual Libkern classes and operations on bundle files.</li>
198 * <li>Debug - Very verbose logging about internal activities.</li>
199 * </ol>
200 *
201 * Log messages at
202 * <code>@link kOSKextLogErrorLevel kOSKextLogErrorLevel@/link</code> or
203 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
204 * ignore activity flags and the
205 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
206 * OSBundleEnableKextLogging@/link property;
207 * that is, only the filter level is checked for messages at these levels.
208 * Log messages at levels above
209 * <code>@link kOSKextLogWarningLevel kOSKextLogWarningLevel@/link</code>
210 * are filtered according both to the activity flags in the current filter
211 * and to whether the log message is associated with a kext or not.
212 * Normally log messages associated with kexts are not printed
213 * unless the kext has a
214 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
215 * OSBundleEnableKextLogging@/link property set to <code>true</code>.
216 * If you set the high-order bit of the log level (that is, add 8 to the level),
217 * then all kext-specific log messages matching the activity flags are printed.
218 * This can be very verbose.
219 *
220 * <b>Activity Flags</b>
221 *
222 * Each flag governs a category of activity,
223 * such as loading, IPC, or archives; by combining them with bitwise OR,
224 * you can choose which messages you wish to see (or when logging messages,
225 * which bit flags select your message).
226 *
227 * <b>Byte 1:</b> <code>0xF0</code> - Basic activities
228 * (<code>@link kOSKextLogGeneralFlag kOSKextLogGeneralFlag@/link</code>,
229 * <code>@link kOSKextLogLoadFlag kOSKextLogLoadFlag@/link</code>, and
230 * <code>@link kOSKextLogArchiveFlag kOSKextLogArchiveFlag@/link</code>).
231 *
232 * <b>Byte 2:</b> <code>0xF00</code> - Reserved.
233 *
234 * <b>Byte 4:</b> <code>0xF000</code> - Kext diagnostics
235 * (<code>@link kOSKextLogValidationFlag kOSKextLogValidationFlag@/link</code>,
236 * <code>@link kOSKextLogAuthenticationFlag kOSKextLogAuthenticationFlag@/link</code>, and
237 * <code>@link kOSKextLogDependenciesFlag kOSKextLogDependenciesFlag@/link</code>).
238 *
239 * <b>Byte 5:</b> <code>0xF00000</code> - Kext access & bookkeeping
240 * (<code>@link kOSKextLogDirectoryScanFlag kOSKextLogDirectoryScanFlag@/link</code>,
241 * <code>@link kOSKextLogFileAccessFlag kOSKextLogFileAccessFlag@/link</code>,
242 * <code>@link kOSKextLogKextBookkeepingFlag kOSKextLogKextBookkeepingFlag@/link </code>).
243 *
244 * <b>Byte 6:</b> <code>0xF000000</code> - Linking & patching
245 * (<code>@link kOSKextLogLinkFlag kOSKextLogLinkFlag@/link</code> and
246 * <code>@link kOSKextLogPatchFlag kOSKextLogPatchFlag@/link</code>).
247 *
248 * <b>Byte 7:</b> <code>0xF0000000</code> - Reserved.
249 */
250 typedef uint32_t OSKextLogSpec;
251
252 #if PRAGMA_MARK
253 /********************************************************************/
254 #pragma mark Masks
255 /********************************************************************/
256 #endif
257 /*!
258 * @define kOSKextLogLevelMask
259 * @abstract Masks the bottom 3 bits of an
260 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code> to extract
261 * the raw level.
262 */
263 #define kOSKextLogLevelMask ((OSKextLogSpec) 0x00000007)
264
265 /*!
266 * @define kOSKextLogKextOrGlobalMask
267 * @abstract Determines whether per-kext log messages are output.
268 *
269 * @discussion
270 * In filter specifications, if unset (the usual default),
271 * then log messages associated with a kext are only output
272 * if the kext has an
273 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
274 * OSBundleEnableKextLogging@/link
275 * property set to <code>true</code>.
276 * If set, then all log messages associated with kexts
277 * are output.
278 *
279 * In message specifications, if set it indicates that the message is either
280 * not associated with a kext, or is associated with a kext that has an
281 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
282 * OSBundleEnableKextLogging@/link
283 * property set to <code>true</code>.
284 */
285 #define kOSKextLogKextOrGlobalMask ((OSKextLogSpec) 0x00000008)
286
287
288 /*!
289 * @define kOSKextLogFlagsMask
290 * @abstract Masks the flag bits of an
291 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
292 */
293 #define kOSKextLogFlagsMask ((OSKextLogSpec) 0x0ffffff0)
294
295 /*!
296 * @define kOSKextLogFlagsMask
297 * @abstract Masks the flag bits of an
298 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>
299 * to which command-line <code>-v</code> levels apply.
300 */
301 #define kOSKextLogVerboseFlagsMask ((OSKextLogSpec) 0x00000ff0)
302
303 /*!
304 * @define kOSKextLogConfigMask
305 * @abstract Masks the config bits of an
306 * <code>@link OSKextLogSpec OSKextLogSpec@/link</code>.
307 */
308 #define kOSKextLogConfigMask ((OSKextLogSpec) 0xf0000000)
309
310 #if PRAGMA_MARK
311 /********************************************************************/
312 #pragma mark 0xF - Log Level
313 /********************************************************************/
314 #endif
315
316 /*!
317 * @define kOSKextLogExplicitLevel
318 * @abstract Used when logging a message to overrides the current log filter,
319 * even if it's set to silent for log messages.
320 * This is essentially a pass-through for
321 * unconditional print messages to go
322 * through the logging engine.
323 */
324 #define kOSKextLogExplicitLevel ((OSKextLogSpec) 0x0)
325
326 /*!
327 * @define kOSKextLogErrorLevel
328 * @abstract Log messages concerning error conditions in any category.
329 */
330 #define kOSKextLogErrorLevel ((OSKextLogSpec) 0x1)
331
332
333 /*!
334 * @define kOSKextLogWarningLevel
335 * @abstract Log messages concerning warning conditions in any category,
336 * which indicate potential error conditions,
337 * and notices, which may explain unexpected but correct behavior.
338 */
339 #define kOSKextLogWarningLevel ((OSKextLogSpec) 0x2)
340
341
342 /*!
343 * @define kOSKextLogBasicLevel
344 * @abstract Log messages concerning top-level outcome in any category
345 * (kext load/unload, kext cache creation/extration w/# kexts).
346 */
347 #define kOSKextLogBasicLevel ((OSKextLogSpec) 0x3)
348
349
350 /*!
351 * @define kOSKextLogProgressLevel
352 * @abstract Log messages concerning high-level progress in any category,
353 * such as sending a load request to the kernel,
354 * allocation/link/map/start (load operation),
355 * stop/unmap (unload operation), kext added/extracted (archive).
356 */
357 #define kOSKextLogProgressLevel ((OSKextLogSpec) 0x4)
358
359
360 /*!
361 * @define kOSKextLogStepLevel
362 * @abstract Log messages concerning major steps in any category,
363 * such as sending personalities to the IOCatalogue when loading,
364 * detailed IPC with the kernel, or filtering of kexts for an archive.
365 */
366 #define kOSKextLogStepLevel ((OSKextLogSpec) 0x5)
367
368
369 /*!
370 * @define kOSKextLogDetailLevel
371 * @abstract Log messages concerning specific details in any category,
372 * such as classes being registered/unregistered or
373 * operations on indivdual files in a kext.
374 */
375 #define kOSKextLogDetailLevel ((OSKextLogSpec) 0x6)
376
377
378 /*!
379 * @define kOSKextLogDebugLevel
380 * @abstract Log messages concerning very low-level actions that are
381 * useful mainly for debugging the kext system itself.
382 */
383 #define kOSKextLogDebugLevel ((OSKextLogSpec) 0x7)
384
385
386 #if PRAGMA_MARK
387 /********************************************************************/
388 #pragma mark 0xF0 - General Activity, Load, Kernel IPC, Personalities
389 /********************************************************************/
390 #endif
391
392 /*!
393 * @define kOSKextLogGeneralFlag
394 * @abstract Log messages about general activity in the kext system.
395 */
396 #define kOSKextLogGeneralFlag ((OSKextLogSpec) 0x10)
397
398 /*!
399 * @define kOSKextLogLoadFlag
400 * @abstract Log messages regarding kernel extension load, start/stop, or unload activity
401 * in the kernel.
402 */
403 #define kOSKextLogLoadFlag ((OSKextLogSpec) 0x20)
404
405 /*!
406 * @define kOSKextLogIPCFlag
407 * @abstract Log messages about any interaction between kernel and user space
408 * regarding kernel extensions.
409 */
410 #define kOSKextLogIPCFlag ((OSKextLogSpec) 0x40)
411
412 /*!
413 * @define kOSKextLogArchiveFlag
414 * @abstract Log messages about creating or processing a kext startup cache file
415 * (mkext or prelinked kernel).
416 */
417 #define kOSKextLogArchiveFlag ((OSKextLogSpec) 0x80)
418
419
420 #if PRAGMA_MARK
421 /********************************************************************/
422 #pragma mark 0xF00 - Reserved Verbose Area
423 /********************************************************************/
424 #endif
425 // reserved slot for group ((OSKextLogSpec) 0x100)
426 // reserved slot for group ((OSKextLogSpec) 0x200)
427 // reserved slot for group ((OSKextLogSpec) 0x400)
428 // reserved slot for group ((OSKextLogSpec) 0x800)
429
430 #if PRAGMA_MARK
431 /********************************************************************/
432 #pragma mark 0xF000 - Kext diagnostic activity
433 /********************************************************************/
434 #endif
435
436 /*!
437 * @define kOSKextLogValidationFlag
438 * @abstract Log messages when validating kernel extensions.
439 */
440 #define kOSKextLogValidationFlag ((OSKextLogSpec) 0x1000)
441
442 /*!
443 * @define kOSKextLogAuthenticationFlag
444 * @abstract Log messages when autnenticating kernel extension files.
445 * Irrelevant in the kernel.
446 */
447 #define kOSKextLogAuthenticationFlag ((OSKextLogSpec) 0x2000)
448
449 /*!
450 * @define kOSKextLogDependenciesFlag
451 * @abstract Log messages when resolving dependencies for a kernel extension.
452 */
453 #define kOSKextLogDependenciesFlag ((OSKextLogSpec) 0x4000)
454
455 // reserved slot for group ((OSKextLogSpec) 0x8000)
456
457 #if PRAGMA_MARK
458 /********************************************************************/
459 #pragma mark 0xF0000 - Archives, caches, directory scan, file access
460 /********************************************************************/
461 #endif
462
463 /*!
464 * @define kOSKextLogDirectoryScanFlag
465 * @abstract Log messages when scanning directories for kernel extensions.
466 * In the kernel logs every booter kext entry processed.
467 */
468 #define kOSKextLogDirectoryScanFlag ((OSKextLogSpec) 0x10000)
469
470 /*!
471 * @define kOSKextLogFileAccessFlag
472 * @abstract Log messages when performing any filesystem access (very verbose).
473 * Irrelevant in the kernel.
474 */
475 #define kOSKextLogFileAccessFlag ((OSKextLogSpec) 0x20000)
476
477 /*!
478 * @define kOSKextLogKextBookkeepingFlag
479 * @abstract Log messages about internal tracking of kexts. Can be very verbose.
480 */
481 #define kOSKextLogKextBookkeepingFlag ((OSKextLogSpec) 0x40000)
482
483 // reserved slot for group ((OSKextLogSpec) 0x80000)
484
485 #if PRAGMA_MARK
486 /********************************************************************/
487 #pragma mark 0xF00000 - Linking & Patching
488 /********************************************************************/
489 #endif
490
491 /*!
492 * @define kOSKextLogLinkFlag
493 * @abstract Log messages about linking.
494 */
495 #define kOSKextLogLinkFlag ((OSKextLogSpec) 0x100000)
496
497 /*!
498 * @define kOSKextLogPatchFlag
499 * @abstract Log messages about patching.
500 */
501 #define kOSKextLogPatchFlag ((OSKextLogSpec) 0x200000)
502
503 // reserved slot for group ((OSKextLogSpec) 0x400000)
504 // reserved slot for group ((OSKextLogSpec) 0x800000)
505
506 #if PRAGMA_MARK
507 /********************************************************************/
508 #pragma mark 0xF000000 - Reserved
509 /********************************************************************/
510 #endif
511
512 // reserved slot for grouping ((OSKextLogSpec) 0x1000000)
513 // reserved slot for grouping ((OSKextLogSpec) 0x2000000)
514 // reserved slot for grouping ((OSKextLogSpec) 0x4000000)
515 // reserved slot for grouping ((OSKextLogSpec) 0x8000000)
516
517
518 #if PRAGMA_MARK
519 /********************************************************************/
520 #pragma mark 0xF0000000 - Config Flags
521 /********************************************************************/
522 #endif
523
524 // reserved slot for grouping ((OSKextLogSpec) 0x10000000)
525 // reserved slot for grouping ((OSKextLogSpec) 0x20000000)
526 // reserved slot for grouping ((OSKextLogSpec) 0x40000000)
527
528 #if PRAGMA_MARK
529 /********************************************************************/
530 #pragma mark Predefined Specifications
531 /********************************************************************/
532 #endif
533
534 /*!
535 * @define kOSKextLogSilentFilter
536 * @abstract For use in filter specs:
537 * Ignore all log messages with a log level greater than
538 * <code>@link kOSKextLogExplicitLevel kOSKextLogExplicitLevel@/link</code>.
539 */
540 #define kOSKextLogSilentFilter ((OSKextLogSpec) 0x0)
541
542 /*!
543 * @define kOSKextLogShowAllFilter
544 * @abstract For use in filter specs:
545 * Print all log messages not associated with a kext or
546 * associated with a kext that has
547 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
548 * OSBundleEnableKextLogging@/link
549 * set to <code>true</code>.
550 */
551 #define kOSKextLogShowAllFilter ((OSKextLogSpec) 0x0ffffff7)
552
553 /*!
554 * @define kOSKextLogShowAllKextsFilter
555 * @abstract For use in filter specs:
556 * Print all log messages has
557 * @link //apple_ref/c/macro/kOSBundleEnableKextLoggingKey
558 * OSBundleEnableKextLogging@/link
559 * set to <code>true</code>.
560 */
561 #define kOSKextLogShowAllKextsFilter ((OSKextLogSpec) \
562 (kOSKextLogShowAllFilter | \
563 kOSKextLogKextOrGlobalMask))
564
565 #if PRAGMA_MARK
566 #pragma mark -
567 /********************************************************************/
568 #pragma mark Kext Version String Processing
569 /********************************************************************/
570 #endif
571 /*!
572 * @group Kext Version String Processing
573 * Functions for working with kext versions and compatible versions.
574 */
575
576 /*!
577 * @typedef OSKextVersion
578 * @abstract An encoded kext version that can be compared arithmetically.
579 *
580 * @discussion
581 * A value of zero (<code>@link kOSKextVersionUndefined kOSKextVersionUndefined@/link</code>)
582 * is <i>not</i> equivalent to a version string of "0.0",
583 * and typically means there is no version specified
584 * (for example, that there is no CFBundleVersion property at all).
585 * Values below zero are invalid.
586 *
587 * The encoding used is subject to change,
588 * and should never be saved to permanent storage.
589 * Always use proper version strings in files and interprocess communication.
590 */
591 typedef int64_t OSKextVersion;
592
593 /*!
594 * @define kOSKextVersionMaxLength
595 * @abstract The length of a string buffer
596 * guaranteed to be able to hold a kext version.
597 *
598 * @discussion
599 * Kext versions use an extended Mac OS 'vers' format with double the number
600 * of digits before the build stage: ####.##.##s{1-255} where 's'
601 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
602 */
603 #define kOSKextVersionMaxLength (20)
604 // with a few bytes to spare including a nul byte
605 // xx-review: Should we make this much bigger in case we ever need longer strings?
606
607 /*!
608 * @define kOSKextVersionUndefined
609 * @abstract The undefined version.
610 *
611 * @discussion
612 * This value of <code>@link OSKextVersion OSKextVersion@/link</code> represents the
613 * lack of a version
614 * (for example, that there is no CFBundleVersion property at all).
615 */
616 #define kOSKextVersionUndefined (0)
617
618 /*!
619 * @function OSKextParseVersionString
620 *
621 * @abstract
622 * Parses a kext version string into an <code>@link OSKextVersion OSKextVersion@/link</code>.
623 *
624 * @param versionString The kext version string to parse.
625 *
626 * @result
627 * An encoded kext version that can be compared numerically
628 * against other encoded kext versions,
629 * <0 if <code>versionString</code> is <code>NULL</code>, empty,
630 * or cannot be parsed.
631 *
632 * @discussion
633 * Kext versions use an extended Mac OS 'vers' format with double the number
634 * of digits before the build stage: ####.##.##s{1-255} where 's'
635 * is a build stage 'd', 'a', 'b', 'f' or 'fc'.
636 */
637 OSKextVersion OSKextParseVersionString(const char * versionString);
638
639
640 /*!
641 * @function OSKextVersionGetString
642 *
643 * @abstract
644 * Formats an encoded <code>@link OSKextVersion OSKextVersion@/link</code> into a string
645 * representation.
646 *
647 * @param aVersion
648 * The encoded version to format.
649 * @param buffer
650 * A C string buffer of at least
651 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code> bytes.
652 * @param bufferSize The size in bytes of <code>buffer</code>.
653 *
654 * @result
655 * <code>TRUE</code> if the encoded version is formatted successfully.
656 * <code>FALSE</code> if <code>buffer</code> is <code>NULL</code> or
657 * <code>bufferSize</code> is less than
658 * <code>@link kOSKextVersionMaxLength kOSKextVersionMaxLength@/link</code>.
659 *
660 * @discussion
661 * The return value strictly indicates whether <code>buffer</code>
662 * is large enough to hold the result.
663 * If <code>aVersion</code> is 0, the resulting string is "(missing)".
664 * If <code>aVersion</code> is less than 0
665 * or is not a valid kext version encoding,
666 * the resulting string is "(invalid)".
667 */
668 Boolean OSKextVersionGetString(
669 OSKextVersion aVersion,
670 char * buffer,
671 uint32_t bufferSize);
672
673
674 #ifdef KERNEL
675
676
677 #if PRAGMA_MARK
678 /********************************************************************/
679 #pragma mark -
680 #pragma mark Weak linking
681 /********************************************************************/
682 #endif
683 #ifdef XNU_KERNEL_PRIVATE
684 void kext_weak_symbol_referenced(void);
685 #endif /* XNU_KERNEL_PRIVATE */
686
687 #if PRAGMA_MARK
688 #pragma mark -
689 /********************************************************************/
690 #pragma mark Miscellaneous Kernel-Only Kext Functions
691 /********************************************************************/
692 #endif
693
694 /*!
695 * @function kext_get_vm_map
696 * @abstract Returns the vm_map from which the kext was allocated.
697 *
698 * @param info The kmod_info_t structure of the kext.
699 * @result The vm_map from which the kext was allocated. This function
700 * cannot return <code>NULL</code>.
701 */
702 vm_map_t kext_get_vm_map(kmod_info_t * info);
703
704 #ifdef XNU_KERNEL_PRIVATE
705
706 #if CONFIG_DTRACE
707 /*!
708 * @function OSKextRegisterKextsWithDTrace
709 * @abstract
710 * DTrace calls this once when it has started up so that the kext system
711 * will register any already-loaded kexts with it.
712 */
713 void OSKextRegisterKextsWithDTrace(void);
714
715 #endif /* CONFIG_DTRACE */
716
717 /*!
718 * @function kext_dump_panic_lists
719 * @abstract Prints compacted lists of last unloaded & all loaded kexts
720 * during a panic.
721 *
722 * @param printf_func The printf-style function to use for output.
723 */
724 void kext_dump_panic_lists(int (*printf_func)(const char *fmt, ...));
725
726 #endif /* XNU_KERNEL_PRIVATE */
727
728 #ifdef XNU_KERNEL_PRIVATE
729
730 #if PRAGMA_MARK
731 #pragma mark -
732 /********************************************************************/
733 #pragma mark Kext Loading C Functions
734 /********************************************************************/
735 #endif
736 /*!
737 * @function OSKextGetLoadTagForBundleIdentifier
738 * @abstract Look up the load tag for a kext.
739 *
740 * @param kextIdentifier The bundle identifier of the kext to look up.
741 * @result
742 * The load tag of the requested kext, or
743 * <code>@link //apple_ref/c/macro/kOSKextInvalidLoadTag kOSKextInvalidLoadTag@/link</code>
744 * if the kext was not found.
745 *
746 * @discussion
747 * A load tag uniquely identifies a loaded kext.
748 * It can be found as the <code>id</code> field of a loaded kext's
749 * <code>kmod_info_t</code> struct.
750 *
751 * Note that a load tag represents a specific loaded instance of a kext.
752 * If that kext is unloaded, the load tag is no longer a valid reference.
753 * If the same kext is later reloaded, it will have a new load tag.
754 *
755 * You can use the load tag to adjust a kext's reference count
756 * via
757 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
758 * OSKextRetainKextWithLoadTag@/link</code>
759 * and
760 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
761 * OSKextReleaseKextWithLoadTag@/link</code>,
762 * so that the kext is automatically unloaded when no references remain,
763 * or to unload the kext immediately
764 * with <code>@link //apple_ref/c/func/OSKextUnloadKextWithLoadTag OSKextUnloadKextWithLoadTag@/link</code>.
765 *
766 * Those functions are intended for use with non-IOKit kexts
767 * (specifically, kexts that define no subclasses of
768 * <code>@link //apple_ref/doc/class/IOServiceIOService@/link</code>).
769 * Pure IOKit kexts are managed via instance counts
770 * of their libkern C++ object classes;
771 * using those functions on them will only interfere with that mechanism.
772 * If you have a hybrid kext with both IOService subclasses and non-IOKit code,
773 * however, you may want to use reference counting for the non-IOKit portions:
774 * that way the kext will only unload automaticaly
775 * when there are no C++ objects and the kext reference count is zero.
776 */
777 uint32_t OSKextGetLoadTagForBundleIdentifier(
778 const char * kextIdentifier);
779
780
781 /*!
782 * @function OSKextUnloadKextWithLoadTag
783 * @abstract Stop and unload a kext based on its load tag.
784 *
785 * @param loadTag The load tag of the kext to unload.
786 * @result
787 * <code>@link //apple_ref/c/macro/kOSReturnSuccess kOSReturnSuccess@/link</code>
788 * if the kext was found and unloaded.
789 * <code>@link //apple_ref/c/macro/kOSKextReturnNotFound
790 * kOSKextReturnNotFound@/link</code>
791 * if the kext was not found.
792 * <code>@link //apple_ref/c/macro/kOSKextReturnInUse
793 * kOSKextReturnInUse@/link</code>
794 * if the kext has outstanding references
795 * or if there are instances of its libkern C++ subclasses.
796 * Other return values indicate a failure to unload the kext,
797 * typically because the module stop routine failed.
798 *
799 * @discussion
800 * A panic will occur if a kext calls this function to unload itself.
801 * The safest way for a kext to unload itself is to call
802 * <code>@link //apple_ref/c/func/OSKextRetainKextWithLoadTag
803 * OSKextRetainKextWithLoadTag@/link</code>
804 * with its own load tag
805 * (the <code>id</code> field of its <code>kmod_info_t</code> struct),
806 * followed by
807 * <code>@link //apple_ref/c/func/OSKextReleaseKextWithLoadTag
808 * OSKextReleaseKextWithLoadTag@/link</code>;
809 * this will schedule the kext for unload on a separate thread.
810 *
811 * This function can be used when reference-based autounloading is not
812 * appropriate.
813 * If a kernel system or kext is already monitoring
814 * the need for a kext,
815 * it can simply call this function when it's known that the kext is not needed.
816 */
817 OSReturn OSKextUnloadKextWithLoadTag(uint32_t loadTag);
818
819 #endif /* XNU_KERNEL_PRIVATE */
820
821 #endif /* KERNEL */
822
823 #if PRAGMA_MARK
824 #pragma mark -
825 /********************************************************************/
826 #pragma mark Loaded Kext Summary
827 /********************************************************************/
828 #endif
829
830 /*!
831 * @define kOSKextLoadedKextSummaryVersion
832 * @abstract The current version of the loaded kext summary headers.
833 */
834 #define kOSKextLoadedKextSummaryVersion 2
835
836 /*!
837 * @typedef OSKextLoadedKextSummary
838 * @abstract A structure that describes a loaded kext.
839 *
840 * @field name The kext's bundle identifier.
841 * @field uuid The kext's UUID;
842 * @field address The kext's load address.
843 * @field size The kext's load size.
844 * @field version The binary format (OSKextVersion) version of the kext.
845 * @field loadTag The kext's load tag.
846 * @field flags Internal tracking flags.
847 * @field reference_list who this refs (links on).
848 *
849 * @discussion
850 * The OSKextLoadedKextSummary structure contains a basic set of information
851 * about the kext to facilitate kext debugging and panic debug log output.
852 */
853 typedef struct _loaded_kext_summary {
854 char name[KMOD_MAX_NAME];
855 uuid_t uuid;
856 uint64_t address;
857 uint64_t size;
858 uint64_t version;
859 uint32_t loadTag;
860 uint32_t flags;
861 uint64_t reference_list;
862 } OSKextLoadedKextSummary;
863
864 /*!
865 * @typedef OSKextLoadedKextSummaryHeader
866 * @abstract A structure that describes the set of loaded kext summaries.
867 *
868 * @field version The version of the loaded kext summary structures.
869 * @field entry_size The size of each entry in summaries.
870 * @field numSummaries The number of OSKextLoadedKextSummary structures
871 * following the header.
872 * @field summaries A convenience pointer to the array of summaries following
873 * the header.
874 *
875 * @discussion
876 * The OSKextLoadedKextSummaryHeader describes the set of loaded kext summaries
877 * available for use by the debugger or panic log routine.
878 * The array of summaries contains one OSKextLoadedKextSummary for every kext
879 * that declares an executable and is not an interface to the kernel.
880 */
881 typedef struct _loaded_kext_summary_header {
882 uint32_t version;
883 uint32_t entry_size;
884 uint32_t numSummaries;
885 uint32_t reserved; /* explicit alignment for gdb */
886 OSKextLoadedKextSummary summaries[0];
887 } OSKextLoadedKextSummaryHeader;
888
889 /*!
890 * @var gLoadedKextSummaries
891 * @abstract The global pointer to the current set of loaded kext summaries.
892 */
893 extern OSKextLoadedKextSummaryHeader * gLoadedKextSummaries;
894
895 /*!
896 * @function OSKextLoadedKextSummariesUpdated
897 * @abstract Called when gLoadedKextSummaries has been updated.
898 *
899 * @discussion
900 * gLoadedKextSummaries is updated when a kext is loaded or unloaded.
901 * When the update is complete, OSKextLoadedKextSummariesUpdated is called.
902 * gdb can set a breakpoint on this function to detect kext loads and unloads.
903 */
904 void OSKextLoadedKextSummariesUpdated(void);
905
906 __END_DECLS
907
908 #endif /* ! _LIBKERN_OSKEXTLIBPRIVATE_H */