LLVM  5.0.0
FuzzerExtraCounters.cpp
Go to the documentation of this file.
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
15 __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters;
16 __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters;
17 
18 namespace fuzzer {
19 uint8_t *ExtraCountersBegin() { return &__start___libfuzzer_extra_counters; }
20 uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters; }
22 void ClearExtraCounters() { // hand-written memset, don't asan-ify.
23  uintptr_t *Beg = reinterpret_cast<uintptr_t*>(ExtraCountersBegin());
24  uintptr_t *End = reinterpret_cast<uintptr_t*>(ExtraCountersEnd());
25  for (; Beg < End; Beg++) {
26  *Beg = 0;
27  __asm__ __volatile__("" : : : "memory");
28  }
29 }
30 
31 } // namespace fuzzer
32 
33 #else
34 // TODO: implement for other platforms.
35 namespace fuzzer {
36 uint8_t *ExtraCountersBegin() { return nullptr; }
37 uint8_t *ExtraCountersEnd() { return nullptr; }
39 } // namespace fuzzer
40 
41 #endif
uint8_t * ExtraCountersBegin()
__attribute__((weak)) int LLVMFuzzerInitialize(int *argc
static const unsigned End
void ClearExtraCounters()
#define ATTRIBUTE_NO_SANITIZE_ALL
Definition: FuzzerDefs.h:79
uint8_t * ExtraCountersEnd()