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