[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] Use volatile trick for explicit_bzero
From: |
roucaries . bastien |
Subject: |
[PATCH 4/5] Use volatile trick for explicit_bzero |
Date: |
Sat, 11 Apr 2020 23:20:34 +0200 |
From: Bastien Roucariès <address@hidden>
Use a volatile pointer to memset function to avoid dead end optimization
Signed-off-by: Bastien Roucariès <address@hidden>
---
lib/explicit_bzero.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 21bbd67e8..59215852c 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -43,6 +43,10 @@
# undef explicit_bzero
#endif
+#if !defined __GNUC__
+static void * (* const volatile volatile_memset)(void *, int, size_t) = memset;
+#endif
+
/* Set LEN bytes of S to 0. The compiler will not delete a call to
this function, even if S is dead after the call. */
void
@@ -54,17 +58,17 @@ explicit_bzero (void *s, size_t len)
(void) memset_s(s,len,'\0',len);
#elif HAVE_SECUREZEROMEMORY
(void) SecureZeroMemory(s,len);
-#else
- memset (s, '\0', len);
-#if defined __GNUC__
+#elif defined __GNUC__
+ (void) memset (s, '\0', len);
# if !defined __clang__
/* Compiler barrier. */
- asm volatile ("" ::: "memory");
+ asm volatile ("" ::: "memory");
# else
/* https://bugs.llvm.org/show_bug.cgi?id=15495#c11 */
__asm__ volatile("" : : "g"(s) : "memory");
# endif
+#else
+ (void) volatile_memset(s,'\0',len);
#endif
-
#endif
}
--
2.25.1
- [patch] Improve explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 1/5] Use memset_s if possible for explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 2/5] Use SecureZeroMemory on windows for explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 5/5] Fix styling in explicit bzero, roucaries . bastien, 2020/04/11
- [PATCH 3/5] Support clang for explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 4/5] Use volatile trick for explicit_bzero,
roucaries . bastien <=
- Re: [patch] Improve explicit_bzero, Bruno Haible, 2020/04/11