Path: blob/main/contrib/llvm-project/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp
35262 views
//===- FuzzerExtraCounters.cpp - Extra coverage counters ------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7// Extra coverage counters defined by user code.8//===----------------------------------------------------------------------===//910#include "FuzzerPlatform.h"11#include <cstdint>1213#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \14LIBFUZZER_FUCHSIA || LIBFUZZER_EMSCRIPTEN15__attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters;16__attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters;1718namespace fuzzer {19uint8_t *ExtraCountersBegin() { return &__start___libfuzzer_extra_counters; }20uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters; }21ATTRIBUTE_NO_SANITIZE_ALL22void ClearExtraCounters() { // hand-written memset, don't asan-ify.23uintptr_t *Beg = reinterpret_cast<uintptr_t*>(ExtraCountersBegin());24uintptr_t *End = reinterpret_cast<uintptr_t*>(ExtraCountersEnd());25for (; Beg < End; Beg++) {26*Beg = 0;27__asm__ __volatile__("" : : : "memory");28}29}3031} // namespace fuzzer3233#endif343536