explicit_bzero_chk.c 1.8 KB

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