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