github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-manager/cover.go (about) 1 // Copyright 2015 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package main 5 6 import ( 7 "sync" 8 9 "github.com/google/syzkaller/pkg/cover" 10 "github.com/google/syzkaller/pkg/log" 11 "github.com/google/syzkaller/pkg/mgrconfig" 12 ) 13 14 var ( 15 cachedRepGenMu sync.Mutex 16 cachedRepGen *cover.ReportGenerator 17 ) 18 19 func getReportGenerator(cfg *mgrconfig.Config, modules []cover.KernelModule) (*cover.ReportGenerator, error) { 20 cachedRepGenMu.Lock() 21 defer cachedRepGenMu.Unlock() 22 if cachedRepGen == nil { 23 log.Logf(0, "initializing coverage information...") 24 rg, err := cover.MakeReportGenerator(cfg, cfg.KernelSubsystem, modules, cfg.RawCover) 25 if err != nil { 26 return nil, err 27 } 28 cachedRepGen = rg 29 } 30 return cachedRepGen, nil 31 } 32 33 func resetReportGenerator() { 34 cachedRepGenMu.Lock() 35 defer cachedRepGenMu.Unlock() 36 cachedRepGen = nil 37 } 38 39 func coverToPCs(rg *cover.ReportGenerator, cov []uint32) []uint64 { 40 pcs := make([]uint64, 0, len(cov)) 41 for _, pc := range cov { 42 pcs = append(pcs, rg.RestorePC(pc)) 43 } 44 return pcs 45 }