From ed0858a8c5b193f91423c7043a0f34083db5724d Mon Sep 17 00:00:00 2001 From: kosaki Date: Tue, 1 Dec 2015 00:07:21 +0000 Subject: fix r52806 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/explicit_bzero.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'missing/explicit_bzero.c') 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 -/* 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 -- cgit v1.2.3