From a4d38b39a8e23244bea7a53e9d7a759474f85dae Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 4 May 2020 08:58:32 +0200 Subject: prog: support disabled attribute Update #477 Update #502 --- prog/rand.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'prog/rand.go') 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] { -- cgit mrf-deployment