github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/subsystem/raw_extractor.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package subsystem 5 6 import ( 7 "github.com/google/syzkaller/prog" 8 ) 9 10 // rawExtractor performs low-level subsystem matching (directly by a path or a syscall). 11 type rawExtractor struct { 12 matcher *PathMatcher 13 perCall map[string][]*Subsystem 14 } 15 16 func makeRawExtractor(list []*Subsystem) *rawExtractor { 17 ret := &rawExtractor{ 18 matcher: MakePathMatcher(list), 19 perCall: make(map[string][]*Subsystem), 20 } 21 for _, subsystem := range list { 22 for _, call := range subsystem.Syscalls { 23 ret.perCall[call] = append(ret.perCall[call], subsystem) 24 } 25 } 26 return ret 27 } 28 29 func (e *rawExtractor) FromPath(path string) []*Subsystem { 30 return e.matcher.Match(path) 31 } 32 33 func (e *rawExtractor) FromProg(progBytes []byte) []*Subsystem { 34 calls := make(map[*Subsystem]struct{}) 35 progCalls, _, _ := prog.CallSet(progBytes) 36 for call := range progCalls { 37 for _, subsystem := range e.perCall[call] { 38 calls[subsystem] = struct{}{} 39 } 40 } 41 list := []*Subsystem{} 42 for key := range calls { 43 list = append(list, key) 44 } 45 return list 46 }