blob: 3f38f4fb70c12219fbcc10e187c579afce080e88 [file] [log] [blame]
george.karpenkov29efa6d2017-08-21 23:25:50 +00001//===- FuzzerExtraCounters.cpp - Extra coverage counters ------------------===//
2//
chandlerc40284492019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
george.karpenkov29efa6d2017-08-21 23:25:50 +00006//
7//===----------------------------------------------------------------------===//
8// Extra coverage counters defined by user code.
9//===----------------------------------------------------------------------===//
10
11#include "FuzzerDefs.h"
12
vitalybuka5f3206d2018-04-09 22:38:26 +000013#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \
14 LIBFUZZER_OPENBSD
george.karpenkov29efa6d2017-08-21 23:25:50 +000015__attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters;
16__attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters;
17
18namespace fuzzer {
19uint8_t *ExtraCountersBegin() { return &__start___libfuzzer_extra_counters; }
20uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters; }
21ATTRIBUTE_NO_SANITIZE_ALL
22void 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.
35namespace fuzzer {
36uint8_t *ExtraCountersBegin() { return nullptr; }
37uint8_t *ExtraCountersEnd() { return nullptr; }
38void ClearExtraCounters() {}
39} // namespace fuzzer
40
41#endif