From 20d36249e791ac8a7f31725e3e2b54ec5270ac73 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 30 Aug 2020 12:57:58 +0000 Subject: [PATCH] explicit_bzero.c: uses explicit_memset for NetBSD. It provides the same guarantee as explicit_bzero to avoid compiler optimisation. Signed-off-by: David Carlier --- configure | 13 +++++++++++++ configure.ac | 1 + src/include/pg_config.h.in | 3 +++ src/port/explicit_bzero.c | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/configure b/configure index cb8fbe1051..c3da20c050 100755 --- a/configure +++ b/configure @@ -15735,6 +15735,19 @@ esac fi +ac_fn_c_check_func "$LINENO" "explicit_memset" "ac_cv_func_explicit_memset" +if test "x$ac_cv_func_explicit_memset" = xyes; then : + $as_echo "#define HAVE_EXPLICIT_MEMSET 1" >>confdefs.h + +else + case " $LIBOBJS " in + *" explicit_memset.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS explicit_memset.$ac_objext" + ;; +esac + +fi + ac_fn_c_check_func "$LINENO" "fls" "ac_cv_func_fls" if test "x$ac_cv_func_fls" = xyes; then : $as_echo "#define HAVE_FLS 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index eb2c731b58..38e59a7eee 100644 --- a/configure.ac +++ b/configure.ac @@ -1721,6 +1721,7 @@ fi AC_REPLACE_FUNCS(m4_normalize([ dlopen explicit_bzero + explicit_memset fls getopt getpeereid diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index fb270df678..07ad2bcff5 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -185,6 +185,9 @@ /* Define to 1 if you have the `explicit_bzero' function. */ #undef HAVE_EXPLICIT_BZERO +/* Define to 1 if you have the `explicit_memset' function. */ +#undef HAVE_EXPLICIT_MEMSET + /* Define to 1 if you have the `fdatasync' function. */ #undef HAVE_FDATASYNC diff --git a/src/port/explicit_bzero.c b/src/port/explicit_bzero.c index 6bd8b0dd9d..214ba4aa26 100644 --- a/src/port/explicit_bzero.c +++ b/src/port/explicit_bzero.c @@ -22,6 +22,14 @@ explicit_bzero(void *buf, size_t len) (void) memset_s(buf, len, 0, len); } +#elif defined(HAVE_EXPLICIT_MEMSET) + +void +explicit_bzero(void *buf, size_t len) +{ + (void) explicit_memset(buf, 0, len); +} + #elif defined(WIN32) void -- 2.27.0