Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,6 @@ RUNNER_LINKOPTS = [
RUNNER_DEPS = [
":byte_array_mutator",
":callstack",
":dispatcher_flag_helper",
":execution_metadata",
":feature",
":foreach_nonzero",
Expand Down Expand Up @@ -1208,15 +1207,6 @@ cc_library(
],
)

cc_library(
name = "dispatcher_flag_helper",
hdrs = ["dispatcher_flag_helper.h"],
copts = DISABLE_SANCOV_COPTS,
deps = [
"@abseil-cpp//absl/base:nullability",
],
)

cc_library(
name = "sancov_runtime",
srcs = [
Expand All @@ -1238,7 +1228,6 @@ cc_library(
copts = DISABLE_SANCOV_COPTS,
deps = [
":callstack",
":dispatcher_flag_helper",
":engine_abi",
":execution_metadata",
":feature",
Expand Down
76 changes: 0 additions & 76 deletions centipede/dispatcher_flag_helper.h

This file was deleted.

12 changes: 6 additions & 6 deletions centipede/engine_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,12 @@ void HandlePersistentMode(const FuzzTestAdapter& adapter) {
// to happen when the stdout/stderr are not redirected to a file.
(void)ftruncate(fd, 0);
}
WorkerLog("FuzzTest engine worker (",
req == PersistentModeRequest::kExit ? "exiting persistent mode"
: "persistent mode batch",
"); flags: ",
GetWorkerFlagsEnv() != nullptr ? GetWorkerFlagsEnv() : "",
LogLnSync{});
WorkerLog(
"FuzzTest engine worker (",
req == PersistentModeRequest::kExit ? "exiting persistent mode"
: "persistent mode batch",
"); flags: ", GetWorkerFlagsEnv() ? GetWorkerFlagsEnv() : "(unset)",
LogLnSync{});
}
if (req == PersistentModeRequest::kExit) break;
WorkerCheck(req == PersistentModeRequest::kRunBatch,
Expand Down
35 changes: 20 additions & 15 deletions centipede/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "absl/base/optimization.h"
#include "absl/types/span.h"
#include "./centipede/byte_array_mutator.h"
#include "./centipede/dispatcher_flag_helper.h"
#include "./centipede/execution_metadata.h"
#include "./centipede/feature.h"
#include "./centipede/mutation_data.h"
Expand Down Expand Up @@ -810,7 +809,7 @@ static void SetLimits() {
// No-op under ASAN/TSAN/MSAN - those may still rely on rss_limit_mb.
if (vm_size_in_bytes < one_tb) {
size_t address_space_limit_mb =
state->flag_helper.HasIntFlag(":address_space_limit_mb=", 0);
state->flag_helper.GetIntFlag("address_space_limit_mb=", 0);
if (address_space_limit_mb > 0) {
size_t limit_in_bytes = address_space_limit_mb << 20;
struct rlimit rlimit_as = {limit_in_bytes, limit_in_bytes};
Expand Down Expand Up @@ -902,7 +901,7 @@ void GlobalRunnerState::OnTermination() {
// This means, the binary is standalone with its own main(), and we need to
// report the coverage now.
if (!state->centipede_runner_main_executed &&
flag_helper.HasFlag(":shmem:")) {
flag_helper.HasSwitchFlag("shmem")) {
PostProcessSancov(); // TODO(xinhaoyuan): do we know our exit status?
SharedMemoryBlobSequence outputs_blobseq(sancov_state->arg2);
StartSendingOutputsToEngine(outputs_blobseq);
Expand Down Expand Up @@ -966,10 +965,11 @@ static int HandlePersistentMode(RunnerCallbacks& callbacks,
// to happen when the stdout/stderr are not redirected to a file.
(void)ftruncate(fd, 0);
}
fprintf(stderr, "Centipede fuzz target runner (%s); flags: %s\n",
req == PersistentModeRequest::kExit ? "exiting persistent mode"
: "persistent mode batch",
state->flag_helper.flags);
fprintf(
stderr, "Centipede fuzz target runner (%s); flags: %s\n",
req == PersistentModeRequest::kExit ? "exiting persistent mode"
: "persistent mode batch",
CentipedeGetRunnerFlags() ? CentipedeGetRunnerFlags() : "(unset)");
}
if (req == PersistentModeRequest::kExit) break;
RunnerCheck(req == PersistentModeRequest::kRunBatch,
Expand All @@ -987,7 +987,7 @@ static int HandlePersistentMode(RunnerCallbacks& callbacks,
return EXIT_SUCCESS;
}

// If HasFlag(:shmem:), state->arg1 and state->arg2 are the names
// If HasSwitchFlag(:shmem:), state->arg1 and state->arg2 are the names
// of in/out shared memory locations.
// Read inputs and write outputs via shared memory.
//
Expand All @@ -998,22 +998,23 @@ int RunnerMain(int argc, char** argv, RunnerCallbacks& callbacks) {
state->centipede_runner_main_executed = true;

fprintf(stderr, "Centipede fuzz target runner; argv[0]: %s flags: %s\n",
argv[0], state->flag_helper.flags);
argv[0],
CentipedeGetRunnerFlags() ? CentipedeGetRunnerFlags() : "(unset)");

if (state->flag_helper.HasFlag(":dump_configuration:")) {
if (state->flag_helper.HasSwitchFlag("dump_configuration")) {
DumpSerializedTargetConfigToFile(callbacks,
/*output_file_path=*/sancov_state->arg1);
return EXIT_SUCCESS;
}

if (state->flag_helper.HasFlag(":dump_seed_inputs:")) {
if (state->flag_helper.HasSwitchFlag("dump_seed_inputs")) {
// Seed request.
DumpSeedsToDir(callbacks, /*output_dir=*/sancov_state->arg1);
return EXIT_SUCCESS;
}

// Inputs / outputs from shmem.
if (state->flag_helper.HasFlag(":shmem:")) {
if (state->flag_helper.HasSwitchFlag("shmem")) {
if (!sancov_state->arg1 || !sancov_state->arg2) return EXIT_FAILURE;
SharedMemoryBlobSequence inputs_blobseq(sancov_state->arg1);
SharedMemoryBlobSequence outputs_blobseq(sancov_state->arg2);
Expand Down Expand Up @@ -1067,9 +1068,13 @@ extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input) {

extern "C" __attribute__((weak)) const char* absl_nullable
CentipedeGetRunnerFlags() {
if (const char* runner_flags_env = getenv("CENTIPEDE_RUNNER_FLAGS"))
return strdup(runner_flags_env);
return nullptr;
static const char* flags = []() -> const char* {
if (const char* runner_flags_env = getenv("CENTIPEDE_RUNNER_FLAGS")) {
return strdup(runner_flags_env);
}
return nullptr;
}();
return flags;
}

// TODO: xinhaoyuan - write test for this.
Expand Down
22 changes: 10 additions & 12 deletions centipede/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <cstdint>

#include "./centipede/byte_array_mutator.h"
#include "./centipede/dispatcher_flag_helper.h"
#include "./centipede/knobs.h"
#include "./centipede/runner_interface.h"
#include "./centipede/runner_result.h"
Expand Down Expand Up @@ -59,29 +58,28 @@ struct GlobalRunnerState {
// Performs necessary cleanup on process termination.
void OnTermination();

DispatcherFlagHelper flag_helper =
DispatcherFlagHelper(CentipedeGetRunnerFlags());
EngineFlagHelper flag_helper = EngineFlagHelper(CentipedeGetRunnerFlags());

// Note that this field reflects the initial runner flags. But some
// flags can change later (if wrapped with std::atomic).
RunTimeFlags run_time_flags = {
/*timeout_per_input=*/flag_helper.HasIntFlag(":timeout_per_input=", 0),
/*rss_limit_mb=*/flag_helper.HasIntFlag(":rss_limit_mb=", 0),
/*crossover_level=*/flag_helper.HasIntFlag(":crossover_level=", 50),
/*timeout_per_input=*/flag_helper.GetIntFlag("timeout_per_input=", 0),
/*rss_limit_mb=*/flag_helper.GetIntFlag("rss_limit_mb=", 0),
/*crossover_level=*/flag_helper.GetIntFlag("crossover_level=", 50),
/*ignore_timeout_reports=*/
flag_helper.HasFlag(":ignore_timeout_reports:"),
/*max_len=*/flag_helper.HasIntFlag(":max_len=", 4000),
/*stack_limit_kb=*/flag_helper.HasIntFlag(":stack_limit_kb=", 0),
flag_helper.HasSwitchFlag("ignore_timeout_reports"),
/*max_len=*/flag_helper.GetIntFlag("max_len=", 4000),
/*stack_limit_kb=*/flag_helper.GetIntFlag("stack_limit_kb=", 0),
};

// The path to a file where the runner may write the description of failure.
const char *failure_description_path =
flag_helper.GetStringFlag(":failure_description_path=");
const char* failure_description_path =
flag_helper.GetStringFlag("failure_description_path=");

std::atomic<bool> has_failure_description;

const char* persistent_mode_socket_path =
flag_helper.GetStringFlag(":persistent_mode_socket=");
flag_helper.GetStringFlag("persistent_mode_socket=");
int persistent_mode_socket = 0;

pthread_mutex_t execution_result_override_mu = PTHREAD_MUTEX_INITIALIZER;
Expand Down
3 changes: 2 additions & 1 deletion centipede/runner_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input);
// gets the flags from CENTIPEDE_RUNNER_FLAGS env var.
//
// It should return either a nullptr or a constant string that is valid
// throughout the entire process life-time.
// throughout the entire process life-time. Multiple calls should always return
// the same value.
extern "C" const char* absl_nullable CentipedeGetRunnerFlags();

// An overridable function to override `LLVMFuzzerMutate` behavior.
Expand Down
3 changes: 1 addition & 2 deletions centipede/sancov_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "absl/base/nullability.h"
#include "absl/base/optimization.h"
#include "./centipede/dispatcher_flag_helper.h"
#include "./centipede/feature.h"
#include "./centipede/int_utils.h"
#include "./centipede/pc_info.h"
Expand Down Expand Up @@ -356,7 +355,7 @@ static void UpdatePcCounterSetSizeAligned(size_t size) {
static pthread_once_t main_object_lazy_init_once = PTHREAD_ONCE_INIT;
static void MainObjectLazyInitOnceCallback() {
sancov_state->main_object = fuzztest::internal::GetDlInfo(
sancov_state->flag_helper.GetStringFlag(":dl_path_suffix="));
sancov_state->flag_helper.GetStringFlag("dl_path_suffix="));
fprintf(stderr, "MainObjectLazyInitOnceCallback %zx\n",
sancov_state->main_object.start_address);
UpdatePcCounterSetSizeAligned(sancov_state->reverse_pc_table.NumPcs());
Expand Down
21 changes: 12 additions & 9 deletions centipede/sancov_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <vector>

#include "absl/base/nullability.h"
#include "./centipede/dispatcher_flag_helper.h"
#include "./centipede/engine_abi.h"
#include "./centipede/execution_metadata.h"
#include "./centipede/feature.h"
Expand Down Expand Up @@ -197,7 +196,7 @@ void SancovState::CleanUpDetachedTls() {

static void MaybePopulateReversePcTable() {
const char* pcs_file_path =
sancov_state->flag_helper.GetStringFlag(":pcs_file_path=");
sancov_state->flag_helper.GetStringFlag("pcs_file_path=");
if (!pcs_file_path) return;
const auto pc_table = ReadBytesFromFilePath<PCInfo>(pcs_file_path);
sancov_state->reverse_pc_table.SetFromPCs(pc_table);
Expand Down Expand Up @@ -253,16 +252,16 @@ static void DumpDsoTable(const char *absl_nonnull output_path) {
SancovState::SancovState() {
tls.OnThreadStart();
// Compute main_object.
main_object = GetDlInfo(flag_helper.GetStringFlag(":dl_path_suffix="));
if (!sancov_state->main_object.IsSet()) {
main_object = GetDlInfo(flag_helper.GetStringFlag("dl_path_suffix="));
if (!main_object.IsSet()) {
fprintf(
stderr,
"Failed to compute main_object. This may happen"
" e.g. when instrumented code is in a DSO opened later by dlopen()\n");
}

// Dump the binary info tables.
if (flag_helper.HasFlag(":dump_binary_info:")) {
if (flag_helper.HasSwitchFlag("dump_binary_info")) {
RunnerCheck(arg1 && arg2 && arg3, "dump_binary_info requires 3 arguments");
if (!arg1 || !arg2 || !arg3) _exit(EXIT_FAILURE);
DumpPcTable(arg1);
Expand Down Expand Up @@ -561,10 +560,14 @@ const ExecutionMetadata& SanCovRuntimeGetExecutionMetadata() {
} // namespace fuzztest::internal

// Can be overridden to not depend explicitly on CENTIPEDE_RUNNER_FLAGS.
extern "C" __attribute__((weak)) const char *absl_nullable GetSancovFlags() {
if (const char *sancov_flags_env = getenv("CENTIPEDE_RUNNER_FLAGS"))
return strdup(sancov_flags_env);
return nullptr;
extern "C" __attribute__((weak)) const char* absl_nullable GetSancovFlags() {
static const char* flags = []() -> const char* {
if (const char* sancov_flags_env = getenv("CENTIPEDE_RUNNER_FLAGS")) {
return strdup(sancov_flags_env);
}
return nullptr;
}();
return flags;
}

void SanCovRuntimeClearCoverage(bool full_clear) {
Expand Down
Loading
Loading