KextManager.h Reference

Declared in
KextManager.h

Overview

The KextManager API provides a simple interface for applications to load kernel extensions (kexts) via RPC to kextd, and to look up the URLs for kexts by bundle identifier.

Included Headers

  • <CoreFoundation/CoreFoundation.h>

  • <libkern/OSReturn.h>

  • <sys/cdefs.h>

Functions

See the Overview for header-level documentation.

KextManagerCopyLoadedKextInfo

Returns information about loaded kexts in a dictionary.

CFDictionaryRef KextManagerCopyLoadedKextInfo(
   CFArrayRef kextIdentifiers,
   CFArrayRef infoKeys)AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER;
Parameters
kextIdentifiers

An array of kext identifiers to read from the kernel. Pass NULL to read info for all loaded kexts.

infoKeys

An array of info keys to read from the kernel. Pass NULL to read all information.

Return Value

A dictionary, keyed by bundle identifier, of dictionaries containing information about loaded kexts.

Discussion

The information keys returned by this function are listed below. Some are taken directly from the kext's information property list, and some are generated at run time. Never assume a given key will be present for a kext.

  • CFBundleIdentifier - CFString

  • CFBundleVersion - CFString (note: version strings may be canonicalized but their numeric values will be the same; "1.2.0" may become "1.2", for example)

  • OSBundleCompatibleVersion - CFString

  • OSBundleIsInterface - CFBoolean

  • OSKernelResource - CFBoolean

  • OSBundleCPUType - CFNumber

  • OSBundleCPUSubtype - CFNumber

  • OSBundlePath - CFString (this is merely a hint stored in the kernel; the kext is not guaranteed to be at this path)

  • OSBundleExecutablePath - CFString (the absolute path to the executable within the kext bundle; a hint as above)

  • OSBundleUUID - CFData (the UUID of the kext executable, if it has one)

  • OSBundleStarted - CFBoolean (true if the kext is running)

  • OSBundlePrelinked - CFBoolean (true if the kext is loaded from a prelinked kernel)

  • OSBundleLoadTag - CFNumber (the "Index" given by kextstat)

  • OSBundleLoadAddress - CFNumber

  • OSBundleLoadSize - CFNumber

  • OSBundleWiredSize - CFNumber

  • OSBundleDependencies - CFArray of load tags identifying immediate link dependencies

  • OSBundleRetainCount - CFNumber (the OSObject retain count of the kext itself)

  • OSBundleClasses - CFArray of CFDictionary containing info on C++ classes defined by the kext:

  • OSMetaClassName - CFString

  • OSMetaClassSuperclassName - CFString, absent for root classes

  • OSMetaClassTrackingCount - CFNumber giving the instance count of the class itself, plus 1 for each direct subclass with any instances

Availability
  • Available in OS X v10.7 and later.
Declared In
KextManager.h

KextManagerCreateURLForBundleIdentifier

Create a URL locating a kext with a given bundle identifier.

CFURLRef KextManagerCreateURLForBundleIdentifier(
   CFAllocatorRef allocator,
   CFStringRef kextIdentifier)AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER;
Parameters
allocator

The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

kextIdentifier

The bundle identifier to look up.

Return Value

A CFURLRef locating a kext with the requested bundle identifier. Returns NULL if the kext cannot be found, or on error.

Discussion

Kexts are looked up first by whether they are loaded, second by version. Specifically, if kextIdentifier identifies a kext that is currently loaded, the returned URL will locate that kext if it's still present on disk. If the requested kext is not loaded, or if its bundle is not at the location it was originally loaded from, the returned URL will locate the latest version of the desired kext, if one can be found within the system extensions folder. If no version of the kext can be found, NULL is returned.

Availability
  • Available in OS X v10.2 and later.
Declared In
KextManager.h

KextManagerLoadKextWithIdentifier

Request the kext loading system to load a kext with a given bundle identifier.

OSReturn KextManagerLoadKextWithIdentifier(
   CFStringRef kextIdentifier,
   CFArrayRef dependencyKextAndFolderURLs)AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
Parameters
kextIdentifier

The bundle identifier of the kext to look up and load.

dependencyKextAndFolderURLs

An array of additional URLs, of individual kexts and of folders that may contain kexts.

Return Value

kOSReturnSuccess if the kext is successfully loaded (or is already loaded), otherwise returns on error.

Discussion

kextIdentifier is looked up in the system extensions folder and among any kexts from dependencyKextAndFolderURLs. Any non-kext URLs in dependencyKextAndFolderURLs are scanned at the top level for kexts and plugins of kexts.

Either the calling process must have an effective user id of 0 (superuser), or the kext being loaded and all its dependencies must reside in /System and have an OSBundleAllowUserLoad property of true.

Availability
  • Available in OS X v10.6 and later.
Declared In
KextManager.h

KextManagerLoadKextWithURL

Request the kext loading system to load a kext with a given URL.

OSReturn KextManagerLoadKextWithURL(
   CFURLRef kextURL,
   CFArrayRef dependencyKextAndFolderURLs)AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
Parameters
kextURL

The URL of the kext to load.

dependencyKextAndFolderURLs

An array of additional URLs, of individual kexts and of folders that may contain kexts.

Return Value

kOSReturnSuccess if the kext is successfully loaded (or is already loaded), otherwise returns on error.

Discussion

Any non-kext URLs in dependencyKextAndFolderURLs are scanned at the top level for kexts and plugins of kexts.

Either the calling process must have an effective user id of 0 (superuser), or the kext being loaded and all its dependencies must reside in /System and have an OSBundleAllowUserLoad property of true.

Availability
  • Available in OS X v10.6 and later.
Declared In
KextManager.h

KextManagerUnloadKextWithIdentifier

Request the kernel to unload a kext with a given bundle identifier.

OSReturn KextManagerUnloadKextWithIdentifier(
   CFStringRef kextIdentifier)AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER;
Parameters
kextIdentifier

The bundle identifier of the kext to unload.

Return Value

kOSReturnSuccess if the kext is found and successfully unloaded, otherwise returns on error. See /usr/include/libkern/OSKextLib.h for error codes.

Discussion

The calling process must have an effective user id of 0 (superuser).

Availability
  • Available in OS X v10.7 and later.
Declared In
KextManager.h