aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/raw_extractor.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-01-20 18:00:47 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-10 14:34:44 +0100
commit5ca014a29eab3dcdecd58d34c0a332fa78958872 (patch)
tree12815af4043ba70470f07aa16ac447b10cc29acd /pkg/subsystem/raw_extractor.go
parent3a4c5e2da302d43152f2e8b1362d8568c0d57e6e (diff)
pkg/subsystem: add the basic caller-facing interface
Users of the pkg/subsystem are only interested in 1) Fetching the list of subsystems for a given OS. 2) Matching a crash against the extracted set of subsystems.
Diffstat (limited to 'pkg/subsystem/raw_extractor.go')
-rw-r--r--pkg/subsystem/raw_extractor.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/subsystem/raw_extractor.go b/pkg/subsystem/raw_extractor.go
new file mode 100644
index 000000000..4a86b1f6b
--- /dev/null
+++ b/pkg/subsystem/raw_extractor.go
@@ -0,0 +1,48 @@
+// 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/pkg/subsystem/entity"
+ "github.com/google/syzkaller/pkg/subsystem/match"
+ "github.com/google/syzkaller/prog"
+)
+
+// rawExtractor performs low-level subsystem matching (directly by a path or a syscall).
+type rawExtractor struct {
+ matcher *match.PathMatcher
+ perCall map[string][]*entity.Subsystem
+}
+
+func makeRawExtractor(list []*entity.Subsystem) *rawExtractor {
+ ret := &rawExtractor{
+ matcher: match.MakePathMatcher(list),
+ perCall: make(map[string][]*entity.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) []*entity.Subsystem {
+ return e.matcher.Match(path)
+}
+
+func (e *rawExtractor) FromProg(progBytes []byte) []*entity.Subsystem {
+ calls := make(map[*entity.Subsystem]struct{})
+ progCalls, _, _ := prog.CallSet(progBytes)
+ for call := range progCalls {
+ for _, subsystem := range e.perCall[call] {
+ calls[subsystem] = struct{}{}
+ }
+ }
+ list := []*entity.Subsystem{}
+ for key := range calls {
+ list = append(list, key)
+ }
+ return list
+}