|
37 | 37 | #include <sys/limits.h> |
38 | 38 | #endif /* !CHAR_BIT*/ |
39 | 39 |
|
| 40 | +#define NO_THREAD_LS |
| 41 | +#define NO_ATTRIBUTE_CONSTRUCTOR |
| 42 | + |
40 | 43 | /* needed to prevent wolfcrypt/src/asn.c version shadowing |
41 | 44 | * extern global version from /usr/src/sys/sys/systm.h */ |
42 | 45 | #define version wc_version |
43 | 46 |
|
44 | | -#define wc_km_printf printf |
| 47 | +/* printf and logging defines */ |
| 48 | +#define wc_km_printf printf |
| 49 | +#define WOLFSSL_DEBUG_PRINTF_FN printf |
45 | 50 |
|
46 | 51 | /* str and char utility functions */ |
47 | 52 | #define XATOI(s) ({ \ |
|
51 | 56 | _xatoi_ret = 0; \ |
52 | 57 | } \ |
53 | 58 | (int)_xatoi_ret; \ |
54 | | - }) |
| 59 | +}) |
55 | 60 |
|
56 | 61 | #if !defined(XMALLOC_OVERRIDE) |
57 | 62 | #error bsdkm requires XMALLOC_OVERRIDE |
|
60 | 65 | /* use malloc and free from /usr/include/sys/malloc.h */ |
61 | 66 | extern struct malloc_type M_WOLFSSL[1]; |
62 | 67 |
|
63 | | -#define XMALLOC(s, h, t) \ |
64 | | - ({(void)(h); (void)(t); malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO);}) |
| 68 | +#if defined(WOLFSSL_BSDKM_MEMORY_DEBUG) |
| 69 | + #define XMALLOC(s, h, t) ({ \ |
| 70 | + (void)(h); (void)(t); \ |
| 71 | + void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \ |
| 72 | + printf("info: malloc: %p, M_WOLFSSL, %zu\n", _ptr, (size_t) s); \ |
| 73 | + (void *)_ptr; \ |
| 74 | + }) |
65 | 75 |
|
66 | | -#ifdef WOLFSSL_XFREE_NO_NULLNESS_CHECK |
67 | | - #define XFREE(p, h, t) \ |
68 | | - ({(void)(h); (void)(t); free(p, M_WOLFSSL);}) |
| 76 | + #define XFREE(p, h, t) ({ \ |
| 77 | + void* _xp; (void)(h); (void)(t); _xp = (p); \ |
| 78 | + printf("info: free: %p, M_WOLFSSL\n", p); \ |
| 79 | + if(_xp) free(_xp, M_WOLFSSL); \ |
| 80 | + }) |
69 | 81 | #else |
70 | | - #define XFREE(p, h, t) \ |
71 | | - ({void* _xp; (void)(h); (void)(t); _xp = (p); \ |
72 | | - if(_xp) free(_xp, M_WOLFSSL);}) |
73 | | -#endif |
| 82 | + #define XMALLOC(s, h, t) ({ \ |
| 83 | + (void)(h); (void)(t); \ |
| 84 | + void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \ |
| 85 | + (void *)_ptr; \ |
| 86 | + }) |
| 87 | + |
| 88 | + #define XFREE(p, h, t) ({ \ |
| 89 | + void* _xp; (void)(h); (void)(t); _xp = (p); \ |
| 90 | + if(_xp) free(_xp, M_WOLFSSL); \ |
| 91 | + }) |
| 92 | +#endif /* WOLFSSL_BSDKM_DEBUG_MEMORY */ |
74 | 93 |
|
75 | 94 | #if !defined(SINGLE_THREADED) |
76 | 95 | #define WC_MUTEX_OPS_INLINE |
77 | 96 |
|
| 97 | + /* Copied from wc_port.h */ |
| 98 | + #if defined(HAVE_FIPS) && !defined(WOLFSSL_API_PREFIX_MAP) |
| 99 | + /* For FIPS keep the function names the same */ |
| 100 | + #define wc_InitMutex InitMutex |
| 101 | + #define wc_FreeMutex FreeMutex |
| 102 | + #define wc_LockMutex LockMutex |
| 103 | + #define wc_UnLockMutex UnLockMutex |
| 104 | + #define NO_THREAD_LS |
| 105 | + #endif /* HAVE_FIPS */ |
| 106 | + |
78 | 107 | typedef struct wolfSSL_Mutex { |
79 | 108 | struct mtx lock; |
80 | 109 | } wolfSSL_Mutex; |
@@ -106,12 +135,18 @@ extern struct malloc_type M_WOLFSSL[1]; |
106 | 135 |
|
107 | 136 | #if defined(WOLFSSL_HAVE_ATOMIC_H) && !defined(WOLFSSL_NO_ATOMICS) |
108 | 137 | #include <machine/atomic.h> |
109 | | - typedef volatile int wolfSSL_Atomic_Int; |
| 138 | + typedef volatile int wolfSSL_Atomic_Int; |
110 | 139 | typedef volatile unsigned int wolfSSL_Atomic_Uint; |
111 | 140 | #define WOLFSSL_ATOMIC_INITIALIZER(x) (x) |
112 | 141 | #define WOLFSSL_ATOMIC_LOAD(x) (int)atomic_load_acq_int(&(x)) |
113 | 142 | #define WOLFSSL_ATOMIC_STORE(x, v) atomic_store_rel_int(&(x), (v)) |
114 | 143 | #define WOLFSSL_ATOMIC_OPS |
| 144 | + |
| 145 | + #if defined(HAVE_FIPS) |
| 146 | + /* There is no corresponding ATOMIC_INIT macro in FreeBSD. |
| 147 | + * The FreeBSD equivalent is just an integer initialization. */ |
| 148 | + #define ATOMIC_INIT(x) (x) |
| 149 | + #endif |
115 | 150 | #endif /* WOLFSSL_HAVE_ATOMIC_H && !WOLFSSL_NO_ATOMICS */ |
116 | 151 |
|
117 | 152 | #endif /* WOLFSSL_BSDKM */ |
|
0 commit comments