7#ifndef PROTO_FUZZER_ALLOCATION_FAULT_INJECTION_H_
8#define PROTO_FUZZER_ALLOCATION_FAULT_INJECTION_H_
13namespace proto_fuzzer::allocation_fault_injection {
18inline thread_local std::size_t failure_suppression_depth = 0;
20inline thread_local std::uint64_t failure_suppression_generation = 0;
24inline std::uint64_t BeginFailureSuppression() noexcept {
25 ++failure_suppression_depth;
26 return failure_suppression_generation;
31inline void EndFailureSuppression(std::uint64_t generation)
noexcept {
32 if (generation == failure_suppression_generation && failure_suppression_depth != 0) {
33 --failure_suppression_depth;
38inline bool FailuresSuppressed() noexcept {
return failure_suppression_depth != 0; }
41inline void ResetFailureSuppression() noexcept {
42 failure_suppression_depth = 0;
43 ++failure_suppression_generation;
57class ScopedFailureSuppression final {
59 ScopedFailureSuppression() noexcept : generation_(internal::BeginFailureSuppression()) {}
60 ~ScopedFailureSuppression() { internal::EndFailureSuppression(generation_); }
62 ScopedFailureSuppression(
const ScopedFailureSuppression&) =
delete;
63 ScopedFailureSuppression& operator=(
const ScopedFailureSuppression&) =
delete;
64 ScopedFailureSuppression(ScopedFailureSuppression&&) =
delete;
65 ScopedFailureSuppression& operator=(ScopedFailureSuppression&&) =
delete;
69 std::uint64_t generation_;
84bool InitializeCurl() noexcept;
85bool ReinitializeCurl() noexcept;
86bool CurlInitializationSucceeded() noexcept;
87bool ClaimCurlInitializationReference() noexcept;
88void Configure(const std::uint32_t* ordinals, std::
size_t count) noexcept;
90void ArmNextAllocationFailure() noexcept;
91void Disarm() noexcept;
100void* Malloc(std::size_t size)
noexcept;
101void Free(
void* pointer)
noexcept;
102void* Realloc(
void* pointer, std::size_t size)
noexcept;
103char* Strdup(
const char*
string)
noexcept;
104void* Calloc(std::size_t count, std::size_t size)
noexcept;
Snapshot of the calling thread's current allocation-failure plan.
std::uint64_t allocation_attempts
Positive-size allocation calls observed since the last Arm().
std::uint64_t injected_failures
Selected calls rejected since the last Arm().
bool armed
Whether allocation calls on this thread are currently observed.
std::size_t configured_failures
Distinct ordinals retained in the bounded plan.