aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorPatrick Meyer <meyerpatrick@google.com>2021-05-06 23:08:43 +0200
committerDmitry Vyukov <dvyukov@google.com>2021-05-20 13:29:54 +0200
commitac040bb3def51ecf81966d7801521b5a59fac0db (patch)
treec0196e1c3266495243b0c83759d9c89b34a8fb8a /sys
parentebc32b110a66a9bebfced77df99dcd3001489158 (diff)
sys/syz-extract: initial darwin support
Diffstat (limited to 'sys')
-rw-r--r--sys/sys.go1
-rw-r--r--sys/syz-extract/darwin.go51
-rw-r--r--sys/syz-extract/extract.go1
3 files changed, 53 insertions, 0 deletions
diff --git a/sys/sys.go b/sys/sys.go
index 2c3d169d5..b0ae67839 100644
--- a/sys/sys.go
+++ b/sys/sys.go
@@ -6,6 +6,7 @@ package sys
import (
// Import all targets, so that users only need to import sys.
_ "github.com/google/syzkaller/sys/akaros/gen"
+ _ "github.com/google/syzkaller/sys/darwin/gen"
_ "github.com/google/syzkaller/sys/freebsd/gen"
_ "github.com/google/syzkaller/sys/fuchsia/gen"
_ "github.com/google/syzkaller/sys/linux/gen"
diff --git a/sys/syz-extract/darwin.go b/sys/syz-extract/darwin.go
new file mode 100644
index 000000000..c6d694696
--- /dev/null
+++ b/sys/syz-extract/darwin.go
@@ -0,0 +1,51 @@
+// Copyright 2021 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 main
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "github.com/google/syzkaller/pkg/compiler"
+)
+
+type darwin struct{}
+
+func (*darwin) prepare(sourcedir string, build bool, arches []*Arch) error {
+ if sourcedir == "" {
+ return fmt.Errorf("provide path to kernel checkout via -sourcedir flag (or make extract SOURCEDIR)")
+ }
+ return nil
+}
+
+func (*darwin) prepareArch(arch *Arch) error {
+ return nil
+}
+
+func (*darwin) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
+ args := []string{
+ "-nostdinc",
+ "-I", filepath.Join(arch.sourceDir, "bsd"),
+ "-I", filepath.Join(arch.sourceDir, "bsd", "sys"),
+ "-I", filepath.Join(arch.sourceDir, "osfmk"),
+ }
+ for _, incdir := range info.Incdirs {
+ args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir))
+ }
+ fmt.Printf("dirs: %v", arch.includeDirs)
+ if arch.includeDirs != "" {
+ for _, dir := range strings.Split(arch.includeDirs, ",") {
+ args = append(args, "-I"+dir)
+ }
+ }
+ // TODO(HerrSpace): investigate use of bsd/kern/syscalls.master and
+ // osfmk/mach/mach_traps.h here.
+ params := &extractParams{
+ AddSource: "#include <sys/syscall.h>",
+ DeclarePrintf: true,
+ TargetEndian: arch.target.HostEndian,
+ }
+ return extract(info, "clang", args, params)
+}
diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go
index 00ab16cd8..24ea5f725 100644
--- a/sys/syz-extract/extract.go
+++ b/sys/syz-extract/extract.go
@@ -61,6 +61,7 @@ var extractors = map[string]Extractor{
targets.Akaros: new(akaros),
targets.Linux: new(linux),
targets.FreeBSD: new(freebsd),
+ targets.Darwin: new(darwin),
targets.NetBSD: new(netbsd),
targets.OpenBSD: new(openbsd),
"android": new(linux),