| // Copyright 2025 The Centipede Authors. | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| #ifndef FUZZTEST_FRAMEWORK_SHARED_SANCOV_RUNTIME_H_ | |
| #define FUZZTEST_FRAMEWORK_SHARED_SANCOV_RUNTIME_H_ | |
| // Sancov runtime interface. | |
| // | |
| // This header needs to be C compatible. | |
| #include <stdbool.h> // NOLINT | |
| #include <stddef.h> | |
| #include <stdint.h> | |
| #include "./centipede/engine_abi.h" | |
| #ifdef __cplusplus | |
| extern "C" { | |
| #endif | |
| struct SanCovRuntimeRawFeatureParts { | |
| const uint64_t* features; | |
| size_t num_features; | |
| }; | |
| // Clears coverage data accumulated so far from sancov callbacks and/or | |
| // interceptors. | |
| // | |
| // Will always clear the thread-local data updated during execution, and if | |
| // `full_clear==true` will clear all accumulated coverage data. | |
| void SanCovRuntimeClearCoverage(bool full_clear); | |
| // Post-processes all coverage data, putting it all into an array of features, | |
| // and returning a ptr and the length of this array. | |
| // | |
| // Will return a valid `features` pointer to a 64-bit element array of length | |
| // `num_features`: This feature array is initialized at process startup, and | |
| // its data (belonging to a global state) will remain valid for the duration of | |
| // the process. | |
| // | |
| // If `reject_input==true`, then it will simply empty the feature array. | |
| // | |
| // DEPRECATED: the features here is in the raw Centipede layout instead of | |
| // the standard engine layout. Use `SanCovRuntimePostProcessCoverage` + | |
| // `SanCovRuntimeEmitFeatures` to work with the engine. | |
| struct SanCovRuntimeRawFeatureParts SanCovRuntimeGetCoverage(bool reject_input); | |
| // Registers the SanCov coverage domains. Returns next available domain ID. | |
| size_t SanCovRuntimeSetUpCoverageDomains( | |
| const FuzzTestCoverageDomainRegistry* registry); | |
| // Post-processes all coverage data, and saves it internally for later emission | |
| // and retrival. | |
| // | |
| // If `reject_input==true`, no coverage would be saved. | |
| void SanCovRuntimePostProcessCoverage(bool reject_input); | |
| // Emits post-processed SanCov coverage features into the engine `sink`. | |
| // | |
| // Should be called at most once after `SanCovPostProcessCoverage` - later calls | |
| // will emit empty coverage. | |
| void SanCovRuntimeEmitFeatures(const FuzzTestFeedbackSink* sink); | |
| #ifdef __cplusplus | |
| } // extern "C" | |
| #endif | |
| #endif // FUZZTEST_FRAMEWORK_SHARED_SANCOV_RUNTIME_H_ |