# HG changeset patch # User Vadim Fedorenko <vadim.fedore...@cdnnow.ru> # Date 1681771172 -10800 # Tue Apr 18 01:39:32 2023 +0300 # Node ID 0a1c8cb5c05141f3ea3135d9f01688f7693fc7df # Parent 252a7acd35ceff4fca7a8c60a9aa6d4d22b688bf Core: use explicit_bzero if possible.
GCC 11+ expanded the scope of dead store elimination optimization and memory barrier trick doesn't work anymore. But there is new function exists in glibc to explicitly clear the buffer - explicit_bzero(). Let's use it instead. --- auto/unix | 10 ++++++++++ src/core/ngx_string.c | 4 ++++ src/core/ngx_string.h | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff -r 252a7acd35ce -r 0a1c8cb5c051 auto/unix --- a/auto/unix Mon Apr 17 14:08:00 2023 +0400 +++ b/auto/unix Tue Apr 18 01:39:32 2023 +0300 @@ -1002,3 +1002,13 @@ if (getaddrinfo("localhost", NULL, NULL, &res) != 0) return 1; freeaddrinfo(res)' . auto/feature + + +ngx_feature="explicit_bzero()" +ngx_feature_name="NGX_HAVE_EXPLICIT_BZERO" +ngx_feature_run=no +ngx_feature_incs='#include <string.h>' +ngx_feature_path= +ngx_feature_libs= +ngx_feature_test="char p[16]; explicit_bzero(p, sizeof(p));" +. auto/feature diff -r 252a7acd35ce -r 0a1c8cb5c051 src/core/ngx_string.c --- a/src/core/ngx_string.c Mon Apr 17 14:08:00 2023 +0400 +++ b/src/core/ngx_string.c Tue Apr 18 01:39:32 2023 +0300 @@ -2080,6 +2080,8 @@ } +#if !(NGX_HAVE_EXPLICIT_BZERO) + void ngx_explicit_memzero(void *buf, size_t n) { @@ -2087,6 +2089,8 @@ ngx_memory_barrier(); } +#endif + #if (NGX_MEMCPY_LIMIT) diff -r 252a7acd35ce -r 0a1c8cb5c051 src/core/ngx_string.h --- a/src/core/ngx_string.h Mon Apr 17 14:08:00 2023 +0400 +++ b/src/core/ngx_string.h Tue Apr 18 01:39:32 2023 +0300 @@ -87,8 +87,11 @@ */ #define ngx_memzero(buf, n) (void) memset(buf, 0, n) #define ngx_memset(buf, c, n) (void) memset(buf, c, n) - +#if (NGX_HAVE_EXPLICIT_BZERO) +#define ngx_explicit_memzero(buf, n) explicit_bzero(buf, n) +#else void ngx_explicit_memzero(void *buf, size_t n); +#endif #if (NGX_MEMCPY_LIMIT) _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel