aboutsummaryrefslogtreecommitdiffstats
path: root/missing
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-01 00:07:21 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-01 00:07:21 +0000
commit140db65de03f452804ef1d5ff7dde900a23e7ea9 (patch)
tree1a31082d13c81b74f9bf9d714e1910b676065926 /missing
parentfdd86ed358b2467a101f00f1bd68d8a23cd7cd27 (diff)
downloadruby-140db65de03f452804ef1d5ff7dde900a23e7ea9.tar.gz
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 cb11bd6da1..f140acb374 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