-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathOSKext.h
2752 lines (2621 loc) · 99.1 KB
/
OSKext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2008 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#ifndef __OSKEXT_H__
#define __OSKEXT_H__
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <CoreFoundation/CoreFoundation.h>
//#include <System/libkern/OSReturn.h>
//#include <System/libkern/OSKextLib.h>
//#include <System/libkern/OSKextLibPrivate.h>
#include <mach/mach.h>
#include <mach-o/arch.h>
// xxx - should I use "Clear" everywhere I use "Flush"
/*!
* @header
* @ignore CF_EXPORT
* @ignore
*
* The OSKext library provides a comprehensive interface for creating,
* examining, and loading kernel extensions (kexts).
*
* <b>NOTICE:</b> This library is neither thread-safe nor garbage-collection
* safe. You must use your own locking with threads sharing access to OSKext.
* You can not use this library in an application with garbage collection.
*/
#pragma mark Types and Constants
/*******************************************************************************
* Types and Constants
*******************************************************************************/
/*!
* @typedef OSKextRef
* @abstract A reference to a kernel extension object.
*
* @discussion
* The OSKextRef type refers to a KXKext object, which represents a kernel
* extension bundle on disk, from an archive, or loaded into the kernel.
* OSKext is an opaque type that defines the characteristics and behavior of
* OSKext objects.
*
* The kernel counterpart of OSKext is the OSKext libkern C++ class.
*/
typedef struct __OSKext * OSKextRef
;
#define kOSKextBundleExtension "kext"
#define kOSKextMkextExtension "mkext"
/*!
* @typedef OSKextDiagnosticsFlags
* @constant kOSKextDiagnosticsFlagAll
* @constant kOSKextDiagnosticsFlagValidation
* @constant kOSKextDiagnosticsFlagAuthentication
* @constant kOSKextDiagnosticsFlagDependencies
* @constant kOSKextDiagnosticsFlagWarnings
*/
enum {
kOSKextDiagnosticsFlagNone = (UInt32) 0x0U,
kOSKextDiagnosticsFlagValidation = (UInt32) 0x1U,
kOSKextDiagnosticsFlagAuthentication = (UInt32) 0x2U,
kOSKextDiagnosticsFlagDependencies = (UInt32) 0x4U,
kOSKextDiagnosticsFlagWarnings = (UInt32) 0x8U,
kOSKextDiagnosticsFlagAll = (UInt32)0xFFFFFFFFU,
};
typedef UInt32 OSKextDiagnosticsFlags;
typedef UInt64 OSKextLogFlags;
typedef SInt64 OSKextVersion;
typedef kern_return_t OSReturn;
typedef uint8_t OSKextExcludeLevel;
#define kOSKextExcludeNone (0)
#define kOSKextExcludeKext (1)
#define kOSKextExcludeAll (2)
/* Top-level keys for diagnostics dicts. See @link OSKextCopyDiagnostics@/link.
*/
// xxx - not sure we need to include these, but it's convenient
const CFStringRef kOSKextDiagnosticsValidationKey;
const CFStringRef kOSKextDiagnosticsAuthenticationKey;
const CFStringRef kOSKextDiagnosticsLinkLoadKey;
const CFStringRef kOSKextDiagnosticsDependenciesKey;
const CFStringRef kOSKextDiagnosticsWarningsKey;
#pragma mark Basic CF Functions
/*********************************************************************
* Basic CF Functions
*********************************************************************/
/*!
* @function OSKextGetTypeID
* @abstract Returns the type identifier for the OSKext opaque type.
*
* @result The type identifier for the OSKext opaque type.
*/
CF_EXPORT CFTypeID
OSKextGetTypeID(void)
;
#pragma mark Module Configuration
/*********************************************************************
* Module Configuration
*********************************************************************/
/*!
* @function OSKextSetArchitecture
* @abstract Sets the architecture used for operations on kexts.
*
* @param anArch
* An <code>NXArchInfo</code> pointer with cputype/subtype or name set.
* Ownership remains with the caller.
* Pass <code>NULL</code> to set the architecture to taht of the running kernel.
*
* @result
* <code>true</code> if the architecture was set as desired,
* <code>false</code> if <code>anArch</code> was not found;
* if <code>false</code>, the architecture will now be that
* of the running kernel.
* xxx - should it just be left unchanged instead?
*
* @discussion
* The kext library uses this architecture for any architecture-specific
* operation, such as property lookups
* (see @link OSKextGetValueForInfoDictionaryKey@/link),
* dependency resolution, executable access during validation and linking.
* The kext architecture is initially that of the running kernel (not of
* the user-space process).
*
* This function looks up the system <code>NXArchInfo</code> struct
* for the struct passed in, first using the cputype/subtype, and if that fails,
* the name. You can therefore use this function to set the architecture
* from an architecture name alone by passing an <code>NXArchInfo</code> struct
* with the desired name,
* but the cputype/subtype set to CPU_TYPE_ANY and CPU_SUBTYPE_ANY.
*
* Changing the kext architecture causes all kexts to flush their load info
* and dependencies with @link OSKextFlushLoadInfo@/link.
*/
// xxx - should this also have a flushDependenciesFlag?
CF_EXPORT Boolean
OSKextSetArchitecture(const NXArchInfo * archInfo)
;
/*!
* @function OSKextGetArchitecture
* @abstract Gets the architecutre used for operations on kexts.
*
* @result
* The architecture used for operations on kexts.
* The caller does not own the returned pointer and should not free it.
*
* @discussion
* The kext library uses this architecture for any architecture-specific
* operation, such as property lookups
* (see @link OSKextGetValueForInfoDictionaryKey@/link),
* dependency resolution, executable access during validation and linking.
* The kext architecture is initially that of the running kernel (not of
* the user-space process).
*/
CF_EXPORT const NXArchInfo *
OSKextGetArchitecture(void)
;
/*!
* @function OSKextGetRunningKernelArchitecture
* @abstract Returns the architecture of the running kernel.
*
* @result
* The architecture of the running kernel.
* The caller does not own the returned pointer and should not free it.
*
* @discussion
* This function consults the kernel task and returns a pointer to the
* <code>NXArchInfo</code> struct representing its architecture.
* The running kernel's architecture does not necessarily match that
* of user space tasks (for example, a 32-bit user space task could be
* running with a 64-bit kernel, or vice-versa).
*/
CF_EXPORT const NXArchInfo *
OSKextGetRunningKernelArchitecture(void)
;
/*! @function OSKextGetLogFlags
@param kext The kext to get the log flags. Pass NULL to get the global flag. */
CF_EXPORT OSKextLogFlags OSKextGetLogFlags(OSKextRef kext);
/*! @function OSKextSetLogFlags */
CF_EXPORT void OSKextSetLogFlags(OSKextRef kext, OSKextLogFlags logFlags);
/*!
* @typedef OSKextLogFunction
* @abstract
* Prototype of a callback function used to log messages from the library.
*
* @param format A printf(3) style format string.
*
* @discussion
* The default log function simply prints to <code>stderr</code
* if <code>msgLogSpec</code> has any bits set.
* If you set the log function to <code>NULL</code>,
* no log messages will be printed.
*
* Log messages have no trailing newline, to accommodate system log facilities.
*/
/* xxx - no CF_EXPORT, compiler dies */
typedef void (*OSKextLogFunction)(
OSKextLogFlags flags,
const char * format,
...)
;
/*!
* @function OSKextSetLogFunction
* @abstract Sets the function called to log messages.
*
* @param funct The log function to set.
*
* @discussion
* The default log function simply prints to stderr. If you set the
* log function to <code>NULL</code>, no log messages will be printed.
*
* Log messages have no trailing newline, to accommodate system log facilities.
*/
CF_EXPORT void
OSKextSetLogFunction(OSKextLogFunction func)
;
/*!
* @function OSKextSetSimulatedSafeBoot
* @abstract Sets whether safe boot mode is simulated in the library.
*
* @param flag <code>true</code> to simulate safe boot mode,
* <code>false</code> to not simulate.
*
* @discussion
* Kexts without a valid OSBundleRequired property are not allowed to load
* by the kernel when the system has started in safe boot mode.
* If you turn on simulated safe boot, the kext library can
* catch non-loadable kexts and present appropriate diagnostics.
*/
CF_EXPORT void
OSKextSetSimulatedSafeBoot(Boolean flag)
;
/*!
* @function OSKextGetSimulatedSafeBoot
* @abstract Returns whether safe boot mode is simulated in the library.
*
* @result
* <code>true</code> if safe boot mode is being simulated,
* <code>false</code> if not.
*
* @discussion
* Kexts without a valid OSBundleRequired property are not allowed to load
* by the kernel when the system has started in safe boot mode.
* When simulated safe boot is on, the kext library can
* catch non-loadable kexts and present appropriate diagnostics.
*/
CF_EXPORT Boolean
OSKextGetSimulatedSafeBoot(void)
;
/*!
* @function OSKextGetActualSafeBoot
* @abstract Returns whether safe boot mode is active.
*
* @result
* <code>true</code> if safe boot mode is active,
* <code>false</code> if not.
*
* @discussion
* Kexts without a valid OSBundleRequired property are not allowed to load
* by the kernel when the system has started in safe boot mode.
* The kext library ignores actual safe boot mode, leaving decisions
* regarding safe boot to the kernel.
* If you want to analyze kexts in safe boot mode using the library,
* call @link OSKextSetSimulatedSafeBoot@/link.
*/
// xxx - we used to disallow kexts w/debug-log flags in safe boot, too
CF_EXPORT Boolean
OSKextGetActualSafeBoot(void)
;
/*!
* @function OSKextGetSystemExtensionsFolderURLs
* @abstract Returns the standard system extension folder URLs.
*
* @result
* An array containing the standard system extension folder URLs.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* To open all the kexts normally considered for loading by the system,
* pass the return value of this function to
* @link OSKextCreateKextsFromURLs@/link.
*/
CF_EXPORT CFArrayRef
OSKextGetSystemExtensionsFolderURLs(void)
;
/*!
* @function OSKextSetRecordsDiagnostics
* @abstract Sets whether kexts record diagnostic information.
*
* @param flags Indicates which diagnostics to record.
*
* @discussion
* The kext library can record diagnostic information for kexts as
* problems are encountered. These diagnostics can consume a fair
* amount of memory, and should be generated only when desired.
* Recording of diagnostics is set to
* @link kOSKextDiagnosticsFlagNone@/link by default.
* Use this function to turn diagnostics recording off (or back on)
* for particular diagnostic types.
*
* Turning on diagnostics does not calculate or recalculate
* diagnostics. Call the various functions that operate on kexts
* to begin accumulating diagnostics.
*
* Turning diagnostics off does not clear any existing diagnostics.
* Use @link OSKextFlushDiagnostics@/link explicitly to clear
* any diagnostics currently stored.
*
* See also @link OSKextCopyDiagnostics@/link,
* @link OSKextValidate@/link,
* @link OSKextAuthenticate@/link, and
* @link OSKextResolveDependencies@/link.
*/
// Could list a pile of see also's here....
CF_EXPORT void
OSKextSetRecordsDiagnostics(OSKextDiagnosticsFlags flags)
;
/*!
* @function OSKextGetRecordsDiagnostics
* @abstract
* Returns what kinds of diagnostic information kexts record.
*
* @result
* Flags indicating which types of diagnostics are currently
* being recorded. You can bitwise-OR or -AND these with other flags
* to add or remove diagnostics being recorded with
* @link OSKextSetRecordsDiagnostics@/link.
*/
CF_EXPORT OSKextDiagnosticsFlags
OSKextGetRecordsDiagnostics(void)
;
/*!
* @function OSKextSetUsesCaches
* @abstract Sets whether the kext library uses cache files.
*
* @param flag
* <code>true</code> to use caches,
* <code>false</code> to not use caches.
*
* @discussion
* The kext library normally uses caches to speed up reading kexts from
* the system extensions folders.
* Use this function to turn off use of caches; this will cause reading
* of kexts to be dramatically slower.
*
* See also @link OSKextGetUsesCaches@/link.
*/
CF_EXPORT void
OSKextSetUsesCaches(Boolean flag)
;
/*!
* @function OSKextGetUsesCaches
* @abstract
* Returns whether the OSKext library uses cache files.
*
* @result
* <code>true</code> if the library uses caches to speed up reading of kexts,
* <code>false</code> if it doesn't.
*
* @discussion
* The kext library normally uses caches to speed up reading kexts from
* the system extensions folders.
* Use this function to check whether the library is using caches.
*
* See also @link OSKextGetUsesCaches@/link.
*/
CF_EXPORT Boolean
OSKextGetUsesCaches(void)
;
#pragma mark Instance Management
/*********************************************************************
* Instance Management
*********************************************************************/
/*!
* @function OSKextCreate
* @abstract Read a single kext from an on-disk bundle, without plugins.
*
* @param allocator
* The allocator to use to allocate memory for the new object.
* Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
* to use the current default allocator.
* @param anURL
* The location of the bundle for which to create an OSKext object.
* @result
* An OSKext object created from the bundle at anURL.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
*
* Returns <code>NULL</code> if there was a memory allocation problem or
* if the bundle doesn't exist at anURL (see Discussion).
* May return an existing OSKext object with the reference count incremented.
*
* @discussion
* Once a kext has been created, it is cached in memory; the kext bundle cache
* is flushed only periodically. OSKextCreate does not check that a cached kext
* bundle still exists in the filesystem. If a kext bundle is deleted
* from the filesystem, it is therefore possible for OSKextCreate
* to return a cached bundle that has actually been deleted.
*
* OSKext uses a CFBundle briefly during initialization, but in order
* to save memory and allow re-reading of kext bundle contents
* from disk, does not retain it. Applications can save further memory
* by flushing info dictionaries so that they are read from disk again
* when needed; see @link OSKextFlushInfoDictionary@/link.
*/
CF_EXPORT OSKextRef
OSKextCreate(
CFAllocatorRef allocator,
CFURLRef anURL)
;
/*!
* @function OSKextCreateKextsFromURL
* @abstract Reads all kexts at an on-disk URL along with their plugins.
*
* @param allocator
* The allocator to use to allocate memory for the new objects.
* Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
* to use the current default allocator.
* @param anURL The URL to scan for kernel extensions.
* @result
* Returns an array containing the kext objects created,
* or <code>NULL</code> on failure.
*
* @discussion
* This function scans <code>anURL</code> for kexts.
* If <code>anURL</code> represents a kext,
* this function reads that kext and its plugins.
* If <code>anURL</code> represents a non-kext directory,
* this functions scans the directory's immediate contents for kext bundles
* and their plugins. It does not scan recursively; only plugins one level
* deep are read.
*
* If given an URL for a kext that is a plugin of another kext, this
* function does not scan for further plugins.
*
* This function does not scan for or read mkext files. Use
* @link OSKextCreateKextsFromMkextFile@/link to read an mkext file.
*
* See @link OSKextCreate OSKextCreate @/link for information
* about kext object caching.
*/
CFArrayRef OSKextCreateKextsFromURL(
CFAllocatorRef allocator,
CFURLRef anURL)
;
/*!
* @function OSKextCreateKextsFromURLs
* @abstract Reads all kexts at an array on-disk URLs along with their plugins.
*
* @param allocator
* The allocator to use to allocate memory for the new objects.
* Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
* to use the current default allocator.
* @param arrayOfURLs The URLs to scan for kernel extensions.
* @result
* Returns an array containing the kext objects created,
* or <code>NULL</code> on failure.
*
* @discussion
* This function scans each URL in <code>arrayOfURLs</code> for kexts.
* If a given URL represents a kext,
* this function reads that kext and its plugins.
* If the URL represents a non-kext directory, this functions scans the
* directory's immediate contents for kext bundles and their plugins.
* It does not scan recursively; only plugins one level deep are read.
*
* If given an URL for a kext that is a plugin of another kext, this
* function does not scan for further plugins.
*
* This function does not scan for or read mkext files. Use
* @link OSKextCreateKextsFromMkextFile@/link to read an mkext file.
*
* See @link OSKextCreate@/link for discussion about kext object caching.
*/
CF_EXPORT CFArrayRef
OSKextCreateKextsFromURLs(
CFAllocatorRef allocator,
CFArrayRef arrayOfURLs)
;
/*!
* @function OSKextGetAllKexts
* @abstract
* Returns an array containing all of the kexts currently open in the application.
*
* @result
* A CFArray object containing OSKext objects for each open kext
* in the application. Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* This function is potentially expensive, so use with care.
*/
CF_EXPORT CFArrayRef
OSKextGetAllKexts(void)
;
/*! @function OSKextCopyKextsWithIdentifier */
CF_EXPORT CFArrayRef OSKextCopyKextsWithIdentifier(CFStringRef bundleID);
/*! @function OSKextGetKextsWithIdentifiers
@discussion Follows Create Rule.
*/
CF_EXPORT CFArrayRef OSKextGetKextsWithIdentifiers(CFArrayRef bundleIDs);
/*!
* @function OSKextGetKextWithIdentifierAndVersion
* @abstract
* Locate a kext given its program-defined identifier and version.
*
* @param aBundleID
* The identifier of the kext to locate.
* Note that identifier names are case-sensitive.
* @param aVersion
* The version of the kext to locate.
* @result
* An OSKext object, or <code>NULL</code> if the kext was not found.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* For a kext to be located using its identifier and version,
* the kext object must have already been created.
* See @link OSKextGetKextWithIdentifierAndVersion@/link for more.
*/
// xxx - check on same-version ordering with folks
CF_EXPORT OSKextRef
OSKextGetKextWithIdentifierAndVersion(
CFStringRef aBundleID, OSKextVersion aVersion)
;
/*!
* @function OSKextGetKextsWithIdentifier
* @abstract Locate all kexts with a given program-defined identifier.
*
* @param aBundleID
* The identifier of the kext to locate.
* Note that identifier names are case-sensitive.
* @result
* An CFArray of kext objects with the given identifier,
* or <code>NULL</code> on error.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
*
* @discussion
* This function is useful for locating duplicates of a given kext.
*
* See @link OSKextGetKextWithIdentifier@/link for general information
* on looking up kexts by identifier.
*/
CF_EXPORT CFArrayRef
OSKextCopyKextsWithIdentifier(
CFStringRef aBundleID)
;
/*!
* @function OSKextGetLoadedKextWithIdentifier
* @abstract
* Locate the loaded kext with a given program-defined identifier.
*
* @param aBundleID
* The identifier of the kext to locate.
* Note that identifier names are case-sensitive.
* @result
* An OSKext object, or <code>NULL</code> if the kext was not found.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* You must call @link OSKextReadLoadedKextInfo@/link before calling this
* function for it to find anything.
*
* See @link OSKextGetKextWithIdentifier@/link for general information
* on looking up kexts by identifier.
*/
CF_EXPORT OSKextRef
OSKextGetLoadedKextWithIdentifier(
CFStringRef aBundleID)
;
/*!
* @function OSKextGetCompatibleKextWithIdentifier
* @abstract
* Locate the kext with a given program-defined identifier
* that is compatible with a requested version.
*
* @param aBundleID
* The identifier of the kext to locate.
* Note that identifier names are case-sensitive.
* @param requestedVersion
* The version that the kext must be compatible with.
* @result
* An OSKext object, or <code>NULL</code> if the kext was not found.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* A kext is compatible with a version if that version lies between
* its CFBundleVersion and its OSBundleCompatibleVersion (inclusive).
*
* See @link OSKextGetKextWithIdentifier@/link for general information
* on looking up kexts by identifier.
*/
CF_EXPORT OSKextRef
OSKextGetCompatibleKextWithIdentifier(
CFStringRef aBundleID,
OSKextVersion requestedVersion)
;
#pragma mark Basic Accessors
/*********************************************************************
* Basic Accessors
*********************************************************************/
/*!
* @function OSKextGetURL
* @abstract Returns the CFURL of a kext bundle.
*
* @param aKext The kext to get the URL for.
* @result A CFURL object. Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* This function returns the CFURL that <code>aKext</code>
* was originally created with.
* It should be resolved to its base for comparison with other kext
* URLs.
*/
CF_EXPORT CFURLRef
OSKextGetURL(OSKextRef aKext)
; // always absolute
/*!
* @function OSKextGetIdentifier
* @abstract Returns the bundle identifier from a kext's information property list.
*
* @param aKext The kext to get the identifier for.
* @result
* A CFString object containing the kext bundle's identifier,
* or <code>NULL</code> if none was specified in the information property list.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*/
CF_EXPORT CFStringRef
OSKextGetIdentifier(OSKextRef aKext)
;
/*!
* @function OSKextGetValueForInfoDictionaryKey
* @abstract
* Returns a (possibly architecture-specific) value
* in a kext's information dictionary.
*
* @param aKext The kext to get the property for.
* @param key The base key identifying the property.
* @result
* A value corresponding to <code>key</code> in <code>aKext</code>'s
* information dictionary.
* If available, an architecture-specific value is returned,
* otherwise the global value is returned. Ownership follows the
* @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
*
* @discussion
* This function first looks for a property value specific to the current kext
* architecture, as set with @link OSKextSetArchitecture@/link,
* by appending an underscore plus the architecture name to the base key.
* If such a value is not found, it looks for the property using the base key.
* For example, if the currently set architecture is i386, and
* IOKitPersonalities is requested, this function looks up the key
* IOKitPersonalities_i386; if that doesn't exist, then it uses
* IOKitPersonalities.
*
* Some properties are not allowed to be made architecture-specific;
* if such keys are defined, they are ignored by this function:
*
* * CFBundleIdentifier
* * CFBundleVersion
* * CFBundleExecutable
* * OSBundleIsInterface
* * OSKernelResource
*
* This function looks up architecture-specific values for generic bundle
* properties, such as CFBundlePackageType, but such values are of course
* ignored by CFBundle.
*
* If you want to look up a property with a raw key, get the information
* dictionary directly using @link OSKextCopyInfoDictionary@/link or
* by opening a CFBundle for the kext's URL.
*
* This function reads the info dictionary from disk if necessary.
* See @link OSKextFlushInfoDictionary@/link.
*/
CF_EXPORT CFTypeRef
OSKextGetValueForInfoDictionaryKey(
OSKextRef aKext,
CFStringRef key)
;
/*!
* @function OSKextCopyInfoDictionary
* @abstract Returns a copy of a kext's information dictionary.
*
* @param aKext The kext to get the information dictionary for.
* @result
* A CFDictionary object containing the data stored in the kext's
* information property list.
* OSKext may add extra keys to this dictionary for its own use.
* Ownership follows the
* @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
*
* @discussion
* This function uses @link IOCFUnserialize@/link to parse the XML
* of the info dictionary, in order to match the parsing used in the kernel.
*/
CF_EXPORT CFMutableDictionaryRef
OSKextCopyInfoDictionary(OSKextRef aKext)
;
/*!
* @function OSKextFlushInfoDictionary
* @abstract Releases a kext's info dictionary.
*
* @param aKext The kext that should release its info dictionary.
* If <code>NULL</code>, all open kexts' info dictionaries
* are flushed.
*
* @discussion
* OSKexts accumulate a fair amount of information as they are created
* and used; when many kext objects are created the total memory
* consumption can be significant. If an application won't be using
* kexts for long periods of time, it can flush this information
* to save memory; the information will later be re-read from disk
* or recreated as necessary.
*
* Flushing info dictionaries also allows kext objects to synchronize
* with updates on disk; they will automatically re-sort in the
* internal lookup tables to reflect changed versions, for example.
* (xxx - well they will! that's not fully implemented yet)
*
* See also @link OSKextFlushDependencies@/link,
* @link OSKextFlushLoadInfo@/link,
* and @link OSKextFlushDiagnostics@/link.
*
* Kext objects created from an mkext cannot flush their info
* dictionaries.
*/
CF_EXPORT void
OSKextFlushInfoDictionary(OSKextRef aKext)
;
/*!
* @function OSKextGetVersion
* @abstract Returns the version of a kext.
*
* @param aKext The kext to get the version for.
* @result The version of the kext as a 64-bit integer.
*
* @discussion
* xxx - needs more info on version format
* xxx - need to fix definition of OSKextVersion.
*/
CF_EXPORT OSKextVersion
OSKextGetVersion(OSKextRef aKext)
;
/*!
* @function OSKextGetCompatibleVersion
* @abstract Returns the compatible version of a kext
*
* @param aKext The kext to get the compatible version for.
* @result The compatible version of the kext as a 64-bit integer.
*
* @discussion
* This function returns the value of a kext's OSBundleCompatibleVersion
* property, parsed into a 64-bit integer that can be compared using
* standard integer comparison operators.
*
* xxx - needs more info on version format, ref to tn: http://developer.apple.com/technotes/tn/tn1132.html
*/
CF_EXPORT OSKextVersion
OSKextGetCompatibleVersion(OSKextRef aKext)
;
/*!
* @function OSKextCopyUUIDForArchitecture
* @abstract
* Returns the compiler-generated UUID of a kext for a given architecture.
*
* @param aKext The kext to get the UUID for.
* @param anArch The architecture desired.
* Pass <code>NULL</code> to get the UUID for the
* current architecture.
* @result
* A CFData object containing the UUID of the kext's executable
* for <code>anArch</code>, or the currently set architecture if
* <code>anArch</code> is <code>NULL</code>.
*
* @discussion
* UUIDs are used in addition to bundle versions to check the identify of
* kexts loaded in the kernel.
*/
CF_EXPORT CFDataRef
OSKextCopyUUIDForArchitecture(OSKextRef aKext,
const NXArchInfo * anArch)
;
/*!
* @function OSKextIsKernelComponent
* @abstract Returns whether a kext represents a kerne programming interface.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if <code>aKext</code> represents
* a kerne programming interface, <code>false</code> otherwise.
*
* @discussion
* A small set of kexts represent interfaces built into the kernel that can
* be linked against individually. These are commonly known as
* kernel programming interfaces (KPIs),
* and the kexts containing them as "pseudokexts".
*
* If a kext is a kernel component, then it is also always an interface
* (see @link OSKextIsInterface@/link).
*/
CF_EXPORT Boolean
OSKextIsKernelComponent(OSKextRef aKext)
;
/*!
* @function OSKextIsInterface
* @abstract
* Returns whether a kext acts as a linkage subset for another kext,
* also known as a symbol set.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if <code>aKext</code> is an interface kext,
* <code>false</code> otherwise.
*
* @discussion
* An interface kext has no actual code in its executable, but merely
* re-exports a set of symbols (typically a subset)
* from those of its dependencies.
*
* Currently the only interface kexts are the kernel component kexts
* the define the kernel programming interfaces for Mac OS X.
*/
CF_EXPORT Boolean
OSKextIsInterface(OSKextRef aKext)
;
/*!
* @function OSKextIsLibrary
* @abstract Returns whether a kext can be declared as a library.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if <code>aKext</code> is a library kext, <code>false</code>
* otherwise.
*
* @discussion
* A kext is a library kext if it has a valid OSBundleCompatibleVersion
* property. Another kext can link against a library kext by listing
* the library's identifier and required version in its OSBundleLibraries
* property.
*/
CF_EXPORT Boolean
OSKextIsLibrary(OSKextRef aKext)
;
/*!
* @function OSKextDeclaresExecutable
* @abstract Returns whether a kext declares a CFBundleExecutable property.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if <code>aKext</code> has a nonempty CFBundleExecutable
* property, <code>false</code> otherwise.
*
* @discussion
* A kext with an executable is either a loadable kext with actual executable
* code, or an interface kext whose executable serves to restrict linkage
* to a subset of the symbols of another kext. See @link OSKextIsInterface@/link
* for more on the latter type.
*/
CF_EXPORT Boolean
OSKextDeclaresExecutable(OSKextRef aKext)
;
/*!
* @function OSKextHasLogOrDebugFlags
* @abstract
* Returns whether a kext has OSBundleEnableKextLogging set to a true value or
* any of its IOKitPersonalities has a nonzero IOKitDebug property.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if <code>aKext</code> has a true OSBundleEnableKextLogging
* property or if any personality for the currently set architecture has a
* nonzero IOKitDebug property, <code>false</code> otherwise.
*
* @discussion
* Kexts built for distribution should not have any logging or debug flags set.
*/
CF_EXPORT Boolean
OSKextHasLogOrDebugFlags(OSKextRef aKext)
;
/*!
* @function OSKextIsLoadableInSafeBoot
* @abstract Returns whether the kernel will load a kext during safe boot.
*
* @param aKext The kext to examine.
* @result
* <code>true</code> if the kernel will allow <code>aKext</code> during
* safe boot, <code>false</code> otherwise.
*
* @discussion
* A kext is loadable during safe boot if it has an OSBundleRequired
* property for the kernel's architecture with a value of
* "Root", "Local-Root", "Network-Root", "Console", or "Safe Boot".
*
* This function does not generally cover the issue of loadability due
* to problems with validation, authentication, or dependency resolution.
* To determine whether a kext can actually be loaded, use
* @link OSKextIsLoadable@/link.
*/
CF_EXPORT Boolean
OSKextIsLoadableInSafeBoot(OSKextRef aKext)
;
/*!
* @function OSKextCopyArchitectures
* @abstract
* Returns a list of <code>NXArchInfo</code> structs for the architectures
* found in a kext's executable.
*
* @param aKext The kext to examine.
* @result
* A <code>NULL</code>-terminated list of <code>NXArchInfo</code>
* struct pointers describing
* the architectures supported by <code>aKext</code>,
* or <code>NULL</code> if <code>aKext</code> has no executable.
* The caller is responsible for freeing the list, but not the individual
* <code>NXArchInfo</code> pointers.
*/