-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cover.go
78 lines (67 loc) · 2 KB
/
cover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2024 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package fuzzer
import (
"sync"
"github.com/google/syzkaller/pkg/signal"
"github.com/google/syzkaller/pkg/stats"
)
// Cover keeps track of the signal known to the fuzzer.
type Cover struct {
mu sync.RWMutex
maxSignal signal.Signal // max signal ever observed (including flakes)
newSignal signal.Signal // newly identified max signal
dropSignal signal.Signal // the newly dropped max signal
}
func newCover() *Cover {
cover := new(Cover)
stats.Create("max signal", "Maximum fuzzing signal (including flakes)",
stats.Graph("signal"), stats.LenOf(&cover.maxSignal, &cover.mu))
return cover
}
// Signal that should no longer be chased after.
// It is not returned in GrabSignalDelta().
func (cover *Cover) AddMaxSignal(sign signal.Signal) {
cover.mu.Lock()
defer cover.mu.Unlock()
cover.maxSignal.Merge(sign)
cover.dropSignal.Subtract(sign)
}
func (cover *Cover) addRawMaxSignal(signal []uint32, prio uint8) signal.Signal {
cover.mu.Lock()
defer cover.mu.Unlock()
diff := cover.maxSignal.DiffRaw(signal, prio)
if diff.Empty() {
return diff
}
cover.maxSignal.Merge(diff)
cover.newSignal.Merge(diff)
cover.dropSignal.Subtract(diff)
return diff
}
func (cover *Cover) pureMaxSignal(corpus signal.Signal) signal.Signal {
cover.mu.RLock()
defer cover.mu.RUnlock()
return corpus.Diff(cover.maxSignal)
}
func (cover *Cover) CopyMaxSignal() signal.Signal {
cover.mu.RLock()
defer cover.mu.RUnlock()
return cover.maxSignal.Copy()
}
func (cover *Cover) GrabSignalDelta() (plus, minus signal.Signal) {
cover.mu.Lock()
defer cover.mu.Unlock()
plus = cover.newSignal
cover.newSignal = nil
minus = cover.dropSignal
cover.dropSignal = nil
return
}
func (cover *Cover) subtract(delta signal.Signal) {
cover.mu.Lock()
defer cover.mu.Unlock()
cover.maxSignal.Subtract(delta)
cover.newSignal.Subtract(delta)
cover.dropSignal.Merge(delta)
}