1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

fix r52806

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2015-12-01 00:07:21 +00:00
parent b44b129e12
commit ed0858a8c5

View file

@ -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