summaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-01 00:07:21 (GMT)
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-01 00:07:21 (GMT)
commited0858a8c5b193f91423c7043a0f34083db5724d (patch)
tree1a31082d13c81b74f9bf9d714e1910b676065926 /missing
parentb44b129e12897c5e2bb3387d79296f8545baf3fd (diff)
fix r52806
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'missing')
-rw-r--r--missing/explicit_bzero.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/missing/explicit_bzero.c b/missing/explicit_bzero.c
index cb11bd6..f140acb 100644
--- a/missing/explicit_bzero.c
+++ b/missing/explicit_bzero.c
@@ -1,8 +1,34 @@
+#include "ruby/missing.h"
#include <string.h>
-/* prevent the compiler from optimizing away memset or bzero */
+/*
+ *BSD have explicit_bzero().
+ Windows, OS-X have memset_s().
+ Linux has none. *Sigh*
+*/
+
+#ifndef HAVE_EXPLICIT_BZERO
+/* Similar to bzero(), but have a guarantee not to be eliminated from compiler
+ optimization. */
void
-explicit_bzero(void *p, size_t n)
+explicit_bzero(void *b, size_t len)
{
- memset(p, 0, n);
+#ifdef HAVE_MEMSET_S
+ memset_s(b, len, 0, len);
+#else
+ {
+ /*
+ * TODO: volatile is not enough if compiler have a LTO (link time
+ * optimization)
+ */
+ volatile char* p = (volatile char*)b;
+
+ while(len) {
+ *p = 0;
+ p++;
+ len--;
+ }
+ }
+#endif
}
+#endif