blob: 3c85a4843a4752e218fc210c645619bbade4300d [file] [log] [blame]
Damien Miller1d2c4562014-02-04 11:18:20 +11001/* OPENBSD ORIGINAL: lib/libc/string/explicit_bzero.c */
2/* $OpenBSD: explicit_bzero.c,v 1.1 2014/01/22 21:06:45 tedu Exp $ */
3/*
4 * Public domain.
5 * Written by Ted Unangst
6 */
7
8#include "includes.h"
9
Damien Miller1d2c4562014-02-04 11:18:20 +110010/*
11 * explicit_bzero - don't let the compiler optimize away bzero
12 */
Damien Miller3d673d12014-08-27 06:32:01 +100013
14#ifndef HAVE_EXPLICIT_BZERO
15
16#ifdef HAVE_MEMSET_S
17
Damien Miller1d2c4562014-02-04 11:18:20 +110018void
19explicit_bzero(void *p, size_t n)
20{
Damien Miller3d673d12014-08-27 06:32:01 +100021 (void)memset_s(p, n, 0, n);
Damien Miller1d2c4562014-02-04 11:18:20 +110022}
Damien Miller3d673d12014-08-27 06:32:01 +100023
24#else /* HAVE_MEMSET_S */
25
26/*
27 * Indirect bzero through a volatile pointer to hopefully avoid
28 * dead-store optimisation eliminating the call.
29 */
30static void (* volatile ssh_bzero)(void *, size_t) = bzero;
31
32void
33explicit_bzero(void *p, size_t n)
34{
35 ssh_bzero(p, n);
36}
37
38#endif /* HAVE_MEMSET_S */
39
40#endif /* HAVE_EXPLICIT_BZERO */