2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _LIBKERN_OSKEXT_H
30 #define _LIBKERN_OSKEXT_H
33 #include <kern/thread_call.h>
34 #include <libkern/OSKextLibPrivate.h>
35 #include <libkern/kernel_mach_header.h>
36 #include <libkern/kxld.h>
37 #include <mach/kmod.h>
39 #ifdef XNU_KERNEL_PRIVATE
40 #include <kern/thread_call.h>
41 #endif /* XNU_KERNEL_PRIVATE */
45 #include <libkern/OSKextLib.h>
46 #include <libkern/OSKextLibPrivate.h>
47 #include <libkern/c++/OSObject.h>
48 #include <libkern/c++/OSContainers.h>
50 #include <libkern/c++/OSPtr.h>
51 #include <IOKit/IOLocks.h>
53 /*********************************************************************
54 * C functions used for callbacks.
55 *********************************************************************/
56 #ifdef XNU_KERNEL_PRIVATE
58 void osdata_kmem_free(void * ptr
, unsigned int length
);
59 void osdata_phys_free(void * ptr
, unsigned int length
);
60 void osdata_vm_deallocate(void * ptr
, unsigned int length
);
61 void osdata_kext_free(void * ptr
, unsigned int length
);
62 void kxld_log_callback(
63 KXLDLogSubsystem subsystem
,
69 #endif /* XNU_KERNEL_PRIVATE */
71 /*********************************************************************
72 * C Function Prototypes for Friend Declarations.
73 *********************************************************************/
79 OSKextLogSpec msgLogSpec
,
80 const char * format
, ...)
81 __attribute__((format(printf
, 3, 4)));
85 OSKextLogSpec msgLogSpec
,
89 #ifdef XNU_KERNEL_PRIVATE
90 void OSKextRemoveKextBootstrap(void);
92 kern_return_t
OSRuntimeInitializeCPP(
94 kern_return_t
OSRuntimeFinalizeCPP(
96 void OSRuntimeUnloadCPPForSegment(
97 kernel_segment_command_t
* segment
);
99 OSRuntimeSignStructors(
100 kernel_mach_header_t
* header
);
102 OSRuntimeSignStructorsInFileset(
103 kernel_mach_header_t
* fileset_header
);
105 kern_return_t
is_io_catalog_send_data(
106 mach_port_t masterPort
,
109 mach_msg_type_number_t inDataCount
,
110 kern_return_t
* result
);
112 void kmod_dump_log(vm_offset_t
*, unsigned int, boolean_t
);
113 void *OSKextKextForAddress(const void *addr
);
115 #endif /* XNU_KERNEL_PRIVATE */
118 /********************************************************************/
124 struct list_head
*prev
;
125 struct list_head
*next
;
128 struct OSKextGrabPgoStruct
{
134 struct list_head list_head
;
138 #define container_of(ptr, type, member) ((type*)(((uintptr_t)ptr) - offsetof(type, member)))
140 /********************************************************************/
142 #if XNU_KERNEL_PRIVATE
144 struct OSKextAccount
{
145 vm_allocation_site_t site
;
150 struct OSKextActiveAccount
{
152 uintptr_t address_end
;
153 OSKextAccount
* account
;
155 typedef struct OSKextActiveAccount OSKextActiveAccount
;
157 class OSKextSavedMutableSegment
: public OSObject
{
158 OSDeclareDefaultStructors(OSKextSavedMutableSegment
);
160 static OSPtr
<OSKextSavedMutableSegment
> withSegment(kernel_segment_command_t
*seg
);
161 OSReturn
restoreContents(kernel_segment_command_t
*seg
);
162 vm_offset_t
getVMAddr() const;
163 vm_size_t
getVMSize() const;
164 virtual void free(void) APPLE_KEXT_OVERRIDE
;
166 bool initWithSegment(kernel_segment_command_t
*seg
);
167 kernel_segment_command_t
*savedSegment
;
173 #endif /* XNU_KERNEL_PRIVATE */
178 /********************************************************************/
179 class OSKext
: public OSObject
181 OSDeclareDefaultStructors(OSKext
);
184 /**************************************/
185 #pragma mark Friend Declarations
186 /**************************************/
188 friend class IOCatalogue
;
189 friend class KLDBootstrap
;
190 friend class OSMetaClass
;
192 friend int OSKextGrabPgoData(uuid_t uuid
,
199 #ifdef XNU_KERNEL_PRIVATE
200 friend void OSKextVLog(
202 OSKextLogSpec msgLogSpec
,
206 friend void OSKextRemoveKextBootstrap(void);
207 friend OSReturn
OSKextUnloadKextWithLoadTag(uint32_t);
209 friend kern_return_t
kext_request(
210 host_priv_t hostPriv
,
211 /* in only */ uint32_t clientLogSpec
,
212 /* in only */ vm_offset_t requestIn
,
213 /* in only */ mach_msg_type_number_t requestLengthIn
,
214 /* out only */ vm_offset_t
* responseOut
,
215 /* out only */ mach_msg_type_number_t
* responseLengthOut
,
216 /* out only */ vm_offset_t
* logDataOut
,
217 /* out only */ mach_msg_type_number_t
* logDataLengthOut
,
218 /* out only */ kern_return_t
* op_result
);
220 friend kxld_addr_t
kern_allocate(
222 KXLDAllocateFlags
* flags
,
225 friend void kxld_log_shim(
226 KXLDLogSubsystem subsystem
,
232 friend void _OSKextConsiderUnloads(
233 __unused thread_call_param_t p0
,
234 __unused thread_call_param_t p1
);
236 friend kern_return_t
OSRuntimeInitializeCPP(
238 friend kern_return_t
OSRuntimeFinalizeCPP(
240 friend void OSRuntimeUnloadCPPForSegment(
241 kernel_segment_command_t
* segment
);
243 friend kern_return_t
is_io_catalog_send_data(
244 mach_port_t masterPort
,
247 mach_msg_type_number_t inDataCount
,
248 kern_return_t
* result
);
250 friend void kmod_panic_dump(vm_offset_t
*, unsigned int);
251 friend void kmod_dump_log(vm_offset_t
*, unsigned int, boolean_t
);
252 friend void kext_dump_panic_lists(int (*printf_func
)(const char * fmt
, ...));
253 friend void *OSKextKextForAddress(const void *addr
);
255 #endif /* XNU_KERNEL_PRIVATE */
259 /*************************
261 *************************/
262 OSPtr
<OSDictionary
> infoDict
;
264 OSPtr
<const OSSymbol
> bundleID
;
265 OSPtr
<OSString
> path
; // not necessarily correct :-/
266 OSPtr
<OSString
> executableRelPath
;// relative to bundle
267 OSPtr
<OSString
> userExecutableRelPath
;// relative to bundle
269 OSKextVersion version
; // parsed
270 OSKextVersion compatibleVersion
;// parsed
272 /* These fields are required for tracking loaded kexts and
273 * will always have values for a loaded kext.
275 OSKextLoadTag loadTag
; // 'id' from old kmod_info;
276 // kOSKextInvalidLoadTag invalid
277 kmod_info_t
* kmod_info
; // address into linkedExec./alloced for interface
279 OSPtr
<OSArray
> dependencies
; // kernel resource does not have any;
280 // links directly to kernel
282 /* Only real kexts have these; interface kexts do not.
284 OSPtr
<OSData
> linkedExecutable
;
285 OSPtr
<OSSet
> metaClasses
; // for C++/OSMetaClass kexts
287 /* Only interface kexts have these; non-interface kexts can get at them
288 * in the linked Executable.
290 OSPtr
<OSData
> interfaceUUID
;
291 OSPtr
<OSData
> driverKitUUID
;
294 unsigned int loggingEnabled
:1;
296 unsigned int hasAllDependencies
:1;
297 unsigned int hasBleedthrough
:1;
299 unsigned int interface
:1;
300 unsigned int kernelComponent
:1;
301 unsigned int prelinked
:1;
302 unsigned int builtin
:1;
303 unsigned int loaded
:1;
304 unsigned int dtraceInitialized
:1;
305 unsigned int starting
:1;
306 unsigned int started
:1;
307 unsigned int stopping
:1;
308 unsigned int unloading
:1;
309 unsigned int resetSegmentsFromVnode
:1;
311 unsigned int requireExplicitLoad
:1;
312 unsigned int autounloadEnabled
:1;
313 unsigned int delayAutounload
:1; // for development
315 unsigned int CPPInitialized
:1;
316 unsigned int jettisonLinkeditSeg
:1;
317 unsigned int resetSegmentsFromImmutableCopy
:1;
320 uint32_t matchingRefCount
;
323 struct list_head pendingPgoHead
;
324 uuid_t instance_uuid
;
325 OSKextAccount
* account
;
326 uint32_t builtinKmodIdx
;
327 OSPtr
<OSArray
> savedMutableSegments
;
330 /**************************************/
331 #pragma mark Private Functions
332 /**************************************/
335 #ifdef XNU_KERNEL_PRIVATE
336 /* Startup/shutdown phases.
339 static void initialize(void);
340 static OSPtr
<OSDictionary
> copyKexts(void);
341 static OSReturn
removeKextBootstrap(void);
342 static void willShutdown(void);// called by IOPMrootDomain on shutdown
343 static void willUserspaceReboot(void);
344 static void resetAfterUserspaceReboot(void);
345 static void reportOSMetaClassInstances(
346 const char * kextIdentifier
,
347 OSKextLogSpec msgLogSpec
);
348 static void OSKextLogDriverKitInfoLoad(OSKext
*kext
);
349 #endif /* XNU_KERNEL_PRIVATE */
352 /* Called by power management at sleep/shutdown.
354 static bool setLoadEnabled(bool flag
);
355 static bool setUnloadEnabled(bool flag
);
356 static bool setAutounloadsEnabled(bool flag
);
357 static bool setKernelRequestsEnabled(bool flag
);
359 // all getters subject to race condition, caller beware
360 static bool getLoadEnabled(void);
361 static bool getUnloadEnabled(void);
362 static bool getAutounloadEnabled(void);
363 static bool getKernelRequestsEnabled(void);
365 /* Instance life cycle.
367 static OSPtr
<OSKext
> withBooterData(
368 OSString
* deviceTreeName
,
369 OSData
* booterData
);
370 virtual bool initWithBooterData(
371 OSString
* deviceTreeName
,
372 OSData
* booterData
);
374 static OSPtr
<OSKext
> withPrelinkedInfoDict(
375 OSDictionary
* infoDict
,
376 bool doCoalesedSlides
, kc_kind_t type
);
377 virtual bool initWithPrelinkedInfoDict(
378 OSDictionary
* infoDict
,
379 bool doCoalesedSlides
, kc_kind_t type
);
381 static OSSharedPtr
<OSKext
> withCodelessInfo(
382 OSDictionary
* infoDict
);
383 virtual bool initWithCodelessInfo(
384 OSDictionary
* infoDict
);
386 static void setAllVMAttributes(void);
388 virtual bool setInfoDictionaryAndPath(
389 OSDictionary
* aDictionary
,
391 virtual bool setExecutable(
392 OSData
* anExecutable
,
393 OSData
* externalData
= NULL
,
394 bool externalDataIsMkext
= false);
395 virtual bool registerIdentifier(void);
397 virtual void free(void) APPLE_KEXT_OVERRIDE
;
399 static OSReturn
removeKext(
401 bool terminateServicesAndRemovePersonalitiesFlag
= false);
403 virtual bool isInExcludeList(void);
404 virtual bool isLoadable(void);
409 static OSPtr
<OSKext
> withMkext2Info(
410 OSDictionary
* anInfoDict
,
412 virtual bool initWithMkext2Info(
413 OSDictionary
* anInfoDict
,
416 static OSReturn
readMkextArchive(
418 uint32_t * checksumPtr
= NULL
);
419 static OSReturn
readMkext2Archive(
421 OSDictionary
** mkextPlistOut
,
422 uint32_t * checksumPtr
= NULL
);
424 static OSReturn
readMkext2Archive(
426 OSSharedPtr
<OSDictionary
> &mkextPlistOut
,
427 uint32_t * checksumPtr
= NULL
);
429 virtual OSPtr
<OSData
> createMkext2FileEntry(
431 OSNumber
* offsetNum
,
432 const char * entryName
);
433 virtual OSPtr
<OSData
> extractMkext2FileData(
436 uint32_t compressedSize
,
438 #endif // CONFIG_KXLD
442 virtual bool resolveDependencies(
443 OSArray
* loopStack
= NULL
); // priv/prot
444 virtual bool addBleedthroughDependencies(OSArray
* anArray
);
445 virtual bool flushDependencies(bool forceFlag
= false); // priv/prot
446 virtual uint32_t getNumDependencies(void);
447 virtual OSArray
* getDependencies(void);
449 /* User-space requests (load/generic).
451 static OSReturn
loadFromMkext(
452 OSKextLogSpec clientLogSpec
,
454 uint32_t mkextBufferLength
,
456 uint32_t * logInfoLengthOut
);
457 static OSReturn
handleRequest(
458 host_priv_t hostPriv
,
459 OSKextLogSpec clientLogSpec
,
460 char * requestBuffer
,
461 uint32_t requestLength
,
463 uint32_t * responseLengthOut
,
465 uint32_t * logInfoLengthOut
);
466 static OSReturn
loadCodelessKext(
467 OSString
* kextIdentifier
,
468 OSDictionary
* requestDict
);
469 static OSReturn
serializeLogInfo(
470 OSArray
* logInfoArray
,
472 uint32_t * logInfoLengthOut
);
476 static bool addKextsFromKextCollection(kernel_mach_header_t
*mh
,
477 OSDictionary
*infoDict
, const char *text_seg_name
,
478 OSData
**kcUUID
, kc_kind_t type
);
480 static bool addKextsFromKextCollection(kernel_mach_header_t
*mh
,
481 OSDictionary
*infoDict
, const char *text_seg_name
,
482 OSSharedPtr
<OSData
> &kcUUID
, kc_kind_t type
);
484 static bool registerDeferredKextCollection(kernel_mach_header_t
*mh
,
485 OSSharedPtr
<OSObject
> &parsedXML
, kc_kind_t type
);
486 static OSSharedPtr
<OSObject
> consumeDeferredKextCollection(kc_kind_t type
);
488 virtual OSReturn
load(
489 OSKextExcludeLevel startOpt
= kOSKextExcludeNone
,
490 OSKextExcludeLevel startMatchingOpt
= kOSKextExcludeAll
,
491 OSArray
* personalityNames
= NULL
);// priv/prot
492 virtual OSReturn
unload(void);
493 virtual OSReturn
queueKextNotification(
494 const char * notificationName
,
495 OSString
* kextIdentifier
);
497 static void recordIdentifierRequest(
498 OSString
* kextIdentifier
);
500 virtual OSReturn
slidePrelinkedExecutable(bool doCoalesedSlides
);
501 virtual OSReturn
loadExecutable(void);
502 virtual void jettisonLinkeditSegment(void);
503 virtual void jettisonDATASegmentPadding(void);
504 static void considerDestroyingLinkContext(void);
505 virtual OSData
* getExecutable(void);
506 virtual void setLinkedExecutable(OSData
* anExecutable
);
509 friend void OSKextRegisterKextsWithDTrace(void);
510 static void registerKextsWithDTrace(void);
511 virtual void registerWithDTrace(void);
512 virtual void unregisterWithDTrace(void);
513 #endif /* CONFIG_DTRACE */
515 virtual OSReturn
start(bool startDependenciesFlag
= true);
516 virtual OSReturn
stop(void);
517 virtual OSReturn
setVMAttributes(bool protect
, bool wire
);
518 virtual boolean_t
segmentShouldBeWired(kernel_segment_command_t
*seg
);
519 virtual OSReturn
validateKextMapping(bool startFlag
);
520 virtual boolean_t
verifySegmentMapping(kernel_segment_command_t
*seg
);
522 static OSPtr
<OSArray
> copyAllKextPersonalities(
523 bool filterSafeBootFlag
= false);
525 static void setPrelinkedPersonalities(OSArray
* personalitiesArray
);
527 static void sendAllKextPersonalitiesToCatalog(
528 bool startMatching
= false);
529 virtual OSReturn
sendPersonalitiesToCatalog(
530 bool startMatching
= false,
531 OSArray
* personalityNames
= NULL
);
533 static bool canUnloadKextWithIdentifier(
534 OSString
* kextIdentifier
,
535 bool checkClassesFlag
= true);
537 static OSReturn
autounloadKext(OSKext
* aKext
);
539 /* Sync with user space.
541 static OSReturn
pingIOKitDaemon(void);
543 /* Getting info about loaded kexts (kextstat).
545 static OSPtr
<OSDictionary
> copyLoadedKextInfo(
546 OSArray
* kextIdentifiers
= NULL
,
547 OSArray
* keys
= NULL
);
548 static OSPtr
<OSDictionary
> copyLoadedKextInfoByUUID(
549 OSArray
* kextIdentifiers
= NULL
,
550 OSArray
* keys
= NULL
);
551 static OSPtr
<OSDictionary
> copyKextCollectionInfo(
552 OSDictionary
*requestDict
,
553 OSArray
*infoKeys
= NULL
);
554 static OSPtr
<OSData
> copyKextUUIDForAddress(OSNumber
*address
= NULL
);
555 virtual OSPtr
<OSDictionary
> copyInfo(OSArray
* keys
= NULL
);
557 /* Logging to user space.
559 static OSKextLogSpec
setUserSpaceLogFilter(
560 OSKextLogSpec userLogSpec
,
561 bool captureFlag
= false);
562 static OSPtr
<OSArray
> clearUserSpaceLogFilter(void);
563 static OSKextLogSpec
getUserSpaceLogFilter(void);
565 /* OSMetaClasses defined by kext.
567 virtual OSReturn
addClass(
568 OSMetaClass
* aClass
,
569 uint32_t numClasses
);
570 virtual OSReturn
removeClass(
571 OSMetaClass
* aClass
);
572 virtual bool hasOSMetaClassInstances(void);
573 virtual OSSet
* getMetaClasses(void);
575 virtual void reportOSMetaClassInstances(
576 OSKextLogSpec msgLogSpec
);
578 /* Resource requests and other callback stuff.
580 static OSReturn
loadFileSetKexts(OSDictionary
* requestDict
);
582 static OSReturn
loadKCFileSet(const char *filepath
, kc_kind_t type
);
584 #if defined(__x86_64__) || defined(__i386__)
585 static OSReturn
mapKCFileSet(
588 kernel_mach_header_t
**mh
,
592 void *map_entry_buffer
);
593 static OSReturn
protectKCFileSet(
594 kernel_mach_header_t
*mh
,
596 static OSReturn
mapKCTextSegment(
598 kernel_mach_header_t
**mhp
,
601 void *map_entry_list
);
602 static void freeKCFileSetcontrol(void);
603 OSReturn
resetKCFileSetSegments(void);
604 static void jettisonFileSetLinkeditSegment(kernel_mach_header_t
*mh
);
605 #endif //(__x86_64__) || defined(__i386__)
607 static OSReturn
validateKCFileSetUUID(
608 OSDictionary
*infoDict
,
611 static OSReturn
validateKCUUIDfromPrelinkInfo(
612 uuid_t
*loaded_kcuuid
,
614 OSDictionary
*infoDict
,
615 const char *uuid_key
);
617 static OSReturn
dispatchResource(OSDictionary
* requestDict
);
619 static OSReturn
setMissingAuxKCBundles(OSDictionary
* requestDict
);
621 static OSReturn
setAuxKCBundleAvailable(OSString
*kextIdentifier
,
622 OSDictionary
*requestDict
);
624 static OSReturn
dequeueCallbackForRequestTag(
625 OSKextRequestTag requestTag
,
626 LIBKERN_RETURNS_RETAINED OSDictionary
** callbackRecordOut
);
627 static OSReturn
dequeueCallbackForRequestTag(
628 OSNumber
* requestTagNum
,
629 LIBKERN_RETURNS_RETAINED OSDictionary
** callbackRecordOut
);
631 static OSReturn
dequeueCallbackForRequestTag(
632 OSKextRequestTag requestTag
,
633 OSSharedPtr
<OSDictionary
> &callbackRecordOut
);
634 static OSReturn
dequeueCallbackForRequestTag(
635 OSNumber
* requestTagNum
,
636 OSSharedPtr
<OSDictionary
> &callbackRecordOut
);
638 static void invokeRequestCallback(
639 OSDictionary
* callbackRecord
,
640 OSReturn requestResult
);
641 virtual void invokeOrCancelRequestCallbacks(
642 OSReturn callbackResult
,
643 bool invokeFlag
= true);
644 virtual uint32_t countRequestCallbacks(void);
645 OSReturn
resetMutableSegments(void);
651 kPrintKextsLock
= 0x01,
652 kPrintKextsUnslide
= 0x02,
653 kPrintKextsTerse
= 0x04
655 static void printKextsInBacktrace(
658 int (* printf_func
)(const char *fmt
, ...),
660 bool isDriverKit(void);
661 bool isInFileset(void);
663 static OSKextLoadedKextSummary
*summaryForAddress(const uintptr_t addr
);
664 static void *kextForAddress(const void *addr
);
665 static boolean_t
summaryIsInBacktrace(
666 OSKextLoadedKextSummary
* summary
,
669 static void printSummary(
670 OSKextLoadedKextSummary
* summary
,
671 int (* printf_func
)(const char *fmt
, ...),
674 static int saveLoadedKextPanicListTyped(
680 static void saveLoadedKextPanicList(void);
681 void savePanicString(bool isLoading
);
682 static void printKextPanicLists(int (*printf_func
)(const char *fmt
, ...));
684 /* Kext summary support.
686 static void updateLoadedKextSummaries(void);
687 void updateLoadedKextSummary(OSKextLoadedKextSummary
*summary
);
688 void updateActiveAccount(OSKextActiveAccount
*accountp
);
690 #ifdef XNU_KERNEL_PRIVATE
692 #endif /* XNU_KERNEL_PRIVATE */
694 /* C++ Initialization.
696 virtual void setCPPInitialized(bool initialized
= true);
699 /**************************************/
700 #pragma mark Public Functions
701 /**************************************/
704 // caller must release
705 static OSPtr
<OSKext
> lookupKextWithIdentifier(const char * kextIdentifier
);
706 static OSPtr
<OSKext
> lookupKextWithIdentifier(OSString
* kextIdentifier
);
707 static OSPtr
<OSKext
> lookupKextWithLoadTag(OSKextLoadTag aTag
);
708 static OSPtr
<OSKext
> lookupKextWithAddress(vm_address_t address
);
709 static OSPtr
<OSKext
> lookupKextWithUUID(uuid_t uuid
);
711 kernel_section_t
*lookupSection(const char *segname
, const char*secname
);
713 static bool isKextWithIdentifierLoaded(const char * kextIdentifier
);
715 static OSReturn
loadKextWithIdentifier(
716 const char * kextIdentifier
,
717 Boolean allowDeferFlag
= true,
718 Boolean delayAutounloadFlag
= false,
719 OSKextExcludeLevel startOpt
= kOSKextExcludeNone
,
720 OSKextExcludeLevel startMatchingOpt
= kOSKextExcludeAll
,
721 OSArray
* personalityNames
= NULL
);
723 static OSReturn
loadKextWithIdentifier(
724 OSString
* kextIdentifier
,
725 LIBKERN_RETURNS_RETAINED_ON_ZERO OSObject
** kextRef
,
726 Boolean allowDeferFlag
= true,
727 Boolean delayAutounloadFlag
= false,
728 OSKextExcludeLevel startOpt
= kOSKextExcludeNone
,
729 OSKextExcludeLevel startMatchingOpt
= kOSKextExcludeAll
,
730 OSArray
* personalityNames
= NULL
);
732 static OSReturn
loadKextWithIdentifier(
733 OSString
* kextIdentifier
,
734 OSSharedPtr
<OSObject
> &kextRef
,
735 Boolean allowDeferFlag
= true,
736 Boolean delayAutounloadFlag
= false,
737 OSKextExcludeLevel startOpt
= kOSKextExcludeNone
,
738 OSKextExcludeLevel startMatchingOpt
= kOSKextExcludeAll
,
739 OSArray
* personalityNames
= NULL
);
741 static OSReturn
loadKextFromKC(OSKext
*theKext
, OSDictionary
*requestDict
);
743 static void dropMatchingReferences(
746 bool hasDependency(const OSSymbol
* depID
);
748 static OSReturn
removeKextWithIdentifier(
749 const char * kextIdentifier
,
750 bool terminateServicesAndRemovePersonalitiesFlag
= false);
751 static OSReturn
removeKextWithLoadTag(
752 OSKextLoadTag loadTag
,
753 bool terminateServicesAndRemovePersonalitiesFlag
= false);
754 static OSReturn
requestDaemonLaunch(
755 OSString
* kextIdentifier
,
756 OSString
* serverName
,
757 OSNumber
* serverTag
,
758 class IOUserServerCheckInToken
** checkInToken
);
760 static OSReturn
requestDaemonLaunch(
761 OSString
* kextIdentifier
,
762 OSString
* serverName
,
763 OSNumber
* serverTag
,
764 OSSharedPtr
<class IOUserServerCheckInToken
> &checkInToken
);
766 static OSReturn
requestResource(
767 const char * kextIdentifier
,
768 const char * resourceName
,
769 OSKextRequestResourceCallback callback
,
771 OSKextRequestTag
* requestTagOut
);
772 static OSReturn
cancelRequest(
773 OSKextRequestTag requestTag
,
776 static void considerUnloads(Boolean rescheduleOnlyFlag
= false);
777 static void flushNonloadedKexts(Boolean flushPrelinkedKexts
);
778 static void setIOKitDaemonActive(bool active
= true);
779 static void setDeferredLoadSucceeded(Boolean succeeded
= true);
780 static void considerRebuildOfPrelinkedKernel(void);
781 static void createExcludeListFromBooterData(
782 OSDictionary
* theDictionary
,
783 OSCollectionIterator
* theIterator
);
784 static void createExcludeListFromPrelinkInfo(OSArray
* theInfoArray
);
785 static boolean_t
updateExcludeList(OSDictionary
* infoDict
);
787 static bool pendingIOKitDaemonRequests(void);
789 virtual bool setAutounloadEnabled(bool flag
);
791 virtual const OSSymbol
* getIdentifier(void);
792 virtual const char * getIdentifierCString(void);
793 virtual OSKextVersion
getVersion(void);
794 virtual OSKextVersion
getCompatibleVersion(void);
795 virtual bool isLibrary(void);
796 virtual bool isCompatibleWithVersion(OSKextVersion aVersion
);
797 virtual OSObject
* getPropertyForHostArch(const char * key
);
799 virtual OSKextLoadTag
getLoadTag(void);
800 virtual void getSizeInfo(uint32_t *loadSize
, uint32_t *wiredSize
);
801 virtual OSPtr
<OSData
> copyUUID(void);
802 OSPtr
<OSData
> copyTextUUID(void);
803 OSPtr
<OSData
> copyMachoUUID(const kernel_mach_header_t
* header
);
804 virtual OSPtr
<OSArray
> copyPersonalitiesArray(void);
805 static bool copyUserExecutablePath(const OSSymbol
* bundleID
, char * pathResult
, size_t pathSize
);
806 virtual void setDriverKitUUID(OSData
*uuid
);
807 /* This removes personalities naming the kext (by CFBundleIdentifier),
808 * not all personalities defined by the kext (IOPersonalityPublisher or CFBundleIdentifier).
810 virtual void removePersonalitiesFromCatalog(void);
812 /* Converts common string-valued properties to OSSymbols for lower memory consumption.
814 static void uniquePersonalityProperties(OSDictionary
* personalityDict
);
815 #ifdef XNU_KERNEL_PRIVATE
816 static void uniquePersonalityProperties(OSDictionary
* personalityDict
, bool defaultAddKernelBundleIdentifier
);
819 virtual bool declaresExecutable(void); // might be missing
820 virtual bool isInterface(void);
821 virtual bool isKernel(void);
822 virtual bool isKernelComponent(void);
823 virtual bool isExecutable(void);
824 virtual bool isLoadableInSafeBoot(void);
825 virtual bool isPrelinked(void);
826 virtual bool isLoaded(void);
827 virtual bool isStarted(void);
828 virtual bool isCPPInitialized(void);
831 getKCTypeString(void)
835 return kKCTypePrimary
;
837 return kKCTypeSystem
;
838 case KCKindAuxiliary
:
839 return kKCTypeAuxiliary
;
841 return kKCTypeCodeless
;
848 extern "C" void OSKextResetAfterUserspaceReboot(void);
850 #endif /* !_LIBKERN_OSKEXT_H */