mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Improve explicit_bzero implementation
Using the weak symbol explicit_bzero_hook does not work if LTO is enabled. Instead avoid memset optimizations using an asm memory barrier. Use a fallback implementation where the memory is zeroed through volatile.
This commit is contained in:
parent
ff7c9990d4
commit
e835e3c132
@ -30,15 +30,18 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((weak)) void
|
||||
__explicit_bzero_hook(void *dst, size_t siz)
|
||||
{
|
||||
}
|
||||
|
||||
PHPAPI void php_explicit_bzero(void *dst, size_t siz)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
memset(dst, 0, siz);
|
||||
__explicit_bzero_hook(dst, siz);
|
||||
asm __volatile__("" :: "r"(dst) : "memory");
|
||||
#else
|
||||
size_t i = 0;
|
||||
volatile unsigned char *buf = (volatile unsigned char *)dst;
|
||||
|
||||
for (; i < siz; i ++)
|
||||
buf[i] = 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user