aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-repro
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-10-11 13:41:40 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-10-11 11:59:58 +0000
commitafa86b09bcac3bc4220aa5b71285d98ff57422a5 (patch)
treec775a4a3c12d600fdfab95948411e153b6300728 /tools/syz-repro
parent8b02337e33dbcc9aae5b80ebe850733ca7c8fac7 (diff)
tools/syz-repro: order Loop() and vmPool.Close()
There used to be no strict ordering between cancelling the loop context and the actual moment the Loop() method exits. Now that we assert that all instances are freed in vmPool.Close(), we need to wait until Loop() finishes before closing the VM pool. Restructure the main() method to ensure this order.
Diffstat (limited to 'tools/syz-repro')
-rw-r--r--tools/syz-repro/repro.go72
1 files changed, 37 insertions, 35 deletions
diff --git a/tools/syz-repro/repro.go b/tools/syz-repro/repro.go
index c7526af3d..220170599 100644
--- a/tools/syz-repro/repro.go
+++ b/tools/syz-repro/repro.go
@@ -62,45 +62,47 @@ func main() {
}
pool := vm.NewDispatcher(vmPool, nil)
pool.ReserveForRun(count)
- ctx, done := context.WithCancel(context.Background())
- go pool.Loop(ctx)
- defer done()
- res, stats, err := repro.Run(data, cfg, flatrpc.AllFeatures, reporter, pool)
- if err != nil {
- log.Logf(0, "reproduction failed: %v", err)
- }
- if stats != nil {
- fmt.Printf("extracting prog: %v\n", stats.ExtractProgTime)
- fmt.Printf("minimizing prog: %v\n", stats.MinimizeProgTime)
- fmt.Printf("simplifying prog options: %v\n", stats.SimplifyProgTime)
- fmt.Printf("extracting C: %v\n", stats.ExtractCTime)
- fmt.Printf("simplifying C: %v\n", stats.SimplifyCTime)
- }
- if res == nil {
- return
- }
+ ctx, done := context.WithCancel(context.Background())
+ go func() {
+ defer done()
- fmt.Printf("opts: %+v crepro: %v\n\n", res.Opts, res.CRepro)
+ res, stats, err := repro.Run(data, cfg, flatrpc.AllFeatures, reporter, pool)
+ if err != nil {
+ log.Logf(0, "reproduction failed: %v", err)
+ }
+ if stats != nil {
+ fmt.Printf("extracting prog: %v\n", stats.ExtractProgTime)
+ fmt.Printf("minimizing prog: %v\n", stats.MinimizeProgTime)
+ fmt.Printf("simplifying prog options: %v\n", stats.SimplifyProgTime)
+ fmt.Printf("extracting C: %v\n", stats.ExtractCTime)
+ fmt.Printf("simplifying C: %v\n", stats.SimplifyCTime)
+ }
+ if res == nil {
+ return
+ }
- progSerialized := res.Prog.Serialize()
- fmt.Printf("%s\n", progSerialized)
- if err = osutil.WriteFile(*flagOutput, progSerialized); err == nil {
- fmt.Printf("program saved to %s\n", *flagOutput)
- } else {
- log.Logf(0, "failed to write prog to file: %v", err)
- }
+ fmt.Printf("opts: %+v crepro: %v\n\n", res.Opts, res.CRepro)
+ progSerialized := res.Prog.Serialize()
+ fmt.Printf("%s\n", progSerialized)
+ if err = osutil.WriteFile(*flagOutput, progSerialized); err == nil {
+ fmt.Printf("program saved to %s\n", *flagOutput)
+ } else {
+ log.Logf(0, "failed to write prog to file: %v", err)
+ }
- if res.Report != nil && *flagTitle != "" {
- recordTitle(res, *flagTitle)
- }
- if res.CRepro {
- recordCRepro(res, *flagCRepro)
- }
- if *flagStrace != "" {
- result := repro.RunStrace(res, cfg, reporter, pool)
- recordStraceResult(result, *flagStrace)
- }
+ if res.Report != nil && *flagTitle != "" {
+ recordTitle(res, *flagTitle)
+ }
+ if res.CRepro {
+ recordCRepro(res, *flagCRepro)
+ }
+ if *flagStrace != "" {
+ result := repro.RunStrace(res, cfg, reporter, pool)
+ recordStraceResult(result, *flagStrace)
+ }
+ }()
+ pool.Loop(ctx)
}
func recordTitle(res *repro.Result, fileName string) {