Skip to content

Commit 01e78e2

Browse files
committed
Kmod (NetBSD): add support
1 parent 0ac0100 commit 01e78e2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/util/kmod.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,50 @@ bool ffKmodLoaded(const char* modName)
3131
{
3232
return modfind(modName) >= 0;
3333
}
34+
#elif __NetBSD__
35+
#include "util/stringUtils.h"
36+
37+
#include <sys/module.h>
38+
#include <sys/param.h>
39+
40+
typedef struct FFNbsdModList
41+
{
42+
int len;
43+
modstat_t mods[];
44+
} FFNbsdModList;
45+
46+
bool ffKmodLoaded(const char* modName)
47+
{
48+
static FFNbsdModList* list = NULL;
49+
50+
if (list == NULL)
51+
{
52+
struct iovec iov = {};
53+
54+
// 初始尝试分配的内存大小
55+
for (size_t len = 8192;; len = iov.iov_len)
56+
{
57+
iov.iov_len = len;
58+
iov.iov_base = realloc(iov.iov_base, len);
59+
if (modctl(MODCTL_STAT, &iov) < 0)
60+
{
61+
free(iov.iov_base);
62+
return true; // ignore errors
63+
}
64+
65+
if (len >= iov.iov_len) break;
66+
}
67+
list = (FFNbsdModList*) iov.iov_base;
68+
}
69+
70+
for (int i = 0; i < list->len; i++)
71+
{
72+
if (ffStrEquals(list->mods[i].ms_name, modName))
73+
return true;
74+
}
75+
76+
return false;
77+
}
3478
#elif __APPLE__
3579
#include "util/apple/cf_helpers.h"
3680
#include <IOKit/kext/KextManager.h>

0 commit comments

Comments
 (0)