diff options
| author | Dokyung Song <dokyungs@google.com> | 2018-09-05 12:45:17 -0700 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-09-06 21:18:15 +0200 |
| commit | e30d3b524053cf8d688a1f486a5cde9b67d49e87 (patch) | |
| tree | 8743bf3e125c306042793f7f7f23822e747715c0 | |
| parent | 0bb7a7eb8e0958c6fbe2d69615b9fae4af88c8ee (diff) | |
sys/fuchsia: add Go script that generates fidl descriptions
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | docs/fuchsia.md | 8 | ||||
| -rw-r--r-- | sys/fuchsia/fidlgen/main.go | 78 | ||||
| -rw-r--r-- | sys/fuchsia/init.go | 2 |
4 files changed, 92 insertions, 0 deletions
@@ -160,6 +160,10 @@ generate_go: bin/syz-sysgen format_cpp generate_sys: bin/syz-sysgen bin/syz-sysgen +generate_fidl: + $(GO) generate ./sys/fuchsia + $(MAKE) format_sys + bin/syz-sysgen: $(GO) build $(GOHOSTFLAGS) -o $@ ./sys/syz-sysgen diff --git a/docs/fuchsia.md b/docs/fuchsia.md index 44b6eeaff..ce7b82f1e 100644 --- a/docs/fuchsia.md +++ b/docs/fuchsia.md @@ -48,6 +48,14 @@ Run `syz-manager` with a config along the lines of: ## How to generate syscall description for FIDL +Use `generate_fidl` target to automatically generate syscall descriptions for all the supported FIDL files. + +```bash +make generate_fidl TARGETARCH=amd64 SOURCEDIR=/path/to/fuchsia/checkout +``` + +To manually generate syscall description for a given `.fidl` file, use the following instruction. + FIDL files should first be compiled into FIDL intermediate representation (JSON) files using `fidlc`: ```bash diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go new file mode 100644 index 000000000..38189bae8 --- /dev/null +++ b/sys/fuchsia/fidlgen/main.go @@ -0,0 +1,78 @@ +// Copyright 2018 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" + "os" + "path/filepath" + "strings" + "time" + + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/sys/targets" +) + +var zirconLibs = []string{ + "fuchsia-process", + "fuchsia-io", +} + +func main() { + targetArch := os.Getenv("TARGETARCH") + target := targets.Get("fuchsia", targetArch) + if target == nil { + failf("unknown TARGETARCH %s", targetArch) + } + arch := target.KernelHeaderArch + + sourceDir := os.Getenv("SOURCEDIR") + if !osutil.IsExist(sourceDir) { + failf("cannot find SOURCEDIR %s", sourceDir) + } + + fidlgenPath := filepath.Join( + sourceDir, + "out", + arch, + fmt.Sprintf("host_%s", arch), + "fidlgen", + ) + if !osutil.IsExist(fidlgenPath) { + failf("cannot find fidlgen %s", fidlgenPath) + } + + for _, lib := range zirconLibs { + jsonPath := filepath.Join( + sourceDir, + "out", + arch, + "fidling/gen/zircon/public/fidl", + lib, + fmt.Sprintf("%s.fidl.json", lib), + ) + + if !osutil.IsExist(jsonPath) { + failf("cannot find %s", jsonPath) + } + + txtPath := strings.Replace(lib, "fuchsia-", "fidl_", 1) + _, err := osutil.RunCmd(time.Minute, "", + fidlgenPath, + "-generators", "syzkaller", + "-json", jsonPath, + "-output-base", txtPath, + "-include-base", txtPath, + ) + + if err != nil { + failf("fidlgen failed: %v\n", err) + } + } +} + +func failf(msg string, args ...interface{}) { + fmt.Fprintf(os.Stderr, msg+"\n", args...) + os.Exit(1) +} diff --git a/sys/fuchsia/init.go b/sys/fuchsia/init.go index eefba3950..30cb3d7d1 100644 --- a/sys/fuchsia/init.go +++ b/sys/fuchsia/init.go @@ -1,6 +1,8 @@ // Copyright 2017 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. +//go:generate go run fidlgen/main.go + package fuchsia import ( |
