Blame gl/explicit_bzero.c

Packit Service 991b93
/* Erasure of sensitive data, generic implementation.
Packit Service 991b93
   Copyright (C) 2016-2020 Free Software Foundation, Inc.
Packit Service 991b93
   This file is part of the GNU C Library.
Packit Service 991b93
Packit Service 991b93
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 991b93
   modify it under the terms of the GNU Lesser General Public
Packit Service 991b93
   License as published by the Free Software Foundation; either
Packit Service 991b93
   version 2.1 of the License, or (at your option) any later version.
Packit Service 991b93
Packit Service 991b93
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 991b93
   Lesser General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received a copy of the GNU Lesser General Public
Packit Service 991b93
   License along with the GNU C Library; if not, see
Packit Service 991b93
   <https://www.gnu.org/licenses/>.  */
Packit Service 991b93
Packit Service 991b93
/* An assembler implementation of explicit_bzero can be created as an
Packit Service 991b93
   assembler alias of an optimized bzero implementation.
Packit Service 991b93
   Architecture-specific implementations also need to define
Packit Service 991b93
   __explicit_bzero_chk.  */
Packit Service 991b93
Packit Service 991b93
#if !_LIBC
Packit Service 991b93
# include <config.h>
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* memset_s need this define */
Packit Service 991b93
#if HAVE_MEMSET_S
Packit Service 991b93
# define __STDC_WANT_LIB_EXT1__ 1
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#include <string.h>
Packit Service 991b93
Packit Service 991b93
#if defined _WIN32 && !defined __CYGWIN__
Packit Service 991b93
# define  WIN32_LEAN_AND_MEAN
Packit Service 991b93
# include <windows.h>
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#if _LIBC
Packit Service 991b93
/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
Packit Service 991b93
   redirects to that.  */
Packit Service 991b93
# undef explicit_bzero
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Set LEN bytes of S to 0.  The compiler will not delete a call to
Packit Service 991b93
   this function, even if S is dead after the call.  */
Packit Service 991b93
void
Packit Service 991b93
explicit_bzero (void *s, size_t len)
Packit Service 991b93
{
Packit Service 991b93
#if defined _WIN32 && !defined __CYGWIN__
Packit Service 991b93
  (void) SecureZeroMemory (s, len);
Packit Service 991b93
#elif HAVE_EXPLICIT_MEMSET
Packit Service 991b93
  explicit_memset (s, '\0', len);
Packit Service 991b93
#elif HAVE_MEMSET_S
Packit Service 991b93
  (void) memset_s (s, len, '\0', len);
Packit Service 991b93
#else
Packit Service 991b93
  memset (s, '\0', len);
Packit Service 991b93
# if defined __GNUC__ && !defined __clang__
Packit Service 991b93
  /* Compiler barrier.  */
Packit Service 991b93
  asm volatile ("" ::: "memory");
Packit Service 991b93
# endif
Packit Service 991b93
#endif
Packit Service 991b93
}