diff options
author | thegeorg <thegeorg@yandex-team.com> | 2022-11-07 19:34:08 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2022-11-07 19:34:08 +0300 |
commit | 50f76e264c70a223a34b24aa59e97bff97128f4c (patch) | |
tree | e604247a10f09df6158c172577b9bfa431f1e1b5 /contrib/libs/libfuzzer/FuzzerExtraCounters.cpp | |
parent | 278a58c5af63dbd7f7a6d8b8d92dc246651242da (diff) | |
download | ydb-50f76e264c70a223a34b24aa59e97bff97128f4c.tar.gz |
Switch fuzz tests to contrib/libs/libfuzzer
Diffstat (limited to 'contrib/libs/libfuzzer/FuzzerExtraCounters.cpp')
-rw-r--r-- | contrib/libs/libfuzzer/FuzzerExtraCounters.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/libs/libfuzzer/FuzzerExtraCounters.cpp b/contrib/libs/libfuzzer/FuzzerExtraCounters.cpp new file mode 100644 index 00000000000..54ecbf7c62f --- /dev/null +++ b/contrib/libs/libfuzzer/FuzzerExtraCounters.cpp @@ -0,0 +1,34 @@ +//===- FuzzerExtraCounters.cpp - Extra coverage counters ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// Extra coverage counters defined by user code. +//===----------------------------------------------------------------------===// + +#include "FuzzerPlatform.h" +#include <cstdint> + +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ + LIBFUZZER_FUCHSIA || LIBFUZZER_EMSCRIPTEN +__attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters; +__attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters; + +namespace fuzzer { +uint8_t *ExtraCountersBegin() { return &__start___libfuzzer_extra_counters; } +uint8_t *ExtraCountersEnd() { return &__stop___libfuzzer_extra_counters; } +ATTRIBUTE_NO_SANITIZE_ALL +void ClearExtraCounters() { // hand-written memset, don't asan-ify. + uintptr_t *Beg = reinterpret_cast<uintptr_t*>(ExtraCountersBegin()); + uintptr_t *End = reinterpret_cast<uintptr_t*>(ExtraCountersEnd()); + for (; Beg < End; Beg++) { + *Beg = 0; + __asm__ __volatile__("" : : : "memory"); + } +} + +} // namespace fuzzer + +#endif |