diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-01 00:07:21 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-01 00:07:21 +0000 |
commit | ed0858a8c5b193f91423c7043a0f34083db5724d (patch) | |
tree | 1a31082d13c81b74f9bf9d714e1910b676065926 /missing/explicit_bzero.c | |
parent | b44b129e12897c5e2bb3387d79296f8545baf3fd (diff) | |
download | ruby-ed0858a8c5b193f91423c7043a0f34083db5724d.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/explicit_bzero.c')
-rw-r--r-- | missing/explicit_bzero.c | 32 |
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 |