bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/5] Use volatile trick for explicit_bzero


From: Bruno Haible
Subject: Re: [PATCH 4/5] Use volatile trick for explicit_bzero
Date: Sun, 12 Apr 2020 00:31:35 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-174-generic; KDE/5.18.0; x86_64; ; )

Hi Bastien,

> diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
> index 21bbd67e8..59215852c 100644
> --- a/lib/explicit_bzero.c
> +++ b/lib/explicit_bzero.c
> @@ -43,6 +43,10 @@
>  # undef explicit_bzero
>  #endif
>  
> +#if !defined __GNUC__
> +static void * (* const volatile volatile_memset)(void *, int, size_t) = 
> memset;
> +#endif
> +
>  /* Set LEN bytes of S to 0.  The compiler will not delete a call to
>     this function, even if S is dead after the call.  */
>  void
> @@ -54,17 +58,17 @@ explicit_bzero (void *s, size_t len)
>    (void) memset_s(s,len,'\0',len);
>  #elif HAVE_SECUREZEROMEMORY
>    (void) SecureZeroMemory(s,len);
> -#else
> -  memset (s, '\0', len);
> -#if defined __GNUC__
> +#elif defined __GNUC__
> +  (void) memset (s, '\0', len);
>  #   if !defined __clang__
>      /* Compiler barrier.  */
> -    asm volatile ("" ::: "memory");
> +  asm volatile ("" ::: "memory");
>  #  else
>     /* https://bugs.llvm.org/show_bug.cgi?id=15495#c11 */
>    __asm__ volatile("" : : "g"(s) : "memory");
>  #  endif
> +#else
> +  (void) volatile_memset(s,'\0',len);
>  #endif
> -
>  #endif
>  }

Nice trick. But does it need to be a static variable? A local variable
should work the same way (like in [1]) and requires less #ifs.

Bruno

[1] 
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=bdf8b1d2b74e12648edafffcda43832bc35e3d1f




reply via email to

[Prev in Thread] Current Thread [Next in Thread]