AST_OP_MOD,
AST_OP_PLUS,
AST_OP_MINUS,
- AST_OP_RSHIFT,
- AST_OP_LSHIFT,
+ AST_OP_BIT_RSHIFT,
+ AST_OP_BIT_LSHIFT,
AST_OP_AND,
AST_OP_OR,
AST_OP_BIT_AND,
FILTER_OP_MOD = 4,
FILTER_OP_PLUS = 5,
FILTER_OP_MINUS = 6,
- FILTER_OP_RSHIFT = 7,
- FILTER_OP_LSHIFT = 8,
+ FILTER_OP_BIT_RSHIFT = 7,
+ FILTER_OP_BIT_LSHIFT = 8,
FILTER_OP_BIT_AND = 9,
FILTER_OP_BIT_OR = 10,
FILTER_OP_BIT_XOR = 11,
FILTER_OP_LOAD_FIELD_SEQUENCE = 96,
FILTER_OP_LOAD_FIELD_DOUBLE = 97,
+ FILTER_OP_UNARY_BIT_NOT = 98,
+
NR_FILTER_OPS,
};
{ $$ = $1; }
| shift_expression LEFT_OP additive_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_LSHIFT, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_LSHIFT, $1, $3);
}
| shift_expression RIGHT_OP additive_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_RSHIFT, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_RSHIFT, $1, $3);
}
;
case AST_UNARY_NOT:
insn.op = FILTER_OP_UNARY_NOT;
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
+ case AST_UNARY_BIT_NOT:
+ insn.op = FILTER_OP_UNARY_BIT_NOT;
+ return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
}
}
case AST_OP_MINUS:
insn.op = FILTER_OP_MINUS;
break;
- case AST_OP_RSHIFT:
- insn.op = FILTER_OP_RSHIFT;
+ case AST_OP_BIT_RSHIFT:
+ insn.op = FILTER_OP_BIT_RSHIFT;
break;
- case AST_OP_LSHIFT:
- insn.op = FILTER_OP_LSHIFT;
+ case AST_OP_BIT_LSHIFT:
+ insn.op = FILTER_OP_BIT_LSHIFT;
break;
case AST_OP_BIT_AND:
insn.op = FILTER_OP_BIT_AND;
child, side);
}
+static
+struct ir_op *make_op_unary_bit_not(struct ir_op *child, enum ir_side side)
+{
+ return make_op_unary(AST_UNARY_BIT_NOT, "~", child->signedness,
+ child, side);
+}
+
static
struct ir_op *make_op_binary_compare(enum op_type bin_op_type,
const char *op_str, struct ir_op *left, struct ir_op *right,
return make_op_binary_logical(AST_OP_OR, "||", left, right, side);
}
+static
+struct ir_op *make_op_binary_bitwise_rshift(struct ir_op *left, struct ir_op *right,
+ enum ir_side side)
+{
+ return make_op_binary_bitwise(AST_OP_BIT_RSHIFT, ">>", left, right, side);
+}
+
+static
+struct ir_op *make_op_binary_bitwise_lshift(struct ir_op *left, struct ir_op *right,
+ enum ir_side side)
+{
+ return make_op_binary_bitwise(AST_OP_BIT_LSHIFT, "<<", left, right, side);
+}
+
static
struct ir_op *make_op_binary_bitwise_and(struct ir_op *left, struct ir_op *right,
enum ir_side side)
case AST_OP_MINUS:
op_str = "-";
goto error_not_supported;
- case AST_OP_RSHIFT:
- op_str = ">>";
- goto error_not_supported;
- case AST_OP_LSHIFT:
- op_str = "<<";
- goto error_not_supported;
+ case AST_OP_BIT_RSHIFT:
+ case AST_OP_BIT_LSHIFT:
case AST_OP_BIT_AND:
case AST_OP_BIT_OR:
case AST_OP_BIT_XOR:
case AST_OP_LE:
op = make_op_binary_le(lchild, rchild, side);
break;
+ case AST_OP_BIT_RSHIFT:
+ op = make_op_binary_bitwise_rshift(lchild, rchild, side);
+ break;
+ case AST_OP_BIT_LSHIFT:
+ op = make_op_binary_bitwise_lshift(lchild, rchild, side);
+ break;
case AST_OP_BIT_AND:
op = make_op_binary_bitwise_and(lchild, rchild, side);
break;
struct ir_op *make_unary_op(struct filter_parser_ctx *ctx,
struct filter_node *node, enum ir_side side)
{
- const char *op_str = "?";
-
switch (node->u.unary_op.type) {
case AST_UNARY_UNKNOWN:
default:
}
case AST_UNARY_BIT_NOT:
{
- op_str = "~";
- goto error_not_supported;
+ struct ir_op *op, *child;
+
+ child = generate_ir_recursive(ctx, node->u.unary_op.child,
+ side);
+ if (!child)
+ return NULL;
+ op = make_op_unary_bit_not(child, side);
+ if (!op) {
+ filter_free_ir_recursive(child);
+ return NULL;
+ }
+ return op;
}
}
-error_not_supported:
- fprintf(stderr, "[error] %s: unary operation '%s' not supported\n",
- __func__, op_str);
return NULL;
}
case AST_OP_MINUS:
fprintf(stream, "\"-\"");
break;
- case AST_OP_RSHIFT:
+ case AST_OP_BIT_RSHIFT:
fprintf(stream, "\">>\"");
break;
- case AST_OP_LSHIFT:
+ case AST_OP_BIT_LSHIFT:
fprintf(stream, "\"<<\"");
break;
case AST_OP_AND:
ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr"
TRACE_PATH=$(mktemp -d)
NUM_GLOBAL_TESTS=2
-NUM_UST_TESTS=144
-NUM_KERNEL_TESTS=144
+NUM_UST_TESTS=135
+NUM_KERNEL_TESTS=135
NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
source $TESTDIR/utils/utils.sh
"intfield/1"
"intfield+1"
"intfield-1"
- "intfield>>1"
- "intfield<<1"
- "~intfield"
"1+11111-3333+1"
"(1+2)*(55*666)"
"1+2*55*666"
ENABLE_EVENT_STDERR="/tmp/unsupported-ops-enable"
TRACE_PATH=$(mktemp -d)
NUM_GLOBAL_TESTS=2
-NUM_UST_TESTS=32
-NUM_KERNEL_TESTS=32
+NUM_UST_TESTS=20
+NUM_KERNEL_TESTS=20
NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
source $TESTDIR/utils/utils.sh
print_test_banner "$TEST_DESC"
# Unsupported operators
-OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS" "LSHIFT" "RSHIFT"
- "UNARY_BIN_NOT")
+OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS")
-OP_TKN=("*" "/" "%" "+" "-" "<<" ">>" "~")
+OP_TKN=("*" "/" "%" "+" "-")
OP_COUNT=${#OP_STR[@]}
SESSION_NAME="valid_filter"
NR_ITER=100
NUM_GLOBAL_TESTS=2
-NUM_UST_TESTS=1002
-NUM_KERNEL_TESTS=936
+NUM_UST_TESTS=1074
+NUM_KERNEL_TESTS=1008
NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
source $TESTDIR/utils/utils.sh
true_statement
"0xF00F0F ^ 0xFF0F00 == 0x0F000F"
+ true_statement
+ "(1 << 1) == 2"
+
+ true_statement
+ "(4 >> 1) == 2"
+
+ true_statement
+ "(1 << 8) == 256"
+
+ true_statement
+ "(262144 >> 16) == 4"
+
+ true_statement
+ "(~0 & 0xffff) == 0xffff"
+
+ true_statement
+ "(~0 & 0xffffffff) == 0xffffffff"
+
+ true_statement
+ "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff"
+
+ true_statement
+ "-1==~0"
+
+ true_statement
+ "1<<1==2" # C99 operator priority: comparator before bitwise
+
+ has_no_event
+ "!(1<<1==2)" # C99 operator priority: comparator before bitwise
+
+ true_statement
+ "(1 << 32) == 4294967296"
+
+ true_statement
+ "(1 << 63) == 9223372036854775808"
+
true_statement
"arrfield1[2] & 1 == 1"
true_statement
"0xF00F0F ^ 0xFF0F00 == 0x0F000F"
+ true_statement
+ "(1 << 1) == 2"
+
+ true_statement
+ "(4 >> 1) == 2"
+
+ true_statement
+ "(1 << 8) == 256"
+
+ true_statement
+ "(262144 >> 16) == 4"
+
+ true_statement
+ "(~0 & 0xffff) == 0xffff"
+
+ true_statement
+ "(~0 & 0xffffffff) == 0xffffffff"
+
+ true_statement
+ "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff"
+
+ true_statement
+ "-1==~0"
+
+ true_statement
+ "1<<1==2" # C99 operator priority: comparator before bitwise
+
+ has_no_event
+ "!(1<<1==2)" # C99 operator priority: comparator before bitwise
+
+ true_statement
+ "(1 << 32) == 4294967296"
+
+ true_statement
+ "(1 << 63) == 9223372036854775808"
+
true_statement
"arrfield1[2] & 1 == 1"