From a1990d2bd9d1f54baf83802e2874069ee73b4fa4 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 25 Nov 2024 11:55:37 +0100 Subject: tools/syz-declextract: accept manager config Make the tool accept a manager config. This will be required for dynamic extraction of info from the kernel. --- pkg/osutil/osutil.go | 7 +++++-- tools/syz-declextract/run.go | 26 +++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 465679ced..3c98a7f68 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -333,10 +333,13 @@ func Abs(path string) string { if wd1, err := os.Getwd(); err == nil && wd1 != wd { panic(fmt.Sprintf("wd changed: %q -> %q", wd, wd1)) } - if path == "" || filepath.IsAbs(path) { + if path == "" { return path } - return filepath.Join(wd, path) + if !filepath.IsAbs(path) { + path = filepath.Join(wd, path) + } + return filepath.Clean(path) } // MonotonicNano returns monotonic time in nanoseconds from some unspecified point in time. diff --git a/tools/syz-declextract/run.go b/tools/syz-declextract/run.go index 181fca96c..5e5e546fd 100644 --- a/tools/syz-declextract/run.go +++ b/tools/syz-declextract/run.go @@ -23,6 +23,7 @@ import ( "github.com/google/syzkaller/pkg/ast" "github.com/google/syzkaller/pkg/compiler" + "github.com/google/syzkaller/pkg/mgrconfig" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/subsystem" _ "github.com/google/syzkaller/pkg/subsystem/lists" @@ -37,21 +38,16 @@ var ( func main() { var ( - binary = flag.String("binary", "syz-declextract", "path to binary") - sourceDir = flag.String("sourcedir", "", "kernel source directory") - buildDir = flag.String("builddir", "", "kernel build directory (defaults to source directory)") + flagConfig = flag.String("config", "", "manager config file") + flagBinary = flag.String("binary", "syz-declextract", "path to syz-declextract binary") ) defer tool.Init()() - if *sourceDir == "" { - tool.Failf("path to kernel source directory is required") - } - if *buildDir == "" { - *buildDir = *sourceDir + cfg, err := mgrconfig.LoadFile(*flagConfig) + if err != nil { + tool.Failf("failed to load manager config: %v", err) } - *sourceDir = filepath.Clean(osutil.Abs(*sourceDir)) - *buildDir = filepath.Clean(osutil.Abs(*buildDir)) - compilationDatabase := filepath.Join(*buildDir, "compile_commands.json") + compilationDatabase := filepath.Join(cfg.KernelObj, "compile_commands.json") cmds, err := loadCompileCommands(compilationDatabase) if err != nil { tool.Failf("failed to load compile commands: %v", err) @@ -62,7 +58,7 @@ func main() { outputs := make(chan *output, len(cmds)) files := make(chan string, len(cmds)) for w := 0; w < runtime.NumCPU(); w++ { - go worker(outputs, files, *binary, compilationDatabase) + go worker(outputs, files, *flagBinary, compilationDatabase) } for _, cmd := range cmds { @@ -70,7 +66,7 @@ func main() { } close(files) - syscallNames := readSyscallMap(*sourceDir) + syscallNames := readSyscallMap(cfg.KernelSrc) var nodes []ast.Node interfaces := make(map[string]Interface) @@ -80,7 +76,7 @@ func main() { if out == nil { continue } - file, err := filepath.Rel(*sourceDir, out.file) + file, err := filepath.Rel(cfg.KernelSrc, out.file) if err != nil { tool.Fail(err) } @@ -91,7 +87,7 @@ func main() { if parse == nil { tool.Failf("%v: parsing error:\n%s", file, out.output) } - appendNodes(&nodes, interfaces, parse.Nodes, syscallNames, *sourceDir, *buildDir, file) + appendNodes(&nodes, interfaces, parse.Nodes, syscallNames, cfg.KernelSrc, cfg.KernelObj, file) } desc := finishDescriptions(nodes) -- cgit mrf-deployment