mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* missing/explicit_bzero.c: add ruby_explicit_bzero_hook_unused
for preventing optimization. Inspired from OpenBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8ea5564183
commit
48de9684b9
3 changed files with 60 additions and 27 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Dec 2 06:47:25 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* missing/explicit_bzero.c: add ruby_explicit_bzero_hook_unused
|
||||||
|
for preventing optimization. Inspired from OpenBSD.
|
||||||
|
|
||||||
Tue Dec 1 23:36:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Dec 1 23:36:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (rb_thread_setname): allow to reset thread name.
|
* thread.c (rb_thread_setname): allow to reset thread name.
|
||||||
|
|
|
@ -1752,6 +1752,10 @@ RUBY_FUNC_ATTRIBUTE(deprecated, DEPRECATED)
|
||||||
RUBY_FUNC_ATTRIBUTE(deprecated("by "@%:@n), DEPRECATED_BY(n,x), rb_cv_func_deprecated_by)
|
RUBY_FUNC_ATTRIBUTE(deprecated("by "@%:@n), DEPRECATED_BY(n,x), rb_cv_func_deprecated_by)
|
||||||
RUBY_TYPE_ATTRIBUTE(deprecated mesg, DEPRECATED_TYPE(mesg,x), rb_cv_type_deprecated)
|
RUBY_TYPE_ATTRIBUTE(deprecated mesg, DEPRECATED_TYPE(mesg,x), rb_cv_type_deprecated)
|
||||||
RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE)
|
RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE)
|
||||||
|
RUBY_FUNC_ATTRIBUTE(weak, WEAK, rb_cv_func_weak)
|
||||||
|
if test "$rb_cv_func_weak" != x; then
|
||||||
|
AC_DEFINE(HAVE_FUNC_WEAK)
|
||||||
|
fi
|
||||||
|
|
||||||
if_i386=${universal_binary+[defined __i386__]}
|
if_i386=${universal_binary+[defined __i386__]}
|
||||||
RUBY_FUNC_ATTRIBUTE(stdcall, [], [], ${if_i386})
|
RUBY_FUNC_ATTRIBUTE(stdcall, [], [], ${if_i386})
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/* Similar to bzero(), but have a guarantee not to be eliminated from compiler
|
||||||
|
optimization. */
|
||||||
|
|
||||||
|
/* OS support note:
|
||||||
* BSD have explicit_bzero().
|
* BSD have explicit_bzero().
|
||||||
Windows, OS-X have memset_s().
|
* Windows, OS-X have memset_s().
|
||||||
Linux has none. *Sigh*
|
* Linux has none. *Sigh*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -21,26 +24,48 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_EXPLICIT_BZERO
|
#ifndef HAVE_EXPLICIT_BZERO
|
||||||
/* Similar to bzero(), but have a guarantee not to be eliminated from compiler
|
#ifdef HAVE_MEMSET_S
|
||||||
optimization. */
|
void
|
||||||
|
explicit_bzero(void *b, size_t len)
|
||||||
|
{
|
||||||
|
memset_s(b, len, 0, len);
|
||||||
|
}
|
||||||
|
#elif defined SecureZeroMemory
|
||||||
|
void
|
||||||
|
explicit_bzero(void *b, size_t len)
|
||||||
|
{
|
||||||
|
SecureZeroMemory(b, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined HAVE_FUNC_WEAK
|
||||||
|
|
||||||
|
/* A weak function never be optimization away. Even if nobody use it. */
|
||||||
|
WEAK(void ruby_explicit_bzero_hook_unused(void *buf, size_t len));
|
||||||
|
void
|
||||||
|
ruby_explicit_bzero_hook_unused(void *buf, size_t len)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
explicit_bzero(void *b, size_t len)
|
||||||
|
{
|
||||||
|
memset(b, len);
|
||||||
|
ruby_explicit_bzero_hook_unused(b, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* Your OS have no capability. Sigh. */
|
||||||
|
|
||||||
#ifndef HAVE_MEMSET_S
|
|
||||||
FUNC_UNOPTIMIZED(void explicit_bzero(void *b, size_t len));
|
FUNC_UNOPTIMIZED(void explicit_bzero(void *b, size_t len));
|
||||||
#endif
|
|
||||||
#undef explicit_bzero
|
#undef explicit_bzero
|
||||||
|
|
||||||
void
|
void
|
||||||
explicit_bzero(void *b, size_t len)
|
explicit_bzero(void *b, size_t len)
|
||||||
{
|
|
||||||
#ifdef HAVE_MEMSET_S
|
|
||||||
memset_s(b, len, 0, len);
|
|
||||||
#elif defined SecureZeroMemory
|
|
||||||
SecureZeroMemory(b, len);
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* TODO: volatile is not enough if compiler have a LTO (link time
|
* volatile is not enough if compiler have a LTO (link time
|
||||||
* optimization)
|
* optimization). At least, the standard provide no guarantee.
|
||||||
|
* However, gcc and major other compiler never optimization a volatile
|
||||||
|
* variable away. So, using volatile is practically ok.
|
||||||
*/
|
*/
|
||||||
volatile char* p = (volatile char*)b;
|
volatile char* p = (volatile char*)b;
|
||||||
|
|
||||||
|
@ -51,5 +76,4 @@ explicit_bzero(void *b, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
#endif /* HAVE_EXPLICIT_BZERO */
|
||||||
#endif
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue