Skip to content

Commit 551f904

Browse files
committed
bsdkm: review cleanup.
1 parent 28e4fe3 commit 551f904

File tree

4 files changed

+91
-90
lines changed

4 files changed

+91
-90
lines changed

bsdkm/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
# wolfssl module name and source.
1+
# wolfssl kernel module name and source, and root dir.
22
KMOD=libwolfssl
33
SRCS=wolfkmod.c
44
WOLFSSL_DIR=../
55

66
CFLAGS+=-I${WOLFSSL_DIR}
7-
CFLAGS+=-DWOLFSSL_IGNORE_FILE_WARN -DHAVE_CONFIG_H
8-
CFLAGS+=-DNO_MAIN_DRIVER
9-
# debug mode
10-
CFLAGS+=-DWOLFSSL_BSDKM_VERBOSE_DEBUG
7+
CFLAGS+=-DWOLFSSL_IGNORE_FILE_WARN -DHAVE_CONFIG_H -DNO_MAIN_DRIVER
8+
# debug printing
9+
# CFLAGS+=-DWOLFSSL_BSDKM_VERBOSE_DEBUG
1110
CFLAGS+=$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
1211

1312
# FreeBSD make does not support GNU make's patsubst and related. Filter
1413
# through sed instead.
15-
OBJS != echo ${src_libwolfssl_la_OBJECTS} | sed 's|src_libwolfssl_la-||g' | \
16-
sed 's|\.lo|.o|g' | sed 's|wolfcrypt/src/|${WOLFSSL_DIR}/wolfcrypt/src/|g'
14+
WOLFSSL_OBJS != echo ${src_libwolfssl_la_OBJECTS} | \
15+
sed 's|src_libwolfssl_la-||g' | sed 's|\.lo|.o|g' | \
16+
sed 's|wolfcrypt/src/|${WOLFSSL_DIR}/wolfcrypt/src/|g'
1717

1818
.if ${ENABLED_CRYPT_TESTS} == "yes"
19-
OBJS += ${WOLFSSL_DIR}/wolfcrypt/test/test.o
19+
WOLFSSL_OBJS += ${WOLFSSL_DIR}/wolfcrypt/test/test.o
2020
.else
2121
CFLAGS+=-DNO_CRYPT_TEST
2222
.endif
2323

24+
OBJS += ${WOLFSSL_OBJS}
25+
2426
# Export no public symbols by default.
2527
.if !defined(BSDKM_EXPORT_SYMS)
2628
EXPORT_SYMS=NO

bsdkm/wolfkmod.c

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -44,87 +44,6 @@ static int wolfkmod_cleanup(void);
4444
static int wolfkmod_load(void);
4545
static int wolfkmod_unload(void);
4646

47-
#if defined(WOLFSSL_ATOMIC_OPS)
48-
/* Note: using compiler built-ins like __atomic_fetch_add will technically
49-
* build, but are not commonly used in FreeBSD and may not be safe / portable.
50-
* */
51-
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i)
52-
{
53-
*c = i;
54-
}
55-
56-
void wolfSSL_Atomic_Uint_Init(wolfSSL_Atomic_Uint* c, unsigned int i)
57-
{
58-
*c = i;
59-
}
60-
61-
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i)
62-
{
63-
return atomic_fetchadd_int(c, i);
64-
}
65-
66-
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
67-
{
68-
return atomic_fetchadd_int(c, -i);
69-
}
70-
71-
int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int* c, int i)
72-
{
73-
int val = atomic_fetchadd_int(c, i);
74-
return val + i;
75-
}
76-
77-
int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i)
78-
{
79-
int val = atomic_fetchadd_int(c, -i);
80-
return val - i;
81-
}
82-
83-
unsigned int wolfSSL_Atomic_Uint_FetchAdd(wolfSSL_Atomic_Uint* c,
84-
unsigned int i)
85-
{
86-
return atomic_fetchadd_int(c, i);
87-
}
88-
89-
unsigned int wolfSSL_Atomic_Uint_FetchSub(wolfSSL_Atomic_Uint* c,
90-
unsigned int i)
91-
{
92-
return atomic_fetchadd_int(c, -i);
93-
}
94-
95-
unsigned int wolfSSL_Atomic_Uint_AddFetch(wolfSSL_Atomic_Uint* c,
96-
unsigned int i)
97-
{
98-
unsigned int val = atomic_fetchadd_int(c, i);
99-
return val + i;
100-
}
101-
102-
unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint* c,
103-
unsigned int i)
104-
{
105-
unsigned int val = atomic_fetchadd_int(c, -i);
106-
return val - i;
107-
}
108-
109-
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
110-
int new_i)
111-
{
112-
u_int exp = (u_int) *expected_i;
113-
int ret = atomic_fcmpset_int(c, &exp, new_i);
114-
*expected_i = (int)exp;
115-
return ret;
116-
}
117-
118-
int wolfSSL_Atomic_Uint_CompareExchange(
119-
wolfSSL_Atomic_Uint* c, unsigned int *expected_i, unsigned int new_i)
120-
{
121-
u_int exp = (u_int) *expected_i;
122-
int ret = atomic_fcmpset_int(c, &exp, new_i);
123-
*expected_i = (unsigned int)exp;
124-
return ret;
125-
}
126-
#endif /* WOLFSSL_ATOMIC_OPS */
127-
12847
static int wolfkmod_init(void)
12948
{
13049
int ret = 0;

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,12 @@ then
814814
KERNEL_MODE_DEFAULTS=yes
815815
ENABLED_NO_LIBRARY=yes
816816
ENABLED_BENCHMARK=no
817+
ENABLED_ASM=no
817818

818819
output_objdir="$(realpath "$output_objdir")/bsdkm"
819820

820821
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_BSDKM -DWC_SIPHASH_NO_ASM"
822+
AM_CFLAGS="$AM_CFLAGS -DTFM_NO_ASM -DWOLFSSL_NO_ASM"
821823
AM_CFLAGS="$AM_CFLAGS -DNO_DEV_RANDOM -DNO_WRITEV -DNO_STDIO_FILESYSTEM"
822824
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_NO_SOCK -DWOLFSSL_USER_IO"
823825
AM_CFLAGS="$AM_CFLAGS -DXMALLOC_OVERRIDE -DWOLFCRYPT_ONLY"

wolfcrypt/src/wc_port.c

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,86 @@ char* wc_strdup_ex(const char *src, int memType) {
12781278
#elif defined(SINGLE_THREADED)
12791279

12801280
#elif defined(WOLFSSL_BSDKM)
1281+
/* Note: using compiler built-ins like __atomic_fetch_add will technically
1282+
* build in FreeBSD kernel, but are not commonly used in FreeBSD kernel and
1283+
* might not be safe or portable.
1284+
* */
1285+
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i)
1286+
{
1287+
*c = i;
1288+
}
1289+
1290+
void wolfSSL_Atomic_Uint_Init(wolfSSL_Atomic_Uint* c, unsigned int i)
1291+
{
1292+
*c = i;
1293+
}
1294+
1295+
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i)
1296+
{
1297+
return atomic_fetchadd_int(c, i);
1298+
}
1299+
1300+
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
1301+
{
1302+
return atomic_fetchadd_int(c, -i);
1303+
}
1304+
1305+
int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int* c, int i)
1306+
{
1307+
int val = atomic_fetchadd_int(c, i);
1308+
return val + i;
1309+
}
1310+
1311+
int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i)
1312+
{
1313+
int val = atomic_fetchadd_int(c, -i);
1314+
return val - i;
1315+
}
1316+
1317+
unsigned int wolfSSL_Atomic_Uint_FetchAdd(wolfSSL_Atomic_Uint* c,
1318+
unsigned int i)
1319+
{
1320+
return atomic_fetchadd_int(c, i);
1321+
}
1322+
1323+
unsigned int wolfSSL_Atomic_Uint_FetchSub(wolfSSL_Atomic_Uint* c,
1324+
unsigned int i)
1325+
{
1326+
return atomic_fetchadd_int(c, -i);
1327+
}
1328+
1329+
unsigned int wolfSSL_Atomic_Uint_AddFetch(wolfSSL_Atomic_Uint* c,
1330+
unsigned int i)
1331+
{
1332+
unsigned int val = atomic_fetchadd_int(c, i);
1333+
return val + i;
1334+
}
1335+
1336+
unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint* c,
1337+
unsigned int i)
1338+
{
1339+
unsigned int val = atomic_fetchadd_int(c, -i);
1340+
return val - i;
1341+
}
1342+
1343+
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
1344+
int new_i)
1345+
{
1346+
u_int exp = (u_int) *expected_i;
1347+
int ret = atomic_fcmpset_int(c, &exp, new_i);
1348+
*expected_i = (int)exp;
1349+
return ret;
1350+
}
1351+
1352+
int wolfSSL_Atomic_Uint_CompareExchange(
1353+
wolfSSL_Atomic_Uint* c, unsigned int *expected_i, unsigned int new_i)
1354+
{
1355+
u_int exp = (u_int) *expected_i;
1356+
int ret = atomic_fcmpset_int(c, &exp, new_i);
1357+
*expected_i = (unsigned int)exp;
1358+
return ret;
1359+
}
12811360

1282-
/* definitions are in bsdkm/bsdkm_wc_port.h */
12831361

12841362
#elif defined(HAVE_C___ATOMIC) && defined(WOLFSSL_HAVE_ATOMIC_H) && \
12851363
!defined(__cplusplus)

0 commit comments

Comments
 (0)