tftsr-devops_investigation/src-tauri/memset_s_shim.c
Shaun Arman 5c4fb05802
Some checks failed
Test / frontend-tests (pull_request) Successful in 1m45s
Test / frontend-typecheck (pull_request) Successful in 1m57s
PR Review Automation / review (pull_request) Successful in 4m23s
Test / rust-fmt-check (pull_request) Has been cancelled
Test / rust-clippy (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
fix(windows): ensure memset_explicit symbol is properly exported for MinGW
- Add __MINGW32__ detection in memset_s_shim.c for proper EXPORT macro
- Add WIN32 and __WIN32__ defines when compiling the shim in build.rs
- The memset_explicit symbol is required by libsodium-sys-stable but not
  available in MinGW runtime
- The shim is compiled as a static library and linked before libsodium
2026-06-19 09:44:17 -05:00

34 lines
1.0 KiB
C

/* 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.
*
* This shim is compiled as part of the build process when targeting
* Windows with MinGW (x86_64-w64-mingw32).
*/
#include <string.h>
#include <stddef.h>
/*
* 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)
#else
#define EXPORT __attribute__((visibility("default")))
#endif
/*
* 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.
*/
EXPORT void memset_explicit(void *dest, int val, size_t n) {
volatile unsigned char *p = (volatile unsigned char *)dest;
while (n--) {
*p++ = (unsigned char)val;
}
}