struct ir_op *node);
static
-int bytecode_patch(struct lttng_filter_bytecode_alloc **fb,
+int bytecode_patch(struct lttng_bytecode_alloc **fb,
const void *data,
uint16_t offset,
uint32_t len)
return ret;
/* Generate end of bytecode instruction */
- insn.op = FILTER_OP_RETURN;
+ insn.op = BYTECODE_OP_RETURN;
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
}
*/
static
int load_expression_legacy_match(const struct ir_load_expression *exp,
- enum filter_op *op_type,
+ enum bytecode_op *op_type,
char **symbol)
{
const struct ir_load_expression_op *op;
op = exp->child;
switch (op->type) {
case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT:
- *op_type = FILTER_OP_GET_CONTEXT_REF;
+ *op_type = BYTECODE_OP_GET_CONTEXT_REF;
if (append_str(symbol, "$ctx.")) {
return -ENOMEM;
}
need_dot = false;
break;
case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT:
- *op_type = FILTER_OP_GET_CONTEXT_REF;
+ *op_type = BYTECODE_OP_GET_CONTEXT_REF;
if (append_str(symbol, "$app.")) {
return -ENOMEM;
}
need_dot = false;
break;
case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT:
- *op_type = FILTER_OP_LOAD_FIELD_REF;
+ *op_type = BYTECODE_OP_LOAD_FIELD_REF;
need_dot = false;
break;
struct field_ref ref_offset;
uint32_t reloc_offset_u32;
uint16_t reloc_offset;
- enum filter_op op_type;
+ enum bytecode_op op_type;
char *symbol = NULL;
int ret;
switch (op->type) {
case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT:
{
- struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op);
- int ret;
+ ret = bytecode_push_get_context_root(&ctx->bytecode);
- insn = calloc(insn_len, 1);
- if (!insn)
- return -ENOMEM;
- insn->op = FILTER_OP_GET_CONTEXT_ROOT;
- ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
- free(insn);
if (ret) {
return ret;
}
+
break;
}
case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT:
{
- struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op);
- int ret;
+ ret = bytecode_push_get_app_context_root(
+ &ctx->bytecode);
- insn = calloc(insn_len, 1);
- if (!insn)
- return -ENOMEM;
- insn->op = FILTER_OP_GET_APP_CONTEXT_ROOT;
- ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
- free(insn);
if (ret) {
return ret;
}
+
break;
}
case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT:
{
- struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op);
- int ret;
+ ret = bytecode_push_get_payload_root(&ctx->bytecode);
- insn = calloc(insn_len, 1);
- if (!insn)
- return -ENOMEM;
- insn->op = FILTER_OP_GET_PAYLOAD_ROOT;
- ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
- free(insn);
if (ret) {
return ret;
}
+
break;
}
case IR_LOAD_EXPRESSION_GET_SYMBOL:
{
- struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op)
- + sizeof(struct get_symbol);
- struct get_symbol symbol_offset;
- uint32_t reloc_offset_u32;
- uint16_t reloc_offset;
- uint32_t bytecode_reloc_offset_u32;
- int ret;
+ ret = bytecode_push_get_symbol(&ctx->bytecode,
+ &ctx->bytecode_reloc, op->u.symbol);
- insn = calloc(insn_len, 1);
- if (!insn)
- return -ENOMEM;
- insn->op = FILTER_OP_GET_SYMBOL;
- bytecode_reloc_offset_u32 =
- bytecode_get_len(&ctx->bytecode_reloc->b)
- + sizeof(reloc_offset);
- symbol_offset.offset =
- (uint16_t) bytecode_reloc_offset_u32;
- memcpy(insn->data, &symbol_offset,
- sizeof(symbol_offset));
- /* reloc_offset points to struct load_op */
- reloc_offset_u32 = bytecode_get_len(&ctx->bytecode->b);
- if (reloc_offset_u32 > LTTNG_FILTER_MAX_LEN - 1) {
- free(insn);
- return -EINVAL;
- }
- reloc_offset = (uint16_t) reloc_offset_u32;
- ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
- if (ret) {
- free(insn);
- return ret;
- }
- /* append reloc */
- ret = bytecode_push(&ctx->bytecode_reloc, &reloc_offset,
- 1, sizeof(reloc_offset));
- if (ret) {
- free(insn);
- return ret;
- }
- ret = bytecode_push(&ctx->bytecode_reloc,
- op->u.symbol,
- 1, strlen(op->u.symbol) + 1);
- free(insn);
if (ret) {
return ret;
}
+
break;
}
case IR_LOAD_EXPRESSION_GET_INDEX:
{
- struct load_op *insn;
- uint32_t insn_len = sizeof(struct load_op)
- + sizeof(struct get_index_u64);
- struct get_index_u64 index;
- int ret;
+ ret = bytecode_push_get_index_u64(
+ &ctx->bytecode, op->u.index);
- insn = calloc(insn_len, 1);
- if (!insn)
- return -ENOMEM;
- insn->op = FILTER_OP_GET_INDEX_U64;
- index.index = op->u.index;
- memcpy(insn->data, &index, sizeof(index));
- ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
- free(insn);
if (ret) {
return ret;
}
+
break;
}
case IR_LOAD_EXPRESSION_LOAD_FIELD:
{
struct load_op *insn;
uint32_t insn_len = sizeof(struct load_op);
- int ret;
insn = calloc(insn_len, 1);
if (!insn)
return -ENOMEM;
- insn->op = FILTER_OP_LOAD_FIELD;
+ insn->op = BYTECODE_OP_LOAD_FIELD;
ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
free(insn);
if (ret) {
* that the appropriate matching function can be
* called. Also, see comment below.
*/
- insn->op = FILTER_OP_LOAD_STAR_GLOB_STRING;
+ insn->op = BYTECODE_OP_LOAD_STAR_GLOB_STRING;
break;
default:
/*
* can be anywhere in the string) is a special
* case.
*/
- insn->op = FILTER_OP_LOAD_STRING;
+ insn->op = BYTECODE_OP_LOAD_STRING;
break;
}
insn = calloc(insn_len, 1);
if (!insn)
return -ENOMEM;
- insn->op = FILTER_OP_LOAD_S64;
+ insn->op = BYTECODE_OP_LOAD_S64;
memcpy(insn->data, &node->u.load.u.num, sizeof(int64_t));
ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
free(insn);
insn = calloc(insn_len, 1);
if (!insn)
return -ENOMEM;
- insn->op = FILTER_OP_LOAD_DOUBLE;
+ insn->op = BYTECODE_OP_LOAD_DOUBLE;
memcpy(insn->data, &node->u.load.u.flt, sizeof(double));
ret = bytecode_push(&ctx->bytecode, insn, 1, insn_len);
free(insn);
/* Nothing to do. */
return 0;
case AST_UNARY_MINUS:
- insn.op = FILTER_OP_UNARY_MINUS;
+ insn.op = BYTECODE_OP_UNARY_MINUS;
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
case AST_UNARY_NOT:
- insn.op = FILTER_OP_UNARY_NOT;
+ insn.op = BYTECODE_OP_UNARY_NOT;
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
case AST_UNARY_BIT_NOT:
- insn.op = FILTER_OP_UNARY_BIT_NOT;
+ insn.op = BYTECODE_OP_UNARY_BIT_NOT;
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
}
}
return -EINVAL;
case AST_OP_MUL:
- insn.op = FILTER_OP_MUL;
+ insn.op = BYTECODE_OP_MUL;
break;
case AST_OP_DIV:
- insn.op = FILTER_OP_DIV;
+ insn.op = BYTECODE_OP_DIV;
break;
case AST_OP_MOD:
- insn.op = FILTER_OP_MOD;
+ insn.op = BYTECODE_OP_MOD;
break;
case AST_OP_PLUS:
- insn.op = FILTER_OP_PLUS;
+ insn.op = BYTECODE_OP_PLUS;
break;
case AST_OP_MINUS:
- insn.op = FILTER_OP_MINUS;
+ insn.op = BYTECODE_OP_MINUS;
break;
case AST_OP_BIT_RSHIFT:
- insn.op = FILTER_OP_BIT_RSHIFT;
+ insn.op = BYTECODE_OP_BIT_RSHIFT;
break;
case AST_OP_BIT_LSHIFT:
- insn.op = FILTER_OP_BIT_LSHIFT;
+ insn.op = BYTECODE_OP_BIT_LSHIFT;
break;
case AST_OP_BIT_AND:
- insn.op = FILTER_OP_BIT_AND;
+ insn.op = BYTECODE_OP_BIT_AND;
break;
case AST_OP_BIT_OR:
- insn.op = FILTER_OP_BIT_OR;
+ insn.op = BYTECODE_OP_BIT_OR;
break;
case AST_OP_BIT_XOR:
- insn.op = FILTER_OP_BIT_XOR;
+ insn.op = BYTECODE_OP_BIT_XOR;
break;
case AST_OP_EQ:
- insn.op = FILTER_OP_EQ;
+ insn.op = BYTECODE_OP_EQ;
break;
case AST_OP_NE:
- insn.op = FILTER_OP_NE;
+ insn.op = BYTECODE_OP_NE;
break;
case AST_OP_GT:
- insn.op = FILTER_OP_GT;
+ insn.op = BYTECODE_OP_GT;
break;
case AST_OP_LT:
- insn.op = FILTER_OP_LT;
+ insn.op = BYTECODE_OP_LT;
break;
case AST_OP_GE:
- insn.op = FILTER_OP_GE;
+ insn.op = BYTECODE_OP_GE;
break;
case AST_OP_LE:
- insn.op = FILTER_OP_LE;
+ insn.op = BYTECODE_OP_LE;
break;
}
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
if (node->u.binary.left->data_type == IR_DATA_FIELD_REF
|| node->u.binary.left->data_type == IR_DATA_GET_CONTEXT_REF
|| node->u.binary.left->data_type == IR_DATA_EXPRESSION) {
- cast_insn.op = FILTER_OP_CAST_TO_S64;
+ cast_insn.op = BYTECODE_OP_CAST_TO_S64;
} else {
- cast_insn.op = FILTER_OP_CAST_DOUBLE_TO_S64;
+ cast_insn.op = BYTECODE_OP_CAST_DOUBLE_TO_S64;
}
ret = bytecode_push(&ctx->bytecode, &cast_insn,
1, sizeof(cast_insn));
return -EINVAL;
case AST_OP_AND:
- insn.op = FILTER_OP_AND;
+ insn.op = BYTECODE_OP_AND;
break;
case AST_OP_OR:
- insn.op = FILTER_OP_OR;
+ insn.op = BYTECODE_OP_OR;
break;
}
insn.skip_offset = (uint16_t) -1UL; /* Temporary */
if (node->u.binary.right->data_type == IR_DATA_FIELD_REF
|| node->u.binary.right->data_type == IR_DATA_GET_CONTEXT_REF
|| node->u.binary.right->data_type == IR_DATA_EXPRESSION) {
- cast_insn.op = FILTER_OP_CAST_TO_S64;
+ cast_insn.op = BYTECODE_OP_CAST_TO_S64;
} else {
- cast_insn.op = FILTER_OP_CAST_DOUBLE_TO_S64;
+ cast_insn.op = BYTECODE_OP_CAST_DOUBLE_TO_S64;
}
ret = bytecode_push(&ctx->bytecode, &cast_insn,
1, sizeof(cast_insn));
}
}
-LTTNG_HIDDEN
void filter_bytecode_free(struct filter_parser_ctx *ctx)
{
if (!ctx) {
}
}
-LTTNG_HIDDEN
int filter_visitor_bytecode_generate(struct filter_parser_ctx *ctx)
{
int ret;