/src/mozilla-central/tools/fuzzing/libfuzzer/FuzzerExtraCounters.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- FuzzerExtraCounters.cpp - Extra coverage counters ------------------===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // Extra coverage counters defined by user code. |
10 | | //===----------------------------------------------------------------------===// |
11 | | |
12 | | #include "FuzzerDefs.h" |
13 | | |
14 | | #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ |
15 | | LIBFUZZER_OPENBSD |
16 | | __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters; |
17 | | __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters; |
18 | | |
19 | | namespace fuzzer { |
20 | 48.6k | uint8_t *ExtraCountersBegin() { return &__start___libfuzzer_extra_counters; } |
21 | 48.6k | uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters; } |
22 | | ATTRIBUTE_NO_SANITIZE_ALL |
23 | 16.2k | void ClearExtraCounters() { // hand-written memset, don't asan-ify. |
24 | 16.2k | uintptr_t *Beg = reinterpret_cast<uintptr_t*>(ExtraCountersBegin()); |
25 | 16.2k | uintptr_t *End = reinterpret_cast<uintptr_t*>(ExtraCountersEnd()); |
26 | 16.2k | for (; Beg < End; Beg++) { |
27 | 0 | *Beg = 0; |
28 | 0 | __asm__ __volatile__("" : : : "memory"); |
29 | 0 | } |
30 | 16.2k | } |
31 | | |
32 | | } // namespace fuzzer |
33 | | |
34 | | #else |
35 | | // TODO: implement for other platforms. |
36 | | namespace fuzzer { |
37 | | uint8_t *ExtraCountersBegin() { return nullptr; } |
38 | | uint8_t *ExtraCountersEnd() { return nullptr; } |
39 | | void ClearExtraCounters() {} |
40 | | } // namespace fuzzer |
41 | | |
42 | | #endif |