mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-23 11:29:46 +00:00
sys/syz-extract: refactor main
main is too long and complex. Move more logic into helper functions. Update #538
This commit is contained in:
parent
394e6910d0
commit
88d4a8fc56
@ -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" {
|
||||
|
Loading…
Reference in New Issue
Block a user