explicit_bzero_chk.c 1.7 KB

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