Debian Codegraph @

lib/util-xbzero.c

raw symbols SCIP
1 /* Copyright (C) 2018-2019 Björn Esser <[email protected]>
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted.
5 *
6 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
10 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16 * SUCH DAMAGE.
17 */
18
19 #include "crypt-port.h"
20
21 #if INCLUDE_explicit_bzero
22 /* As long as this function is defined in a translation unit all by
23 itself, and we aren't doing LTO, it would be enough for it to just
24 call memset. While compiling _this_ translation unit, the compiler
25 has no information about what the callers do with the buffer, so it
26 cannot eliminate the memset. While compiling code that _calls_
27 this function, the compiler doesn't know what it does, so it cannot
28 eliminate the call (if it has special knowledge of a function with
29 this name, we would hope that it knows _not_ to optimize it out!)
30
31 However, in anticipation of doing LTO on this library one day, we
32 add two more defensive measures, when we know how: the function is
33 marked no-inline, and there is a no-op assembly insert immediately
34 after the memset call, declared to read the memory that the memset
35 writes. */
36
37 NO_INLINE void
38 explicit_bzero (void *s, size_t len)
39 {
40 s = memset (s, 0, len);
41 asm volatile ("" : : "g" (s) : "memory");
42 }
43 #endif