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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
%{
// Copyright 2018 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.
// +build !codeanalysis
package parser
%}
%start syscall
%union {
data string
val_int int64
val_double float64
val_ret_type int64
val_uint uint64
val_constant Constant
val_identifiers []*BufferType
val_buf_type *BufferType
val_group_type *GroupType
val_type IrType
val_types []IrType
val_syscall *Syscall
}
%token <data> STRING_LITERAL IPV6 IDENTIFIER FLAG DATETIME SIGNAL_PLUS SIGNAL_MINUS MAC
%token <val_int> INT
%token <val_uint> UINT
%token <val_double> DOUBLE
%type <val_ret_type> ret_type
%type <val_buf_type> buf_type
%type <val_group_type> group_type
%type <val_constant> constant
%type <val_type> parenthetical, parentheticals, type, field_type
%type <val_types> types
%type <val_syscall> syscall
%token STRING_LITERAL MAC IDENTIFIER FLAG INT UINT QUESTION DOUBLE ARROW
%token OR AND LOR TIMES LAND LEQUAL ONESCOMP LSHIFT RSHIFT TIMES NOT MINUS PLUS
%token COMMA LBRACKET RBRACKET LBRACKET_SQUARE RBRACKET_SQUARE LPAREN RPAREN EQUALS
%token UNFINISHED RESUMED
%token SIGNAL_PLUS SIGNAL_MINUS NULL EQUALAT COLON FORWARDSLASH
%nonassoc LOWEST
%nonassoc NOFLAG
%nonassoc LBRACKET_SQUARE
%left OR
%left AND
%left LSHIFT RSHIFT
%left PLUS
%left MINUS
%left TIMES
%right NEG ONESCOMP
%left COLON
%left ARROW
%left EQUALS
%left EQUALAT
%%
syscall:
IDENTIFIER LPAREN types UNFINISHED %prec NOFLAG { $$ = NewSyscall(-1, $1, $3, int64(-1), true, false);
Stracelex.(*Stracelexer).result = $$ }
| RESUMED UNFINISHED RPAREN EQUALS QUESTION %prec NOFLAG
{
$$ = NewSyscall(-1, "tmp", nil, -1, true, true);
Stracelex.(*Stracelexer).result = $$
}
| IDENTIFIER LPAREN RESUMED RPAREN EQUALS INT %prec NOFLAG
{
$$ = NewSyscall(-1, $1, nil, int64($6), false, false);
Stracelex.(*Stracelexer).result = $$
}
| RESUMED types RPAREN EQUALS ret_type %prec NOFLAG { $$ = NewSyscall(-1, "tmp", $2, $5, false, true);
Stracelex.(*Stracelexer).result = $$ }
| RESUMED types RPAREN EQUALS QUESTION %prec NOFLAG { $$ = NewSyscall(-1, "tmp", $2, -1, false, true);
Stracelex.(*Stracelexer).result = $$ }
| RESUMED types RPAREN EQUALS ret_type LPAREN parentheticals RPAREN { $$ = NewSyscall(-1, "tmp", $2, $5, false, true);
Stracelex.(*Stracelexer).result = $$ }
| RESUMED types RPAREN EQUALS ret_type FLAG LPAREN parentheticals RPAREN { $$ = NewSyscall(-1, "tmp", $2, $5, false, true);
Stracelex.(*Stracelexer).result = $$ }
| IDENTIFIER LPAREN types RPAREN EQUALS ret_type %prec NOFLAG{
$$ = NewSyscall(-1, $1, $3, $6, false, false);
Stracelex.(*Stracelexer).result = $$}
| IDENTIFIER LPAREN types RPAREN EQUALS QUESTION %prec NOFLAG {
$$ = NewSyscall(-1, $1, $3, -1, false, false);
Stracelex.(*Stracelexer).result = $$}
| IDENTIFIER LPAREN types RPAREN EQUALS ret_type FLAG LPAREN parentheticals RPAREN {
$$ = NewSyscall(-1, $1, $3, $6, false, false);
Stracelex.(*Stracelexer).result = $$}
| IDENTIFIER LPAREN types RPAREN EQUALS ret_type LPAREN parentheticals RPAREN {
$$ = NewSyscall(-1, $1, $3, $6, false, false);
Stracelex.(*Stracelexer).result = $$}
| INT syscall {call := $2; call.Pid = $1; Stracelex.(*Stracelexer).result = call}
parentheticals:
parenthetical {$$ = nil}
| parentheticals parenthetical {$$ = nil}
parenthetical:
COMMA {$$=nil}
| OR {$$ = nil}
| AND {$$ = nil}
| LSHIFT {$$ = nil}
| RSHIFT {$$ = nil}
| IDENTIFIER {$$ = nil}
| FORWARDSLASH {$$ = nil}
| group_type {$$ = nil}
| FLAG {$$ = nil}
| INT {$$ = nil}
| UINT {$$ = nil}
ret_type:
INT {$$ = $1}
| UINT {$$ = int64($1)}
| MINUS INT {$$ = -1 * $2}
types:
{$$ = []IrType{}}
| types COMMA type {$1 = append($1, $3); $$ = $1}
| types type {$1 = append($1, $2); $$ = $1}
type:
buf_type {$$ = $1}
| field_type {$$ = $1}
| group_type {$$ = $1}
| constant %prec LOWEST {$$ = $1}
| ONESCOMP group_type {$$ = $2}
constant:
INT {$$ = Constant($1)}
| UINT {$$ = Constant($1)}
| NULL {$$ = Constant(uint64(0))}
| constant OR constant {$$ = $1 | $3}
| constant AND constant {$$ = $1 & $3}
| constant LSHIFT constant {$$ = $1 << $3}
| constant RSHIFT constant {$$ = $1 >> $3}
| LPAREN constant RPAREN {$$ = $2}
| constant TIMES constant {$$ = $1 * $3}
| constant MINUS constant {$$ = $1 - $3}
| constant PLUS constant {$$ = $1 + $3}
| ONESCOMP constant {$$ = ^$2}
| MINUS constant %prec NEG {$$ = Constant(-int64($2))}
group_type:
LBRACKET_SQUARE types RBRACKET_SQUARE {$$ = newGroupType($2)}
| LBRACKET types RBRACKET {$$ = newGroupType($2)}
| LBRACKET types COMMA RBRACKET {$$ = newGroupType($2)}
field_type:
type COLON type {$$ = $3}
| type EQUALAT type {$$ = $3}
| type EQUALS type {$$ = $3}
| type ARROW type {$$ = $1}
| IDENTIFIER LBRACKET_SQUARE FLAG RBRACKET_SQUARE EQUALS type {$$ = $6}
buf_type:
STRING_LITERAL {$$ = newBufferType($1)}
| IDENTIFIER %prec LOWEST {$$ = newBufferType($1)}
| DATETIME {$$ = newBufferType($1)}
| MAC {$$ = newBufferType($1)}
|