OSKext.h 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753
  1. /*
  2. * Copyright (c) 2008 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. #ifndef __OSKEXT_H__
  29. #define __OSKEXT_H__
  30. #include <sys/cdefs.h>
  31. __BEGIN_DECLS
  32. #include <CoreFoundation/CoreFoundation.h>
  33. //#include <System/libkern/OSReturn.h>
  34. //#include <System/libkern/OSKextLib.h>
  35. //#include <System/libkern/OSKextLibPrivate.h>
  36. #include <mach/mach.h>
  37. #include <mach-o/arch.h>
  38. // xxx - should I use "Clear" everywhere I use "Flush"
  39. /*!
  40. * @header
  41. * @ignore CF_EXPORT
  42. * @ignore
  43. *
  44. * The OSKext library provides a comprehensive interface for creating,
  45. * examining, and loading kernel extensions (kexts).
  46. *
  47. * <b>NOTICE:</b> This library is neither thread-safe nor garbage-collection
  48. * safe. You must use your own locking with threads sharing access to OSKext.
  49. * You can not use this library in an application with garbage collection.
  50. */
  51. #pragma mark Types and Constants
  52. /*******************************************************************************
  53. * Types and Constants
  54. *******************************************************************************/
  55. /*!
  56. * @typedef OSKextRef
  57. * @abstract A reference to a kernel extension object.
  58. *
  59. * @discussion
  60. * The OSKextRef type refers to a KXKext object, which represents a kernel
  61. * extension bundle on disk, from an archive, or loaded into the kernel.
  62. * OSKext is an opaque type that defines the characteristics and behavior of
  63. * OSKext objects.
  64. *
  65. * The kernel counterpart of OSKext is the OSKext libkern C++ class.
  66. */
  67. typedef struct __OSKext * OSKextRef
  68. ;
  69. #define kOSKextBundleExtension "kext"
  70. #define kOSKextMkextExtension "mkext"
  71. /*!
  72. * @typedef OSKextDiagnosticsFlags
  73. * @constant kOSKextDiagnosticsFlagAll
  74. * @constant kOSKextDiagnosticsFlagValidation
  75. * @constant kOSKextDiagnosticsFlagAuthentication
  76. * @constant kOSKextDiagnosticsFlagDependencies
  77. * @constant kOSKextDiagnosticsFlagWarnings
  78. */
  79. enum {
  80. kOSKextDiagnosticsFlagNone = (UInt32) 0x0U,
  81. kOSKextDiagnosticsFlagValidation = (UInt32) 0x1U,
  82. kOSKextDiagnosticsFlagAuthentication = (UInt32) 0x2U,
  83. kOSKextDiagnosticsFlagDependencies = (UInt32) 0x4U,
  84. kOSKextDiagnosticsFlagWarnings = (UInt32) 0x8U,
  85. kOSKextDiagnosticsFlagAll = (UInt32)0xFFFFFFFFU,
  86. };
  87. typedef UInt32 OSKextDiagnosticsFlags;
  88. typedef UInt64 OSKextLogFlags;
  89. typedef SInt64 OSKextVersion;
  90. typedef kern_return_t OSReturn;
  91. typedef uint8_t OSKextExcludeLevel;
  92. #define kOSKextExcludeNone (0)
  93. #define kOSKextExcludeKext (1)
  94. #define kOSKextExcludeAll (2)
  95. /* Top-level keys for diagnostics dicts. See @link OSKextCopyDiagnostics@/link.
  96. */
  97. // xxx - not sure we need to include these, but it's convenient
  98. const CFStringRef kOSKextDiagnosticsValidationKey;
  99. const CFStringRef kOSKextDiagnosticsAuthenticationKey;
  100. const CFStringRef kOSKextDiagnosticsLinkLoadKey;
  101. const CFStringRef kOSKextDiagnosticsDependenciesKey;
  102. const CFStringRef kOSKextDiagnosticsWarningsKey;
  103. #pragma mark Basic CF Functions
  104. /*********************************************************************
  105. * Basic CF Functions
  106. *********************************************************************/
  107. /*!
  108. * @function OSKextGetTypeID
  109. * @abstract Returns the type identifier for the OSKext opaque type.
  110. *
  111. * @result The type identifier for the OSKext opaque type.
  112. */
  113. CF_EXPORT CFTypeID
  114. OSKextGetTypeID(void)
  115. ;
  116. #pragma mark Module Configuration
  117. /*********************************************************************
  118. * Module Configuration
  119. *********************************************************************/
  120. /*!
  121. * @function OSKextSetArchitecture
  122. * @abstract Sets the architecture used for operations on kexts.
  123. *
  124. * @param anArch
  125. * An <code>NXArchInfo</code> pointer with cputype/subtype or name set.
  126. * Ownership remains with the caller.
  127. * Pass <code>NULL</code> to set the architecture to taht of the running kernel.
  128. *
  129. * @result
  130. * <code>true</code> if the architecture was set as desired,
  131. * <code>false</code> if <code>anArch</code> was not found;
  132. * if <code>false</code>, the architecture will now be that
  133. * of the running kernel.
  134. * xxx - should it just be left unchanged instead?
  135. *
  136. * @discussion
  137. * The kext library uses this architecture for any architecture-specific
  138. * operation, such as property lookups
  139. * (see @link OSKextGetValueForInfoDictionaryKey@/link),
  140. * dependency resolution, executable access during validation and linking.
  141. * The kext architecture is initially that of the running kernel (not of
  142. * the user-space process).
  143. *
  144. * This function looks up the system <code>NXArchInfo</code> struct
  145. * for the struct passed in, first using the cputype/subtype, and if that fails,
  146. * the name. You can therefore use this function to set the architecture
  147. * from an architecture name alone by passing an <code>NXArchInfo</code> struct
  148. * with the desired name,
  149. * but the cputype/subtype set to CPU_TYPE_ANY and CPU_SUBTYPE_ANY.
  150. *
  151. * Changing the kext architecture causes all kexts to flush their load info
  152. * and dependencies with @link OSKextFlushLoadInfo@/link.
  153. */
  154. // xxx - should this also have a flushDependenciesFlag?
  155. CF_EXPORT Boolean
  156. OSKextSetArchitecture(const NXArchInfo * archInfo)
  157. ;
  158. /*!
  159. * @function OSKextGetArchitecture
  160. * @abstract Gets the architecutre used for operations on kexts.
  161. *
  162. * @result
  163. * The architecture used for operations on kexts.
  164. * The caller does not own the returned pointer and should not free it.
  165. *
  166. * @discussion
  167. * The kext library uses this architecture for any architecture-specific
  168. * operation, such as property lookups
  169. * (see @link OSKextGetValueForInfoDictionaryKey@/link),
  170. * dependency resolution, executable access during validation and linking.
  171. * The kext architecture is initially that of the running kernel (not of
  172. * the user-space process).
  173. */
  174. CF_EXPORT const NXArchInfo *
  175. OSKextGetArchitecture(void)
  176. ;
  177. /*!
  178. * @function OSKextGetRunningKernelArchitecture
  179. * @abstract Returns the architecture of the running kernel.
  180. *
  181. * @result
  182. * The architecture of the running kernel.
  183. * The caller does not own the returned pointer and should not free it.
  184. *
  185. * @discussion
  186. * This function consults the kernel task and returns a pointer to the
  187. * <code>NXArchInfo</code> struct representing its architecture.
  188. * The running kernel's architecture does not necessarily match that
  189. * of user space tasks (for example, a 32-bit user space task could be
  190. * running with a 64-bit kernel, or vice-versa).
  191. */
  192. CF_EXPORT const NXArchInfo *
  193. OSKextGetRunningKernelArchitecture(void)
  194. ;
  195. /*! @function OSKextGetLogFlags
  196. @param kext The kext to get the log flags. Pass NULL to get the global flag. */
  197. CF_EXPORT OSKextLogFlags OSKextGetLogFlags(OSKextRef kext);
  198. /*! @function OSKextSetLogFlags */
  199. CF_EXPORT void OSKextSetLogFlags(OSKextRef kext, OSKextLogFlags logFlags);
  200. /*!
  201. * @typedef OSKextLogFunction
  202. * @abstract
  203. * Prototype of a callback function used to log messages from the library.
  204. *
  205. * @param format A printf(3) style format string.
  206. *
  207. * @discussion
  208. * The default log function simply prints to <code>stderr</code
  209. * if <code>msgLogSpec</code> has any bits set.
  210. * If you set the log function to <code>NULL</code>,
  211. * no log messages will be printed.
  212. *
  213. * Log messages have no trailing newline, to accommodate system log facilities.
  214. */
  215. /* xxx - no CF_EXPORT, compiler dies */
  216. typedef void (*OSKextLogFunction)(
  217. OSKextLogFlags flags,
  218. const char * format,
  219. ...)
  220. ;
  221. /*!
  222. * @function OSKextSetLogFunction
  223. * @abstract Sets the function called to log messages.
  224. *
  225. * @param funct The log function to set.
  226. *
  227. * @discussion
  228. * The default log function simply prints to stderr. If you set the
  229. * log function to <code>NULL</code>, no log messages will be printed.
  230. *
  231. * Log messages have no trailing newline, to accommodate system log facilities.
  232. */
  233. CF_EXPORT void
  234. OSKextSetLogFunction(OSKextLogFunction func)
  235. ;
  236. /*!
  237. * @function OSKextSetSimulatedSafeBoot
  238. * @abstract Sets whether safe boot mode is simulated in the library.
  239. *
  240. * @param flag <code>true</code> to simulate safe boot mode,
  241. * <code>false</code> to not simulate.
  242. *
  243. * @discussion
  244. * Kexts without a valid OSBundleRequired property are not allowed to load
  245. * by the kernel when the system has started in safe boot mode.
  246. * If you turn on simulated safe boot, the kext library can
  247. * catch non-loadable kexts and present appropriate diagnostics.
  248. */
  249. CF_EXPORT void
  250. OSKextSetSimulatedSafeBoot(Boolean flag)
  251. ;
  252. /*!
  253. * @function OSKextGetSimulatedSafeBoot
  254. * @abstract Returns whether safe boot mode is simulated in the library.
  255. *
  256. * @result
  257. * <code>true</code> if safe boot mode is being simulated,
  258. * <code>false</code> if not.
  259. *
  260. * @discussion
  261. * Kexts without a valid OSBundleRequired property are not allowed to load
  262. * by the kernel when the system has started in safe boot mode.
  263. * When simulated safe boot is on, the kext library can
  264. * catch non-loadable kexts and present appropriate diagnostics.
  265. */
  266. CF_EXPORT Boolean
  267. OSKextGetSimulatedSafeBoot(void)
  268. ;
  269. /*!
  270. * @function OSKextGetActualSafeBoot
  271. * @abstract Returns whether safe boot mode is active.
  272. *
  273. * @result
  274. * <code>true</code> if safe boot mode is active,
  275. * <code>false</code> if not.
  276. *
  277. * @discussion
  278. * Kexts without a valid OSBundleRequired property are not allowed to load
  279. * by the kernel when the system has started in safe boot mode.
  280. * The kext library ignores actual safe boot mode, leaving decisions
  281. * regarding safe boot to the kernel.
  282. * If you want to analyze kexts in safe boot mode using the library,
  283. * call @link OSKextSetSimulatedSafeBoot@/link.
  284. */
  285. // xxx - we used to disallow kexts w/debug-log flags in safe boot, too
  286. CF_EXPORT Boolean
  287. OSKextGetActualSafeBoot(void)
  288. ;
  289. /*!
  290. * @function OSKextGetSystemExtensionsFolderURLs
  291. * @abstract Returns the standard system extension folder URLs.
  292. *
  293. * @result
  294. * An array containing the standard system extension folder URLs.
  295. * Ownership follows the
  296. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  297. *
  298. * @discussion
  299. * To open all the kexts normally considered for loading by the system,
  300. * pass the return value of this function to
  301. * @link OSKextCreateKextsFromURLs@/link.
  302. */
  303. CF_EXPORT CFArrayRef
  304. OSKextGetSystemExtensionsFolderURLs(void)
  305. ;
  306. /*!
  307. * @function OSKextSetRecordsDiagnostics
  308. * @abstract Sets whether kexts record diagnostic information.
  309. *
  310. * @param flags Indicates which diagnostics to record.
  311. *
  312. * @discussion
  313. * The kext library can record diagnostic information for kexts as
  314. * problems are encountered. These diagnostics can consume a fair
  315. * amount of memory, and should be generated only when desired.
  316. * Recording of diagnostics is set to
  317. * @link kOSKextDiagnosticsFlagNone@/link by default.
  318. * Use this function to turn diagnostics recording off (or back on)
  319. * for particular diagnostic types.
  320. *
  321. * Turning on diagnostics does not calculate or recalculate
  322. * diagnostics. Call the various functions that operate on kexts
  323. * to begin accumulating diagnostics.
  324. *
  325. * Turning diagnostics off does not clear any existing diagnostics.
  326. * Use @link OSKextFlushDiagnostics@/link explicitly to clear
  327. * any diagnostics currently stored.
  328. *
  329. * See also @link OSKextCopyDiagnostics@/link,
  330. * @link OSKextValidate@/link,
  331. * @link OSKextAuthenticate@/link, and
  332. * @link OSKextResolveDependencies@/link.
  333. */
  334. // Could list a pile of see also's here....
  335. CF_EXPORT void
  336. OSKextSetRecordsDiagnostics(OSKextDiagnosticsFlags flags)
  337. ;
  338. /*!
  339. * @function OSKextGetRecordsDiagnostics
  340. * @abstract
  341. * Returns what kinds of diagnostic information kexts record.
  342. *
  343. * @result
  344. * Flags indicating which types of diagnostics are currently
  345. * being recorded. You can bitwise-OR or -AND these with other flags
  346. * to add or remove diagnostics being recorded with
  347. * @link OSKextSetRecordsDiagnostics@/link.
  348. */
  349. CF_EXPORT OSKextDiagnosticsFlags
  350. OSKextGetRecordsDiagnostics(void)
  351. ;
  352. /*!
  353. * @function OSKextSetUsesCaches
  354. * @abstract Sets whether the kext library uses cache files.
  355. *
  356. * @param flag
  357. * <code>true</code> to use caches,
  358. * <code>false</code> to not use caches.
  359. *
  360. * @discussion
  361. * The kext library normally uses caches to speed up reading kexts from
  362. * the system extensions folders.
  363. * Use this function to turn off use of caches; this will cause reading
  364. * of kexts to be dramatically slower.
  365. *
  366. * See also @link OSKextGetUsesCaches@/link.
  367. */
  368. CF_EXPORT void
  369. OSKextSetUsesCaches(Boolean flag)
  370. ;
  371. /*!
  372. * @function OSKextGetUsesCaches
  373. * @abstract
  374. * Returns whether the OSKext library uses cache files.
  375. *
  376. * @result
  377. * <code>true</code> if the library uses caches to speed up reading of kexts,
  378. * <code>false</code> if it doesn't.
  379. *
  380. * @discussion
  381. * The kext library normally uses caches to speed up reading kexts from
  382. * the system extensions folders.
  383. * Use this function to check whether the library is using caches.
  384. *
  385. * See also @link OSKextGetUsesCaches@/link.
  386. */
  387. CF_EXPORT Boolean
  388. OSKextGetUsesCaches(void)
  389. ;
  390. #pragma mark Instance Management
  391. /*********************************************************************
  392. * Instance Management
  393. *********************************************************************/
  394. /*!
  395. * @function OSKextCreate
  396. * @abstract Read a single kext from an on-disk bundle, without plugins.
  397. *
  398. * @param allocator
  399. * The allocator to use to allocate memory for the new object.
  400. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  401. * to use the current default allocator.
  402. * @param anURL
  403. * The location of the bundle for which to create an OSKext object.
  404. * @result
  405. * An OSKext object created from the bundle at anURL.
  406. * Ownership follows the
  407. * @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
  408. *
  409. * Returns <code>NULL</code> if there was a memory allocation problem or
  410. * if the bundle doesn't exist at anURL (see Discussion).
  411. * May return an existing OSKext object with the reference count incremented.
  412. *
  413. * @discussion
  414. * Once a kext has been created, it is cached in memory; the kext bundle cache
  415. * is flushed only periodically. OSKextCreate does not check that a cached kext
  416. * bundle still exists in the filesystem. If a kext bundle is deleted
  417. * from the filesystem, it is therefore possible for OSKextCreate
  418. * to return a cached bundle that has actually been deleted.
  419. *
  420. * OSKext uses a CFBundle briefly during initialization, but in order
  421. * to save memory and allow re-reading of kext bundle contents
  422. * from disk, does not retain it. Applications can save further memory
  423. * by flushing info dictionaries so that they are read from disk again
  424. * when needed; see @link OSKextFlushInfoDictionary@/link.
  425. */
  426. CF_EXPORT OSKextRef
  427. OSKextCreate(
  428. CFAllocatorRef allocator,
  429. CFURLRef anURL)
  430. ;
  431. /*!
  432. * @function OSKextCreateKextsFromURL
  433. * @abstract Reads all kexts at an on-disk URL along with their plugins.
  434. *
  435. * @param allocator
  436. * The allocator to use to allocate memory for the new objects.
  437. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  438. * to use the current default allocator.
  439. * @param anURL The URL to scan for kernel extensions.
  440. * @result
  441. * Returns an array containing the kext objects created,
  442. * or <code>NULL</code> on failure.
  443. *
  444. * @discussion
  445. * This function scans <code>anURL</code> for kexts.
  446. * If <code>anURL</code> represents a kext,
  447. * this function reads that kext and its plugins.
  448. * If <code>anURL</code> represents a non-kext directory,
  449. * this functions scans the directory's immediate contents for kext bundles
  450. * and their plugins. It does not scan recursively; only plugins one level
  451. * deep are read.
  452. *
  453. * If given an URL for a kext that is a plugin of another kext, this
  454. * function does not scan for further plugins.
  455. *
  456. * This function does not scan for or read mkext files. Use
  457. * @link OSKextCreateKextsFromMkextFile@/link to read an mkext file.
  458. *
  459. * See @link OSKextCreate OSKextCreate @/link for information
  460. * about kext object caching.
  461. */
  462. CFArrayRef OSKextCreateKextsFromURL(
  463. CFAllocatorRef allocator,
  464. CFURLRef anURL)
  465. ;
  466. /*!
  467. * @function OSKextCreateKextsFromURLs
  468. * @abstract Reads all kexts at an array on-disk URLs along with their plugins.
  469. *
  470. * @param allocator
  471. * The allocator to use to allocate memory for the new objects.
  472. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  473. * to use the current default allocator.
  474. * @param arrayOfURLs The URLs to scan for kernel extensions.
  475. * @result
  476. * Returns an array containing the kext objects created,
  477. * or <code>NULL</code> on failure.
  478. *
  479. * @discussion
  480. * This function scans each URL in <code>arrayOfURLs</code> for kexts.
  481. * If a given URL represents a kext,
  482. * this function reads that kext and its plugins.
  483. * If the URL represents a non-kext directory, this functions scans the
  484. * directory's immediate contents for kext bundles and their plugins.
  485. * It does not scan recursively; only plugins one level deep are read.
  486. *
  487. * If given an URL for a kext that is a plugin of another kext, this
  488. * function does not scan for further plugins.
  489. *
  490. * This function does not scan for or read mkext files. Use
  491. * @link OSKextCreateKextsFromMkextFile@/link to read an mkext file.
  492. *
  493. * See @link OSKextCreate@/link for discussion about kext object caching.
  494. */
  495. CF_EXPORT CFArrayRef
  496. OSKextCreateKextsFromURLs(
  497. CFAllocatorRef allocator,
  498. CFArrayRef arrayOfURLs)
  499. ;
  500. /*!
  501. * @function OSKextGetAllKexts
  502. * @abstract
  503. * Returns an array containing all of the kexts currently open in the application.
  504. *
  505. * @result
  506. * A CFArray object containing OSKext objects for each open kext
  507. * in the application. Ownership follows the
  508. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  509. *
  510. * @discussion
  511. * This function is potentially expensive, so use with care.
  512. */
  513. CF_EXPORT CFArrayRef
  514. OSKextGetAllKexts(void)
  515. ;
  516. /*! @function OSKextCopyKextsWithIdentifier */
  517. CF_EXPORT CFArrayRef OSKextCopyKextsWithIdentifier(CFStringRef bundleID);
  518. /*! @function OSKextGetKextsWithIdentifiers
  519. @discussion Follows Create Rule.
  520. */
  521. CF_EXPORT CFArrayRef OSKextGetKextsWithIdentifiers(CFArrayRef bundleIDs);
  522. /*!
  523. * @function OSKextGetKextWithIdentifierAndVersion
  524. * @abstract
  525. * Locate a kext given its program-defined identifier and version.
  526. *
  527. * @param aBundleID
  528. * The identifier of the kext to locate.
  529. * Note that identifier names are case-sensitive.
  530. * @param aVersion
  531. * The version of the kext to locate.
  532. * @result
  533. * An OSKext object, or <code>NULL</code> if the kext was not found.
  534. * Ownership follows the
  535. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  536. *
  537. * @discussion
  538. * For a kext to be located using its identifier and version,
  539. * the kext object must have already been created.
  540. * See @link OSKextGetKextWithIdentifierAndVersion@/link for more.
  541. */
  542. // xxx - check on same-version ordering with folks
  543. CF_EXPORT OSKextRef
  544. OSKextGetKextWithIdentifierAndVersion(
  545. CFStringRef aBundleID, OSKextVersion aVersion)
  546. ;
  547. /*!
  548. * @function OSKextGetKextsWithIdentifier
  549. * @abstract Locate all kexts with a given program-defined identifier.
  550. *
  551. * @param aBundleID
  552. * The identifier of the kext to locate.
  553. * Note that identifier names are case-sensitive.
  554. * @result
  555. * An CFArray of kext objects with the given identifier,
  556. * or <code>NULL</code> on error.
  557. * Ownership follows the
  558. * @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
  559. *
  560. * @discussion
  561. * This function is useful for locating duplicates of a given kext.
  562. *
  563. * See @link OSKextGetKextWithIdentifier@/link for general information
  564. * on looking up kexts by identifier.
  565. */
  566. CF_EXPORT CFArrayRef
  567. OSKextCopyKextsWithIdentifier(
  568. CFStringRef aBundleID)
  569. ;
  570. /*!
  571. * @function OSKextGetLoadedKextWithIdentifier
  572. * @abstract
  573. * Locate the loaded kext with a given program-defined identifier.
  574. *
  575. * @param aBundleID
  576. * The identifier of the kext to locate.
  577. * Note that identifier names are case-sensitive.
  578. * @result
  579. * An OSKext object, or <code>NULL</code> if the kext was not found.
  580. * Ownership follows the
  581. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  582. *
  583. * @discussion
  584. * You must call @link OSKextReadLoadedKextInfo@/link before calling this
  585. * function for it to find anything.
  586. *
  587. * See @link OSKextGetKextWithIdentifier@/link for general information
  588. * on looking up kexts by identifier.
  589. */
  590. CF_EXPORT OSKextRef
  591. OSKextGetLoadedKextWithIdentifier(
  592. CFStringRef aBundleID)
  593. ;
  594. /*!
  595. * @function OSKextGetCompatibleKextWithIdentifier
  596. * @abstract
  597. * Locate the kext with a given program-defined identifier
  598. * that is compatible with a requested version.
  599. *
  600. * @param aBundleID
  601. * The identifier of the kext to locate.
  602. * Note that identifier names are case-sensitive.
  603. * @param requestedVersion
  604. * The version that the kext must be compatible with.
  605. * @result
  606. * An OSKext object, or <code>NULL</code> if the kext was not found.
  607. * Ownership follows the
  608. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  609. *
  610. * @discussion
  611. * A kext is compatible with a version if that version lies between
  612. * its CFBundleVersion and its OSBundleCompatibleVersion (inclusive).
  613. *
  614. * See @link OSKextGetKextWithIdentifier@/link for general information
  615. * on looking up kexts by identifier.
  616. */
  617. CF_EXPORT OSKextRef
  618. OSKextGetCompatibleKextWithIdentifier(
  619. CFStringRef aBundleID,
  620. OSKextVersion requestedVersion)
  621. ;
  622. #pragma mark Basic Accessors
  623. /*********************************************************************
  624. * Basic Accessors
  625. *********************************************************************/
  626. /*!
  627. * @function OSKextGetURL
  628. * @abstract Returns the CFURL of a kext bundle.
  629. *
  630. * @param aKext The kext to get the URL for.
  631. * @result A CFURL object. Ownership follows the
  632. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  633. *
  634. * @discussion
  635. * This function returns the CFURL that <code>aKext</code>
  636. * was originally created with.
  637. * It should be resolved to its base for comparison with other kext
  638. * URLs.
  639. */
  640. CF_EXPORT CFURLRef
  641. OSKextGetURL(OSKextRef aKext)
  642. ; // always absolute
  643. /*!
  644. * @function OSKextGetIdentifier
  645. * @abstract Returns the bundle identifier from a kext's information property list.
  646. *
  647. * @param aKext The kext to get the identifier for.
  648. * @result
  649. * A CFString object containing the kext bundle's identifier,
  650. * or <code>NULL</code> if none was specified in the information property list.
  651. * Ownership follows the
  652. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  653. */
  654. CF_EXPORT CFStringRef
  655. OSKextGetIdentifier(OSKextRef aKext)
  656. ;
  657. /*!
  658. * @function OSKextGetValueForInfoDictionaryKey
  659. * @abstract
  660. * Returns a (possibly architecture-specific) value
  661. * in a kext's information dictionary.
  662. *
  663. * @param aKext The kext to get the property for.
  664. * @param key The base key identifying the property.
  665. * @result
  666. * A value corresponding to <code>key</code> in <code>aKext</code>'s
  667. * information dictionary.
  668. * If available, an architecture-specific value is returned,
  669. * otherwise the global value is returned. Ownership follows the
  670. * @link //apple_ref/doc/uid/20001148-SW1 Get Rule@/link.
  671. *
  672. * @discussion
  673. * This function first looks for a property value specific to the current kext
  674. * architecture, as set with @link OSKextSetArchitecture@/link,
  675. * by appending an underscore plus the architecture name to the base key.
  676. * If such a value is not found, it looks for the property using the base key.
  677. * For example, if the currently set architecture is i386, and
  678. * IOKitPersonalities is requested, this function looks up the key
  679. * IOKitPersonalities_i386; if that doesn't exist, then it uses
  680. * IOKitPersonalities.
  681. *
  682. * Some properties are not allowed to be made architecture-specific;
  683. * if such keys are defined, they are ignored by this function:
  684. *
  685. * * CFBundleIdentifier
  686. * * CFBundleVersion
  687. * * CFBundleExecutable
  688. * * OSBundleIsInterface
  689. * * OSKernelResource
  690. *
  691. * This function looks up architecture-specific values for generic bundle
  692. * properties, such as CFBundlePackageType, but such values are of course
  693. * ignored by CFBundle.
  694. *
  695. * If you want to look up a property with a raw key, get the information
  696. * dictionary directly using @link OSKextCopyInfoDictionary@/link or
  697. * by opening a CFBundle for the kext's URL.
  698. *
  699. * This function reads the info dictionary from disk if necessary.
  700. * See @link OSKextFlushInfoDictionary@/link.
  701. */
  702. CF_EXPORT CFTypeRef
  703. OSKextGetValueForInfoDictionaryKey(
  704. OSKextRef aKext,
  705. CFStringRef key)
  706. ;
  707. /*!
  708. * @function OSKextCopyInfoDictionary
  709. * @abstract Returns a copy of a kext's information dictionary.
  710. *
  711. * @param aKext The kext to get the information dictionary for.
  712. * @result
  713. * A CFDictionary object containing the data stored in the kext's
  714. * information property list.
  715. * OSKext may add extra keys to this dictionary for its own use.
  716. * Ownership follows the
  717. * @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
  718. *
  719. * @discussion
  720. * This function uses @link IOCFUnserialize@/link to parse the XML
  721. * of the info dictionary, in order to match the parsing used in the kernel.
  722. */
  723. CF_EXPORT CFMutableDictionaryRef
  724. OSKextCopyInfoDictionary(OSKextRef aKext)
  725. ;
  726. /*!
  727. * @function OSKextFlushInfoDictionary
  728. * @abstract Releases a kext's info dictionary.
  729. *
  730. * @param aKext The kext that should release its info dictionary.
  731. * If <code>NULL</code>, all open kexts' info dictionaries
  732. * are flushed.
  733. *
  734. * @discussion
  735. * OSKexts accumulate a fair amount of information as they are created
  736. * and used; when many kext objects are created the total memory
  737. * consumption can be significant. If an application won't be using
  738. * kexts for long periods of time, it can flush this information
  739. * to save memory; the information will later be re-read from disk
  740. * or recreated as necessary.
  741. *
  742. * Flushing info dictionaries also allows kext objects to synchronize
  743. * with updates on disk; they will automatically re-sort in the
  744. * internal lookup tables to reflect changed versions, for example.
  745. * (xxx - well they will! that's not fully implemented yet)
  746. *
  747. * See also @link OSKextFlushDependencies@/link,
  748. * @link OSKextFlushLoadInfo@/link,
  749. * and @link OSKextFlushDiagnostics@/link.
  750. *
  751. * Kext objects created from an mkext cannot flush their info
  752. * dictionaries.
  753. */
  754. CF_EXPORT void
  755. OSKextFlushInfoDictionary(OSKextRef aKext)
  756. ;
  757. /*!
  758. * @function OSKextGetVersion
  759. * @abstract Returns the version of a kext.
  760. *
  761. * @param aKext The kext to get the version for.
  762. * @result The version of the kext as a 64-bit integer.
  763. *
  764. * @discussion
  765. * xxx - needs more info on version format
  766. * xxx - need to fix definition of OSKextVersion.
  767. */
  768. CF_EXPORT OSKextVersion
  769. OSKextGetVersion(OSKextRef aKext)
  770. ;
  771. /*!
  772. * @function OSKextGetCompatibleVersion
  773. * @abstract Returns the compatible version of a kext
  774. *
  775. * @param aKext The kext to get the compatible version for.
  776. * @result The compatible version of the kext as a 64-bit integer.
  777. *
  778. * @discussion
  779. * This function returns the value of a kext's OSBundleCompatibleVersion
  780. * property, parsed into a 64-bit integer that can be compared using
  781. * standard integer comparison operators.
  782. *
  783. * xxx - needs more info on version format, ref to tn: http://developer.apple.com/technotes/tn/tn1132.html
  784. */
  785. CF_EXPORT OSKextVersion
  786. OSKextGetCompatibleVersion(OSKextRef aKext)
  787. ;
  788. /*!
  789. * @function OSKextCopyUUIDForArchitecture
  790. * @abstract
  791. * Returns the compiler-generated UUID of a kext for a given architecture.
  792. *
  793. * @param aKext The kext to get the UUID for.
  794. * @param anArch The architecture desired.
  795. * Pass <code>NULL</code> to get the UUID for the
  796. * current architecture.
  797. * @result
  798. * A CFData object containing the UUID of the kext's executable
  799. * for <code>anArch</code>, or the currently set architecture if
  800. * <code>anArch</code> is <code>NULL</code>.
  801. *
  802. * @discussion
  803. * UUIDs are used in addition to bundle versions to check the identify of
  804. * kexts loaded in the kernel.
  805. */
  806. CF_EXPORT CFDataRef
  807. OSKextCopyUUIDForArchitecture(OSKextRef aKext,
  808. const NXArchInfo * anArch)
  809. ;
  810. /*!
  811. * @function OSKextIsKernelComponent
  812. * @abstract Returns whether a kext represents a kerne programming interface.
  813. *
  814. * @param aKext The kext to examine.
  815. * @result
  816. * <code>true</code> if <code>aKext</code> represents
  817. * a kerne programming interface, <code>false</code> otherwise.
  818. *
  819. * @discussion
  820. * A small set of kexts represent interfaces built into the kernel that can
  821. * be linked against individually. These are commonly known as
  822. * kernel programming interfaces (KPIs),
  823. * and the kexts containing them as "pseudokexts".
  824. *
  825. * If a kext is a kernel component, then it is also always an interface
  826. * (see @link OSKextIsInterface@/link).
  827. */
  828. CF_EXPORT Boolean
  829. OSKextIsKernelComponent(OSKextRef aKext)
  830. ;
  831. /*!
  832. * @function OSKextIsInterface
  833. * @abstract
  834. * Returns whether a kext acts as a linkage subset for another kext,
  835. * also known as a symbol set.
  836. *
  837. * @param aKext The kext to examine.
  838. * @result
  839. * <code>true</code> if <code>aKext</code> is an interface kext,
  840. * <code>false</code> otherwise.
  841. *
  842. * @discussion
  843. * An interface kext has no actual code in its executable, but merely
  844. * re-exports a set of symbols (typically a subset)
  845. * from those of its dependencies.
  846. *
  847. * Currently the only interface kexts are the kernel component kexts
  848. * the define the kernel programming interfaces for Mac OS X.
  849. */
  850. CF_EXPORT Boolean
  851. OSKextIsInterface(OSKextRef aKext)
  852. ;
  853. /*!
  854. * @function OSKextIsLibrary
  855. * @abstract Returns whether a kext can be declared as a library.
  856. *
  857. * @param aKext The kext to examine.
  858. * @result
  859. * <code>true</code> if <code>aKext</code> is a library kext, <code>false</code>
  860. * otherwise.
  861. *
  862. * @discussion
  863. * A kext is a library kext if it has a valid OSBundleCompatibleVersion
  864. * property. Another kext can link against a library kext by listing
  865. * the library's identifier and required version in its OSBundleLibraries
  866. * property.
  867. */
  868. CF_EXPORT Boolean
  869. OSKextIsLibrary(OSKextRef aKext)
  870. ;
  871. /*!
  872. * @function OSKextDeclaresExecutable
  873. * @abstract Returns whether a kext declares a CFBundleExecutable property.
  874. *
  875. * @param aKext The kext to examine.
  876. * @result
  877. * <code>true</code> if <code>aKext</code> has a nonempty CFBundleExecutable
  878. * property, <code>false</code> otherwise.
  879. *
  880. * @discussion
  881. * A kext with an executable is either a loadable kext with actual executable
  882. * code, or an interface kext whose executable serves to restrict linkage
  883. * to a subset of the symbols of another kext. See @link OSKextIsInterface@/link
  884. * for more on the latter type.
  885. */
  886. CF_EXPORT Boolean
  887. OSKextDeclaresExecutable(OSKextRef aKext)
  888. ;
  889. /*!
  890. * @function OSKextHasLogOrDebugFlags
  891. * @abstract
  892. * Returns whether a kext has OSBundleEnableKextLogging set to a true value or
  893. * any of its IOKitPersonalities has a nonzero IOKitDebug property.
  894. *
  895. * @param aKext The kext to examine.
  896. * @result
  897. * <code>true</code> if <code>aKext</code> has a true OSBundleEnableKextLogging
  898. * property or if any personality for the currently set architecture has a
  899. * nonzero IOKitDebug property, <code>false</code> otherwise.
  900. *
  901. * @discussion
  902. * Kexts built for distribution should not have any logging or debug flags set.
  903. */
  904. CF_EXPORT Boolean
  905. OSKextHasLogOrDebugFlags(OSKextRef aKext)
  906. ;
  907. /*!
  908. * @function OSKextIsLoadableInSafeBoot
  909. * @abstract Returns whether the kernel will load a kext during safe boot.
  910. *
  911. * @param aKext The kext to examine.
  912. * @result
  913. * <code>true</code> if the kernel will allow <code>aKext</code> during
  914. * safe boot, <code>false</code> otherwise.
  915. *
  916. * @discussion
  917. * A kext is loadable during safe boot if it has an OSBundleRequired
  918. * property for the kernel's architecture with a value of
  919. * "Root", "Local-Root", "Network-Root", "Console", or "Safe Boot".
  920. *
  921. * This function does not generally cover the issue of loadability due
  922. * to problems with validation, authentication, or dependency resolution.
  923. * To determine whether a kext can actually be loaded, use
  924. * @link OSKextIsLoadable@/link.
  925. */
  926. CF_EXPORT Boolean
  927. OSKextIsLoadableInSafeBoot(OSKextRef aKext)
  928. ;
  929. /*!
  930. * @function OSKextCopyArchitectures
  931. * @abstract
  932. * Returns a list of <code>NXArchInfo</code> structs for the architectures
  933. * found in a kext's executable.
  934. *
  935. * @param aKext The kext to examine.
  936. * @result
  937. * A <code>NULL</code>-terminated list of <code>NXArchInfo</code>
  938. * struct pointers describing
  939. * the architectures supported by <code>aKext</code>,
  940. * or <code>NULL</code> if <code>aKext</code> has no executable.
  941. * The caller is responsible for freeing the list, but not the individual
  942. * <code>NXArchInfo</code> pointers.
  943. */
  944. CF_EXPORT const NXArchInfo **
  945. OSKextCopyArchitectures(OSKextRef aKext)
  946. ;
  947. /*!
  948. * @function OSKextSupportsArchitecture
  949. * @abstract Returns whether a kext has an executable for a given architecture.
  950. *
  951. * @param aKext The kext to examine.
  952. * @param anArch The <code>NXArchInfo</code> description to check.
  953. * If <code>NULL</code>, uses the currently set architecture.
  954. * @result
  955. * <code>true</code> if <code>aKext</code>'s executable contains code for
  956. * <code>anArch</code>.
  957. *
  958. * @discussion
  959. */
  960. // null for current (NOT host) arch
  961. Boolean OSKextSupportsArchitecture(OSKextRef aKext,
  962. const NXArchInfo * anArch)
  963. ; // if NULL, uses current default
  964. /*!
  965. * @function OSKextCopyPlugins
  966. * @abstract Retrieve the plugins of a kext.
  967. *
  968. * @param aKext The kext to get plugins for.
  969. * @result
  970. * An array containing the kexts that are plugins of <code>aKext</code>.
  971. *
  972. * @discussion
  973. * This function scans the plugins folder of <code>aKext</code>
  974. * and returns an array of the kexts found.
  975. * This may result in the creation of new kext objects.
  976. *
  977. * If <code>aKext</code> is a plugin of another kext
  978. * see @link OSKextIsPlugin@/link),
  979. * this function returns an empty array.
  980. */
  981. CF_EXPORT CFArrayRef
  982. OSKextCopyPlugins(OSKextRef aKext)
  983. ;
  984. /*!
  985. * @function OSKextIsPlugin
  986. * @abstract Returns whether a kext is a plugin of some other kext.
  987. *
  988. * @param aKext The kext to examine.
  989. * @result
  990. * <code>true</code> if <code>aKext</code> is a plugin of another kext,
  991. * <code>false</code> otherwise.
  992. *
  993. * @discussion
  994. * This function uses a simple algorithm that just checks for the substring
  995. * ".kext/" in the absolute path leading up to the kext's bundle name.
  996. */
  997. CF_EXPORT Boolean
  998. OSKextIsPlugin(OSKextRef aKext)
  999. ;
  1000. /*!
  1001. * @function OSKextCopyContainerForPluginKext
  1002. * @abstract Returns the kext that is the container for a plugin kext.
  1003. *
  1004. * @param aKext The kext to find a parent for.
  1005. * @result
  1006. * The kext that contains <code>aKext</code> in its PlugIns folder,
  1007. * or <code>NULL</code> if <code>aKext</code> is not a plugin.
  1008. * Ownership follows the
  1009. * @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
  1010. *
  1011. * @discussion
  1012. * This function creates a kext object for the longest portion of the
  1013. * path leading to <code>aKext</code>, then checks to see whether
  1014. * <code>aKext</code> is a plugin of that kext by <code>CFBundle</code>'s
  1015. * semantics. If so, that kext is returned.
  1016. * This may result in the creation of a new kext.
  1017. */
  1018. CF_EXPORT OSKextRef
  1019. OSKextCopyContainerForPluginKext(OSKextRef aKext)
  1020. ;
  1021. /*!
  1022. * @function OSKextCopyPersonalitiesArray
  1023. * @abstract Returns the personalities of a kext for the current kext architecture.
  1024. *
  1025. * @param aKext The kext to retrieve personalities for.
  1026. * @result An array of IOKit personality dictionaries.
  1027. *
  1028. * @discussion
  1029. * IOKitPersonalities in kexts require some processing before being sent
  1030. * to the kernel, and the functions that send personalities expect an array
  1031. * rather than a dictionary. This function facilitates such use.
  1032. *
  1033. * Use @link OSKextGetValueForInfoDictionaryKey@/link to retrieve the raw
  1034. * personalities dictionary for the current architecture.
  1035. */
  1036. CF_EXPORT CFArrayRef
  1037. OSKextCopyPersonalitiesArray(OSKextRef aKext)
  1038. ;
  1039. // xxx - would it be awful to have a function that takes a CFTypeRef that's
  1040. // xxx - a single kext, an array of kexts, or NULL for all open kexts?
  1041. /*!
  1042. * @function OSKextCopyPersonalitiesOfKexts
  1043. * @abstract
  1044. * Returns the personalities of multiple kexts for the current kext architecture.
  1045. *
  1046. * @param kextArray The kexts to retrieve personalities for.
  1047. * Pass <code>NULL</code> to retrieve personalities for all open kexts.
  1048. * @result An array of IOKit personality dictionaries.
  1049. *
  1050. * @discussion
  1051. * IOKitPersonalities in kexts require some processing before being sent
  1052. * to the kernel, and the functions that send personalities expect an array
  1053. * rather than a dictionary. This function facilitates such use.
  1054. */
  1055. CF_EXPORT CFArrayRef
  1056. OSKextCopyPersonalitiesOfKexts(CFArrayRef kextArray)
  1057. ;
  1058. /*!
  1059. * @function OSKextCopyExecutableForArchitecture
  1060. * @abstract
  1061. * Returns a kext's Mach-O executable, thinned to a single architecture
  1062. * if desired.
  1063. *
  1064. * @param aKext The kext to retrieve the executable from.
  1065. * @param anArch The architecture desired.
  1066. * Pass <code>NULL</code> to get the whole, unthinned exectuable.
  1067. * @result
  1068. * A <code>CFData</code> object containing the code
  1069. * for the specified architecture, or <code>NULL</code> if it can't be found.
  1070. *
  1071. * @discussion
  1072. * Note that this function does not use the default kext architecture set by
  1073. * @link OSKextSetArchitecture@/link when given no architecture.
  1074. */
  1075. CF_EXPORT CFDataRef
  1076. OSKextCopyExecutableForArchitecture(OSKextRef aKext,
  1077. const NXArchInfo * anArch)
  1078. ;
  1079. /*!
  1080. * @function OSKextCopyResource
  1081. * @abstract Returns a named resource from a kext's bundle.
  1082. *
  1083. * @param aKext The kext to get a resource from.
  1084. * @param resourceName The name of the requested resource.
  1085. * @param resourceType The abstract type of the requested resource.
  1086. * The type is expressed as a filename extension,
  1087. * such as <code>jpg</code>.
  1088. * Pass <code>NULL</code> if you don’t need
  1089. * to search by type.
  1090. *
  1091. * @result
  1092. * A <code>CFData</code> object containing the resource file's contents,
  1093. * or <code>NULL</code> if the resource can't be found.
  1094. *
  1095. * @discussion
  1096. * For a kext created from an on-disk URL, this function uses CFBundle
  1097. * semantics to locate the resource file. Note that localized resources
  1098. * and resource subdirectories are not available to kexts calling
  1099. * @link //apple_ref/c/func/OSKextRequestResource OSKextRequestResource@/link
  1100. * from within the kernel (because the process providing them runs as root).
  1101. * You can store such resources in a kext bundle and use them in applications,
  1102. * but they will not be available to the kext loaded in kernel.
  1103. */
  1104. CF_EXPORT CFDataRef
  1105. OSKextCopyResource(
  1106. OSKextRef aKext,
  1107. CFStringRef resourceName,
  1108. CFStringRef resourceType)
  1109. ;
  1110. #pragma mark Dependency Resolution
  1111. /*********************************************************************
  1112. * Dependency Resolution
  1113. *********************************************************************/
  1114. /*!
  1115. * @function OSKextResolveDependencies
  1116. * @abstract Calculate the dependency graph for a kext.
  1117. *
  1118. * @param aKext The kext to resolve dependencies for.
  1119. * @result
  1120. * <code>true</code> if all dependencies are successfully resolved,
  1121. * <code>false</code> otherwise.
  1122. *
  1123. * @discussion
  1124. * This function examines the OSBundleLibraries property of <code>aKext</code>
  1125. * and looks for compatible open kexts. Priority is given to kexts marked as
  1126. * loaded (see @link OSKextReadLoadedKextInfo@/link and
  1127. * @link OSKextFlushLoadInfo@/link). Otherwise the most recent
  1128. * compatible version is used; if multiple kexts with the same identifier and
  1129. * version exist, the last one created is used.
  1130. *
  1131. * Any problems resolving dependencies are stored in a diagnostics dictionary,
  1132. * which you can retrieve using @link OSKextCopyDiagnostics@/link.
  1133. *
  1134. * If a kext's dependencies have already been resolved, this function does
  1135. * no work and returns <code>true</code>.
  1136. * If you want to recalculate a kext's dependencies, call
  1137. * @link OSKextFlushDependencies@/link first.
  1138. */
  1139. // xxx - check on same-version ordering with folks
  1140. CF_EXPORT Boolean
  1141. OSKextResolveDependencies(OSKextRef aKext)
  1142. ;
  1143. /*!
  1144. * @function OSKextFlushDependencies
  1145. * @abstract Clears the dependency graph of a kext.
  1146. *
  1147. * @param aKext The kext to flush dependencies for.
  1148. * Pass <code>NULL</code> to flush dependencies for all kexts.
  1149. *
  1150. * @discussion
  1151. * OSKexts accumulate a fair amount of information as they are created
  1152. * and used; when many kext objects are created the total memory
  1153. * consumption can be significant. If an application won't be using
  1154. * kexts for long periods of time, it can flush this information
  1155. * to save memory; the information will later be re-read from disk
  1156. * or recreated as necessary.
  1157. *
  1158. * Flushing dependencies is also useful when readling loaded kext
  1159. * information from the kernel with @link OSKextReadLoadedKextInfo@/link
  1160. * (in fact, that function takes a flag to do it as part of its work).
  1161. * Dependency resolution gives priority to kexts marked as loaded,
  1162. * so it's wise to call flush dependencies before reading load info
  1163. * and before doing any operation that resolves dependencies.
  1164. * Conversely, if you want to resolve dependencies without consideration
  1165. * for which kexts are loaded, call @link OSKextFlushLoadInfo@/link
  1166. * beforehand (with or without the flag to flush dependencies).
  1167. *
  1168. * This function also clears any dependency resolution diagnostics.
  1169. * See also @link OSKextFlushInfoDictionary@/link,
  1170. * @link OSKextFlushLoadInfo@/link,
  1171. * and @link OSKextFlushDiagnostics@/link.
  1172. */
  1173. CF_EXPORT void
  1174. OSKextFlushDependencies(OSKextRef aKext)
  1175. ;
  1176. /*!
  1177. * @function OSKextCopyDeclaredDependencies
  1178. * @abstract Returns the kexts identified in a kext's OSBundleLibraries property.
  1179. *
  1180. * @param aKext The kext to get dependencies for.
  1181. * @param needAllFlag If <code>true</code>, the function returns
  1182. * <code>NULL</code> if any dependency isn't found.
  1183. * @result
  1184. * A <code>CFArray</code> containing the kexts found.
  1185. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1186. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1187. * dependencies are found, this function returns <code>NULL</code>.
  1188. *
  1189. * @discussion
  1190. * This function calls @link OSKextResolveDependencies@/link to find
  1191. * dependencies.
  1192. */
  1193. CF_EXPORT CFArrayRef
  1194. OSKextCopyDeclaredDependencies(
  1195. OSKextRef aKext,
  1196. Boolean needAllFlag)
  1197. ;
  1198. /*!
  1199. * @function OSKextCopyLinkDependencies
  1200. * @abstract Returns the kexts that a kext links directly against.
  1201. *
  1202. * @param aKext The kext to get dependencies for.
  1203. * @param needAllFlag If <code>true</code>, the function returns
  1204. * <code>NULL</code> if any dependency isn't found.
  1205. * @result
  1206. * A <code>CFArray</code> containing the kexts found.
  1207. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1208. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1209. * dependencies are found, this function returns <code>NULL</code>.
  1210. *
  1211. * @discussion
  1212. * Link dependencies are how loaded kext relationships are tracked
  1213. * in the kernel (as shown by the <code>kextstat(8)</code> program).
  1214. * Some library kexts contain no executable, merely collecting sets of
  1215. * other libraries for convenience or compatiblity purposes.
  1216. * This function follows through such indirect libraries to find kexts
  1217. * with executables that <code>aKext</code> will actually link against.
  1218. *
  1219. * This function calls @link OSKextResolveDependencies@/link to find
  1220. * dependencies.
  1221. */
  1222. // xxx - need to insert a manpage link on kextstat
  1223. CF_EXPORT CFArrayRef
  1224. OSKextCopyLinkDependencies(
  1225. OSKextRef aKext,
  1226. Boolean needAllFlag)
  1227. ;
  1228. /*!
  1229. * @function OSKextCopyLoadList
  1230. * @abstract
  1231. * Returns the entire list of kexts in the load graph of a kext
  1232. * (including that kext).
  1233. *
  1234. * @param aKext The kext to get the load list for.
  1235. * @param needAllFlag If <code>true</code>, the function returns
  1236. * <code>NULL</code> if any dependency isn't found.
  1237. * @result
  1238. * A <code>CFArray</code> containing the kexts found.
  1239. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1240. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1241. * dependencies are found, this function returns <code>NULL</code>.
  1242. *
  1243. * @discussion
  1244. * The fully-resolved load list represents all the kexts needed to load
  1245. * <code>aKext</code> into the kernel, in an order guaranteed to work for
  1246. * sequential starting and matching with IOKit personalities.
  1247. *
  1248. * This function calls @link OSKextResolveDependencies@/link to find
  1249. * dependencies.
  1250. */
  1251. CF_EXPORT CFMutableArrayRef
  1252. OSKextCopyLoadList(
  1253. OSKextRef aKext,
  1254. Boolean needAllFlag)
  1255. ;
  1256. /*!
  1257. * @function OSKextCopyLoadListForKexts
  1258. * @abstract
  1259. * Returns the entire list of kexts in load order of the merged load graph
  1260. * of the provided list of kexts (including those kexts).
  1261. *
  1262. * @param kexts The kexts to get the load list for.
  1263. * @param needAllFlag If <code>true</code>, the function returns
  1264. * <code>NULL</code> if any dependency isn't found.
  1265. *
  1266. * @result
  1267. * A <code>CFArray</code> containing the kexts found.
  1268. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1269. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1270. * dependencies are found, this function returns <code>NULL</code>.
  1271. *
  1272. * @discussion
  1273. * The fully-resolved load list represents all of the kexts needed to load
  1274. * every kext in <code>kexts</code> into the kernel, in an order guaranteed to
  1275. * work for sequential starting and matching with IOKit personalities.
  1276. *
  1277. * This function calls @link OSKextResolveDependencies@/link to find
  1278. * dependencies.
  1279. */
  1280. CF_EXPORT CFMutableArrayRef
  1281. OSKextCopyLoadListForKexts(
  1282. CFArrayRef kexts,
  1283. Boolean needAllFlag)
  1284. ;
  1285. /*!
  1286. * @function OSKextCopyAllDependencies
  1287. * @abstract
  1288. * Returns all kexts that a given kexts depends on, directly or indirectly.
  1289. *
  1290. * @param aKext The kext to get dependencies for.
  1291. * @param needAllFlag If <code>true</code>, the function returns
  1292. * <code>NULL</code> if any dependency isn't found.
  1293. * @result
  1294. * A <code>CFArray</code> containing the kexts found.
  1295. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1296. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1297. * dependencies are found, this function returns <code>NULL</code>.
  1298. *
  1299. * @discussion
  1300. * This function calls @link OSKextResolveDependencies@/link to find
  1301. * dependencies.
  1302. */
  1303. CF_EXPORT CFMutableArrayRef
  1304. OSKextCopyAllDependencies(
  1305. OSKextRef aKext,
  1306. Boolean needAllFlag)
  1307. ;
  1308. /*!
  1309. * @function OSKextCopyIndirectDependencies
  1310. * @abstract
  1311. * Returns all kexts that a given kexts depends on indirectly.
  1312. *
  1313. * @param aKext The kext to get dependencies for.
  1314. * @param needAllFlag If <code>true</code>, the function returns
  1315. * <code>NULL</code> if any dependency isn't found.
  1316. * @result
  1317. * A <code>CFArray</code> containing the kexts found.
  1318. * If <code>needAllFlag</code> is <code>false</code>, the array may be missing
  1319. * some kexts. If <code>needAllFlag</code> is <code>true</code> and not all
  1320. * dependencies are found, this function returns <code>NULL</code>.
  1321. *
  1322. * @discussion
  1323. * Note that the list of indirect dependencies includes all kexts declared
  1324. * as dependencies by the direct dependencies of <code>aKext</code> -
  1325. * it may therefore include a direct dependency as well if some other
  1326. * kext in the load graph declares it.
  1327. *
  1328. * This function calls @link OSKextResolveDependencies@/link to find
  1329. * dependencies.
  1330. */
  1331. // xxx - This one isn't really useful, is it?
  1332. CFMutableArrayRef OSKextCopyIndirectDependencies(
  1333. OSKextRef aKext,
  1334. Boolean needAllFlag)
  1335. ;
  1336. /*!
  1337. * @function OSKextDependsOnKext
  1338. * @abstract
  1339. * Returns whether a kext depends on a given library kext,
  1340. * directly or indirectly.
  1341. *
  1342. * @param aKext The kext to examine.
  1343. * @param libraryKext The possible library kext.
  1344. * @param directFlag
  1345. * If <code>true</code>, only checks for a direct declared dependency;
  1346. * if <code>false</code> check for direct or indirect dependencies.
  1347. * @result
  1348. * <code>true</code> if <code>aKext</code> depends on <code>libraryKext</code>,
  1349. * either directly or indirectly per <code>directFlag</code>.
  1350. * Returns <code>false</code> otherwise.
  1351. *
  1352. * @discussion
  1353. * This function calls @link OSKextResolveDependencies@/link to find
  1354. * dependencies.
  1355. *
  1356. * This function works with actual dependency resolution, not potential.
  1357. * If there are multiple kexts with the same bundle identifier,
  1358. * <code>aKext</code> may not be the one chosen during resolution
  1359. * and so it might appear that no kexts depend on it, even though they could.
  1360. */
  1361. CF_EXPORT Boolean
  1362. OSKextDependsOnKext(
  1363. OSKextRef aKext,
  1364. OSKextRef libraryKext,
  1365. Boolean directFlag)
  1366. ;
  1367. /*!
  1368. * @function OSKextCopyDependents
  1369. * @abstract
  1370. * Return all kexts that depend on a given kext, directly or indirectly.
  1371. *
  1372. * @param aKext The kext to get dependents for.
  1373. * @param directFlag
  1374. * <code>true</code> to get only kexts that declare a direct
  1375. * dependency on <code>aKext</code>,
  1376. * <code>false</code> to get all dependents, direct or indirect.
  1377. * @result
  1378. * An array of all kexts that ultimately depend on <code>aKext</code>,
  1379. * directly or indirectly according to <code>directFlag</code>.
  1380. *
  1381. * @discussion
  1382. * This function calls @link OSKextResolveDependencies@/link on all open
  1383. * kexts to find dependencies. This can be somewhat expensive.
  1384. *
  1385. * This function works with actual dependency resolution, not potential.
  1386. * If there are multiple kexts with the same bundle identifier,
  1387. * <code>aKext</code> may not be the one chosen during resolution
  1388. * and so it might appear that no kexts depend on it, even though they could.
  1389. */
  1390. CF_EXPORT CFMutableArrayRef
  1391. OSKextCopyDependents(OSKextRef aKext,
  1392. Boolean directFlag)
  1393. ;
  1394. /*!
  1395. * @function OSKextIsCompatibleWithVersion
  1396. * @abstract Returns whether a library kext is compatible with a given version.
  1397. *
  1398. * @param aKext The kext to examine.
  1399. * @param aVersion The kext version to check compatibility with
  1400. *
  1401. * @result
  1402. * <code>truer</code> if <code>aKext</code> has a compatible version and
  1403. * if <code>aVersion</code> is between the version and compatible version of
  1404. * <code>aKext</code> (inclusive), <code>false</code> otherwise.
  1405. *
  1406. * @discussion
  1407. */
  1408. CF_EXPORT Boolean
  1409. OSKextIsCompatibleWithVersion(
  1410. OSKextRef aKext,
  1411. OSKextVersion aVersion)
  1412. ;
  1413. /*!
  1414. * @function OSKextLogDependencyGraph
  1415. * @abstract Prints the resolved dependency graph of a kext.
  1416. *
  1417. * @param aKext The kext to log the dependency graph of.
  1418. * @param bundleIDFlag <code>true</code> to log kexts by bundle ID,
  1419. * <code>false</code> to log them by URL.
  1420. * @param linkFlag <code>true</code> to log the link graph only,
  1421. * <code>false</code> to log the full dependency graph.
  1422. *
  1423. * @discussion
  1424. * <code>linkFlag</code> allows you to display the dependencies as they will
  1425. * be recorded in the kernel when the kext is loaded.
  1426. * If it is <code>true</code>, then only kexts with executables are included
  1427. * in the logged dependency graph. If it is <code>false</code>, all kexts
  1428. * needed to load </code>aKext</code> are included.
  1429. *
  1430. * This function calls @link OSKextResolveDependencies@/link to find
  1431. * dependencies.
  1432. */
  1433. CF_EXPORT void
  1434. OSKextLogDependencyGraph(OSKextRef aKext,
  1435. Boolean bundleIDFlag,
  1436. Boolean linkFlag)
  1437. ;
  1438. /*!
  1439. * @function OSKextFindLinkDependencies
  1440. * @abstract Finds kexts that define symbols a kext needs resolved.
  1441. *
  1442. * @param aKext The kext to examine.
  1443. * @param nonKPIFlag
  1444. * <code>false</code> to look in com.apple.kpi.* kernel component
  1445. * for kernel symbols;
  1446. * <code>true</code> to look in com.apple.kernel.* kernel components
  1447. * instead (not recommended for later versions of Mac OS X).
  1448. * @param allowUnsupportedFlag
  1449. * <code>false</code> to skip unsupported libraries in the search;
  1450. * <code>true</code> to include them.
  1451. * @param onedefSymbolsOut
  1452. * A dictionary containing symbols that were found once;
  1453. * keys are the symbols, values are the kexts defining the key symbol.
  1454. * Ownership follows the Create Rule.
  1455. * Pass <code>NULL</code> to not retrieve.
  1456. * @param undefinedSymbolsOut
  1457. * A dictionary containing symbols that weren't found;
  1458. * keys are the symbols, values are undefined.
  1459. * Ownership follows the Create Rule.
  1460. * Pass <code>NULL</code> to not retrieve.
  1461. * @param multiplyDefinedSymbolsOut
  1462. * A dictionary containing symbols found in multiple library kexts;
  1463. * keys are the symbols, values are the kexts defining the key symbol.
  1464. * Ownership follows the Create Rule.
  1465. * Pass <code>NULL</code> to not retrieve.
  1466. * @param multipleDefinitionLibraries
  1467. * A array of all library kexts in which multiply defined symbols
  1468. * were found; sorted by CFBundleIdentifier.
  1469. * Ownership follows the Create Rule.
  1470. * Pass <code>NULL</code> to not retrieve.
  1471. * @result
  1472. * An array of kexts that export symbols referenced by <code>aKext</code>,
  1473. * sorted by CFBundleIdentifier.
  1474. *
  1475. * @discussion
  1476. * This function searches in all open kexts for symbols referenced by
  1477. * <code>aKext</code>, ignoring the OSBundleLibraries property.
  1478. * You can use this function to find out what you should list
  1479. * in a kext's OSBundleLibraries property.
  1480. *
  1481. * If <code>undefinedSymbolsOut</code> has a nonzero count,
  1482. * the symbols named by its keys could not be found in any open kext.
  1483. *
  1484. * If <code>multiplyDefinedSymbolsOut</code> has a nonzero count,
  1485. * some of the result kexts define the same symbol,
  1486. * and if those duplicates are listed
  1487. * in OSBundleLibraries a link failure will occur.
  1488. * You can inspect the contents of <code>multiplyDefinedSymbolsOut</code>
  1489. * and <code>multipleDefinitionLibraries</code>
  1490. * by hand to sort out which libraries you should actually declare.
  1491. *
  1492. * This function is fairly expensive, as it has to search through all open
  1493. * kexts' information dictionaries, and all library kexts' executables.
  1494. */
  1495. CFArrayRef OSKextFindLinkDependencies(
  1496. OSKextRef aKext,
  1497. Boolean nonKPIFlag,
  1498. Boolean allowUnsupportedFlag,
  1499. CFDictionaryRef * undefinedSymbolsOut,
  1500. CFDictionaryRef * onedefSymbolsOut,
  1501. CFDictionaryRef * multiplyDefinedSymbolsOut,
  1502. CFArrayRef * multipleDefinitionLibrariesOut)
  1503. ;
  1504. #pragma mark Linking and Loading; Other Kernel Operations
  1505. /*********************************************************************
  1506. * Linking and Loading; Other Kernel Operations
  1507. *********************************************************************/
  1508. /*!
  1509. * @function OSKextLoad
  1510. * @abstract Loads a kext and its dependencies into the kernel.
  1511. *
  1512. * @param aKext The kext to load.
  1513. * @result
  1514. * kOSReturnSuccess if <code>aKext</code> is successfully loaded
  1515. * into the kernel, or was already loaded, or an error result if not.
  1516. *
  1517. * @discussion
  1518. * The calling process must have an effective user ID of 0 (root)
  1519. * to load kexts into the kernel.
  1520. *
  1521. * A kext and all its dependencies must pass all validation and authentication
  1522. * tests to be loadable. See @link OSKextIsLoadable@/link for more information.
  1523. *
  1524. * All kexts loaded into the kernel are started, but IOKit personalities
  1525. * are not sent to the IOCatalogue.
  1526. * See @link OSKextSendPersonalitiesToKernel@/link.
  1527. *
  1528. * This function calls @link OSKextFlushLoadInfo@/link and clears dependencies
  1529. * for all open kexts. It then calls @link OSKextCopyLoadList@/link
  1530. * to find dependencies and @link OSKextReadLoadedKextInfo@/link on the
  1531. * resulting load list.
  1532. */
  1533. // xxx - need to list errors that may be returned
  1534. CF_EXPORT OSReturn
  1535. OSKextLoad(OSKextRef aKext)
  1536. ;
  1537. /*!
  1538. * @function OSKextLoadWithOptions
  1539. * @abstract Loads a kext and its dependencies into the kernel.
  1540. *
  1541. * @param aKext The kext to load.
  1542. * @param startExclusion
  1543. * <code>kOSKextExcludeAll</code> to omit starting <code>aKext</code>
  1544. * and any of its dependencies not already started,
  1545. * <code>kOSKextExcludeKext</code> to start the dependencies of
  1546. * <code>aKext</code> but not <code>aKext</code> itself,
  1547. * or <code>kOSKextExcludeNone</code> to start all loaded kexts.
  1548. * @param addPersonalitiesExclusion
  1549. * <code>kOSKextExcludeAll</code> to omit sending
  1550. * IOKitPersonalities to the IOCatalogue for <code>aKext</code>
  1551. * and any of its dependencies
  1552. * (though they may already be in the IOCatalogue),
  1553. * <code>kOSKextExcludeKext</code> to send personalities for the
  1554. * dependencies of <code>aKext</code> but not <code>aKext</code> itself,
  1555. * or <code>kOSKextExcludeNone</code> to send all personalities.
  1556. * @param personalityNames
  1557. * The names of IOKitPersonalities in <code>aKext</code> to send,
  1558. * <code>addPersonalitiesExclusion</code> allowing.
  1559. * If <code>NULL</code> all personalities are sent.
  1560. * This parameter only affects <code>aKext</code>; if dependency
  1561. * personalities are sent, they are all sent.
  1562. * @param delayAutounloadFlag
  1563. * <code>true</code> to cause the kernel's automatic kext unloader
  1564. * to skip <code>aKext</code> for one cycle, giving extra time
  1565. * to set up a debug session. <code>false</code> for normal behavior.
  1566. *
  1567. * @result
  1568. * Returns <code>kOSReturnSuccess</code> on success, other values on failure.
  1569. *
  1570. * @discussion
  1571. * This function allows a kext to be loaded but not started or matched
  1572. * (for IOKit kexts), which is useful in some debug scenarios.
  1573. * After calling this function, you may need to call @link OSKextStart@/link
  1574. * to start <code>aKext</code> (along with its dependencies).
  1575. * You may also need to call @link OSKextSendPersonalitiesToKernel@/link
  1576. * for any kexts excluded from matching via
  1577. * <code>addPersonalitiesExclusion</code>.
  1578. *
  1579. * The calling process must have an effective user ID of 0 (root)
  1580. * to load kexts into the kernel.
  1581. *
  1582. * A kext and all its dependencies must pass all validation and authentication
  1583. * tests to be loadable. See @link OSKextIsLoadable@/link for more information.
  1584. *
  1585. * This function calls @link OSKextFlushLoadInfo@/link and clears dependencies
  1586. * for all open kexts. It then calls @link OSKextCopyLoadList@/link
  1587. * to find dependencies and @link OSKextReadLoadedKextInfo@/link on the
  1588. * resulting load list.
  1589. */
  1590. // xxx - need to list errors that may be returned
  1591. CF_EXPORT OSReturn
  1592. OSKextLoadWithOptions(
  1593. OSKextRef aKext,
  1594. OSKextExcludeLevel startExclusion,
  1595. OSKextExcludeLevel addPersonalitiesExclusion,
  1596. CFArrayRef personalityNames,
  1597. Boolean delayAutounloadFlag)
  1598. ;
  1599. /*!
  1600. * @function OSKextGenerateDebugSymbols
  1601. * @abstract Generate debug symbols for a kext and its dependencies.
  1602. *
  1603. * @param aKext
  1604. * The kext to generate debug symbols for.
  1605. * @param kernelImage
  1606. * The kernel Mach-O or symbol file to use for linking.
  1607. * If <code>NULL</code>, the running kernel is used.
  1608. *
  1609. * @result
  1610. * A dictionary whose keys are the bundle IDs of the kexts for which symbols
  1611. * have been generated with ".sym" appended, and whose values are CFData
  1612. * objects containing the symbol files. Returns <code>NULL</code> on error.
  1613. *
  1614. * @discussion
  1615. * The result includes only non-interface kexts that have an executable
  1616. * and a load address set.
  1617. * Load addresses are set by @link OSKextReadLoadedKextInfo@/link or by
  1618. * @link OSKextSetLoadAddress@/link.
  1619. *
  1620. * If using the running kernel for load addresses, the current architecture
  1621. * set with @link OSKextSetArchitecture@/link must match that of the running
  1622. * kernel or this function returns <code>NULL</code>.
  1623. *
  1624. * This function calls @link OSKextResolveDependencies@/link to find
  1625. * dependencies.
  1626. */
  1627. CF_EXPORT CFDictionaryRef
  1628. OSKextGenerateDebugSymbols(
  1629. OSKextRef aKext,
  1630. CFDataRef kernelImage)
  1631. ;
  1632. /*!
  1633. * @function OSKextNeedsLoadAddressForDebugSymbols
  1634. * @abstract
  1635. * Returns whether a kext needs a load address set to generate debug symbols.
  1636. *
  1637. * @param aKext The kext to examine.
  1638. * @result
  1639. * <code>true</code> if <code>aKext</code> needs a load address set
  1640. * in order to generate debug symbols with
  1641. * @link OSKextGenerateDebugSymbols@/link, <code>false</code> otherwise.
  1642. */
  1643. CF_EXPORT Boolean
  1644. OSKextNeedsLoadAddressForDebugSymbols(OSKextRef aKext)
  1645. ;
  1646. /*!
  1647. * @function OSKextUnload
  1648. * @abstract Unloads a kext from the kernel if possible.
  1649. *
  1650. * @param aKext The kext to unload.
  1651. * @param terminateServiceAndRemovePersonalities
  1652. * If <code>true</code>, and the kext to unload has no kexts loaded
  1653. * against it, all IOService objects defined by that kext will be
  1654. * asked to terminate so that the unload can proceed, and the personalities
  1655. * for the kext will be removed from the IOCatalogue.
  1656. *
  1657. * @result
  1658. * <code>kOSReturnSuccess</code> on success, an error code
  1659. * (typically <code>kOSKextReturnInUse</code>) on failure.
  1660. *
  1661. * @discussion
  1662. * The calling process must have an effective user ID of 0 (root)
  1663. * to unload kexts from the kernel.
  1664. * A kext cannot be unloaded if it has any loaed dependents.
  1665. *
  1666. * See also the @link IOCatalogueTerminate@/link function.
  1667. */
  1668. // xxx - need to list errors that may be returned
  1669. CF_EXPORT OSReturn
  1670. OSKextUnload(OSKextRef aKext,
  1671. Boolean terminateServiceAndRemovePersonalities)
  1672. ;
  1673. /*!
  1674. * OSKextUnload
  1675. * @abstract Unloads a kext from the kernel if possible, based on its
  1676. * CFBundleIdentifier.
  1677. *
  1678. * @param kextIdentifier The CFBundleIDentifier of the kext to unload.
  1679. * @param terminateServiceAndRemovePersonalities
  1680. * If <code>true</code>, and the kext to unload has no kexts loaded
  1681. * against it, all IOService objects defined by that kext will be
  1682. * asked to terminate so that the unload can proceed, and the personalities
  1683. * for the kext will be removed from the IOCatalogue.
  1684. *
  1685. * @result
  1686. * <code>kOSReturnSuccess</code> on success, an error code
  1687. * (typically <code>kOSKextReturnInUse</code>) on failure.
  1688. *
  1689. * @discussion
  1690. * The calling process must have an effective user ID of 0 (root)
  1691. * to unload kexts from the kernel.
  1692. * A kext cannot be unloaded if it has any loaed dependents.
  1693. *
  1694. * See also the @link IOCatalogueTerminate@/link function.
  1695. */
  1696. // xxx - need to list errors that may be returned
  1697. CF_EXPORT OSReturn
  1698. OSKextUnloadKextWithIdentifier(CFStringRef kextIdentifier,
  1699. Boolean terminateServiceAndRemovePersonalities)
  1700. ;
  1701. /*!
  1702. * @function OSKextIsStarted
  1703. * @abstract Returns whether a kext loaded in the kernel is started.
  1704. *
  1705. * @param aKext The kext to examine.
  1706. * @result
  1707. * <code>true</code> if <code>aKext</code> is active and running in the kernel,
  1708. * <code>false</code> if not loaded or loaded and not started.
  1709. *
  1710. * @discussion
  1711. * This function returns the state recorded the last time
  1712. * @link OSKextReadLoadedKextInfo@/link was called.
  1713. */
  1714. CF_EXPORT Boolean
  1715. OSKextIsStarted(OSKextRef aKext)
  1716. ;
  1717. /*!
  1718. * @function OSKextStart
  1719. * @abstract Starts a kext loaded in the kernel if possible.
  1720. *
  1721. * @param aKext The kext to start.
  1722. * @result
  1723. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1724. *
  1725. * @discussion
  1726. * This function allows an application to start a kext that is loaded
  1727. * in the kernel (typically via @link OSKextLoadWithOptions@/link),
  1728. * and any of its dependencies that aren't also started.
  1729. * If the kext is already started, this does nothing.
  1730. *
  1731. * To start a kext means to call its start function, which is distinct from
  1732. * the start method of an IOService object.
  1733. *
  1734. * The calling process must have an effective user ID of 0 (root)
  1735. * to start kexts in the kernel.
  1736. // xxx - need to list errors that may be returned
  1737. */
  1738. CF_EXPORT OSReturn
  1739. OSKextStart(OSKextRef aKext)
  1740. ;
  1741. /*!
  1742. * @function OSKextStop
  1743. * @abstract Stops a kext loaded in the kernel if possible.
  1744. *
  1745. * @param aKext The kext to stop.
  1746. * @result
  1747. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1748. *
  1749. * @discussion
  1750. * This function allows an application to stop a kext that is loaded
  1751. * in the kernel without unloading it. This may be useful in certain
  1752. * debugging scenarios.
  1753. *
  1754. * A kext cannot be stopped via this function if it has any dependents
  1755. * that reference it, any client references within the kernel,
  1756. * or any instances of libkern/IOKit C++ classes.
  1757. *
  1758. * To stop a kext means to call its stop function, which is distinct from
  1759. * the stop method of an IOService object.
  1760. *
  1761. * The calling process must have an effective user ID of 0 (root)
  1762. * to stop kexts in the kernel.
  1763. */
  1764. // xxx - should it be allowed to stop a kext with dependents that are
  1765. // xxx - themselves not started?
  1766. // xxx - need to list errors that may be returned
  1767. CF_EXPORT OSReturn
  1768. OSKextStop(OSKextRef aKext)
  1769. ;
  1770. /*!
  1771. * @function OSKextSendPersonalitiesToKernel
  1772. * @abstract Sends an array of IOKit personalities to the kernel.
  1773. *
  1774. * @param personalities The personalities to send.
  1775. * @result
  1776. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1777. *
  1778. * @discussion
  1779. * This function simply sends an anonymous array of personalities to the
  1780. * I/O Kit's IOCatalogue object in the kernel.
  1781. * You can get personalities from kexts using
  1782. * @link OSKextCopyPersonalitiesArray@/link or
  1783. * @link OSKextCopyPersonalitiesOfKexts@/link.
  1784. *
  1785. * The calling process must have an effective user ID of 0 (root)
  1786. * to send personalities to the kernel.
  1787. */
  1788. // xxx - need to list errors that may be returned
  1789. CF_EXPORT OSReturn
  1790. OSKextSendPersonalitiesToKernel(CFArrayRef personalities)
  1791. ;
  1792. /*!
  1793. * @function OSKextSendKextPersonalitiesToKernel
  1794. * @abstract
  1795. * Sends the personalities of a single kext to the kernel, optionally
  1796. * filtered by name.
  1797. *
  1798. * @param aKext The kext whose personalities to send.
  1799. * @param personalityNames
  1800. * An array of names. Only personalities from <code>aKext</code>
  1801. * with these names are sent to the kernel.
  1802. * @result
  1803. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1804. *
  1805. * @discussion
  1806. * If any names in <code>personalityNames</code> are not found,
  1807. * they are simply skipped rather than causing an error.
  1808. *
  1809. * This function may be useful in certain debugging scenarios,
  1810. * where a particular personality is causing problems.
  1811. *
  1812. * The calling process must have an effective user ID of 0 (root)
  1813. * to send personalities to the kernel.
  1814. */
  1815. // xxx - should names not found cause an error?
  1816. // xxx - need to list errors that may be returned
  1817. CF_EXPORT OSReturn
  1818. OSKextSendKextPersonalitiesToKernel(
  1819. OSKextRef aKext,
  1820. CFArrayRef personalityNames)
  1821. ;
  1822. /*!
  1823. * @function OSKextSendPersonalitiesOfKextsToKernel
  1824. * Sends the personalities of multiple kext to the kernel in a single
  1825. * operation.
  1826. *
  1827. * @param kextArray The kexts whose personalities to send.
  1828. * @result
  1829. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1830. *
  1831. * @discussion
  1832. * This function performs one data transfer to the kernel, collecting
  1833. * all the personalities of the kexts in <code>kextArray</code>.
  1834. *
  1835. * The calling process must have an effective user ID of 0 (root)
  1836. * to send personalities to the kernel.
  1837. */
  1838. // xxx - need to list errors that may be returned
  1839. CF_EXPORT OSReturn
  1840. OSKextSendPersonalitiesOfKextsToKernel(CFArrayRef kextArray)
  1841. ;
  1842. /*!
  1843. * @function OSKextRemoveKextPersonalitiesFromKernel
  1844. * Removes all personalities for a kext's bundle identifier from the kernel.
  1845. *
  1846. * @param aKext The kext whose personalities to remove.
  1847. * @result
  1848. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1849. *
  1850. * @discussion
  1851. * This function removes from the kernel's IOCatalogue all personalities
  1852. * whose CFBundleIdentifiers match that of <code>aKext</code> so that no
  1853. * further load requests for <code>aKext</code> will be made. This is
  1854. * typically done when it is discovered that <code>aKext</code> cannot
  1855. * be loaded from user space (if it fails to load in the kernel, matching
  1856. * personalities are automatically removed).
  1857. *
  1858. * Note that kexts other than <code>aKext</code> might have published
  1859. * personalities in the IOCatalogue under <code>aKext</code>'s identifier.
  1860. * Such personalities will also be removed, since they trigger load requests
  1861. * for a kext that cannot be loaded. The OSKext library adds an
  1862. * IOPersonalityPublisher property to such personalities, that gives the
  1863. * bundle identifier of the originating kext.
  1864. *
  1865. * This function differs from
  1866. * @link OSKextRemovePersonalitiesForIdentifierFromKernel@/link
  1867. * by having a kext object to check for logging or other purposes.
  1868. *
  1869. * The calling process must have an effective user ID of 0 (root)
  1870. * to remove personalities from the kernel.
  1871. */
  1872. // xxx - need to list errors that may be returned
  1873. // xxx - this is a not-so-thin shim over IOCatalogueSendData (kIOCatalogueRemoveDrivers)
  1874. // xxx - might we just want the function to take a bundle ID?
  1875. // xxx - does IOCatalogueSendData really require root access?
  1876. CF_EXPORT OSReturn
  1877. OSKextRemoveKextPersonalitiesFromKernel(OSKextRef aKext)
  1878. ;
  1879. /*!
  1880. * @function OSKextRemovePersonalitiesForIdentifierFromKernel
  1881. * Removes all personalities for a given bundle identifier from the kernel.
  1882. *
  1883. * @param aBundleID The bundle identifier for which to remove personalities.
  1884. * @result
  1885. * <code>kOSReturnSuccess</code> on success, an error code on failure.
  1886. *
  1887. * @discussion
  1888. * This function removes from the kernel's IOCatalogue all personalities
  1889. * whose CFBundleIdentifiers are <code>aBundleID</code> so that no
  1890. * further load requests for the kext with that identifier will be made.
  1891. * This is typically done when it is discovered no kext can be found for
  1892. * <code>aBundleID</code>.
  1893. *
  1894. * This function differs from
  1895. * @link OSKextRemoveKextPersonalitiesFromKernel@/link
  1896. * by not having a kext object to check for logging or other purposes.
  1897. *
  1898. * The calling process must have an effective user ID of 0 (root)
  1899. * to remove personalities from the kernel.
  1900. */
  1901. // xxx - need to list errors that may be returned
  1902. // xxx - this is a not-so-thin shim over IOCatalogueSendData (kIOCatalogueRemoveDrivers)
  1903. // xxx - I want 2 separate functions for logging; a kext can have flags in it
  1904. // xxx - does IOCatalogueSendData really require root access?
  1905. CF_EXPORT OSReturn
  1906. OSKextRemovePersonalitiesForIdentifierFromKernel(CFStringRef aBundleID)
  1907. ;
  1908. /*!
  1909. * @function OSKextCreateLoadedKextInfo
  1910. * @abstract Returns information about loaded kexts in a dictionary.
  1911. *
  1912. * @param kextIdentifiers An array of kext identifiers to read from the kernel.
  1913. * Pass <code>NULL</code> to read info for all loaded kexts.
  1914. * @result
  1915. * An array of dictionaries containing information about loaded kexts.
  1916. *
  1917. * @discussion
  1918. * This function gets information from the kernel without affecting any
  1919. * kext objects. If you want to update open kext objects to reflect
  1920. * whether they are loaded in the kernel, use @link OSKextReadLoadedKextInfo@/link.
  1921. */
  1922. // xxx - need to document the keys from OSKextLib.h.
  1923. CF_EXPORT CFArrayRef
  1924. OSKextCreateLoadedKextInfo(
  1925. CFArrayRef kextIdentifiers)
  1926. ;
  1927. /*!
  1928. * @function OSKextReadLoadedKextInfo
  1929. * @abstract Updates kext objects with load info from the kernel.
  1930. *
  1931. * @param kextIdentifiers An array of kext identifiers to read
  1932. * from the kernel;
  1933. * all matching kexts have their load info updated.
  1934. * Pass <code>NULL</code> to update load info for all kexts.
  1935. * @param flushDependenciesFlag
  1936. * <code>true</code> to clear dependency information from kexts,
  1937. * <code>false</code> to leave it in place.
  1938. *
  1939. * @result
  1940. * <code>kOSReturnSuccess</code> if all information is successfully updated,
  1941. * an error code otherwise. Specifically, if the current architecture set
  1942. * by @link OSKextSetArchitecture@/link is not that of the running kernel,
  1943. * this function returns <code>kOSKextReturnExecutableArchNotFound</code>.
  1944. *
  1945. * @discussion
  1946. * The load status of kexts primarily affects dependency resolution in the
  1947. * kext library, in that kexts marked as loaded are given priority over
  1948. * all other kexts of the same identifier.
  1949. * See @link OSKextResolveDependencies@/link for more.
  1950. *
  1951. * This function calls @link OSKextFlushLoadInfo@/link on the kexts,
  1952. * which clears any previous load info for them
  1953. * (or for all kexts if <code>kextIdentifiers</code> is <code>NULL</code>).
  1954. * If <code>flushDependenciesFlag</code> is <code>true</code>,
  1955. * resolved dependencies (which may not match the loaded kexts
  1956. * in the kernel) are also flushed.
  1957. * Load addresses are then set from the kernel,
  1958. * but dependencies are resolved as needed.
  1959. *
  1960. * If <code>flushDependenciesFlag</code> is <code>false</code>,
  1961. * existing dependency graphs are maintained, allowing you to
  1962. * check whether the dependencies, as resolved before reading
  1963. * load information, reflect loaded kexts (by getting the load list
  1964. * via @link OSKextCopyLoadList@/link and checking the kexts in it
  1965. * with @link OSKextIsLoaded@/link).
  1966. */
  1967. // xxx - need to list errors that may be returned
  1968. CF_EXPORT OSReturn
  1969. OSKextReadLoadedKextInfo(
  1970. CFArrayRef kexts,
  1971. Boolean flushDependenciesFlag)
  1972. ;
  1973. /*!
  1974. * @function OSKextIsLoaded
  1975. * @abstract Returns whether a kext is loaded in the kernel.
  1976. *
  1977. * @param aKext The kext to examine.
  1978. * @result
  1979. * <code>true</code> if a kext with the same identifier, version, and UUID
  1980. * as <code>aKext</code> is loaded in the kernel, <code>false</code> otherwise.
  1981. *
  1982. * @discussion
  1983. * You must call @link OSKextReadLoadedKextInfo@/link for this flag to be meaningful,
  1984. * which in turn requires the current library architecture to match that
  1985. * of the running kernel.
  1986. * Use @link OSKextOtherVersionIsLoaded@/link to check whether
  1987. * a different version of <code>aKext</code> is loaded.
  1988. */
  1989. CF_EXPORT Boolean
  1990. OSKextIsLoaded(OSKextRef aKext)
  1991. ;
  1992. /*!
  1993. * @function OSKextGetLoadAddress
  1994. * @abstract Returns the actual or simulated kernel load address of a kext.
  1995. *
  1996. * @param aKext The kext to examine.
  1997. * @result
  1998. * The load address of <code>aKext</code>, whether read from the kernel using
  1999. * @link OSKextReadLoadedKextInfo@/link or set for symbol generation using
  2000. * @link OSKextSetLoadAddress@/link.
  2001. *
  2002. * @discussion
  2003. * Load addresses are accessed as 64-bit numbers even for 32-bit architectures;
  2004. * cast or truncate the value as necessary.
  2005. *
  2006. * You must call @link OSKextReadLoadedKextInfo@/link or
  2007. * @link OSKextSetLoadAddress@/link for the load address to be nonzero.
  2008. */
  2009. CF_EXPORT uint64_t
  2010. OSKextGetLoadAddress(OSKextRef aKext)
  2011. ;
  2012. /*!
  2013. * @function OSKextSetLoadAddress
  2014. * @abstract
  2015. * Sets the simulated kernel load address of a kext for symbol generation.
  2016. *
  2017. * @param aKext The kext to set a load address for.
  2018. * @result
  2019. * <code>true</code> if the address was set, <code>false</code> if not
  2020. * (because it's too large for the current architecture).
  2021. *
  2022. * @discussion
  2023. * Load addresses are accessed as 64-bit numbers even for 32-bit architectures.
  2024. * If you attempt to set a load address that is too large for a 32-bit link,
  2025. * this function returns <code>false</code>.
  2026. * See @link OSKextSetArchitecture@/link.
  2027. *
  2028. * Setting a load address manually is useful for generating debug symbols
  2029. * with @link OSKextGenerateDebugSymbols@/link.
  2030. */
  2031. CF_EXPORT Boolean
  2032. OSKextSetLoadAddress(OSKextRef aKext, uint64_t anAddress)
  2033. ;
  2034. /*!
  2035. * @function OSKextGetLoadTag
  2036. * @abstract
  2037. * Returns the load tag of a kext if it's loaded in the kernel.
  2038. *
  2039. * @param aKext The kext to examine.
  2040. * @result
  2041. * The load tag (also known as the index or kmod id) of <code>aKext</code>,
  2042. * if it's loaded in the kernel (use @link OSKextIsLoaded@/link to check that).
  2043. * Returns 0 if <code>aKext</code> is not loaded or if it can't be determined
  2044. * whether it is loaded.
  2045. *
  2046. * @discussion
  2047. * You must call @link OSKextReadLoadedKextInfo@/link for the load tag
  2048. * to be meaningful, which in turn requires the current library architecture
  2049. * to match that of the running kernel.
  2050. * Use @link OSKextIsLoaded@/link to check whether <code>aKext</code>
  2051. * is loaded.
  2052. */
  2053. CF_EXPORT uint32_t
  2054. OSKextGetLoadTag(OSKextRef aKext)
  2055. ;
  2056. /*!
  2057. * @function OSKextFlushLoadInfo
  2058. * @abstract Clears all load and dependency information from a kext.
  2059. *
  2060. * @param aKext
  2061. * The kext to clear. If <code>NULL</code>, all open
  2062. * kexts have their load info flushed.
  2063. * @param flushDependenciesFlag
  2064. * <code>true</code> to clear dependency information from kexts,
  2065. * <code>false</code> to leave it in place.
  2066. *
  2067. * @discussion
  2068. * Flushing load information releases the internal load information
  2069. * structs of a kext, including load flags, the bundle executable,
  2070. * link/load diagnostics, and if <code>flushDependenciesFlag</code> is true,
  2071. * the dependencies.
  2072. *
  2073. * OSKexts accumulate a fair amount of information as they are created
  2074. * and used; when many kext objects are created the total memory
  2075. * consumption can be significant. If an application won't be using
  2076. * kexts for long periods of time, it can flush this information
  2077. * to save memory; the information will later be re-read from disk
  2078. * or recreated as necessary.
  2079. *
  2080. * Flushing load info is also useful after readling loaded kext
  2081. * information from the kernel with @link OSKextReadLoadedKextInfo@/link
  2082. * or after working with executables. Executables in particular
  2083. * consume a lot of application memory, often unnecessarily, since
  2084. * the code is loaded and running in the kernel.
  2085. *
  2086. * See also @link OSKextFlushInfoDictionaries@/link,
  2087. * @link OSKextFlushDependencies@/link,
  2088. * and @link OSKextFlushDiagnostics@/link.
  2089. */
  2090. CF_EXPORT void
  2091. OSKextFlushLoadInfo(
  2092. OSKextRef aKext,
  2093. Boolean flushDependenciesFlag)
  2094. ;
  2095. /*!
  2096. * @function OSKextCopyAllRequestedIdentifiers
  2097. * @abstract
  2098. * Copies the list of all unique bundle identifiers of kext load requests
  2099. * that the kernel has received since power-on.
  2100. *
  2101. * @result
  2102. * A CFArray object, or <code>NULL</code> if the copy failed.
  2103. * Ownership follows the
  2104. * @link //apple_ref/doc/uid/20001148-103029 Create Rule@/link.
  2105. *
  2106. */
  2107. CF_EXPORT CFArrayRef
  2108. OSKextCopyAllRequestedIdentifiers(void)
  2109. ;
  2110. #pragma mark Sanity Checking and Diagnostics
  2111. /*********************************************************************
  2112. * Sanity Checking and Diagnostics
  2113. *********************************************************************/
  2114. /*!
  2115. * @function OSKextParseVersionCFString
  2116. * @abstract
  2117. * Parses a kext version from a CFString.
  2118. *
  2119. * @param versionString The kext version string to parse.
  2120. * @result
  2121. * The numeric rendering of <code>versionString</code>, which can
  2122. * compared arithmetically with other valid version numbers.
  2123. * Returns -1 if the version couldn't be parsed.
  2124. */
  2125. CF_EXPORT OSKextVersion
  2126. OSKextParseVersionCFString(CFStringRef versionString)
  2127. ;
  2128. /*! @function OSKextParseVersionString */
  2129. CF_EXPORT OSKextVersion OSKextParseVersionString(const char* versionString);
  2130. CF_EXPORT void OSKextVersionGetString(OSKextVersion version, char* buffer, size_t bufferLength);
  2131. /*!
  2132. * @function OSKextValidate
  2133. * @abstract
  2134. * Sanity checks a kext's info dictionary and executable for the currently
  2135. * set architecture.
  2136. *
  2137. * @param aKext The kext to validate.
  2138. * @result
  2139. * <code>true</code> if <code>aKext</code> passes all validation tests,
  2140. * <code>false</code> otherwise.
  2141. *
  2142. * @discussion
  2143. * This function forces full validation of a kext, collecting all
  2144. * errors found in the validation diagnostics if recording is turned on
  2145. * (with @link OSKextSetRecordsDiagnostics@/link). You can get the diagnostics
  2146. * using @link OSKextCopyDiagnostics@/link.
  2147. *
  2148. * If safe boot is currently simulated (see
  2149. * @link OSKextSetSimulatedSafeBoot@/link),
  2150. * any kext not loadable during safe boot will fail validation.
  2151. */
  2152. // compare with CFBundlePreflightExecutable()
  2153. CF_EXPORT Boolean
  2154. OSKextValidate(OSKextRef aKext)
  2155. ;
  2156. /*!
  2157. * @function OSKextIsValid
  2158. * @abstract
  2159. * Returns whether a kext is valid or not.
  2160. *
  2161. * @param aKext The kext to examine.
  2162. * @result
  2163. * <code>true</code> if <code>aKext</code> passes all validation tests,
  2164. * <code>false</code> otherwise.
  2165. *
  2166. * @discussion
  2167. * This function avoids doing full validation if any problems have been
  2168. * discovered with the kext during other operations. To perform a full
  2169. * validation of all possible problems, use @link OSKextValidate@/link.
  2170. */
  2171. CF_EXPORT Boolean
  2172. OSKextIsValid(OSKextRef aKext)
  2173. ;
  2174. /*!
  2175. * @function OSKextValidateDependencies
  2176. * @abstract Validates all dependencies of a kext.
  2177. *
  2178. * @param aKext The kexts whose dependencies to validate.
  2179. * @result
  2180. * <code>true</code> if all dependencies of <code>aKext</code> are valid,
  2181. * <code>false</code> if any of them are not.
  2182. *
  2183. * @discussion
  2184. * This function calls @link OSKextValidate@/link on <code>aKext</code> and
  2185. * all the current dependencies of <code>aKext</code>.
  2186. * Use @link OSKextCopyDiagnostics@/link
  2187. * with a flag of @link kOSKextDiagnosticsFlagDependencies@/link
  2188. * to get the dependency-resolution failures caused by invalid dependencies.
  2189. *
  2190. * If safe boot is currently simulated (see
  2191. * @link OSKextSetSimulatedSafeBoot@/link),
  2192. * any kext not loadable during safe boot will fail validation.
  2193. *
  2194. * This function calls @link OSKextResolveDependencies@/link to find
  2195. * dependencies.
  2196. */
  2197. CF_EXPORT Boolean
  2198. OSKextValidateDependencies(OSKextRef aKext)
  2199. ;
  2200. /*!
  2201. * @function OSKextAuthenticate
  2202. * @abstract Authenticates file ownership and permissions of a kext.
  2203. *
  2204. * @param aKext The kext to examine.
  2205. * @result
  2206. * <code>true</code> if all directories and files in <code>aKext</code>'s
  2207. * bundle or mkext source have secure ownership and permissions,
  2208. * <code>false</code> if they do not, or if authentication could not be done.
  2209. *
  2210. * @discussion
  2211. * This function forces full authentication of a kext, collecting all
  2212. * errors found in the authentication diagnostics, collecting all
  2213. * errors found in the validation diagnostics if recording is turned on
  2214. * (with @link OSKextSetRecordsDiagnostics@/link). You can get the diagnostics
  2215. * using @link OSKextCopyDiagnostics@/link.
  2216. *
  2217. * For a kext to be loadable into the kernel, it must be owned by
  2218. * user root, group wheel, and its constituent files and directories
  2219. * must be nonwritable by group and other.
  2220. * A kext created from an mkext file uses that mkext file for authentication
  2221. * (see @link OSKextCreateKextsFromMkextFile@/link.
  2222. */
  2223. CF_EXPORT Boolean
  2224. OSKextAuthenticate(OSKextRef aKext)
  2225. ;
  2226. /*!
  2227. * @function OSKextIsAuthentic
  2228. * @abstract
  2229. * Returns whether a kext is authentic or not.
  2230. *
  2231. * @param aKext The kext to examine.
  2232. * @result
  2233. * <code>true</code> if <code>aKext</code> passes all authentication tests,
  2234. * <code>false</code> otherwise.
  2235. *
  2236. * @discussion
  2237. * This function avoids doing full authentication if any problems have been
  2238. * discovered with the kext during other operations. To perform a full
  2239. * validation of all possible problems, use @link OSKextValidate@/link.
  2240. */
  2241. CF_EXPORT Boolean
  2242. OSKextIsAuthentic(OSKextRef aKext)
  2243. ;
  2244. /*!
  2245. * @function OSKextAuthenticateDependencies
  2246. * @abstract Authenticates all dependencies of a kext.
  2247. *
  2248. * @param aKext The kexts whose dependencies to authenticate.
  2249. * @result
  2250. * <code>true</code> if all dependencies of <code>aKext</code> are authentic,
  2251. * <code>false</code> if any of them are not.
  2252. *
  2253. * @discussion
  2254. * This function calls @link OSKextAuthenticate@/link on <code>aKext</code>
  2255. * and all the current dependencies of <code>aKext</code>.
  2256. * Use @link OSKextCopyDiagnostics@/link
  2257. * with a flag of @link kOSKextDiagnosticsFlagDependencies@/link
  2258. * to get the dependency-resolution failures caused by inauthentic dependencies.
  2259. *
  2260. * This function calls @link OSKextResolveDependencies@/link to find
  2261. * dependencies.
  2262. */
  2263. CF_EXPORT Boolean
  2264. OSKextAuthenticateDependencies(OSKextRef aKext)
  2265. ;
  2266. /*!
  2267. * @function OSKextIsLoadable
  2268. * @abstract
  2269. * Returns whether a kext appears loadable for the current architecture.
  2270. *
  2271. * @param aKext The kext to examine.
  2272. * @result
  2273. * <code>true</code> if <code>aKext</code> has no problems with validation,
  2274. * authentication, or dependency resolution for the current architecture,
  2275. * and if it's eligible for the current safe boot mode.
  2276. * Returns <code>false</code> otherwise.
  2277. *
  2278. * @discussion
  2279. * This function resolves dependencies for <code>aKext</code>,
  2280. * validates and authenticsates <code>aKext</code> and its dependencies,
  2281. * and if safe boot is simulated also checks the OSBundleRequired property
  2282. * of <code>aKext</code> and its dependencies. If all these tests pass,
  2283. * the kext is considered loadable for the current architecture
  2284. * (which need not match that of the running kernel).
  2285. *
  2286. * See @link OSKextSetArchitecture@/link and
  2287. * @link OSKextSetSimulatedSafeBoot@/link.
  2288. *
  2289. * This function calls @link OSKextResolveDependencies@/link to find
  2290. * dependencies.
  2291. */
  2292. CF_EXPORT Boolean
  2293. OSKextIsLoadable(OSKextRef aKext)
  2294. ;
  2295. /*!
  2296. * @function OSKextCopyDiagnostics
  2297. * @abstract Returns diagnostics information for a kext.
  2298. *
  2299. * @param aKext The kext to get diagnostics for.
  2300. * @param typeFlags Flags indicating which diagnostics to retrieve.
  2301. * @result
  2302. * A dictionary containing diagnostics for <cod>aKext</code>, suitable
  2303. * for display in an outline view or printout.
  2304. *
  2305. * @discussion
  2306. * You can use this function after validating, authenticating, resolving
  2307. * dependencies, or generating debug symbols to get all the problems encountered
  2308. * with those operations.
  2309. *
  2310. * The exact keys and values used for diagnostics are for informational purposes
  2311. * only, are not formally defined, and may change without warning.
  2312. *
  2313. * You can use @link OSKextLogDiagnostics@/link to print nicely-formatted
  2314. * reports of any problems found with kexts.
  2315. */
  2316. // xxx - need to tie in with the kernel & linker to get link failures
  2317. CFDictionaryRef OSKextCopyDiagnostics(OSKextRef aKext,
  2318. OSKextDiagnosticsFlags typeFlags)
  2319. ;
  2320. /*!
  2321. * @function OSKextLogDiagnostics
  2322. * @abstract Logs specified diagnostics for a kext.
  2323. *
  2324. * @param aKext The kext to log diagnostics for.
  2325. * @param typeFlags Flags indicating which diagnostics to log.
  2326. *
  2327. * @discussion
  2328. * You can use this function after validating, authenticating, resolving
  2329. * dependencies, or generating debug symbols to display all the problems
  2330. * encountered with those operations.
  2331. */
  2332. CF_EXPORT void
  2333. OSKextLogDiagnostics(
  2334. OSKextRef aKext,
  2335. OSKextDiagnosticsFlags typeFlags)
  2336. ;
  2337. /*!
  2338. * @function OSKextFlushDiagnostics
  2339. * @abstract Clears all diagnostics information from a kext.
  2340. *
  2341. * @param aKext
  2342. * The kext to clear diagnostics from.
  2343. * Pass <code>NULL</code> to flush diagnostics from all open kexts.
  2344. * @param typeFlags Flags indicating which diagnostics to flush.
  2345. *
  2346. * @discussion
  2347. * OSKexts accumulate a fair amount of information as they are created
  2348. * and used; when many kext objects are created the total memory
  2349. * consumption can be significant. If an application won't be using
  2350. * kexts for long periods of time, it can flush this information
  2351. * to save memory; the information will later be re-read from disk
  2352. * or recreated as necessary.
  2353. *
  2354. * See also @link OSKextFlushInfoDictionaries@/link,
  2355. * @link OSKextFlushDependencies@/link,
  2356. * and @link OSKextFlushLoadInfo@/link.
  2357. */
  2358. CF_EXPORT void
  2359. OSKextFlushDiagnostics(OSKextRef aKext, OSKextDiagnosticsFlags typeFlags)
  2360. ;
  2361. #pragma mark Mkext and Prelinked Kernel Files
  2362. /*********************************************************************
  2363. * Mkext and Prelinked Kernel Files
  2364. *********************************************************************/
  2365. // xxx - Use "Flag" or "Mask"?
  2366. typedef uint32_t OSKextRequiredFlags
  2367. ;
  2368. #define kOSKextOSBundleRequiredNone 0x0
  2369. #define kOSKextOSBundleRequiredRootFlag 0x1ULL
  2370. #define kOSKextOSBundleRequiredLocalRootFlag 0x1ULL << 1
  2371. #define kOSKextOSBundleRequiredNetworkRootFlag 0x1ULL << 2
  2372. #define kOSKextOSBundleRequiredSafeBootFlag 0x1ULL << 3
  2373. #define kOSKextOSBundleRequiredConsoleFlag 0x1ULL << 4
  2374. /*!
  2375. * @function OSKextIsFromMkext
  2376. * @abstract Returns whether a kext was created from an mkext archive.
  2377. *
  2378. * @param aKext The kext to examine.
  2379. * @result
  2380. * <code>true</code> if <code>aKext</code> was created from an mkext archive,
  2381. * <code>false</code> if it was created from an on-disk bundle.
  2382. *
  2383. * @discussion
  2384. * A kext created from an mkext will have only its info dictionary, executable,
  2385. * and any resources listed in its the OSBundleStartupResources property.
  2386. */
  2387. CF_EXPORT Boolean
  2388. OSKextIsFromMkext(OSKextRef aKext)
  2389. ;
  2390. /*!
  2391. * @function OSKextMatchesRequiredFlags
  2392. * @abstract
  2393. * Returns whether a kext matches a given set of flags for inclusion in an
  2394. * mkext archive.
  2395. *
  2396. * @param aKext The kext to examine.
  2397. * @param requiredFlags
  2398. * Flags indicating which values of OSBundleRequired
  2399. * are needed.
  2400. * @result
  2401. * <code>true</code> if <code>aKext</code>'s OSBundleRequired property
  2402. * matches one of the specified flags, <code>false</code> otherwise.
  2403. *
  2404. * @discussion
  2405. * This function is used to select kexts for inclusion in an mkext archive.
  2406. * See @link OSKextFilterRequiredKexts@/link and
  2407. * @link OSKextCreateMkext@/link.
  2408. */
  2409. CF_EXPORT Boolean
  2410. OSKextMatchesRequiredFlags(OSKextRef aKext,
  2411. OSKextRequiredFlags requiredFlags)
  2412. ;
  2413. /*!
  2414. * @function OSKextFilterRequiredKexts
  2415. * @abstract
  2416. * Filters an array of kexts based on a set of flags
  2417. * for inclusion in an mkext archive.
  2418. *
  2419. * @param kextArray
  2420. * The kexts to filter.
  2421. * Pass <code>NULL</code> to filter all open kexts.
  2422. * @param requiredFlags
  2423. * Flags indicating which values of OSBundleRequired
  2424. * are needed.
  2425. * @result
  2426. * An array of kexts matching <code>requiredFlags</code>.
  2427. *
  2428. * @discussion
  2429. * This function is used to select kexts for inclusion in an mkext archive.
  2430. * See @link OSKextCreateMkext@/link.
  2431. *
  2432. */
  2433. CF_EXPORT CFArrayRef
  2434. OSKextFilterRequiredKexts(CFArrayRef kextArray,
  2435. OSKextRequiredFlags requiredFlags)
  2436. ;
  2437. /*!
  2438. * @function OSKextCreateMkext
  2439. * @abstract Create an mkext file from an array of kexts and set of flags.
  2440. *
  2441. * @param allocator
  2442. * The allocator to use to allocate memory for the new object.
  2443. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  2444. * to use the current default allocator.
  2445. * @param kextArray
  2446. * The kexts to include in the mkext.
  2447. * Pass <code>NULL</code> to use all open kexts.
  2448. * @param volumeRootURL
  2449. * If non-<code>NULL</code>, kexts with this URL as a prefix
  2450. * strip it when saving their paths in the mkext.
  2451. * This allows creation of mkexts for volumes
  2452. * other than the current startup volume.
  2453. * @param requiredFlags
  2454. * A set of flags that filters <code>kextArray</code> to a subset
  2455. * of kexts required for specific startup scenarios
  2456. * (typically local disk vs. network).
  2457. * @param compressFlag
  2458. * <code>true</code> to compress data in the mkext,
  2459. * <code>false</code> to include them at full size.
  2460. * COMPRESSED MKEXTS ARE NOT SUPPORTED IN THE KERNEL YET.
  2461. * @result
  2462. * A <code>CFData</code> object containing the mkext file data on success,
  2463. * <code>NULL</code> on failure.
  2464. *
  2465. * @discussion
  2466. * This function creates a single-architecture mkext file for the currently
  2467. * set library architecture (see @link OSKextSetArchitecture@/link). Kexts
  2468. * with executables lacking code for that architecture are not included.
  2469. *
  2470. * If you want to create a multi-architecture mkext, create a set of single
  2471. * architecture mkext files and use lipo(1) or combine them programmatically.
  2472. *
  2473. * This function generates mkext files in a new format that only works on
  2474. * Mac OS X 10.6 or later.
  2475. */
  2476. // xxx - add a version param and generate old-format mkexts?
  2477. // xxx - add flag to take only most recent version of a given bundle ID?
  2478. CF_EXPORT CFDataRef
  2479. OSKextCreateMkext(
  2480. CFAllocatorRef allocator,
  2481. CFArrayRef kextArray,
  2482. CFURLRef volumeRootURL,
  2483. OSKextRequiredFlags requiredFlags,
  2484. Boolean compressFlag)
  2485. ;
  2486. /*!
  2487. * @function OSKextCreateKextsFromMkextFile
  2488. * @abstract Reads all kexts from an mkext file on disk.
  2489. *
  2490. * @param alocator
  2491. * The allocator to use to allocate memory for the new objects.
  2492. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  2493. * to use the current default allocator.
  2494. * @param mkextURL
  2495. * The mkext file URL from which to create kexts.
  2496. * @result
  2497. * Returns an array containing the kext objects created,
  2498. * or <code>NULL</code> on failure.
  2499. *
  2500. * @discussion
  2501. * This function creates kext objects from an mkext file rather than from
  2502. * bundles on disk. Kexts created with this function are authenticated using
  2503. * the mkext file at <code>mkextURL</code>.
  2504. *
  2505. * A kext created from an mkext has only its info dictionary, executable,
  2506. * and any resources listed in its the OSBundleStartupResources property.
  2507. *
  2508. * Kexts created from an mkext are not uniqued using filesystem URLs,
  2509. * which belong to bundles actually in the filesystem;
  2510. * @link OSKextCreate@/link will never return a kext extracted from an mkext
  2511. * that originally had the URL given (even though the new mkext format
  2512. * stores that original URL).
  2513. * This also means that if you open the same mkext file multiple times,
  2514. * you will create distinct, identical copies of the kexts in that mkext file.
  2515. */
  2516. CF_EXPORT CFArrayRef
  2517. OSKextCreateKextsFromMkextFile(CFAllocatorRef allocator,
  2518. CFURLRef mkextURL)
  2519. ;
  2520. /*!
  2521. * @function OSKextCreateKextsFromMkextData
  2522. * @abstract Reads all kexts from an mkext file in memory.
  2523. *
  2524. * @param alocator
  2525. * The allocator to use to allocate memory for the new objects.
  2526. * Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
  2527. * to use the current default allocator.
  2528. * @param mkextData
  2529. * The mkext file data from which to create kexts.
  2530. * @result
  2531. * Returns an array containing the kext objects created,
  2532. * or <code>NULL</code> on failure.
  2533. *
  2534. * @discussion
  2535. * This function creates kext objects from an mkext file in memory
  2536. * rather than from bundles on disk. Lacking any file in the filesystem,
  2537. * kexts created with this function can not be authenticated.
  2538. *
  2539. * A kext created from an mkext has only its info dictionary, executable,
  2540. * and any resources listed in its the OSBundleStartupResources property.
  2541. *
  2542. * Kexts created from an mkext are not uniqued using filesystem URLs,
  2543. * which belong to bundles actually in the filesystem;
  2544. * @link OSKextCreate@/link will never return a kext extracted from an mkext
  2545. * that originally had the URL given (even though the new mkext format
  2546. * stores that original URL).
  2547. * This also means that if you open the same mkext file multiple times,
  2548. * you will create distinct, identical copies of the kexts in that mkext file.
  2549. */
  2550. CF_EXPORT CFArrayRef
  2551. OSKextCreateKextsFromMkextData(CFAllocatorRef allocator,
  2552. CFDataRef mkextData)
  2553. ;
  2554. /*!
  2555. * @function OSKextCreatePrelinkedKernel
  2556. * @abstract Creates a prelinked kernel from a kernel file and all open kexts.
  2557. *
  2558. * @param kernelImage The kernel image to use.
  2559. * @param kextArray
  2560. * The kexts to include in the prelinked kernel.
  2561. * Pass <code>NULL</code> to consult the running kernel
  2562. * for kexts to include from those open;
  2563. * the current architecture must match the runninng kernel's.
  2564. * @param volumeRootURL
  2565. * If non-<code>NULL</code>, kexts with this URL as a prefix
  2566. * strip it when saving their paths in the prelinked kernel.
  2567. * This allows creation of prelinked kernels from folders
  2568. * other than /System/Library/Extensions.
  2569. * @param needAllFlag
  2570. * If <code>true</code> and any kext fails to link,
  2571. * the skipAuthenticationFlag returns <code>NULL</code>.
  2572. * @param skipAuthenticationFlag
  2573. * If <code>true</code>, kexts are not authenticated for inclusion
  2574. * in the prelinked kernel.
  2575. * @param printDiagnosticsFlag
  2576. * If <code>true</code>, problems with the kexts that prevent
  2577. * inclusion of a kext in the prelinked kernel are logged via
  2578. * @link OSKextLogDiagnostics OSKextLogDiagnostics@/link.
  2579. * @param symbolsOut
  2580. * If non-<code>NULL</code> debug symbols for <code>kernelImage</code>
  2581. * and all kexts included in the result are returned by reference.
  2582. *
  2583. * @result
  2584. * A <code>CFData</code> object containing the prelinked kernel image based
  2585. * on the running kernel.
  2586. * Returns <code>NULL</code> if <code>needAllFlag</code> is <code>true</code>
  2587. * and any kext fails to link.
  2588. */
  2589. CF_EXPORT CFDataRef
  2590. OSKextCreatePrelinkedKernel(
  2591. CFDataRef kernelImage,
  2592. CFArrayRef kextArray,
  2593. CFURLRef volumeRootURL,
  2594. Boolean needAllFlag,
  2595. Boolean skipAuthenticationFlag,
  2596. Boolean printDiagnosticsFlag,
  2597. CFDictionaryRef * symbolsOut)
  2598. ;
  2599. /*!
  2600. * @function OSKextotherCFBundleVersionIsLoaded
  2601. * @abstract
  2602. * Returns whether another version of a given kext is loaded in the kernel.
  2603. *
  2604. * @param aKext The kext to examine.
  2605. * @result
  2606. * <code>true</code> if a kext with the same identifier,
  2607. * but a different version or UUID
  2608. * from <code>aKext</code>, is loaded in the kernel.
  2609. * Returns <code>false</code> if <code>aKext</code> is loaded or if
  2610. * no kext with the same identifier is loaded.
  2611. *
  2612. * @discussion
  2613. * You must call @link OSKextReadLoadedKextInfo@/link for this flag to be meaningful,
  2614. * which in turn requires the current library architecture to match that
  2615. * of the running kernel.
  2616. * Use @link OSKextIsLoaded@/link to check whether <code>aKext</code>
  2617. * itself is loaded.
  2618. */
  2619. CF_EXPORT Boolean OSKextotherCFBundleVersionIsLoaded(OSKextRef kext, Boolean* uuidFlag);
  2620. __END_DECLS
  2621. #endif /* __OSKEXT_H__ */