Skip to content

Commit bf27483

Browse files
committed
executor: move proc opts to a separate struct
This will reduce code duplication and simplify adding new fields.
1 parent 3e79b82 commit bf27483

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

executor/executor_runner.h

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,34 @@ class ProcIDPool
8282
ProcIDPool& operator=(const ProcIDPool&) = delete;
8383
};
8484

85+
class ProcOpts
86+
{
87+
public:
88+
bool use_cover_edges = false;
89+
bool is_kernel_64_bit = false;
90+
uint32 slowdown = 0;
91+
uint32 syscall_timeout_ms = 0;
92+
uint32 program_timeout_ms = 0;
93+
94+
private:
95+
friend std::ostream& operator<<(std::ostream& ss, const ProcOpts& opts)
96+
{
97+
ss << "use_cover_edges=" << opts.use_cover_edges
98+
<< " is_kernel_64_bit=" << opts.is_kernel_64_bit
99+
<< " slowdown=" << opts.slowdown
100+
<< " syscall_timeout_ms=" << opts.syscall_timeout_ms
101+
<< " program_timeout_ms=" << opts.program_timeout_ms;
102+
return ss;
103+
}
104+
};
105+
85106
// Proc represents one subprocess that runs tests (re-execed syz-executor with 'exec' argument).
86107
// The object is persistent and re-starts subprocess when it crashes.
87108
class Proc
88109
{
89110
public:
90-
Proc(Connection& conn, const char* bin, ProcIDPool& proc_id_pool, int& restarting, const bool& corpus_triaged, int max_signal_fd, int cover_filter_fd,
91-
bool use_cover_edges, bool is_kernel_64_bit, uint32 slowdown, uint32 syscall_timeout_ms, uint32 program_timeout_ms)
111+
Proc(Connection& conn, const char* bin, ProcIDPool& proc_id_pool, int& restarting, const bool& corpus_triaged, int max_signal_fd,
112+
int cover_filter_fd, ProcOpts opts)
92113
: conn_(conn),
93114
bin_(bin),
94115
proc_id_pool_(proc_id_pool),
@@ -97,11 +118,7 @@ class Proc
97118
corpus_triaged_(corpus_triaged),
98119
max_signal_fd_(max_signal_fd),
99120
cover_filter_fd_(cover_filter_fd),
100-
use_cover_edges_(use_cover_edges),
101-
is_kernel_64_bit_(is_kernel_64_bit),
102-
slowdown_(slowdown),
103-
syscall_timeout_ms_(syscall_timeout_ms),
104-
program_timeout_ms_(program_timeout_ms),
121+
opts_(opts),
105122
req_shmem_(kMaxInput),
106123
resp_shmem_(kMaxOutput),
107124
resp_mem_(static_cast<OutputData*>(resp_shmem_.Mem()))
@@ -158,7 +175,7 @@ class Proc
158175
#endif
159176
// Sandbox setup can take significant time.
160177
if (state_ == State::Handshaking)
161-
timeout = 60 * 1000 * slowdown_;
178+
timeout = 60 * 1000 * opts_.slowdown;
162179
if (now > exec_start_ + timeout) {
163180
Restart();
164181
return;
@@ -200,11 +217,7 @@ class Proc
200217
const bool& corpus_triaged_;
201218
const int max_signal_fd_;
202219
const int cover_filter_fd_;
203-
const bool use_cover_edges_;
204-
const bool is_kernel_64_bit_;
205-
const uint32 slowdown_;
206-
const uint32 syscall_timeout_ms_;
207-
const uint32 program_timeout_ms_;
220+
const ProcOpts opts_;
208221
State state_ = State::Started;
209222
std::optional<Subprocess> process_;
210223
ShmemFile req_shmem_;
@@ -357,14 +370,14 @@ class Proc
357370
sandbox_arg_ = msg_->exec_opts->sandbox_arg();
358371
handshake_req req = {
359372
.magic = kInMagic,
360-
.use_cover_edges = use_cover_edges_,
361-
.is_kernel_64_bit = is_kernel_64_bit_,
373+
.use_cover_edges = opts_.use_cover_edges,
374+
.is_kernel_64_bit = opts_.is_kernel_64_bit,
362375
.flags = exec_env_,
363376
.pid = static_cast<uint64>(id_),
364377
.sandbox_arg = static_cast<uint64>(sandbox_arg_),
365-
.syscall_timeout_ms = syscall_timeout_ms_,
378+
.syscall_timeout_ms = opts_.syscall_timeout_ms,
366379
.program_timeout_ms = ProgramTimeoutMs(),
367-
.slowdown_scale = slowdown_,
380+
.slowdown_scale = opts_.slowdown,
368381
};
369382
if (write(req_pipe_, &req, sizeof(req)) != sizeof(req)) {
370383
debug("request pipe write failed (errno=%d)\n", errno);
@@ -526,7 +539,7 @@ class Proc
526539
uint32 ProgramTimeoutMs() const
527540
{
528541
// Glob requests can expand to >10K files and can take a while to run.
529-
return program_timeout_ms_ * (req_type_ == rpc::RequestType::Program ? 1 : 10);
542+
return opts_.program_timeout_ms * (req_type_ == rpc::RequestType::Program ? 1 : 10);
530543
}
531544
};
532545

@@ -545,8 +558,7 @@ class Runner
545558
int cover_filter_fd = cover_filter_ ? cover_filter_->FD() : -1;
546559
for (int i = 0; i < num_procs; i++)
547560
procs_.emplace_back(new Proc(conn, bin, *proc_id_pool_, restarting_, corpus_triaged_,
548-
max_signal_fd, cover_filter_fd, use_cover_edges_, is_kernel_64_bit_, slowdown_,
549-
syscall_timeout_ms_, program_timeout_ms_));
561+
max_signal_fd, cover_filter_fd, proc_opts_));
550562

551563
for (;;)
552564
Loop();
@@ -563,11 +575,7 @@ class Runner
563575
std::vector<std::string> leak_frames_;
564576
int restarting_ = 0;
565577
bool corpus_triaged_ = false;
566-
bool use_cover_edges_ = false;
567-
bool is_kernel_64_bit_ = false;
568-
uint32 slowdown_ = 0;
569-
uint32 syscall_timeout_ms_ = 0;
570-
uint32 program_timeout_ms_ = 0;
578+
ProcOpts proc_opts_{};
571579

572580
friend std::ostream& operator<<(std::ostream& ss, const Runner& runner)
573581
{
@@ -576,11 +584,7 @@ class Runner
576584
<< " cover_filter=" << !!runner.cover_filter_
577585
<< " restarting=" << runner.restarting_
578586
<< " corpus_triaged=" << runner.corpus_triaged_
579-
<< " use_cover_edges=" << runner.use_cover_edges_
580-
<< " is_kernel_64_bit=" << runner.is_kernel_64_bit_
581-
<< " slowdown=" << runner.slowdown_
582-
<< " syscall_timeout_ms=" << runner.syscall_timeout_ms_
583-
<< " program_timeout_ms=" << runner.program_timeout_ms_
587+
<< " " << runner.proc_opts_
584588
<< "\n";
585589
ss << "procs:\n";
586590
for (const auto& proc : runner.procs_)
@@ -663,11 +667,12 @@ class Runner
663667
conn_reply.slowdown, conn_reply.syscall_timeout_ms,
664668
conn_reply.program_timeout_ms, static_cast<uint64>(conn_reply.features));
665669
leak_frames_ = conn_reply.leak_frames;
666-
use_cover_edges_ = conn_reply.cover_edges;
667-
is_kernel_64_bit_ = is_kernel_64_bit = conn_reply.kernel_64_bit;
668-
slowdown_ = conn_reply.slowdown;
669-
syscall_timeout_ms_ = conn_reply.syscall_timeout_ms;
670-
program_timeout_ms_ = conn_reply.program_timeout_ms;
670+
671+
proc_opts_.use_cover_edges = conn_reply.cover_edges;
672+
proc_opts_.is_kernel_64_bit = is_kernel_64_bit = conn_reply.kernel_64_bit;
673+
proc_opts_.slowdown = conn_reply.slowdown;
674+
proc_opts_.syscall_timeout_ms = conn_reply.syscall_timeout_ms;
675+
proc_opts_.program_timeout_ms = conn_reply.program_timeout_ms;
671676
if (conn_reply.cover)
672677
max_signal_.emplace();
673678

@@ -836,7 +841,7 @@ class Runner
836841
close(stdin_pipe[0]);
837842
close(stdout_pipe[1]);
838843

839-
int status = process.WaitAndKill(5 * program_timeout_ms_);
844+
int status = process.WaitAndKill(5 * proc_opts_.program_timeout_ms);
840845

841846
std::vector<uint8_t> output;
842847
for (;;) {

0 commit comments

Comments
 (0)