2017-07-16 16:22:33 -07:00
|
|
|
/* Erasure of sensitive data, generic implementation.
|
2020-01-01 00:19:43 +00:00
|
|
|
Copyright (C) 2016-2020 Free Software Foundation, Inc.
|
2017-07-16 16:22:33 -07:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
2017-09-13 02:07:03 -07:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2017-07-16 16:22:33 -07:00
|
|
|
|
|
|
|
/* An assembler implementation of explicit_bzero can be created as an
|
|
|
|
assembler alias of an optimized bzero implementation.
|
|
|
|
Architecture-specific implementations also need to define
|
|
|
|
__explicit_bzero_chk. */
|
|
|
|
|
|
|
|
#if !_LIBC
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
Update from Gnulib
This incorporates:
2018-10-05 explicit_bzero: make it possible to namespace
2018-10-04 fcntl: make it possible to namespace
2018-10-01 mkostemp, mkostemps: fix C++ compilation on Mac OS X
2018-09-19 maint: mktime.c now shared with glibc
2018-09-18 file-has-acl: fix test failure on Cygwin 2.9
2018-09-18 gettime: nanotime never existed
* admin/merge-gnulib (AVOIDED_MODULES): Add mkdir.
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/acl_entries.c, lib/explicit_bzero.c, lib/fcntl.c:
* lib/get-permissions.c, lib/gettime.c, lib/mktime.c:
* lib/set-permissions.c, lib/stdlib.in.h, m4/acl.m4, m4/gettime.m4:
Copy from Gnulib.
* lib/gnulib.mk.in: Regenerate.
2018-10-08 18:21:47 -07:00
|
|
|
#if _LIBC
|
2017-07-16 16:22:33 -07:00
|
|
|
/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
|
|
|
|
redirects to that. */
|
Update from Gnulib
This incorporates:
2018-10-05 explicit_bzero: make it possible to namespace
2018-10-04 fcntl: make it possible to namespace
2018-10-01 mkostemp, mkostemps: fix C++ compilation on Mac OS X
2018-09-19 maint: mktime.c now shared with glibc
2018-09-18 file-has-acl: fix test failure on Cygwin 2.9
2018-09-18 gettime: nanotime never existed
* admin/merge-gnulib (AVOIDED_MODULES): Add mkdir.
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/acl_entries.c, lib/explicit_bzero.c, lib/fcntl.c:
* lib/get-permissions.c, lib/gettime.c, lib/mktime.c:
* lib/set-permissions.c, lib/stdlib.in.h, m4/acl.m4, m4/gettime.m4:
Copy from Gnulib.
* lib/gnulib.mk.in: Regenerate.
2018-10-08 18:21:47 -07:00
|
|
|
# undef explicit_bzero
|
|
|
|
#endif
|
2017-07-16 16:22:33 -07:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
explicit_bzero (void *s, size_t len)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_EXPLICIT_MEMSET
|
|
|
|
explicit_memset (s, 0, len);
|
|
|
|
#else
|
|
|
|
memset (s, '\0', len);
|
2018-01-01 01:19:57 +00:00
|
|
|
# if defined __GNUC__ && !defined __clang__
|
2017-07-16 16:22:33 -07:00
|
|
|
/* Compiler barrier. */
|
|
|
|
asm volatile ("" ::: "memory");
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|