diff options
Diffstat (limited to 'executor/executor_linux.h')
-rw-r--r-- | executor/executor_linux.h | 70 |
1 files changed, 12 insertions, 58 deletions
diff --git a/executor/executor_linux.h b/executor/executor_linux.h index fdd274162..2eab98560 100644 --- a/executor/executor_linux.h +++ b/executor/executor_linux.h @@ -11,30 +11,13 @@ #include <sys/syscall.h> #include <unistd.h> -const unsigned long KCOV_TRACE_PC = 0; -const unsigned long KCOV_TRACE_CMP = 1; - -template <int N> -struct kcov_remote_arg { - unsigned trace_mode; - unsigned area_size; - unsigned num_handles; - __u64 common_handle; - __u64 handles[N]; -}; - #define KCOV_INIT_TRACE32 _IOR('c', 1, uint32) #define KCOV_INIT_TRACE64 _IOR('c', 1, uint64) #define KCOV_ENABLE _IO('c', 100) #define KCOV_DISABLE _IO('c', 101) -#define KCOV_REMOTE_ENABLE _IOW('c', 102, struct kcov_remote_arg<0>) - -#define KCOV_REMOTE_HANDLE_USB 0x4242000000000000ull -static inline __u64 kcov_remote_handle_usb(int bus) -{ - return KCOV_REMOTE_HANDLE_USB + (__u64)bus; -} +const unsigned long KCOV_TRACE_PC = 0; +const unsigned long KCOV_TRACE_CMP = 1; static bool detect_kernel_bitness(); @@ -42,20 +25,20 @@ static void os_init(int argc, char** argv, void* data, size_t data_size) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); is_kernel_64_bit = detect_kernel_bitness(); - if (mmap(data, data_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) != data) + if (mmap(data, data_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) != data) fail("mmap of data segment failed"); } static __thread cover_t* current_cover; -static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs]) +static long execute_syscall(const call_t* c, long a[kMaxArgs]) { if (c->call) return c->call(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]); return syscall(c->sys_nr, a[0], a[1], a[2], a[3], a[4], a[5]); } -static void cover_open(cover_t* cov, bool extra) +static void cover_open(cover_t* cov) { int fd = open("/sys/kernel/debug/kcov", O_RDWR); if (fd == -1) @@ -64,10 +47,9 @@ static void cover_open(cover_t* cov, bool extra) fail("filed to dup2(%d, %d) cover fd", fd, cov->fd); close(fd); const int kcov_init_trace = is_kernel_64_bit ? KCOV_INIT_TRACE64 : KCOV_INIT_TRACE32; - const int cover_size = extra ? kExtraCoverSize : kCoverSize; - if (ioctl(cov->fd, kcov_init_trace, cover_size)) + if (ioctl(cov->fd, kcov_init_trace, kCoverSize)) fail("cover init trace write failed"); - size_t mmap_alloc_size = cover_size * (is_kernel_64_bit ? 8 : 4); + size_t mmap_alloc_size = kCoverSize * (is_kernel_64_bit ? 8 : 4); cov->data = (char*)mmap(NULL, mmap_alloc_size, PROT_READ | PROT_WRITE, MAP_SHARED, cov->fd, 0); if (cov->data == MAP_FAILED) @@ -75,36 +57,15 @@ static void cover_open(cover_t* cov, bool extra) cov->data_end = cov->data + mmap_alloc_size; } -static void cover_protect(cover_t* cov) -{ -} - -static void cover_unprotect(cover_t* cov) -{ -} - -static void cover_enable(cover_t* cov, bool collect_comps, bool extra) +static void cover_enable(cover_t* cov, bool collect_comps) { int kcov_mode = collect_comps ? KCOV_TRACE_CMP : KCOV_TRACE_PC; - // The KCOV_ENABLE call should be fatal, + // This should be fatal, // but in practice ioctl fails with assorted errors (9, 14, 25), // so we use exitf. - if (!extra) { - if (ioctl(cov->fd, KCOV_ENABLE, kcov_mode)) - exitf("cover enable write trace failed, mode=%d", kcov_mode); - current_cover = cov; - return; - } - struct kcov_remote_arg<1> arg; - memset(&arg, 0, sizeof(arg)); - arg.trace_mode = kcov_mode; - // Coverage buffer size of remote threads. - arg.area_size = kExtraCoverSize; - arg.num_handles = 1; - arg.handles[0] = kcov_remote_handle_usb(procid + 1); - arg.common_handle = procid + 1; - if (ioctl(cov->fd, KCOV_REMOTE_ENABLE, &arg)) - exitf("cover enable write trace failed"); + if (ioctl(cov->fd, KCOV_ENABLE, kcov_mode)) + exitf("cover enable write trace failed, mode=%d", kcov_mode); + current_cover = cov; } static void cover_reset(cover_t* cov) @@ -175,10 +136,3 @@ NORETURN void doexit(int status) for (i = 0;; i++) { } } - -#define SYZ_HAVE_FEATURES 1 -static feature_t features[] = { - {"leak", setup_leak}, - {"fault", setup_fault}, - {"binfmt_misc", setup_binfmt_misc}, -}; |