xref: /freebsd-src/contrib/llvm-project/compiler-rt/include/sanitizer/nsan_interface.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1*0fca6ea1SDimitry Andric //===-- sanitizer/nsan_interface.h ------------------------------*- C++ -*-===//
2*0fca6ea1SDimitry Andric //
3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0fca6ea1SDimitry Andric //
7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
8*0fca6ea1SDimitry Andric //
9*0fca6ea1SDimitry Andric // Public interface for nsan.
10*0fca6ea1SDimitry Andric //
11*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
12*0fca6ea1SDimitry Andric #ifndef SANITIZER_NSAN_INTERFACE_H
13*0fca6ea1SDimitry Andric #define SANITIZER_NSAN_INTERFACE_H
14*0fca6ea1SDimitry Andric 
15*0fca6ea1SDimitry Andric #include <sanitizer/common_interface_defs.h>
16*0fca6ea1SDimitry Andric 
17*0fca6ea1SDimitry Andric #ifdef __cplusplus
18*0fca6ea1SDimitry Andric extern "C" {
19*0fca6ea1SDimitry Andric #endif
20*0fca6ea1SDimitry Andric 
21*0fca6ea1SDimitry Andric /// User-provided default option settings.
22*0fca6ea1SDimitry Andric ///
23*0fca6ea1SDimitry Andric /// You can provide your own implementation of this function to return a string
24*0fca6ea1SDimitry Andric /// containing NSan runtime options (for example,
25*0fca6ea1SDimitry Andric /// <c>verbosity=1:halt_on_error=0</c>).
26*0fca6ea1SDimitry Andric ///
27*0fca6ea1SDimitry Andric /// \returns Default options string.
28*0fca6ea1SDimitry Andric const char *__nsan_default_options(void);
29*0fca6ea1SDimitry Andric 
30*0fca6ea1SDimitry Andric // Dumps nsan shadow data for a block of `size_bytes` bytes of application
31*0fca6ea1SDimitry Andric // memory at location `addr`.
32*0fca6ea1SDimitry Andric //
33*0fca6ea1SDimitry Andric // Each line contains application address, shadow types, then values.
34*0fca6ea1SDimitry Andric // Unknown types are shown as `__`, while known values are shown as
35*0fca6ea1SDimitry Andric // `f`, `d`, `l` for float, double, and long double respectively. Position is
36*0fca6ea1SDimitry Andric // shown as a single hex digit. The shadow value itself appears on the line that
37*0fca6ea1SDimitry Andric // contains the first byte of the value.
38*0fca6ea1SDimitry Andric // FIXME: Show both shadow and application value.
39*0fca6ea1SDimitry Andric //
40*0fca6ea1SDimitry Andric // Example: `__nsan_dump_shadow_mem(addr, 32, 8, 0)` might print:
41*0fca6ea1SDimitry Andric //
42*0fca6ea1SDimitry Andric //  0x0add7359:  __ f0 f1 f2 f3 __ __ __   (42.000)
43*0fca6ea1SDimitry Andric //  0x0add7361:  __ d1 d2 d3 d4 d5 d6 d7
44*0fca6ea1SDimitry Andric //  0x0add7369:  d8 f0 f1 f2 f3 __ __ f2   (-1.000) (12.5)
45*0fca6ea1SDimitry Andric //  0x0add7371:  f3 __ __ __ __ __ __ __
46*0fca6ea1SDimitry Andric //
47*0fca6ea1SDimitry Andric // This means that there is:
48*0fca6ea1SDimitry Andric //   - a shadow double for the float at address 0x0add7360, with value 42;
49*0fca6ea1SDimitry Andric //   - a shadow float128 for the double at address 0x0add7362, with value -1;
50*0fca6ea1SDimitry Andric //   - a shadow double for the float at address 0x0add736a, with value 12.5;
51*0fca6ea1SDimitry Andric // There was also a shadow double for the float at address 0x0add736e, but bytes
52*0fca6ea1SDimitry Andric // f0 and f1 were overwritten by one or several stores, so that the shadow value
53*0fca6ea1SDimitry Andric // is no longer valid.
54*0fca6ea1SDimitry Andric // The argument `reserved` can be any value. Its true value is provided by the
55*0fca6ea1SDimitry Andric // instrumentation.
56*0fca6ea1SDimitry Andric void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes,
57*0fca6ea1SDimitry Andric                             size_t bytes_per_line, size_t reserved);
58*0fca6ea1SDimitry Andric 
59*0fca6ea1SDimitry Andric // Explicitly dumps a value.
60*0fca6ea1SDimitry Andric // FIXME: vector versions ?
61*0fca6ea1SDimitry Andric void __nsan_dump_float(float value);
62*0fca6ea1SDimitry Andric void __nsan_dump_double(double value);
63*0fca6ea1SDimitry Andric void __nsan_dump_longdouble(long double value);
64*0fca6ea1SDimitry Andric 
65*0fca6ea1SDimitry Andric // Explicitly checks a value.
66*0fca6ea1SDimitry Andric // FIXME: vector versions ?
67*0fca6ea1SDimitry Andric void __nsan_check_float(float value);
68*0fca6ea1SDimitry Andric void __nsan_check_double(double value);
69*0fca6ea1SDimitry Andric void __nsan_check_longdouble(long double value);
70*0fca6ea1SDimitry Andric 
71*0fca6ea1SDimitry Andric #ifdef __cplusplus
72*0fca6ea1SDimitry Andric } // extern "C"
73*0fca6ea1SDimitry Andric #endif
74*0fca6ea1SDimitry Andric 
75*0fca6ea1SDimitry Andric #endif // SANITIZER_NSAN_INTERFACE_H
76