2026-06-19 03:57:13 +00:00
|
|
|
/* memset_explicit shim for Windows MinGW
|
|
|
|
|
*
|
|
|
|
|
* libsodium-sys-stable expects memset_explicit which isn't available
|
|
|
|
|
* in the MinGW runtime. This provides a compatible implementation.
|
2026-06-19 14:44:17 +00:00
|
|
|
*
|
|
|
|
|
* This shim is compiled as part of the build process when targeting
|
|
|
|
|
* Windows with MinGW (x86_64-w64-mingw32).
|
2026-06-19 03:57:13 +00:00
|
|
|
*/
|
2026-06-14 04:36:54 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
2026-06-19 14:44:17 +00:00
|
|
|
#include <stddef.h>
|
2026-06-14 04:36:54 +00:00
|
|
|
|
2026-06-19 14:44:17 +00:00
|
|
|
/*
|
|
|
|
|
* Windows symbol export macros.
|
|
|
|
|
* __declspec(dllexport) ensures the symbol is visible in the compiled object.
|
|
|
|
|
*/
|
|
|
|
|
#if defined(_WIN32) || defined(__WIN32__) || defined(__MINGW32__)
|
|
|
|
|
#define EXPORT __declspec(dllexport)
|
2026-06-19 04:32:09 +00:00
|
|
|
#else
|
2026-06-19 14:44:17 +00:00
|
|
|
#define EXPORT __attribute__((visibility("default")))
|
2026-06-19 04:32:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
2026-06-19 14:44:17 +00:00
|
|
|
/*
|
|
|
|
|
* memset_explicit implementation - a secure memory clearing function.
|
|
|
|
|
* Uses volatile to prevent compiler optimization from removing the memset.
|
|
|
|
|
* This matches the signature expected by libsodium.
|
|
|
|
|
*/
|
2026-06-19 04:32:09 +00:00
|
|
|
EXPORT void memset_explicit(void *dest, int val, size_t n) {
|
2026-06-19 03:57:13 +00:00
|
|
|
volatile unsigned char *p = (volatile unsigned char *)dest;
|
2026-06-14 04:36:54 +00:00
|
|
|
while (n--) {
|
2026-06-19 03:57:13 +00:00
|
|
|
*p++ = (unsigned char)val;
|
2026-06-14 04:36:54 +00:00
|
|
|
}
|
|
|
|
|
}
|