1  /* Generic implementation of __explicit_bzero_chk.
       2     Copyright (C) 1991-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  /* This is the generic definition of __explicit_bzero_chk.  The
      20     __explicit_bzero_chk symbol is used as the implementation of
      21     explicit_bzero throughout glibc.  If this file is overridden by an
      22     architecture, both __explicit_bzero_chk and
      23     __explicit_bzero_chk_internal have to be defined (the latter not as
      24     an IFUNC).  */
      25  
      26  #include <string.h>
      27  
      28  void
      29  __explicit_bzero_chk (void *dst, size_t len, size_t dstlen)
      30  {
      31    /* Inline __memset_chk to avoid a PLT reference to __memset_chk.  */
      32    if (__glibc_unlikely (dstlen < len))
      33      __chk_fail ();
      34    memset (dst, '\0', len);
      35    /* Compiler barrier.  */
      36    asm volatile ("" ::: "memory");
      37  }
      38  
      39  /* libc-internal references use the hidden
      40     __explicit_bzero_chk_internal symbol.  This is necessary if
      41     __explicit_bzero_chk is implemented as an IFUNC because some
      42     targets do not support hidden references to IFUNC symbols.  */
      43  strong_alias (__explicit_bzero_chk, __explicit_bzero_chk_internal)