From 9dd8cf63e09242d6e3fcf84628f412585fccf057 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 29 Jun 2018 16:33:07 +0200 Subject: executor, pkg/ipc: support output over pipes --- executor/common_fuchsia.h | 2 +- executor/executor.h | 98 ++++++++++++++++++++++++++++---------------- executor/executor_fuchsia.cc | 1 + 3 files changed, 65 insertions(+), 36 deletions(-) (limited to 'executor') diff --git a/executor/common_fuchsia.h b/executor/common_fuchsia.h index 7db03e05e..f7b36ee48 100644 --- a/executor/common_fuchsia.h +++ b/executor/common_fuchsia.h @@ -67,7 +67,7 @@ static void segv_handler() longjmp(segv_env, 1); } debug("recover: exiting\n"); - doexit(1); + doexit(SIGSEGV); } static void* ex_handler(void* arg) diff --git a/executor/executor.h b/executor/executor.h index 15e1aa40b..34c7efd48 100644 --- a/executor/executor.h +++ b/executor/executor.h @@ -142,6 +142,18 @@ struct execute_reply { uint32 status; }; +struct call_reply { + execute_reply header; + uint32 call_index; + uint32 call_num; + uint32 reserrno; + uint32 fault_injected; + uint32 signal_size; + uint32 cover_size; + uint32 comps_size; + // signal/cover/comps follow +}; + enum { KCOV_CMP_CONST = 1, KCOV_CMP_SIZE1 = 0, @@ -581,44 +593,60 @@ void handle_completion(thread_t* th) } } if (!collide && !th->colliding) { - write_output(th->call_index); - write_output(th->call_num); uint32 reserrno = th->res != -1 ? 0 : th->reserrno; - write_output(reserrno); - write_output(th->fault_injected); - uint32* signal_count_pos = write_output(0); // filled in later - uint32* cover_count_pos = write_output(0); // filled in later - uint32* comps_count_pos = write_output(0); // filled in later - - if (flag_collect_comps) { - // Collect only the comparisons - uint32 ncomps = th->cover_size; - kcov_comparison_t* start = (kcov_comparison_t*)(th->cover_data + sizeof(uint64)); - kcov_comparison_t* end = start + ncomps; - if ((char*)end > th->cover_end) - fail("too many comparisons %u", ncomps); - std::sort(start, end); - ncomps = std::unique(start, end) - start; - uint32 comps_size = 0; - for (uint32 i = 0; i < ncomps; ++i) { - if (start[i].ignore()) - continue; - comps_size++; - start[i].write(); + if (SYZ_EXECUTOR_USES_SHMEM) { + write_output(th->call_index); + write_output(th->call_num); + write_output(reserrno); + write_output(th->fault_injected); + uint32* signal_count_pos = write_output(0); // filled in later + uint32* cover_count_pos = write_output(0); // filled in later + uint32* comps_count_pos = write_output(0); // filled in later + + if (flag_collect_comps) { + // Collect only the comparisons + uint32 ncomps = th->cover_size; + kcov_comparison_t* start = (kcov_comparison_t*)(th->cover_data + sizeof(uint64)); + kcov_comparison_t* end = start + ncomps; + if ((char*)end > th->cover_end) + fail("too many comparisons %u", ncomps); + std::sort(start, end); + ncomps = std::unique(start, end) - start; + uint32 comps_size = 0; + for (uint32 i = 0; i < ncomps; ++i) { + if (start[i].ignore()) + continue; + comps_size++; + start[i].write(); + } + // Write out number of comparisons. + *comps_count_pos = comps_size; + } else if (flag_cover) { + if (is_kernel_64_bit) + write_coverage_signal(th, signal_count_pos, cover_count_pos); + else + write_coverage_signal(th, signal_count_pos, cover_count_pos); } - // Write out number of comparisons. - *comps_count_pos = comps_size; - } else if (flag_cover) { - if (is_kernel_64_bit) - write_coverage_signal(th, signal_count_pos, cover_count_pos); - else - write_coverage_signal(th, signal_count_pos, cover_count_pos); + debug("out #%u: index=%u num=%u errno=%d sig=%u cover=%u comps=%u\n", + completed, th->call_index, th->call_num, reserrno, + *signal_count_pos, *cover_count_pos, *comps_count_pos); + completed++; + write_completed(completed); + } else { + call_reply reply; + reply.header.magic = kOutMagic; + reply.header.done = 0; + reply.header.status = 0; + reply.call_index = th->call_index; + reply.call_num = th->call_num; + reply.reserrno = reserrno; + reply.fault_injected = th->fault_injected; + reply.signal_size = 0; + reply.cover_size = 0; + reply.comps_size = 0; + if (write(kOutPipeFd, &reply, sizeof(reply)) != sizeof(reply)) + fail("control pipe call write failed"); } - debug("out #%u: index=%u num=%u errno=%d sig=%u cover=%u comps=%u\n", - completed, th->call_index, th->call_num, reserrno, - *signal_count_pos, *cover_count_pos, *comps_count_pos); - completed++; - write_completed(completed); } th->handled = true; running--; diff --git a/executor/executor_fuchsia.cc b/executor/executor_fuchsia.cc index ab6d627a3..2377ad475 100644 --- a/executor/executor_fuchsia.cc +++ b/executor/executor_fuchsia.cc @@ -27,6 +27,7 @@ int main(int argc, char** argv) install_segv_handler(); main_init(); execute_one(); + reply_execute(0); (void)error; // prevent unused function warning return 0; } -- cgit mrf-deployment