Skip to content

Commit a3a4f0a

Browse files
committed
Kmod: support macOS
1 parent af067c7 commit a3a4f0a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/util/kmod.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ bool ffKmodLoaded(const char* modName)
3131
{
3232
return modfind(modName) >= 0;
3333
}
34+
#elif __APPLE__
35+
#include "util/apple/cf_helpers.h"
36+
#include <IOKit/kext/KextManager.h>
37+
#include <CoreFoundation/CoreFoundation.h>
38+
39+
bool ffKmodLoaded(const char* modName)
40+
{
41+
FF_CFTYPE_AUTO_RELEASE CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, modName, kCFStringEncodingUTF8);
42+
FF_CFTYPE_AUTO_RELEASE CFArrayRef identifiers = CFArrayCreate(kCFAllocatorDefault, (const void**) &name, 1, &kCFTypeArrayCallBacks);
43+
FF_CFTYPE_AUTO_RELEASE CFArrayRef keys = CFArrayCreate(kCFAllocatorDefault, NULL, 0, NULL);
44+
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef kextInfo = KextManagerCopyLoadedKextInfo(identifiers, keys);
45+
return CFDictionaryContainsKey(kextInfo, name);
46+
}
3447
#else
3548
bool ffKmodLoaded(FF_MAYBE_UNUSED const char* modName)
3649
{

0 commit comments

Comments
 (0)