Skip to content

Commit 74476a3

Browse files
committed
Windows: libspl: implement ZFS_MODULE_PARAM for userspace
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
1 parent 3165d5e commit 74476a3

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

lib/libspl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_library(libspl
88
strlcat.c
99
strlcpy.c
1010
timestamp.c
11+
tunables.c
1112
assert.c
1213
backtrace.c
1314
os/windows/posix.c

lib/libspl/include/os/windows/inttypes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
#ifndef _LIBSPL_INTTYPES_H
2323
#define _LIBSPL_INTTYPES_H
2424

25+
#include_next <inttypes.h>
26+
2527
#define SCNi8 "hhi"
2628
#define SCNi16 "hi"
2729
#define SCNi32 "i"
2830
#define SCNi64 "lli"
29-
#define PRId32 "i"
31+
// #define PRId32 "i"
3032
#define PRIu64 "llu"
3133
#define PRIx64 "llx"
3234
#define PRIi64 "lli"
33-
#define PRId64 "lli"
35+
// #define PRId64 "lli"
3436

35-
#define strtoimax strtoull
3637

38+
#define strtoimax strtoull
39+
#define strtoumax strtoull
3740

3841
#endif /* SPL_INTTYPES_H */

lib/libspl/include/sys/mod.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@
3232

3333
#include <sys/tunables.h>
3434

35+
/*
36+
* We use sys/linker_set.h, so let's simulate it
37+
* for the platforms that haven't got that.
38+
*/
39+
40+
#if defined(_WIN32)
41+
42+
#include <sys/linker_set.h>
43+
44+
#else /* Not Windows */
45+
46+
#define SET_ENTRY(set, sym) \
47+
static const zfs_tunable_t * \
48+
_##set##sym \
49+
__attribute__((__section__(ZFS_TUNABLE_SECTION))) \
50+
__attribute__((__used__)) \
51+
= &set##sym;
52+
53+
#endif
54+
3555
#define ZFS_MODULE_PARAM(scope, prefix, name, type, perm, desc) \
3656
static const zfs_tunable_t _zfs_tunable_##prefix##name = { \
3757
.zt_name = #prefix#name, \
@@ -41,11 +61,7 @@
4161
.zt_perm = ZFS_TUNABLE_PERM_##perm, \
4262
.zt_desc = desc \
4363
}; \
44-
static const zfs_tunable_t * \
45-
__zfs_tunable_##prefix##name \
46-
__attribute__((__section__(ZFS_TUNABLE_SECTION))) \
47-
__attribute__((__used__)) \
48-
= &_zfs_tunable_##prefix##name;
64+
SET_ENTRY(zfs_tunables, _zfs_tunable_##prefix##name)
4965

5066
#define ZFS_MODULE_PARAM_ARGS void
5167
#define ZFS_MODULE_PARAM_CALL(scope_prefix, name_prefix, name, setfunc, \

lib/libspl/include/sys/tunables.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#ifndef _SYS_TUNABLES_H
2828
#define _SYS_TUNABLES_H
2929

30+
#if defined(_WIN32)
31+
#include <sys/linker_set.h>
32+
#endif
33+
3034
typedef enum {
3135
ZFS_TUNABLE_TYPE_INT,
3236
ZFS_TUNABLE_TYPE_UINT,
@@ -51,6 +55,8 @@ typedef struct zfs_tunable {
5155

5256
#if defined(__APPLE__)
5357
#define ZFS_TUNABLE_SECTION "__DATA_CONST,zfs_tunables"
58+
#elif defined(_WIN32)
59+
/* Not used */
5460
#else
5561
#define ZFS_TUNABLE_SECTION "zfs_tunables"
5662
#endif

lib/libspl/tunables.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
for ((pvar) = &__start_##set; \
113113
(pvar) < &__stop_##set; (pvar)++)
114114

115+
#elif defined(_WIN32)
116+
117+
#include <sys/linker_set.h>
118+
115119
#else
116120

117121
#define SET_DECLARE(set, type) \
@@ -130,9 +134,11 @@
130134
* that, we force a symbol into that section, and then when iterating, skip
131135
* any NULL pointers.
132136
*/
137+
#ifndef _WIN32
133138
static void *__zfs_tunable__placeholder
134139
__attribute__((__section__(ZFS_TUNABLE_SECTION)))
135140
__attribute__((__used__)) = NULL;
141+
#endif
136142

137143
/*
138144
* Find the name tunable by walking through the linker set and comparing names,

0 commit comments

Comments
 (0)