[前][次][番号順一覧][スレッド一覧]

ruby-changes:40742

From: kosaki <ko1@a...>
Date: Tue, 1 Dec 2015 09:07:26 +0900 (JST)
Subject: [ruby-changes:40742] kosaki:r52821 (trunk): fix r52806

kosaki	2015-12-01 09:07:21 +0900 (Tue, 01 Dec 2015)

  New Revision: 52821

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52821

  Log:
    fix r52806

  Modified files:
    trunk/missing/explicit_bzero.c
Index: missing/explicit_bzero.c
===================================================================
--- missing/explicit_bzero.c	(revision 52820)
+++ missing/explicit_bzero.c	(revision 52821)
@@ -1,8 +1,34 @@ https://github.com/ruby/ruby/blob/trunk/missing/explicit_bzero.c#L1
+#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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]