xref: /aosp_15_r20/external/compiler-rt/include/sanitizer/coverage_interface.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- sanitizer/coverage_interface.h --------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // Public interface for sanitizer coverage.
11*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
12*7c3d14c8STreehugger Robot 
13*7c3d14c8STreehugger Robot #ifndef SANITIZER_COVERAG_INTERFACE_H
14*7c3d14c8STreehugger Robot #define SANITIZER_COVERAG_INTERFACE_H
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot #include <sanitizer/common_interface_defs.h>
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot #ifdef __cplusplus
19*7c3d14c8STreehugger Robot extern "C" {
20*7c3d14c8STreehugger Robot #endif
21*7c3d14c8STreehugger Robot 
22*7c3d14c8STreehugger Robot   // Initialize coverage.
23*7c3d14c8STreehugger Robot   void __sanitizer_cov_init();
24*7c3d14c8STreehugger Robot   // Record and dump coverage info.
25*7c3d14c8STreehugger Robot   void __sanitizer_cov_dump();
26*7c3d14c8STreehugger Robot   // Open <name>.sancov.packed in the coverage directory and return the file
27*7c3d14c8STreehugger Robot   // descriptor. Returns -1 on failure, or if coverage dumping is disabled.
28*7c3d14c8STreehugger Robot   // This is intended for use by sandboxing code.
29*7c3d14c8STreehugger Robot   intptr_t __sanitizer_maybe_open_cov_file(const char *name);
30*7c3d14c8STreehugger Robot   // Get the number of unique covered blocks (or edges).
31*7c3d14c8STreehugger Robot   // This can be useful for coverage-directed in-process fuzzers.
32*7c3d14c8STreehugger Robot   uintptr_t __sanitizer_get_total_unique_coverage();
33*7c3d14c8STreehugger Robot   // Get the number of unique indirect caller-callee pairs.
34*7c3d14c8STreehugger Robot   uintptr_t __sanitizer_get_total_unique_caller_callee_pairs();
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot   // Reset the basic-block (edge) coverage to the initial state.
37*7c3d14c8STreehugger Robot   // Useful for in-process fuzzing to start collecting coverage from scratch.
38*7c3d14c8STreehugger Robot   // Experimental, will likely not work for multi-threaded process.
39*7c3d14c8STreehugger Robot   void __sanitizer_reset_coverage();
40*7c3d14c8STreehugger Robot   // Set *data to the array of covered PCs and return the size of that array.
41*7c3d14c8STreehugger Robot   // Some of the entries in *data will be zero.
42*7c3d14c8STreehugger Robot   uintptr_t __sanitizer_get_coverage_guards(uintptr_t **data);
43*7c3d14c8STreehugger Robot 
44*7c3d14c8STreehugger Robot   // Set *data to the growing buffer with covered PCs and return the size
45*7c3d14c8STreehugger Robot   // of the buffer. The entries are never zero.
46*7c3d14c8STreehugger Robot   // When only unique pcs are collected, the size is equal to
47*7c3d14c8STreehugger Robot   // __sanitizer_get_total_unique_coverage.
48*7c3d14c8STreehugger Robot   // WARNING: EXPERIMENTAL API.
49*7c3d14c8STreehugger Robot   uintptr_t __sanitizer_get_coverage_pc_buffer(uintptr_t **data);
50*7c3d14c8STreehugger Robot 
51*7c3d14c8STreehugger Robot   // The coverage instrumentation may optionally provide imprecise counters.
52*7c3d14c8STreehugger Robot   // Rather than exposing the counter values to the user we instead map
53*7c3d14c8STreehugger Robot   // the counters to a bitset.
54*7c3d14c8STreehugger Robot   // Every counter is associated with 8 bits in the bitset.
55*7c3d14c8STreehugger Robot   // We define 8 value ranges: 1, 2, 3, 4-7, 8-15, 16-31, 32-127, 128+
56*7c3d14c8STreehugger Robot   // The i-th bit is set to 1 if the counter value is in the i-th range.
57*7c3d14c8STreehugger Robot   // This counter-based coverage implementation is *not* thread-safe.
58*7c3d14c8STreehugger Robot 
59*7c3d14c8STreehugger Robot   // Returns the number of registered coverage counters.
60*7c3d14c8STreehugger Robot   uintptr_t __sanitizer_get_number_of_counters();
61*7c3d14c8STreehugger Robot   // Updates the counter 'bitset', clears the counters and returns the number of
62*7c3d14c8STreehugger Robot   // new bits in 'bitset'.
63*7c3d14c8STreehugger Robot   // If 'bitset' is nullptr, only clears the counters.
64*7c3d14c8STreehugger Robot   // Otherwise 'bitset' should be at least
65*7c3d14c8STreehugger Robot   // __sanitizer_get_number_of_counters bytes long and 8-aligned.
66*7c3d14c8STreehugger Robot   uintptr_t
67*7c3d14c8STreehugger Robot   __sanitizer_update_counter_bitset_and_clear_counters(uint8_t *bitset);
68*7c3d14c8STreehugger Robot #ifdef __cplusplus
69*7c3d14c8STreehugger Robot }  // extern "C"
70*7c3d14c8STreehugger Robot #endif
71*7c3d14c8STreehugger Robot 
72*7c3d14c8STreehugger Robot #endif  // SANITIZER_COVERAG_INTERFACE_H
73