From bb47c6540dc13ca4170b0bfb8623d8094a2b5139 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 8 Jan 2016 22:33:40 +0100 Subject: sys: add kvm support --- executor/executor.cc | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'executor/executor.cc') diff --git a/executor/executor.cc b/executor/executor.cc index 93de7c459..d26e97457 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -303,8 +303,7 @@ retry: if (collide && (call_index % 2) == 0) { // Don't wait for every other call. // We already have results from the previous execution. - } - else if (flag_threaded) { + } else if (flag_threaded) { // Wait for call completion. uint64_t start = current_time_ms(); uint64_t now = start; @@ -335,8 +334,7 @@ retry: handle_completion(th); } } - } - else { + } else { // Execute directly. if (th != &threads[0]) fail("using non-main thread in non-thread mode"); @@ -356,7 +354,8 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, { // Figure out whether we need root privs for this call. bool root = false; - switch (syscalls[call_num].sys_nr) { + switch (syscalls[call_num] + .sys_nr) { case __NR_mount: case __NR_umount2: case __NR_syz_fuse_mount: @@ -380,7 +379,9 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, if (i == kMaxThreads) exitf("out of threads"); thread_t* th = &threads[i]; - debug("scheduling call %d [%s] on thread %d\n", call_index, syscalls[call_num].name, th->id); + debug("scheduling call %d [%s] on thread %d\n", call_index, syscalls[call_num] + .name, + th->id); if (th->ready || !th->done || !th->handled) fail("bad thread state in schedule: ready=%d done=%d handled=%d", th->ready, th->done, th->handled); th->copyout_pos = pos; @@ -400,13 +401,17 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, void handle_completion(thread_t* th) { - debug("completion of call %d [%s] on thread %d\n", th->call_index, syscalls[th->call_num].name, th->id); + debug("completion of call %d [%s] on thread %d\n", th->call_index, syscalls[th->call_num] + .name, + th->id); if (th->ready || !th->done || th->handled) fail("bad thread state in completion: ready=%d done=%d handled=%d", th->ready, th->done, th->handled); if (th->res != (uint64_t)-1) { - results[th->call_n].executed = true; - results[th->call_n].val = th->res; + results[th->call_n] + .executed = true; + results[th->call_n] + .val = th->res; for (bool done = false; !done;) { th->call_n++; uint64_t call_num = read_input(&th->copyout_pos); @@ -415,8 +420,10 @@ void handle_completion(thread_t* th) char* addr = (char*)read_input(&th->copyout_pos); uint64_t size = read_input(&th->copyout_pos); uint64_t val = copyout(addr, size); - results[th->call_n].executed = true; - results[th->call_n].val = val; + results[th->call_n] + .executed = true; + results[th->call_n] + .val = val; debug("copyout from %p\n", addr); break; } @@ -493,8 +500,7 @@ void execute_call(thread_t* th) char buf[128]; sprintf(buf, "/dev/pts/%d", ptyno); th->res = open(buf, th->args[1], 0); - } - else { + } else { th->res = -1; } break; @@ -586,7 +592,8 @@ void cover_open() if (ioctl(th->cover_fd, KCOV_INIT_TRACE, kCoverSize)) fail("cover enable write failed"); th->cover_data = (uint32_t*)mmap(NULL, kCoverSize * sizeof(th->cover_data[0]), PROT_READ | PROT_WRITE, MAP_SHARED, th->cover_fd, 0); - if ((void*)th->cover_data == MAP_FAILED) + if ((void*)th + ->cover_data == MAP_FAILED) fail("cover mmap failed"); } } @@ -703,8 +710,10 @@ uint64_t read_result(uint64_t** input_posp) if (idx >= kMaxCommands) fail("command refers to bad result %ld", idx); uint64_t arg = default_value; - if (results[idx].executed) { - arg = results[idx].val; + if (results[idx] + .executed) { + arg = results[idx] + .val; if (op_div != 0) arg = arg / op_div; arg += op_add; @@ -736,7 +745,12 @@ uint64_t current_time_ms() timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); - return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; + return (uint64_t)ts + .tv_sec * + 1000 + + (uint64_t)ts + .tv_nsec / + 1000000; } // logical error (e.g. invalid input program) -- cgit mrf-deployment