diff options
| -rw-r--r-- | docs/fuchsia/README.md | 15 | ||||
| -rw-r--r-- | sys/fuchsia/fidlgen/main.go | 69 | ||||
| -rw-r--r-- | sys/fuchsia/layout/fidl_mappings.go | 78 | ||||
| -rw-r--r-- | sys/syz-extract/fuchsia.go | 6 |
4 files changed, 101 insertions, 67 deletions
diff --git a/docs/fuchsia/README.md b/docs/fuchsia/README.md index 5dddb8f50..93a212c0e 100644 --- a/docs/fuchsia/README.md +++ b/docs/fuchsia/README.md @@ -3,18 +3,19 @@ For information about checking out and building Fuchsia see [Getting Started](https://fuchsia.googlesource.com/fuchsia/+/master/docs/getting_started.md) and [Soure Code](https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/source_code/README.md). + +You need to build fuchsia for both amd64 and arm64: + ```shell -$ fx set core.x64 --build-dir "out/x64" \ - --args extra_authorized_keys_file=\"//.ssh/authorized_keys\" -$ fx full-build +$ fx --dir "out/x64" set core.x64 +$ fx clean-build ``` -You need to build fuchsia for both arm64 and amd64: +And ```shell -$ fx set core.arm64 --build-dir "out/arm64" \ - --args extra_authorized_keys_file=\"//.ssh/authorized_keys\" -$ fx full-build +$ fx --dir "out/arm64" set core.arm64 +$ fx clean-build ``` Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you need to modify the `.txt` file that contains it, make sure your new definition matches the one in zircon's [syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen) file. **If the syscall was used in `executor/common_fuchsia.h`, you need to update the usages there as well**. FIDL definitions do not need manual updating because they are extracted automatically with the commands below. diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go index 8a88e5007..139d6461d 100644 --- a/sys/fuchsia/fidlgen/main.go +++ b/sys/fuchsia/fidlgen/main.go @@ -13,28 +13,10 @@ import ( "github.com/google/syzkaller/pkg/ast" "github.com/google/syzkaller/pkg/compiler" "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/sys/fuchsia/layout" "github.com/google/syzkaller/sys/targets" ) -var layerToLibs = map[string][]string{ - "zircon": { - "fuchsia-mem", - "fuchsia-cobalt", - "fuchsia-ldsvc", - "fuchsia-process", - "fuchsia-io", - "fuchsia-net", - "fuchsia-net-stack", - "fuchsia-hardware-ethernet", - }, - "garnet": { - "fuchsia.devicesettings", - "fuchsia.timezone", - "fuchsia.power", - "fuchsia.scpi", - }, -} - func main() { targetArch := os.Getenv("TARGETARCH") target := targets.Get("fuchsia", targetArch) @@ -60,46 +42,17 @@ func main() { } var newFiles []string + for _, fidlLib := range layout.AllFidlLibraries { + jsonPath := filepath.Join(sourceDir, "out", arch, fidlLib.PathToJSONIr()) + txtPathBase := strings.Replace(strings.Join(fidlLib.FqName, "_"), "^fuchsia", "fidl", 1) - for layer := range layerToLibs { - var jsonPathBase string - if layer == "garnet" { - jsonPathBase = filepath.Join( - sourceDir, - "out", - arch, - "fidling/gen/sdk/fidl", - ) - } else { - jsonPathBase = filepath.Join( - sourceDir, - "out", - arch, - "fidling/gen", - layer, - "public/fidl", - ) - } - - for _, lib := range layerToLibs[layer] { - jsonPath := filepath.Join( - jsonPathBase, - lib, - fmt.Sprintf("%s.fidl.json", lib), - ) + txtPath := fidlgen( + fidlgenPath, + jsonPath, + txtPathBase, + ) - txtPathBase := lib - txtPathBase = strings.Replace(txtPathBase, "fuchsia.", "fidl_", 1) - txtPathBase = strings.Replace(txtPathBase, "fuchsia-", "fidl_", 1) - - txtPath := fidlgen( - fidlgenPath, - jsonPath, - txtPathBase, - ) - - newFiles = append(newFiles, txtPath) - } + newFiles = append(newFiles, txtPath) } var errorPos ast.Pos @@ -157,7 +110,7 @@ func fidlgen(fidlgenPath string, jsonPath string, txtPathBase string) string { failf("fidlgen failed: %v", err) } - return fmt.Sprintf("%s.txt", txtPathBase) + return fmt.Sprintf("%s.syz.txt", txtPathBase) } func failf(msg string, args ...interface{}) { diff --git a/sys/fuchsia/layout/fidl_mappings.go b/sys/fuchsia/layout/fidl_mappings.go new file mode 100644 index 000000000..dd5e3c678 --- /dev/null +++ b/sys/fuchsia/layout/fidl_mappings.go @@ -0,0 +1,78 @@ +// Copyright 2019 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 layout + +import ( + "fmt" + "path/filepath" + "strings" +) + +// layer indicates at which layer a FidlLibrary lives in the Fuchsia build +// system. +type layer int + +const ( + _ layer = iota + zircon + garnet +) + +// FidlLibrary describes a FIDL library. It captures required details such as +// build location, header generation, etc. +type FidlLibrary struct { + layer layer + + // FqName stores the fully-qualified name of the library in parts, e.g. + // the `fuchsia.mem` library is `fuchsia`, `mem`. + FqName []string +} + +// AllFidlLibraries lists all FIDL libraries. +var AllFidlLibraries = []FidlLibrary{ + {zircon, []string{"fuchsia", "mem"}}, + {zircon, []string{"fuchsia", "cobalt"}}, + {zircon, []string{"fuchsia", "ldsvc"}}, + {zircon, []string{"fuchsia", "process"}}, + {zircon, []string{"fuchsia", "io"}}, + {zircon, []string{"fuchsia", "net"}}, + {zircon, []string{"fuchsia", "net", "stack"}}, + {zircon, []string{"fuchsia", "hardware", "ethernet"}}, + {garnet, []string{"fuchsia", "devicesettings"}}, + {garnet, []string{"fuchsia", "timezone"}}, + {garnet, []string{"fuchsia", "power"}}, + {garnet, []string{"fuchsia", "scpi"}}, +} + +func (fidlLib FidlLibrary) dirName() string { + switch fidlLib.layer { + case zircon: + return strings.Join(fidlLib.FqName, "-") + case garnet: + return strings.Join(fidlLib.FqName, ".") + default: + panic(fmt.Sprintf("unknown layer %v", fidlLib.layer)) + } +} + +// PathToJSONIr provides the path to the JSON IR, relative to the out/<arch> +// directory. +func (fidlLib FidlLibrary) PathToJSONIr() string { + return filepath.Join( + fidlLib.PathToCompiledDir(), + fmt.Sprintf("%s.fidl.json", fidlLib.dirName())) +} + +// PathToCompiledDir provides the path to compiled headers, relative to the +// out/<arch> directory. +func (fidlLib FidlLibrary) PathToCompiledDir() string { + switch fidlLib.layer { + case zircon: + return filepath.Join("fidling", "gen", "zircon", "public", "fidl", fidlLib.dirName()) + case garnet: + return filepath.Join("fidling", "gen", "sdk", "fidl", fidlLib.dirName()) + default: + panic(fmt.Sprintf("unknown layer %v", fidlLib.layer)) + } +} diff --git a/sys/syz-extract/fuchsia.go b/sys/syz-extract/fuchsia.go index 2784a1b11..9ec5e117d 100644 --- a/sys/syz-extract/fuchsia.go +++ b/sys/syz-extract/fuchsia.go @@ -8,6 +8,7 @@ import ( "path/filepath" "github.com/google/syzkaller/pkg/compiler" + "github.com/google/syzkaller/sys/fuchsia/layout" ) type fuchsia struct{} @@ -30,8 +31,9 @@ func (*fuchsia) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui includeDir := filepath.Join(dir, "out", headerArch, "sdk", "exported", "zircon_sysroot", "arch", headerArch, "sysroot", "include") args := []string{"-fmessage-length=0", "-I" + includeDir} - fidlingDir := filepath.Join(dir, "out", headerArch, "fidling", "gen") - args = append(args, "-I"+fidlingDir) + for _, fidlLib := range layout.AllFidlLibraries { + args = append(args, "-I"+filepath.Join(dir, "out", headerArch, fidlLib.PathToCompiledDir())) + } for _, incdir := range info.Incdirs { args = append(args, "-I"+filepath.Join(dir, incdir)) } |
