PostgreSQL Source Code  git master
explicit_bzero.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * explicit_bzero.c
4  *
5  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  * src/port/explicit_bzero.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "c.h"
16 
17 #if defined(HAVE_MEMSET_S)
18 
19 void
20 explicit_bzero(void *buf, size_t len)
21 {
22  (void) memset_s(buf, len, 0, len);
23 }
24 
25 #elif defined(WIN32)
26 
27 void
28 explicit_bzero(void *buf, size_t len)
29 {
30  (void) SecureZeroMemory(buf, len);
31 }
32 
33 #else
34 
35 /*
36  * Indirect call through a volatile pointer to hopefully avoid dead-store
37  * optimisation eliminating the call. (Idea taken from OpenSSH.) We can't
38  * assume bzero() is present either, so for simplicity we define our own.
39  */
40 
41 static void
42 bzero2(void *buf, size_t len)
43 {
44  memset(buf, 0, len);
45 }
46 
47 static void (* volatile bzero_p)(void *, size_t) = bzero2;
48 
49 void
50 explicit_bzero(void *buf, size_t len)
51 {
52  bzero_p(buf, len);
53 }
54 
55 #endif
void explicit_bzero(void *buf, size_t len)
static void bzero2(void *buf, size_t len)
static char * buf
Definition: pg_test_fsync.c:68
static void(*volatile bzero_p)(void *, size_t)