aboutsummaryrefslogtreecommitdiffstats
path: root/prog/rand.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-05-04 08:58:32 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-04 20:56:20 +0200
commita4d38b39a8e23244bea7a53e9d7a759474f85dae (patch)
tree6bdb1f795fc5b670c9d2bad96599820cdb1eea85 /prog/rand.go
parent58ae5e18624eaaac79cab00e63d6f32c9bd64ee0 (diff)
prog: support disabled attribute
Update #477 Update #502
Diffstat (limited to 'prog/rand.go')
-rw-r--r--prog/rand.go24
1 files changed, 8 insertions, 16 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 135469fe7..150f4b266 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -379,10 +379,9 @@ func (r *randGen) createResource(s *state, res *ResourceType, dir Dir) (arg Arg,
// TODO: reduce priority of less specialized ctors.
var metas []*Syscall
for _, meta := range metas0 {
- if s.ct == nil || s.ct.run[meta.ID] == nil {
- continue
+ if s.ct.enabled(meta.ID) {
+ metas = append(metas, meta)
}
- metas = append(metas, meta)
}
if len(metas) == 0 {
return res.DefaultArg(dir), nil
@@ -537,19 +536,12 @@ func (r *randGen) nOutOf(n, outOf int) bool {
}
func (r *randGen) generateCall(s *state, p *Prog, insertionPoint int) []*Call {
- idx := 0
- if s.ct == nil {
- idx = r.Intn(len(r.target.Syscalls))
- } else if insertionPoint <= 0 {
- idx = s.ct.enabledCalls[r.Intn(len(s.ct.enabledCalls))].ID
- } else {
- call := -1
- if len(p.Calls) != 0 {
- // Choosing the base call is based on the insertion point of the new calls sequence.
- call = p.Calls[r.Intn(insertionPoint)].Meta.ID
- }
- idx = s.ct.Choose(r.Rand, call)
+ biasCall := -1
+ if insertionPoint > 0 {
+ // Choosing the base call is based on the insertion point of the new calls sequence.
+ biasCall = p.Calls[r.Intn(insertionPoint)].Meta.ID
}
+ idx := s.ct.choose(r.Rand, biasCall)
meta := r.target.Syscalls[idx]
return r.generateParticularCall(s, meta)
}
@@ -573,7 +565,7 @@ func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog {
Target: target,
}
r := newRand(target, rs)
- s := newState(target, nil, nil)
+ s := newState(target, target.DefaultChoiceTable(), nil)
handled := make(map[string]bool)
for _, meta := range target.Syscalls {
if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] {