blob: fa964fd25d08670107d193c5f431a18e3041f91a (
plain)
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
|
// Copyright 2023 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 subsystem
import (
"github.com/google/syzkaller/prog"
)
// rawExtractor performs low-level subsystem matching (directly by a path or a syscall).
type rawExtractor struct {
matcher *PathMatcher
perCall map[string][]*Subsystem
}
func makeRawExtractor(list []*Subsystem) *rawExtractor {
ret := &rawExtractor{
matcher: MakePathMatcher(list),
perCall: make(map[string][]*Subsystem),
}
for _, subsystem := range list {
for _, call := range subsystem.Syscalls {
ret.perCall[call] = append(ret.perCall[call], subsystem)
}
}
return ret
}
func (e *rawExtractor) FromPath(path string) []*Subsystem {
return e.matcher.Match(path)
}
func (e *rawExtractor) FromProg(progBytes []byte) []*Subsystem {
calls := make(map[*Subsystem]struct{})
progCalls, _, _ := prog.CallSet(progBytes)
for call := range progCalls {
for _, subsystem := range e.perCall[call] {
calls[subsystem] = struct{}{}
}
}
list := []*Subsystem{}
for key := range calls {
list = append(list, key)
}
return list
}
|