diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-05-03 17:17:58 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-05-04 12:34:39 +0200 |
| commit | 8e1412d59319a19d61ea48985b13ef550e3ab9ec (patch) | |
| tree | 898f98fe6393d9e33ce9b3cec04e9b42e05a273b /prog/rand.go | |
| parent | 44cadb8c63089bc856779dc81dc1b3df8de361ed (diff) | |
pkg/csource: compile single pseudo syscalls
There seem to be a lot of unclear dependencies between pseudo syscall
code and global methods. By testing them only together we have little
chance to detect these problems because implementations can indiretly
help one another.
In addition to existing tests, also compile all pseudo syscalls
independently.
Diffstat (limited to 'prog/rand.go')
| -rw-r--r-- | prog/rand.go | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/prog/rand.go b/prog/rand.go index c91ffeee4..560e1e176 100644 --- a/prog/rand.go +++ b/prog/rand.go @@ -593,7 +593,23 @@ func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog { } r := newRand(target, rs) s := newState(target, target.DefaultChoiceTable(), nil) + for _, meta := range target.PseudoSyscalls() { + calls := r.generateParticularCall(s, meta) + for _, c := range calls { + s.analyze(c) + p.Calls = append(p.Calls, c) + } + } + if err := p.validate(); err != nil { + panic(err) + } + return p +} + +// PseudoSyscalls selects one *Syscall for each pseudosyscall. +func (target *Target) PseudoSyscalls() []*Syscall { handled := make(map[string]bool) + var ret []*Syscall for _, meta := range target.Syscalls { if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] || @@ -601,12 +617,22 @@ func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog { meta.Attrs.NoGenerate { continue } + ret = append(ret, meta) handled[meta.CallName] = true - calls := r.generateParticularCall(s, meta) - for _, c := range calls { - s.analyze(c) - p.Calls = append(p.Calls, c) - } + } + return ret +} + +// GenSampleProg generates a single sample program for the call. +func (target *Target) GenSampleProg(meta *Syscall, rs rand.Source) *Prog { + r := newRand(target, rs) + s := newState(target, target.DefaultChoiceTable(), nil) + p := &Prog{ + Target: target, + } + for _, c := range r.generateParticularCall(s, meta) { + s.analyze(c) + p.Calls = append(p.Calls, c) } if err := p.validate(); err != nil { panic(err) |
