Changeset 86300 in vbox for trunk/src/VBox/Runtime/r3/darwin/krnlmod-darwin.cpp
- Timestamp:
- Sep 26, 2020 9:59:44 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/darwin/krnlmod-darwin.cpp
r82968 r86300 43 43 #include <CoreFoundation/CoreFoundation.h> 44 44 #include <IOKit/IOKitLib.h> 45 #include <libkern/OSReturn.h> 45 46 46 47 … … 49 50 /** OSKextCopyLoadedKextInfo in IOKit. */ 50 51 typedef CFDictionaryRef (* PFNOSKEXTCOPYLOADEDKEXTINFO)(CFArrayRef, CFArrayRef); 52 /** KextManagerLoadKextWithURL in IOKit. */ 53 typedef OSReturn (* PFNKEXTMANAGERLOADKEXTWITHURL)(CFURLRef, CFArrayRef); 54 /** KextManagerLoadKextWithIdentifier in IOKit */ 55 typedef OSReturn (* PFNKEXTMANAGERLOADKEXTWITHIDENTIFIER)(CFStringRef, CFArrayRef); 56 /** KextManagerUnloadKextWithIdentifier in IOKit */ 57 typedef OSReturn (* PFNKEXTMANAGERUNLOADKEXTWITHIDENTIFIER)(CFStringRef); 51 58 52 59 #ifndef kOSBundleRetainCountKey … … 84 91 * Global Variables * 85 92 *********************************************************************************************************************************/ 86 static RTONCE g_GetIoKitApisOnce = RTONCE_INITIALIZER; 87 static PFNOSKEXTCOPYLOADEDKEXTINFO g_pfnOSKextCopyLoadedKextInfo = NULL; 93 static RTONCE g_GetIoKitApisOnce = RTONCE_INITIALIZER; 94 static PFNOSKEXTCOPYLOADEDKEXTINFO g_pfnOSKextCopyLoadedKextInfo = NULL; 95 static PFNKEXTMANAGERLOADKEXTWITHURL g_pfnKextManagerLoadKextWithUrl = NULL; 96 static PFNKEXTMANAGERLOADKEXTWITHIDENTIFIER g_pfnKextManagerLoadKextWithIdentifier = NULL; 97 static PFNKEXTMANAGERUNLOADKEXTWITHIDENTIFIER g_pfnKextManagerUnloadKextWithIdentifier = NULL; 88 98 89 99 /** Do-once callback for setting g_pfnOSKextCopyLoadedKextInfo. */ … … 94 104 int rc = RTLdrLoadEx("/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit", &hMod, RTLDRLOAD_FLAGS_NO_SUFFIX, NULL); 95 105 if (RT_SUCCESS(rc)) 106 { 96 107 RTLdrGetSymbol(hMod, "OSKextCopyLoadedKextInfo", (void **)&g_pfnOSKextCopyLoadedKextInfo); 108 RTLdrGetSymbol(hMod, "KextManagerLoadKextWithURL", (void **)&g_pfnKextManagerLoadKextWithUrl); 109 RTLdrGetSymbol(hMod, "KextManagerLoadKextWithIdentifier", (void **)&g_pfnKextManagerLoadKextWithIdentifier); 110 RTLdrGetSymbol(hMod, "KextManagerUnloadKextWithIdentifier", (void **)&g_pfnKextManagerUnloadKextWithIdentifier); 111 } 97 112 98 113 RT_NOREF(pvUser); … … 390 405 return VERR_NOT_IMPLEMENTED; 391 406 } 407 408 409 RTDECL(int) RTKrnlModLoadByName(const char *pszName) 410 { 411 AssertPtrReturn(pszName, VERR_INVALID_PARAMETER); 412 413 RTOnce(&g_GetIoKitApisOnce, rtKrnlModDarwinResolveIoKitApis, NULL); 414 if (!g_pfnKextManagerLoadKextWithIdentifier) return VERR_NOT_SUPPORTED; 415 416 int rc = VINF_SUCCESS; 417 CFStringRef hKextName = CFStringCreateWithCString(kCFAllocatorDefault, pszName, kCFStringEncodingUTF8); 418 if (hKextName) 419 { 420 OSReturn rcOsx = g_pfnKextManagerLoadKextWithIdentifier(hKextName, NULL /*dependencyKextAndFolderURLs*/); 421 if (rcOsx != kOSReturnSuccess) 422 rc = VERR_NOT_SUPPORTED; /** @todo Convert OSReturn values. */ 423 CFRelease(hKextName); 424 } 425 else 426 rc = VERR_NO_MEMORY; 427 428 return rc; 429 } 430 431 432 RTDECL(int) RTKrnlModLoadByPath(const char *pszPath) 433 { 434 AssertPtrReturn(pszPath, VERR_INVALID_PARAMETER); 435 436 return VERR_NOT_SUPPORTED; 437 } 438 439 440 RTDECL(int) RTKrnlModUnloadByName(const char *pszName) 441 { 442 AssertPtrReturn(pszName, VERR_INVALID_PARAMETER); 443 444 RTOnce(&g_GetIoKitApisOnce, rtKrnlModDarwinResolveIoKitApis, NULL); 445 if (!g_pfnKextManagerUnloadKextWithIdentifier) return VERR_NOT_SUPPORTED; 446 447 int rc = VINF_SUCCESS; 448 CFStringRef hKextName = CFStringCreateWithCString(kCFAllocatorDefault, pszName, kCFStringEncodingUTF8); 449 if (hKextName) 450 { 451 OSReturn rcOsx = g_pfnKextManagerUnloadKextWithIdentifier(hKextName); 452 if (rcOsx != kOSReturnSuccess) 453 rc = VERR_NOT_SUPPORTED; /** @todo Convert OSReturn values. */ 454 CFRelease(hKextName); 455 } 456 else 457 rc = VERR_NO_MEMORY; 458 459 return rc; 460 }
Note:
See TracChangeset
for help on using the changeset viewer.