[go: up one dir, main page]

Skip to content

Commit

Permalink
use asm volatile memset for memzero if available on Windows
Browse files Browse the repository at this point in the history
When using gcc or clang on Windows, this removes the dependency on the
Windows API.
  • Loading branch information
chrisnc committed Aug 10, 2022
1 parent d68ba63 commit 151502e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/memzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@

#include "memzero.h"

#if defined(_WIN32)
#if defined(__GNUC__) || defined(__clang__)
#include <string.h>
#elif defined(_WIN32)
#include <windows.h>

#include <wincrypt.h>
#elif defined(__GNUC__) || defined(__clang__)
#include <string.h>
#endif

void lith_memzero(void *p, size_t len)
{
#if defined(_WIN32)
SecureZeroMemory(p, len);
#elif defined(__GNUC__) || defined(__clang__)
#if defined(__GNUC__) || defined(__clang__)
/*
* Derived from musl libc's implementation of explicit_bzero.
*
Expand All @@ -36,6 +34,8 @@ void lith_memzero(void *p, size_t len)
* box sees the writes is for them to actually be performed."
*/
__asm__ __volatile__("" : : "r"(memset(p, 0, len)) : "memory");
#elif defined(_WIN32)
SecureZeroMemory(p, len);
#else
/*
* Fall back to writing through a volatile pointer if nothing else is
Expand Down

0 comments on commit 151502e

Please sign in to comment.