aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
Diffstat (limited to 'executor')
-rw-r--r--executor/common.h4
-rw-r--r--executor/common_ext.h6
-rw-r--r--executor/common_ext_example.h10
-rw-r--r--executor/common_ext_test.go34
4 files changed, 52 insertions, 2 deletions
diff --git a/executor/common.h b/executor/common.h
index f4201ca45..2ee0d5bd2 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -507,7 +507,11 @@ static uint16 csum_inet_digest(struct csum_inet* csum)
#error "unknown OS"
#endif
+#if SYZ_TEST_COMMON_EXT_EXAMPLE
+#include "common_ext_example.h"
+#else
#include "common_ext.h"
+#endif
#if SYZ_EXECUTOR || __NR_syz_execute_func
// syz_execute_func(text ptr[in, text[taget]])
diff --git a/executor/common_ext.h b/executor/common_ext.h
index 6485852ef..22361649f 100644
--- a/executor/common_ext.h
+++ b/executor/common_ext.h
@@ -2,8 +2,10 @@
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// This file is included into executor and C reproducers and can be used to add
-// non-mainline pseudo-syscalls w/o changing any other files.
-// These syscalls should start with syz_ext_.
+// non-mainline pseudo-syscalls and to provide some other extension points
+// w/o changing any other files. See common_ext_example.h for an example implementation.
+
+// Pseudo-syscalls defined in this file should start with syz_ext_.
// This file can also define SYZ_HAVE_SETUP_EXT to 1 and provide
// void setup_ext() function that will be called during VM setup.
diff --git a/executor/common_ext_example.h b/executor/common_ext_example.h
new file mode 100644
index 000000000..0299b6d4f
--- /dev/null
+++ b/executor/common_ext_example.h
@@ -0,0 +1,10 @@
+// Copyright 2022 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.
+
+// An example implementation of common_ext.h used for testing.
+
+#define SYZ_HAVE_SETUP_EXT 1
+static void setup_ext()
+{
+ debug("example setup_ext called\n");
+}
diff --git a/executor/common_ext_test.go b/executor/common_ext_test.go
new file mode 100644
index 000000000..45ba3a3cf
--- /dev/null
+++ b/executor/common_ext_test.go
@@ -0,0 +1,34 @@
+// Copyright 2022 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.
+
+package executor
+
+import (
+ "bytes"
+ "os"
+ "testing"
+ "time"
+
+ "github.com/google/syzkaller/pkg/csource"
+ "github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/prog"
+)
+
+func TestCommonExt(t *testing.T) {
+ target, err := prog.GetTarget("test", "64_fork")
+ if err != nil {
+ t.Fatal(err)
+ }
+ bin, err := csource.BuildFile(target, "executor.cc", "-DSYZ_TEST_COMMON_EXT_EXAMPLE=1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.Remove(bin)
+ out, err := osutil.RunCmd(time.Minute, "", bin, "setup")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Contains(out, []byte("example setup_ext called")) {
+ t.Fatalf("setup_ext wasn't called:\n%s", out)
+ }
+}