aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-12-06 12:54:09 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-12-09 09:22:14 +0100
commit716124b06a7c7d1e482f90d16f88db80dab0964b (patch)
treec0fa701a21d9201e5433383c130b035417e0576d /executor
parent99917735b6a974a09d3833c34b3d4a8b8198522d (diff)
executor: minor coverage filter cleanup
Slightly reduce number of ifdef's, define coverage_filter only in shmem mode and remove unnecessary cast.
Diffstat (limited to 'executor')
-rw-r--r--executor/cov_filter.h15
-rw-r--r--executor/executor.cc2
-rw-r--r--executor/test.h7
3 files changed, 16 insertions, 8 deletions
diff --git a/executor/cov_filter.h b/executor/cov_filter.h
index 66cb0bcdc..26eb67ec8 100644
--- a/executor/cov_filter.h
+++ b/executor/cov_filter.h
@@ -1,13 +1,10 @@
// Copyright 2020 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+#if SYZ_EXECUTOR_USES_SHMEM
#include <fcntl.h>
-#include <stdio.h>
-
-#if GOOS_linux || GOOS_freebsd || GOOS_netbsd || GOOS_openbsd || GOOS_akaros
#include <sys/mman.h>
#include <sys/stat.h>
-#endif
struct cov_filter_t {
uint32 pcstart;
@@ -19,7 +16,6 @@ static cov_filter_t* cov_filter;
static void init_coverage_filter()
{
-#if SYZ_EXECUTOR_USES_SHMEM
int f = open("/syz-cover-bitmap", O_RDONLY);
if (f < 0) {
// We don't fail here because we don't know yet if we should use coverage filter or not.
@@ -38,11 +34,12 @@ static void init_coverage_filter()
if ((uint32)st.st_size != sizeof(uint32) * 2 + ((cov_filter->pcsize >> 4) + 7) / 8)
fail("bad coverage filter bitmap size");
close(f);
-#endif
}
static bool coverage_filter(uint64 pc)
{
+ if (!flag_coverage_filter)
+ return true;
if (cov_filter == NULL)
fail("coverage filter was enabled but bitmap initialization failed");
// Prevent out of bound while searching bitmap.
@@ -56,3 +53,9 @@ static bool coverage_filter(uint64 pc)
uint32 shift = pc32 % 8;
return (cov_filter->bitmap[idx] & (1 << shift)) > 0;
}
+
+#else
+static void init_coverage_filter()
+{
+}
+#endif
diff --git a/executor/executor.cc b/executor/executor.cc
index 7c31f9cc2..10bed012c 100644
--- a/executor/executor.cc
+++ b/executor/executor.cc
@@ -878,7 +878,7 @@ void write_coverage_signal(cover_t* cov, uint32* signal_count_pos, uint32* cover
}
cover_data_t sig = pc ^ prev;
prev = hash(pc);
- if (flag_coverage_filter && !coverage_filter((uint64)pc))
+ if (!coverage_filter(pc))
continue;
if (dedup(sig))
continue;
diff --git a/executor/test.h b/executor/test.h
index c8492ed73..9cbc88cc1 100644
--- a/executor/test.h
+++ b/executor/test.h
@@ -201,6 +201,7 @@ static int test_csum_inet_acc()
return 0;
}
+#if SYZ_EXECUTOR_USES_SHMEM
static int test_coverage_filter()
{
struct tmp_cov_filter_t {
@@ -211,8 +212,8 @@ static int test_coverage_filter()
static struct tmp_cov_filter_t tmp_cov_filter;
tmp_cov_filter.pcstart = 0x81000000;
tmp_cov_filter.pcsize = 0x1000;
- memset(tmp_cov_filter.bitmap, 0, ((0x1000 >> 4) + 7) / 8);
cov_filter = (cov_filter_t*)&tmp_cov_filter;
+ flag_coverage_filter = true;
uint64 full_enable_pc = 0xffffffff81000765;
uint64 full_disable_pc = 0xffffffff81000627;
@@ -231,8 +232,10 @@ static int test_coverage_filter()
return 1;
cov_filter = NULL;
+ flag_coverage_filter = false;
return 0;
}
+#endif
static struct {
const char* name;
@@ -244,7 +247,9 @@ static struct {
#if GOOS_linux && (GOARCH_amd64 || GOARCH_ppc64 || GOARCH_ppc64le)
{"test_kvm", test_kvm},
#endif
+#if SYZ_EXECUTOR_USES_SHMEM
{"test_coverage_filter", test_coverage_filter},
+#endif
};
static int run_tests()