aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-08-02 16:54:28 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-08-02 16:57:32 +0200
commit88d4a8fc562c4fe8f975446854358c99c4c876d1 (patch)
treea4c4f10e9fded5a8efe128076c528039be1f4c32 /sys
parent394e6910d0eba8d9c4fcc4d10f66b68f3c097b3d (diff)
sys/syz-extract: refactor main
main is too long and complex. Move more logic into helper functions. Update #538
Diffstat (limited to 'sys')
-rw-r--r--sys/syz-extract/extract.go134
1 files changed, 74 insertions, 60 deletions
diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go
index c1dce0105..8d0d6179c 100644
--- a/sys/syz-extract/extract.go
+++ b/sys/syz-extract/extract.go
@@ -74,56 +74,25 @@ func main() {
failf("-build and -builddir is an invalid combination")
}
- osStr, archArray, files, err := archFileList(*flagOS, *flagArch, flag.Args())
+ OS, archArray, files, err := archFileList(*flagOS, *flagArch, flag.Args())
if err != nil {
failf("%v", err)
}
- extractor := extractors[osStr]
+ extractor := extractors[OS]
if extractor == nil {
- failf("unknown os: %v", osStr)
+ failf("unknown os: %v", OS)
}
if err := extractor.prepare(*flagSourceDir, *flagBuild, archArray); err != nil {
failf("%v", err)
}
+ arches, err := createArches(OS, archArray, files)
+ if err != nil {
+ failf("%v", err)
+ }
jobC := make(chan interface{}, len(archArray)*len(files))
-
- var arches []*Arch
- for _, archStr := range archArray {
- buildDir := ""
- if *flagBuild {
- dir, err := ioutil.TempDir("", "syzkaller-kernel-build")
- if err != nil {
- failf("failed to create temp dir: %v", err)
- }
- buildDir = dir
- } else if *flagBuildDir != "" {
- buildDir = *flagBuildDir
- } else {
- buildDir = *flagSourceDir
- }
-
- target := targets.Get(osStr, archStr)
- if target == nil {
- failf("unknown arch: %v", archStr)
- }
-
- arch := &Arch{
- target: target,
- sourceDir: *flagSourceDir,
- buildDir: buildDir,
- build: *flagBuild,
- done: make(chan bool),
- }
- for _, f := range files {
- arch.files = append(arch.files, &File{
- arch: arch,
- name: f,
- done: make(chan bool),
- })
- }
- arches = append(arches, arch)
+ for _, arch := range arches {
jobC <- arch
}
@@ -171,28 +140,8 @@ func main() {
}
if !failed {
- supported := make(map[string]bool)
- unsupported := make(map[string]string)
- for _, arch := range arches {
- for _, f := range arch.files {
- for name := range f.consts {
- supported[name] = true
- }
- for name := range f.undeclared {
- unsupported[name] = f.name
- }
- }
- }
- for name, file := range unsupported {
- if supported[name] {
- continue
- }
- failed = true
- fmt.Printf("%v: %v is unsupported on all arches (typo?)\n",
- file, name)
- }
+ failed = checkUnsupportedCalls(arches)
}
-
for _, arch := range arches {
if arch.build {
os.RemoveAll(arch.buildDir)
@@ -203,6 +152,71 @@ func main() {
}
}
+func createArches(OS string, archArray, files []string) ([]*Arch, error) {
+ var arches []*Arch
+ for _, archStr := range archArray {
+ buildDir := ""
+ if *flagBuild {
+ dir, err := ioutil.TempDir("", "syzkaller-kernel-build")
+ if err != nil {
+ return nil, fmt.Errorf("failed to create temp dir: %v", err)
+ }
+ buildDir = dir
+ } else if *flagBuildDir != "" {
+ buildDir = *flagBuildDir
+ } else {
+ buildDir = *flagSourceDir
+ }
+
+ target := targets.Get(OS, archStr)
+ if target == nil {
+ return nil, fmt.Errorf("unknown arch: %v", archStr)
+ }
+
+ arch := &Arch{
+ target: target,
+ sourceDir: *flagSourceDir,
+ buildDir: buildDir,
+ build: *flagBuild,
+ done: make(chan bool),
+ }
+ for _, f := range files {
+ arch.files = append(arch.files, &File{
+ arch: arch,
+ name: f,
+ done: make(chan bool),
+ })
+ }
+ arches = append(arches, arch)
+ }
+ return arches, nil
+}
+
+func checkUnsupportedCalls(arches []*Arch) bool {
+ supported := make(map[string]bool)
+ unsupported := make(map[string]string)
+ for _, arch := range arches {
+ for _, f := range arch.files {
+ for name := range f.consts {
+ supported[name] = true
+ }
+ for name := range f.undeclared {
+ unsupported[name] = f.name
+ }
+ }
+ }
+ failed := false
+ for name, file := range unsupported {
+ if supported[name] {
+ continue
+ }
+ failed = true
+ fmt.Printf("%v: %v is unsupported on all arches (typo?)\n",
+ file, name)
+ }
+ return failed
+}
+
func archFileList(os, arch string, files []string) (string, []string, []string, error) {
android := false
if os == "android" {