github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-trace2syz/parser/strace.y (about) 1 %{ 2 // Copyright 2018 syzkaller project authors. All rights reserved. 3 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 4 5 // +build !codeanalysis 6 7 package parser 8 9 %} 10 11 %start syscall 12 13 %union { 14 data string 15 val_int int64 16 val_double float64 17 val_ret_type int64 18 val_uint uint64 19 val_constant Constant 20 val_identifiers []*BufferType 21 val_buf_type *BufferType 22 val_group_type *GroupType 23 val_type IrType 24 val_types []IrType 25 val_syscall *Syscall 26 } 27 28 %token <data> STRING_LITERAL IPV6 IDENTIFIER FLAG DATETIME SIGNAL_PLUS SIGNAL_MINUS MAC 29 %token <val_int> INT 30 %token <val_uint> UINT 31 %token <val_double> DOUBLE 32 %type <val_ret_type> ret_type 33 %type <val_buf_type> buf_type 34 %type <val_group_type> group_type 35 %type <val_constant> constant 36 %type <val_type> parenthetical, parentheticals, type, field_type 37 %type <val_types> types 38 %type <val_syscall> syscall 39 40 %token STRING_LITERAL MAC IDENTIFIER FLAG INT UINT QUESTION DOUBLE ARROW 41 %token OR AND LOR TIMES LAND LEQUAL ONESCOMP LSHIFT RSHIFT TIMES NOT MINUS PLUS 42 %token COMMA LBRACKET RBRACKET LBRACKET_SQUARE RBRACKET_SQUARE LPAREN RPAREN EQUALS 43 %token UNFINISHED RESUMED 44 %token SIGNAL_PLUS SIGNAL_MINUS NULL EQUALAT COLON FORWARDSLASH 45 46 %nonassoc LOWEST 47 %nonassoc NOFLAG 48 %nonassoc LBRACKET_SQUARE 49 50 %left OR 51 %left AND 52 %left LSHIFT RSHIFT 53 %left PLUS 54 %left MINUS 55 %left TIMES 56 %right NEG ONESCOMP 57 %left COLON 58 %left ARROW 59 %left EQUALS 60 %left EQUALAT 61 %% 62 syscall: 63 IDENTIFIER LPAREN types UNFINISHED %prec NOFLAG { $$ = NewSyscall(-1, $1, $3, int64(-1), true, false); 64 Stracelex.(*Stracelexer).result = $$ } 65 | RESUMED UNFINISHED RPAREN EQUALS QUESTION %prec NOFLAG 66 { 67 $$ = NewSyscall(-1, "tmp", nil, -1, true, true); 68 Stracelex.(*Stracelexer).result = $$ 69 } 70 | IDENTIFIER LPAREN RESUMED RPAREN EQUALS INT %prec NOFLAG 71 { 72 $$ = NewSyscall(-1, $1, nil, int64($6), false, false); 73 Stracelex.(*Stracelexer).result = $$ 74 } 75 76 | RESUMED types RPAREN EQUALS ret_type %prec NOFLAG { $$ = NewSyscall(-1, "tmp", $2, $5, false, true); 77 Stracelex.(*Stracelexer).result = $$ } 78 | RESUMED types RPAREN EQUALS QUESTION %prec NOFLAG { $$ = NewSyscall(-1, "tmp", $2, -1, false, true); 79 Stracelex.(*Stracelexer).result = $$ } 80 | RESUMED types RPAREN EQUALS ret_type LPAREN parentheticals RPAREN { $$ = NewSyscall(-1, "tmp", $2, $5, false, true); 81 Stracelex.(*Stracelexer).result = $$ } 82 83 | RESUMED types RPAREN EQUALS ret_type FLAG LPAREN parentheticals RPAREN { $$ = NewSyscall(-1, "tmp", $2, $5, false, true); 84 Stracelex.(*Stracelexer).result = $$ } 85 | IDENTIFIER LPAREN types RPAREN EQUALS ret_type %prec NOFLAG{ 86 $$ = NewSyscall(-1, $1, $3, $6, false, false); 87 Stracelex.(*Stracelexer).result = $$} 88 | IDENTIFIER LPAREN types RPAREN EQUALS QUESTION %prec NOFLAG { 89 $$ = NewSyscall(-1, $1, $3, -1, false, false); 90 Stracelex.(*Stracelexer).result = $$} 91 | IDENTIFIER LPAREN types RPAREN EQUALS ret_type FLAG LPAREN parentheticals RPAREN { 92 $$ = NewSyscall(-1, $1, $3, $6, false, false); 93 Stracelex.(*Stracelexer).result = $$} 94 | IDENTIFIER LPAREN types RPAREN EQUALS ret_type LPAREN parentheticals RPAREN { 95 $$ = NewSyscall(-1, $1, $3, $6, false, false); 96 Stracelex.(*Stracelexer).result = $$} 97 | INT syscall {call := $2; call.Pid = $1; Stracelex.(*Stracelexer).result = call} 98 99 parentheticals: 100 parenthetical {$$ = nil} 101 | parentheticals parenthetical {$$ = nil} 102 103 parenthetical: 104 COMMA {$$=nil} 105 | OR {$$ = nil} 106 | AND {$$ = nil} 107 | LSHIFT {$$ = nil} 108 | RSHIFT {$$ = nil} 109 | IDENTIFIER {$$ = nil} 110 | FORWARDSLASH {$$ = nil} 111 | group_type {$$ = nil} 112 | FLAG {$$ = nil} 113 | INT {$$ = nil} 114 | UINT {$$ = nil} 115 116 ret_type: 117 INT {$$ = $1} 118 | UINT {$$ = int64($1)} 119 | MINUS INT {$$ = -1 * $2} 120 121 types: 122 {$$ = []IrType{}} 123 | types COMMA type {$1 = append($1, $3); $$ = $1} 124 | types type {$1 = append($1, $2); $$ = $1} 125 126 type: 127 buf_type {$$ = $1} 128 | field_type {$$ = $1} 129 | group_type {$$ = $1} 130 | constant %prec LOWEST {$$ = $1} 131 | ONESCOMP group_type {$$ = $2} 132 133 constant: 134 INT {$$ = Constant($1)} 135 | UINT {$$ = Constant($1)} 136 | NULL {$$ = Constant(uint64(0))} 137 | constant OR constant {$$ = $1 | $3} 138 | constant AND constant {$$ = $1 & $3} 139 | constant LSHIFT constant {$$ = $1 << $3} 140 | constant RSHIFT constant {$$ = $1 >> $3} 141 | LPAREN constant RPAREN {$$ = $2} 142 | constant TIMES constant {$$ = $1 * $3} 143 | constant MINUS constant {$$ = $1 - $3} 144 | constant PLUS constant {$$ = $1 + $3} 145 | ONESCOMP constant {$$ = ^$2} 146 | MINUS constant %prec NEG {$$ = Constant(-int64($2))} 147 148 group_type: 149 LBRACKET_SQUARE types RBRACKET_SQUARE {$$ = newGroupType($2)} 150 | LBRACKET types RBRACKET {$$ = newGroupType($2)} 151 | LBRACKET types COMMA RBRACKET {$$ = newGroupType($2)} 152 153 field_type: 154 type COLON type {$$ = $3} 155 | type EQUALAT type {$$ = $3} 156 | type EQUALS type {$$ = $3} 157 | type ARROW type {$$ = $1} 158 | IDENTIFIER LBRACKET_SQUARE FLAG RBRACKET_SQUARE EQUALS type {$$ = $6} 159 160 buf_type: 161 STRING_LITERAL {$$ = newBufferType($1)} 162 | IDENTIFIER %prec LOWEST {$$ = newBufferType($1)} 163 | DATETIME {$$ = newBufferType($1)} 164 | MAC {$$ = newBufferType($1)} 165