github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/subsystem/list.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 "fmt" 7 8 // In general, it's not correct to assume that subsystems are only determined by target.OS, 9 // because subsystems are related not to the user interface of the OS kernel, but rather to 10 // the OS kernel implementation. 11 // 12 // For example, during fuzzing we can treat gVisor in the same way as any other Linux kernel. 13 // In reality, however, not a single MAINTAINERS-based rule will work on the gVisor codebase. 14 // 15 // Therefore, subsystem lists have to be a completely different entity. 16 17 var ( 18 lists = make(map[string]registeredSubsystem) 19 ) 20 21 type registeredSubsystem struct { 22 list []*Subsystem 23 revision int 24 } 25 26 func RegisterList(name string, list []*Subsystem, revision int) { 27 if _, ok := lists[name]; ok { 28 panic(name + " subsystem list already exists!") 29 } 30 lists[name] = registeredSubsystem{ 31 list: list, 32 revision: revision, 33 } 34 } 35 36 func GetList(name string) []*Subsystem { 37 info, ok := lists[name] 38 if !ok { 39 panic(fmt.Sprintf("list %q is not registered", name)) 40 } 41 return info.list 42 } 43 44 func ListService(name string) *Service { 45 info, ok := lists[name] 46 if !ok { 47 panic(fmt.Sprintf("list %q is not registered", name)) 48 } 49 return MustMakeService(info.list, info.revision) 50 }