github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/compiler/meta.go (about) 1 // Copyright 2022 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 compiler 5 6 import ( 7 "path/filepath" 8 9 "github.com/google/syzkaller/pkg/ast" 10 "github.com/google/syzkaller/sys/targets" 11 ) 12 13 type Meta struct { 14 Automatic bool // automatically-generated descriptions 15 NoExtract bool // do not run syz-extract on the descriptions by default 16 Arches map[string]bool 17 } 18 19 func (meta Meta) SupportsArch(arch string) bool { 20 return len(meta.Arches) == 0 || meta.Arches[arch] 21 } 22 23 func FileList(desc *ast.Description, OS string, eh ast.ErrorHandler) map[string]Meta { 24 // Use any target for this OS. 25 for _, target := range targets.List[OS] { 26 return createCompiler(desc, target, eh).fileList() 27 } 28 return nil 29 } 30 31 func (comp *compiler) fileMeta(pos ast.Pos) Meta { 32 if comp.fileMetas == nil { 33 comp.fileMetas = comp.fileList() 34 } 35 return comp.fileMetas[filepath.Base(pos.File)] 36 } 37 38 func (comp *compiler) fileList() map[string]Meta { 39 files := make(map[string]Meta) 40 for _, n := range comp.desc.Nodes { 41 pos, _, _ := n.Info() 42 file := filepath.Base(pos.File) 43 if file == ast.BuiltinFile { 44 continue 45 } 46 meta := files[file] 47 switch n := n.(type) { 48 case *ast.Meta: 49 errors0 := comp.errors 50 comp.checkTypeImpl(checkCtx{}, n.Value, metaTypes[n.Value.Ident], 0) 51 if errors0 != comp.errors { 52 break 53 } 54 switch n.Value.Ident { 55 case metaAutomatic.Names[0]: 56 meta.Automatic = true 57 case metaNoExtract.Names[0]: 58 meta.NoExtract = true 59 case metaArches.Names[0]: 60 meta.Arches = make(map[string]bool) 61 for _, arg := range n.Value.Args { 62 meta.Arches[arg.String] = true 63 } 64 } 65 } 66 files[file] = meta 67 } 68 return files 69 } 70 71 var metaTypes = map[string]*typeDesc{ 72 metaAutomatic.Names[0]: metaAutomatic, 73 metaNoExtract.Names[0]: metaNoExtract, 74 metaArches.Names[0]: metaArches, 75 } 76 77 var metaAutomatic = &typeDesc{ 78 Names: []string{"automatic"}, 79 CantBeOpt: true, 80 } 81 82 var metaNoExtract = &typeDesc{ 83 Names: []string{"noextract"}, 84 CantBeOpt: true, 85 } 86 87 var metaArches = &typeDesc{ 88 Names: []string{"arches"}, 89 CantBeOpt: true, 90 OptArgs: 8, 91 Args: []namedArg{metaArch, metaArch, metaArch, metaArch, metaArch, metaArch, metaArch, metaArch}, 92 } 93 94 var metaArch = namedArg{Name: "arch", Type: &typeArg{ 95 Kind: kindString, 96 Check: func(comp *compiler, t *ast.Type) { 97 if targets.List[comp.target.OS][t.String] == nil { 98 comp.error(t.Pos, "unknown arch %v", t.String) 99 } 100 }, 101 }}