1 /* SPDX-License-Identifier: MIT
3 * lttng-filter-interpreter.c
5 * LTTng modules filter interpreter.
7 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <wrapper/uaccess.h>
11 #include <wrapper/objtool.h>
12 #include <wrapper/types.h>
13 #include <linux/swab.h>
15 #include <lttng/filter.h>
16 #include <lttng/string-utils.h>
18 LTTNG_STACK_FRAME_NON_STANDARD(lttng_filter_interpret_bytecode
);
21 * get_char should be called with page fault handler disabled if it is expected
22 * to handle user-space read.
25 char get_char(struct estack_entry
*reg
, size_t offset
)
27 if (unlikely(offset
>= reg
->u
.s
.seq_len
))
32 /* Handle invalid access as end of string. */
33 if (unlikely(!lttng_access_ok(VERIFY_READ
,
34 reg
->u
.s
.user_str
+ offset
,
37 /* Handle fault (nonzero return value) as end of string. */
38 if (unlikely(__copy_from_user_inatomic(&c
,
39 reg
->u
.s
.user_str
+ offset
,
44 return reg
->u
.s
.str
[offset
];
50 * -2: unknown escape char.
54 int parse_char(struct estack_entry
*reg
, char *c
, size_t *offset
)
59 *c
= get_char(reg
, *offset
);
75 char get_char_at_cb(size_t at
, void *data
)
77 return get_char(data
, at
);
81 int stack_star_glob_match(struct estack
*stack
, int top
, const char *cmp_type
)
83 bool has_user
= false;
85 struct estack_entry
*pattern_reg
;
86 struct estack_entry
*candidate_reg
;
88 /* Disable the page fault handler when reading from userspace. */
89 if (estack_bx(stack
, top
)->u
.s
.user
90 || estack_ax(stack
, top
)->u
.s
.user
) {
95 /* Find out which side is the pattern vs. the candidate. */
96 if (estack_ax(stack
, top
)->u
.s
.literal_type
== ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
) {
97 pattern_reg
= estack_ax(stack
, top
);
98 candidate_reg
= estack_bx(stack
, top
);
100 pattern_reg
= estack_bx(stack
, top
);
101 candidate_reg
= estack_ax(stack
, top
);
104 /* Perform the match operation. */
105 result
= !strutils_star_glob_match_char_cb(get_char_at_cb
,
106 pattern_reg
, get_char_at_cb
, candidate_reg
);
114 int stack_strcmp(struct estack
*stack
, int top
, const char *cmp_type
)
116 size_t offset_bx
= 0, offset_ax
= 0;
117 int diff
, has_user
= 0;
119 if (estack_bx(stack
, top
)->u
.s
.user
120 || estack_ax(stack
, top
)->u
.s
.user
) {
128 char char_bx
, char_ax
;
130 char_bx
= get_char(estack_bx(stack
, top
), offset_bx
);
131 char_ax
= get_char(estack_ax(stack
, top
), offset_ax
);
133 if (unlikely(char_bx
== '\0')) {
134 if (char_ax
== '\0') {
138 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
139 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
140 ret
= parse_char(estack_ax(stack
, top
),
141 &char_ax
, &offset_ax
);
151 if (unlikely(char_ax
== '\0')) {
152 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
153 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
154 ret
= parse_char(estack_bx(stack
, top
),
155 &char_bx
, &offset_bx
);
164 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
165 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
166 ret
= parse_char(estack_bx(stack
, top
),
167 &char_bx
, &offset_bx
);
171 } else if (ret
== -2) {
174 /* else compare both char */
176 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
177 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
178 ret
= parse_char(estack_ax(stack
, top
),
179 &char_ax
, &offset_ax
);
183 } else if (ret
== -2) {
200 diff
= char_bx
- char_ax
;
212 uint64_t lttng_filter_false(void *filter_data
,
213 struct lttng_probe_ctx
*lttng_probe_ctx
,
214 const char *filter_stack_data
)
216 return LTTNG_FILTER_DISCARD
;
219 #ifdef INTERPRETER_USE_SWITCH
222 * Fallback for compilers that do not support taking address of labels.
226 start_pc = &bytecode->data[0]; \
227 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
229 dbg_printk("LTTng: Executing op %s (%u)\n", \
230 lttng_filter_print_op((unsigned int) *(filter_opcode_t *) pc), \
231 (unsigned int) *(filter_opcode_t *) pc); \
232 switch (*(filter_opcode_t *) pc) {
234 #define OP(name) case name
244 * Dispatch-table based interpreter.
248 start_pc = &bytecode->code[0]; \
249 pc = next_pc = start_pc; \
250 if (unlikely(pc - start_pc >= bytecode->len)) \
252 goto *dispatch[*(filter_opcode_t *) pc];
259 goto *dispatch[*(filter_opcode_t *) pc];
265 #define IS_INTEGER_REGISTER(reg_type) \
266 (reg_type == REG_S64 || reg_type == REG_U64)
268 static int context_get_index(struct lttng_probe_ctx
*lttng_probe_ctx
,
269 struct load_ptr
*ptr
,
273 struct lttng_ctx_field
*ctx_field
;
274 struct lttng_event_field
*field
;
275 union lttng_ctx_value v
;
277 ctx_field
= <tng_static_ctx
->fields
[idx
];
278 field
= &ctx_field
->event_field
;
279 ptr
->type
= LOAD_OBJECT
;
280 /* field is only used for types nested within variants. */
283 switch (field
->type
.atype
) {
285 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
286 if (field
->type
.u
.integer
.signedness
) {
287 ptr
->object_type
= OBJECT_TYPE_S64
;
289 ptr
->ptr
= &ptr
->u
.s64
;
291 ptr
->object_type
= OBJECT_TYPE_U64
;
292 ptr
->u
.u64
= v
.s64
; /* Cast. */
293 ptr
->ptr
= &ptr
->u
.u64
;
296 case atype_enum_nestable
:
298 const struct lttng_integer_type
*itype
=
299 &field
->type
.u
.enum_nestable
.container_type
->u
.integer
;
301 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
302 if (itype
->signedness
) {
303 ptr
->object_type
= OBJECT_TYPE_S64
;
305 ptr
->ptr
= &ptr
->u
.s64
;
307 ptr
->object_type
= OBJECT_TYPE_U64
;
308 ptr
->u
.u64
= v
.s64
; /* Cast. */
309 ptr
->ptr
= &ptr
->u
.u64
;
313 case atype_array_nestable
:
314 if (!lttng_is_bytewise_integer(field
->type
.u
.array_nestable
.elem_type
)) {
315 printk(KERN_WARNING
"LTTng: filter: Array nesting only supports integer types.\n");
318 if (field
->type
.u
.array_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
319 printk(KERN_WARNING
"LTTng: filter: Only string arrays are supported for contexts.\n");
322 ptr
->object_type
= OBJECT_TYPE_STRING
;
323 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
326 case atype_sequence_nestable
:
327 if (!lttng_is_bytewise_integer(field
->type
.u
.sequence_nestable
.elem_type
)) {
328 printk(KERN_WARNING
"LTTng: filter: Sequence nesting only supports integer types.\n");
331 if (field
->type
.u
.sequence_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
332 printk(KERN_WARNING
"LTTng: filter: Only string sequences are supported for contexts.\n");
335 ptr
->object_type
= OBJECT_TYPE_STRING
;
336 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
340 ptr
->object_type
= OBJECT_TYPE_STRING
;
341 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
344 case atype_struct_nestable
:
345 printk(KERN_WARNING
"LTTng: filter: Structure type cannot be loaded.\n");
347 case atype_variant_nestable
:
348 printk(KERN_WARNING
"LTTng: filter: Variant type cannot be loaded.\n");
351 printk(KERN_WARNING
"LTTng: filter: Unknown type: %d", (int) field
->type
.atype
);
357 static int dynamic_get_index(struct lttng_probe_ctx
*lttng_probe_ctx
,
358 struct bytecode_runtime
*runtime
,
359 uint64_t index
, struct estack_entry
*stack_top
)
362 const struct filter_get_index_data
*gid
;
365 * Types nested within variants need to perform dynamic lookup
366 * based on the field descriptions. LTTng-UST does not implement
369 if (stack_top
->u
.ptr
.field
)
371 gid
= (const struct filter_get_index_data
*) &runtime
->data
[index
];
372 switch (stack_top
->u
.ptr
.type
) {
374 switch (stack_top
->u
.ptr
.object_type
) {
375 case OBJECT_TYPE_ARRAY
:
379 WARN_ON_ONCE(gid
->offset
>= gid
->array_len
);
380 /* Skip count (unsigned long) */
381 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
382 ptr
= ptr
+ gid
->offset
;
383 stack_top
->u
.ptr
.ptr
= ptr
;
384 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
385 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
386 /* field is only used for types nested within variants. */
387 stack_top
->u
.ptr
.field
= NULL
;
390 case OBJECT_TYPE_SEQUENCE
:
395 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
396 ptr_seq_len
= *(unsigned long *) stack_top
->u
.ptr
.ptr
;
397 if (gid
->offset
>= gid
->elem
.len
* ptr_seq_len
) {
401 ptr
= ptr
+ gid
->offset
;
402 stack_top
->u
.ptr
.ptr
= ptr
;
403 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
404 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
405 /* field is only used for types nested within variants. */
406 stack_top
->u
.ptr
.field
= NULL
;
409 case OBJECT_TYPE_STRUCT
:
410 printk(KERN_WARNING
"LTTng: filter: Nested structures are not supported yet.\n");
413 case OBJECT_TYPE_VARIANT
:
415 printk(KERN_WARNING
"LTTng: filter: Unexpected get index type %d",
416 (int) stack_top
->u
.ptr
.object_type
);
421 case LOAD_ROOT_CONTEXT
:
422 case LOAD_ROOT_APP_CONTEXT
: /* Fall-through */
424 ret
= context_get_index(lttng_probe_ctx
,
432 case LOAD_ROOT_PAYLOAD
:
433 stack_top
->u
.ptr
.ptr
+= gid
->offset
;
434 if (gid
->elem
.type
== OBJECT_TYPE_STRING
)
435 stack_top
->u
.ptr
.ptr
= *(const char * const *) stack_top
->u
.ptr
.ptr
;
436 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
437 stack_top
->u
.ptr
.type
= LOAD_OBJECT
;
438 /* field is only used for types nested within variants. */
439 stack_top
->u
.ptr
.field
= NULL
;
448 static int dynamic_load_field(struct estack_entry
*stack_top
)
452 switch (stack_top
->u
.ptr
.type
) {
455 case LOAD_ROOT_CONTEXT
:
456 case LOAD_ROOT_APP_CONTEXT
:
457 case LOAD_ROOT_PAYLOAD
:
459 dbg_printk("Filter warning: cannot load root, missing field name.\n");
463 switch (stack_top
->u
.ptr
.object_type
) {
465 dbg_printk("op load field s8\n");
466 stack_top
->u
.v
= *(int8_t *) stack_top
->u
.ptr
.ptr
;
467 stack_top
->type
= REG_S64
;
469 case OBJECT_TYPE_S16
:
473 dbg_printk("op load field s16\n");
474 tmp
= *(int16_t *) stack_top
->u
.ptr
.ptr
;
475 if (stack_top
->u
.ptr
.rev_bo
)
477 stack_top
->u
.v
= tmp
;
478 stack_top
->type
= REG_S64
;
481 case OBJECT_TYPE_S32
:
485 dbg_printk("op load field s32\n");
486 tmp
= *(int32_t *) stack_top
->u
.ptr
.ptr
;
487 if (stack_top
->u
.ptr
.rev_bo
)
489 stack_top
->u
.v
= tmp
;
490 stack_top
->type
= REG_S64
;
493 case OBJECT_TYPE_S64
:
497 dbg_printk("op load field s64\n");
498 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
499 if (stack_top
->u
.ptr
.rev_bo
)
501 stack_top
->u
.v
= tmp
;
502 stack_top
->type
= REG_S64
;
506 dbg_printk("op load field u8\n");
507 stack_top
->u
.v
= *(uint8_t *) stack_top
->u
.ptr
.ptr
;
508 stack_top
->type
= REG_U64
;
510 case OBJECT_TYPE_U16
:
514 dbg_printk("op load field u16\n");
515 tmp
= *(uint16_t *) stack_top
->u
.ptr
.ptr
;
516 if (stack_top
->u
.ptr
.rev_bo
)
518 stack_top
->u
.v
= tmp
;
519 stack_top
->type
= REG_U64
;
522 case OBJECT_TYPE_U32
:
526 dbg_printk("op load field u32\n");
527 tmp
= *(uint32_t *) stack_top
->u
.ptr
.ptr
;
528 if (stack_top
->u
.ptr
.rev_bo
)
530 stack_top
->u
.v
= tmp
;
531 stack_top
->type
= REG_U64
;
534 case OBJECT_TYPE_U64
:
538 dbg_printk("op load field u64\n");
539 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
540 if (stack_top
->u
.ptr
.rev_bo
)
542 stack_top
->u
.v
= tmp
;
543 stack_top
->type
= REG_U64
;
546 case OBJECT_TYPE_STRING
:
550 dbg_printk("op load field string\n");
551 str
= (const char *) stack_top
->u
.ptr
.ptr
;
552 stack_top
->u
.s
.str
= str
;
553 if (unlikely(!stack_top
->u
.s
.str
)) {
554 dbg_printk("Filter warning: loading a NULL string.\n");
558 stack_top
->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
559 stack_top
->u
.s
.literal_type
=
560 ESTACK_STRING_LITERAL_TYPE_NONE
;
561 stack_top
->type
= REG_STRING
;
564 case OBJECT_TYPE_STRING_SEQUENCE
:
568 dbg_printk("op load field string sequence\n");
569 ptr
= stack_top
->u
.ptr
.ptr
;
570 stack_top
->u
.s
.seq_len
= *(unsigned long *) ptr
;
571 stack_top
->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
572 if (unlikely(!stack_top
->u
.s
.str
)) {
573 dbg_printk("Filter warning: loading a NULL sequence.\n");
577 stack_top
->u
.s
.literal_type
=
578 ESTACK_STRING_LITERAL_TYPE_NONE
;
579 stack_top
->type
= REG_STRING
;
582 case OBJECT_TYPE_DYNAMIC
:
584 * Dynamic types in context are looked up
585 * by context get index.
589 case OBJECT_TYPE_DOUBLE
:
592 case OBJECT_TYPE_SEQUENCE
:
593 case OBJECT_TYPE_ARRAY
:
594 case OBJECT_TYPE_STRUCT
:
595 case OBJECT_TYPE_VARIANT
:
596 printk(KERN_WARNING
"LTTng: filter: Sequences, arrays, struct and variant cannot be loaded (nested types).\n");
607 * Return 0 (discard), or raise the 0x1 flag (log event).
608 * Currently, other flags are kept for future extensions and have no
611 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
612 struct lttng_probe_ctx
*lttng_probe_ctx
,
613 const char *filter_stack_data
)
615 struct bytecode_runtime
*bytecode
= filter_data
;
616 void *pc
, *next_pc
, *start_pc
;
619 struct estack _stack
;
620 struct estack
*stack
= &_stack
;
621 register int64_t ax
= 0, bx
= 0;
622 register enum entry_type ax_t
= REG_TYPE_UNKNOWN
, bx_t
= REG_TYPE_UNKNOWN
;
623 register int top
= FILTER_STACK_EMPTY
;
624 #ifndef INTERPRETER_USE_SWITCH
625 static void *dispatch
[NR_FILTER_OPS
] = {
626 [ FILTER_OP_UNKNOWN
] = &&LABEL_FILTER_OP_UNKNOWN
,
628 [ FILTER_OP_RETURN
] = &&LABEL_FILTER_OP_RETURN
,
631 [ FILTER_OP_MUL
] = &&LABEL_FILTER_OP_MUL
,
632 [ FILTER_OP_DIV
] = &&LABEL_FILTER_OP_DIV
,
633 [ FILTER_OP_MOD
] = &&LABEL_FILTER_OP_MOD
,
634 [ FILTER_OP_PLUS
] = &&LABEL_FILTER_OP_PLUS
,
635 [ FILTER_OP_MINUS
] = &&LABEL_FILTER_OP_MINUS
,
636 [ FILTER_OP_BIT_RSHIFT
] = &&LABEL_FILTER_OP_BIT_RSHIFT
,
637 [ FILTER_OP_BIT_LSHIFT
] = &&LABEL_FILTER_OP_BIT_LSHIFT
,
638 [ FILTER_OP_BIT_AND
] = &&LABEL_FILTER_OP_BIT_AND
,
639 [ FILTER_OP_BIT_OR
] = &&LABEL_FILTER_OP_BIT_OR
,
640 [ FILTER_OP_BIT_XOR
] = &&LABEL_FILTER_OP_BIT_XOR
,
642 /* binary comparators */
643 [ FILTER_OP_EQ
] = &&LABEL_FILTER_OP_EQ
,
644 [ FILTER_OP_NE
] = &&LABEL_FILTER_OP_NE
,
645 [ FILTER_OP_GT
] = &&LABEL_FILTER_OP_GT
,
646 [ FILTER_OP_LT
] = &&LABEL_FILTER_OP_LT
,
647 [ FILTER_OP_GE
] = &&LABEL_FILTER_OP_GE
,
648 [ FILTER_OP_LE
] = &&LABEL_FILTER_OP_LE
,
650 /* string binary comparator */
651 [ FILTER_OP_EQ_STRING
] = &&LABEL_FILTER_OP_EQ_STRING
,
652 [ FILTER_OP_NE_STRING
] = &&LABEL_FILTER_OP_NE_STRING
,
653 [ FILTER_OP_GT_STRING
] = &&LABEL_FILTER_OP_GT_STRING
,
654 [ FILTER_OP_LT_STRING
] = &&LABEL_FILTER_OP_LT_STRING
,
655 [ FILTER_OP_GE_STRING
] = &&LABEL_FILTER_OP_GE_STRING
,
656 [ FILTER_OP_LE_STRING
] = &&LABEL_FILTER_OP_LE_STRING
,
658 /* globbing pattern binary comparator */
659 [ FILTER_OP_EQ_STAR_GLOB_STRING
] = &&LABEL_FILTER_OP_EQ_STAR_GLOB_STRING
,
660 [ FILTER_OP_NE_STAR_GLOB_STRING
] = &&LABEL_FILTER_OP_NE_STAR_GLOB_STRING
,
662 /* s64 binary comparator */
663 [ FILTER_OP_EQ_S64
] = &&LABEL_FILTER_OP_EQ_S64
,
664 [ FILTER_OP_NE_S64
] = &&LABEL_FILTER_OP_NE_S64
,
665 [ FILTER_OP_GT_S64
] = &&LABEL_FILTER_OP_GT_S64
,
666 [ FILTER_OP_LT_S64
] = &&LABEL_FILTER_OP_LT_S64
,
667 [ FILTER_OP_GE_S64
] = &&LABEL_FILTER_OP_GE_S64
,
668 [ FILTER_OP_LE_S64
] = &&LABEL_FILTER_OP_LE_S64
,
670 /* double binary comparator */
671 [ FILTER_OP_EQ_DOUBLE
] = &&LABEL_FILTER_OP_EQ_DOUBLE
,
672 [ FILTER_OP_NE_DOUBLE
] = &&LABEL_FILTER_OP_NE_DOUBLE
,
673 [ FILTER_OP_GT_DOUBLE
] = &&LABEL_FILTER_OP_GT_DOUBLE
,
674 [ FILTER_OP_LT_DOUBLE
] = &&LABEL_FILTER_OP_LT_DOUBLE
,
675 [ FILTER_OP_GE_DOUBLE
] = &&LABEL_FILTER_OP_GE_DOUBLE
,
676 [ FILTER_OP_LE_DOUBLE
] = &&LABEL_FILTER_OP_LE_DOUBLE
,
678 /* Mixed S64-double binary comparators */
679 [ FILTER_OP_EQ_DOUBLE_S64
] = &&LABEL_FILTER_OP_EQ_DOUBLE_S64
,
680 [ FILTER_OP_NE_DOUBLE_S64
] = &&LABEL_FILTER_OP_NE_DOUBLE_S64
,
681 [ FILTER_OP_GT_DOUBLE_S64
] = &&LABEL_FILTER_OP_GT_DOUBLE_S64
,
682 [ FILTER_OP_LT_DOUBLE_S64
] = &&LABEL_FILTER_OP_LT_DOUBLE_S64
,
683 [ FILTER_OP_GE_DOUBLE_S64
] = &&LABEL_FILTER_OP_GE_DOUBLE_S64
,
684 [ FILTER_OP_LE_DOUBLE_S64
] = &&LABEL_FILTER_OP_LE_DOUBLE_S64
,
686 [ FILTER_OP_EQ_S64_DOUBLE
] = &&LABEL_FILTER_OP_EQ_S64_DOUBLE
,
687 [ FILTER_OP_NE_S64_DOUBLE
] = &&LABEL_FILTER_OP_NE_S64_DOUBLE
,
688 [ FILTER_OP_GT_S64_DOUBLE
] = &&LABEL_FILTER_OP_GT_S64_DOUBLE
,
689 [ FILTER_OP_LT_S64_DOUBLE
] = &&LABEL_FILTER_OP_LT_S64_DOUBLE
,
690 [ FILTER_OP_GE_S64_DOUBLE
] = &&LABEL_FILTER_OP_GE_S64_DOUBLE
,
691 [ FILTER_OP_LE_S64_DOUBLE
] = &&LABEL_FILTER_OP_LE_S64_DOUBLE
,
694 [ FILTER_OP_UNARY_PLUS
] = &&LABEL_FILTER_OP_UNARY_PLUS
,
695 [ FILTER_OP_UNARY_MINUS
] = &&LABEL_FILTER_OP_UNARY_MINUS
,
696 [ FILTER_OP_UNARY_NOT
] = &&LABEL_FILTER_OP_UNARY_NOT
,
697 [ FILTER_OP_UNARY_PLUS_S64
] = &&LABEL_FILTER_OP_UNARY_PLUS_S64
,
698 [ FILTER_OP_UNARY_MINUS_S64
] = &&LABEL_FILTER_OP_UNARY_MINUS_S64
,
699 [ FILTER_OP_UNARY_NOT_S64
] = &&LABEL_FILTER_OP_UNARY_NOT_S64
,
700 [ FILTER_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_PLUS_DOUBLE
,
701 [ FILTER_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_MINUS_DOUBLE
,
702 [ FILTER_OP_UNARY_NOT_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_NOT_DOUBLE
,
705 [ FILTER_OP_AND
] = &&LABEL_FILTER_OP_AND
,
706 [ FILTER_OP_OR
] = &&LABEL_FILTER_OP_OR
,
709 [ FILTER_OP_LOAD_FIELD_REF
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF
,
710 [ FILTER_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_STRING
,
711 [ FILTER_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_SEQUENCE
,
712 [ FILTER_OP_LOAD_FIELD_REF_S64
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_S64
,
713 [ FILTER_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_DOUBLE
,
715 /* load from immediate operand */
716 [ FILTER_OP_LOAD_STRING
] = &&LABEL_FILTER_OP_LOAD_STRING
,
717 [ FILTER_OP_LOAD_STAR_GLOB_STRING
] = &&LABEL_FILTER_OP_LOAD_STAR_GLOB_STRING
,
718 [ FILTER_OP_LOAD_S64
] = &&LABEL_FILTER_OP_LOAD_S64
,
719 [ FILTER_OP_LOAD_DOUBLE
] = &&LABEL_FILTER_OP_LOAD_DOUBLE
,
722 [ FILTER_OP_CAST_TO_S64
] = &&LABEL_FILTER_OP_CAST_TO_S64
,
723 [ FILTER_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_FILTER_OP_CAST_DOUBLE_TO_S64
,
724 [ FILTER_OP_CAST_NOP
] = &&LABEL_FILTER_OP_CAST_NOP
,
726 /* get context ref */
727 [ FILTER_OP_GET_CONTEXT_REF
] = &&LABEL_FILTER_OP_GET_CONTEXT_REF
,
728 [ FILTER_OP_GET_CONTEXT_REF_STRING
] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_STRING
,
729 [ FILTER_OP_GET_CONTEXT_REF_S64
] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_S64
,
730 [ FILTER_OP_GET_CONTEXT_REF_DOUBLE
] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_DOUBLE
,
732 /* load userspace field ref */
733 [ FILTER_OP_LOAD_FIELD_REF_USER_STRING
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_USER_STRING
,
734 [ FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
,
736 /* Instructions for recursive traversal through composed types. */
737 [ FILTER_OP_GET_CONTEXT_ROOT
] = &&LABEL_FILTER_OP_GET_CONTEXT_ROOT
,
738 [ FILTER_OP_GET_APP_CONTEXT_ROOT
] = &&LABEL_FILTER_OP_GET_APP_CONTEXT_ROOT
,
739 [ FILTER_OP_GET_PAYLOAD_ROOT
] = &&LABEL_FILTER_OP_GET_PAYLOAD_ROOT
,
741 [ FILTER_OP_GET_SYMBOL
] = &&LABEL_FILTER_OP_GET_SYMBOL
,
742 [ FILTER_OP_GET_SYMBOL_FIELD
] = &&LABEL_FILTER_OP_GET_SYMBOL_FIELD
,
743 [ FILTER_OP_GET_INDEX_U16
] = &&LABEL_FILTER_OP_GET_INDEX_U16
,
744 [ FILTER_OP_GET_INDEX_U64
] = &&LABEL_FILTER_OP_GET_INDEX_U64
,
746 [ FILTER_OP_LOAD_FIELD
] = &&LABEL_FILTER_OP_LOAD_FIELD
,
747 [ FILTER_OP_LOAD_FIELD_S8
] = &&LABEL_FILTER_OP_LOAD_FIELD_S8
,
748 [ FILTER_OP_LOAD_FIELD_S16
] = &&LABEL_FILTER_OP_LOAD_FIELD_S16
,
749 [ FILTER_OP_LOAD_FIELD_S32
] = &&LABEL_FILTER_OP_LOAD_FIELD_S32
,
750 [ FILTER_OP_LOAD_FIELD_S64
] = &&LABEL_FILTER_OP_LOAD_FIELD_S64
,
751 [ FILTER_OP_LOAD_FIELD_U8
] = &&LABEL_FILTER_OP_LOAD_FIELD_U8
,
752 [ FILTER_OP_LOAD_FIELD_U16
] = &&LABEL_FILTER_OP_LOAD_FIELD_U16
,
753 [ FILTER_OP_LOAD_FIELD_U32
] = &&LABEL_FILTER_OP_LOAD_FIELD_U32
,
754 [ FILTER_OP_LOAD_FIELD_U64
] = &&LABEL_FILTER_OP_LOAD_FIELD_U64
,
755 [ FILTER_OP_LOAD_FIELD_STRING
] = &&LABEL_FILTER_OP_LOAD_FIELD_STRING
,
756 [ FILTER_OP_LOAD_FIELD_SEQUENCE
] = &&LABEL_FILTER_OP_LOAD_FIELD_SEQUENCE
,
757 [ FILTER_OP_LOAD_FIELD_DOUBLE
] = &&LABEL_FILTER_OP_LOAD_FIELD_DOUBLE
,
759 [ FILTER_OP_UNARY_BIT_NOT
] = &&LABEL_FILTER_OP_UNARY_BIT_NOT
,
761 [ FILTER_OP_RETURN_S64
] = &&LABEL_FILTER_OP_RETURN_S64
,
763 #endif /* #ifndef INTERPRETER_USE_SWITCH */
767 OP(FILTER_OP_UNKNOWN
):
768 OP(FILTER_OP_LOAD_FIELD_REF
):
769 OP(FILTER_OP_GET_CONTEXT_REF
):
770 #ifdef INTERPRETER_USE_SWITCH
772 #endif /* INTERPRETER_USE_SWITCH */
773 printk(KERN_WARNING
"LTTng: filter: unknown bytecode op %u\n",
774 (unsigned int) *(filter_opcode_t
*) pc
);
778 OP(FILTER_OP_RETURN
):
779 OP(FILTER_OP_RETURN_S64
):
780 /* LTTNG_FILTER_DISCARD or LTTNG_FILTER_RECORD_FLAG */
781 switch (estack_ax_t
) {
784 retval
= !!estack_ax_v
;
789 case REG_STAR_GLOB_STRING
:
790 case REG_TYPE_UNKNOWN
:
803 printk(KERN_WARNING
"LTTng: filter: unsupported bytecode op %u\n",
804 (unsigned int) *(filter_opcode_t
*) pc
);
814 printk(KERN_WARNING
"LTTng: filter: unsupported non-specialized bytecode op %u\n",
815 (unsigned int) *(filter_opcode_t
*) pc
);
819 OP(FILTER_OP_EQ_STRING
):
823 res
= (stack_strcmp(stack
, top
, "==") == 0);
824 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
826 estack_ax_t
= REG_S64
;
827 next_pc
+= sizeof(struct binary_op
);
830 OP(FILTER_OP_NE_STRING
):
834 res
= (stack_strcmp(stack
, top
, "!=") != 0);
835 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
837 estack_ax_t
= REG_S64
;
838 next_pc
+= sizeof(struct binary_op
);
841 OP(FILTER_OP_GT_STRING
):
845 res
= (stack_strcmp(stack
, top
, ">") > 0);
846 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
848 estack_ax_t
= REG_S64
;
849 next_pc
+= sizeof(struct binary_op
);
852 OP(FILTER_OP_LT_STRING
):
856 res
= (stack_strcmp(stack
, top
, "<") < 0);
857 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
859 estack_ax_t
= REG_S64
;
860 next_pc
+= sizeof(struct binary_op
);
863 OP(FILTER_OP_GE_STRING
):
867 res
= (stack_strcmp(stack
, top
, ">=") >= 0);
868 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
870 estack_ax_t
= REG_S64
;
871 next_pc
+= sizeof(struct binary_op
);
874 OP(FILTER_OP_LE_STRING
):
878 res
= (stack_strcmp(stack
, top
, "<=") <= 0);
879 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
881 estack_ax_t
= REG_S64
;
882 next_pc
+= sizeof(struct binary_op
);
886 OP(FILTER_OP_EQ_STAR_GLOB_STRING
):
890 res
= (stack_star_glob_match(stack
, top
, "==") == 0);
891 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
893 estack_ax_t
= REG_S64
;
894 next_pc
+= sizeof(struct binary_op
);
897 OP(FILTER_OP_NE_STAR_GLOB_STRING
):
901 res
= (stack_star_glob_match(stack
, top
, "!=") != 0);
902 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
904 estack_ax_t
= REG_S64
;
905 next_pc
+= sizeof(struct binary_op
);
909 OP(FILTER_OP_EQ_S64
):
913 res
= (estack_bx_v
== estack_ax_v
);
914 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
916 estack_ax_t
= REG_S64
;
917 next_pc
+= sizeof(struct binary_op
);
920 OP(FILTER_OP_NE_S64
):
924 res
= (estack_bx_v
!= estack_ax_v
);
925 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
927 estack_ax_t
= REG_S64
;
928 next_pc
+= sizeof(struct binary_op
);
931 OP(FILTER_OP_GT_S64
):
935 res
= (estack_bx_v
> estack_ax_v
);
936 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
938 estack_ax_t
= REG_S64
;
939 next_pc
+= sizeof(struct binary_op
);
942 OP(FILTER_OP_LT_S64
):
946 res
= (estack_bx_v
< estack_ax_v
);
947 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
949 estack_ax_t
= REG_S64
;
950 next_pc
+= sizeof(struct binary_op
);
953 OP(FILTER_OP_GE_S64
):
957 res
= (estack_bx_v
>= estack_ax_v
);
958 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
960 estack_ax_t
= REG_S64
;
961 next_pc
+= sizeof(struct binary_op
);
964 OP(FILTER_OP_LE_S64
):
968 res
= (estack_bx_v
<= estack_ax_v
);
969 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
971 estack_ax_t
= REG_S64
;
972 next_pc
+= sizeof(struct binary_op
);
976 OP(FILTER_OP_EQ_DOUBLE
):
977 OP(FILTER_OP_NE_DOUBLE
):
978 OP(FILTER_OP_GT_DOUBLE
):
979 OP(FILTER_OP_LT_DOUBLE
):
980 OP(FILTER_OP_GE_DOUBLE
):
981 OP(FILTER_OP_LE_DOUBLE
):
987 /* Mixed S64-double binary comparators */
988 OP(FILTER_OP_EQ_DOUBLE_S64
):
989 OP(FILTER_OP_NE_DOUBLE_S64
):
990 OP(FILTER_OP_GT_DOUBLE_S64
):
991 OP(FILTER_OP_LT_DOUBLE_S64
):
992 OP(FILTER_OP_GE_DOUBLE_S64
):
993 OP(FILTER_OP_LE_DOUBLE_S64
):
994 OP(FILTER_OP_EQ_S64_DOUBLE
):
995 OP(FILTER_OP_NE_S64_DOUBLE
):
996 OP(FILTER_OP_GT_S64_DOUBLE
):
997 OP(FILTER_OP_LT_S64_DOUBLE
):
998 OP(FILTER_OP_GE_S64_DOUBLE
):
999 OP(FILTER_OP_LE_S64_DOUBLE
):
1004 OP(FILTER_OP_BIT_RSHIFT
):
1008 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1013 /* Catch undefined behavior. */
1014 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1018 res
= ((uint64_t) estack_bx_v
>> (uint32_t) estack_ax_v
);
1019 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1021 estack_ax_t
= REG_U64
;
1022 next_pc
+= sizeof(struct binary_op
);
1025 OP(FILTER_OP_BIT_LSHIFT
):
1029 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1034 /* Catch undefined behavior. */
1035 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1039 res
= ((uint64_t) estack_bx_v
<< (uint32_t) estack_ax_v
);
1040 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1042 estack_ax_t
= REG_U64
;
1043 next_pc
+= sizeof(struct binary_op
);
1046 OP(FILTER_OP_BIT_AND
):
1050 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1055 res
= ((uint64_t) estack_bx_v
& (uint64_t) estack_ax_v
);
1056 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1058 estack_ax_t
= REG_U64
;
1059 next_pc
+= sizeof(struct binary_op
);
1062 OP(FILTER_OP_BIT_OR
):
1066 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1071 res
= ((uint64_t) estack_bx_v
| (uint64_t) estack_ax_v
);
1072 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1074 estack_ax_t
= REG_U64
;
1075 next_pc
+= sizeof(struct binary_op
);
1078 OP(FILTER_OP_BIT_XOR
):
1082 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1087 res
= ((uint64_t) estack_bx_v
^ (uint64_t) estack_ax_v
);
1088 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1090 estack_ax_t
= REG_U64
;
1091 next_pc
+= sizeof(struct binary_op
);
1096 OP(FILTER_OP_UNARY_PLUS
):
1097 OP(FILTER_OP_UNARY_MINUS
):
1098 OP(FILTER_OP_UNARY_NOT
):
1099 printk(KERN_WARNING
"LTTng: filter: unsupported non-specialized bytecode op %u\n",
1100 (unsigned int) *(filter_opcode_t
*) pc
);
1105 OP(FILTER_OP_UNARY_BIT_NOT
):
1107 estack_ax_v
= ~(uint64_t) estack_ax_v
;
1108 estack_ax_t
= REG_S64
;
1109 next_pc
+= sizeof(struct unary_op
);
1113 OP(FILTER_OP_UNARY_PLUS_S64
):
1115 next_pc
+= sizeof(struct unary_op
);
1118 OP(FILTER_OP_UNARY_MINUS_S64
):
1120 estack_ax_v
= -estack_ax_v
;
1121 estack_ax_t
= REG_S64
;
1122 next_pc
+= sizeof(struct unary_op
);
1125 OP(FILTER_OP_UNARY_PLUS_DOUBLE
):
1126 OP(FILTER_OP_UNARY_MINUS_DOUBLE
):
1131 OP(FILTER_OP_UNARY_NOT_S64
):
1133 estack_ax_v
= !estack_ax_v
;
1134 estack_ax_t
= REG_S64
;
1135 next_pc
+= sizeof(struct unary_op
);
1138 OP(FILTER_OP_UNARY_NOT_DOUBLE
):
1147 struct logical_op
*insn
= (struct logical_op
*) pc
;
1149 /* If AX is 0, skip and evaluate to 0 */
1150 if (unlikely(estack_ax_v
== 0)) {
1151 dbg_printk("Jumping to bytecode offset %u\n",
1152 (unsigned int) insn
->skip_offset
);
1153 next_pc
= start_pc
+ insn
->skip_offset
;
1155 /* Pop 1 when jump not taken */
1156 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1157 next_pc
+= sizeof(struct logical_op
);
1163 struct logical_op
*insn
= (struct logical_op
*) pc
;
1165 /* If AX is nonzero, skip and evaluate to 1 */
1167 if (unlikely(estack_ax_v
!= 0)) {
1169 dbg_printk("Jumping to bytecode offset %u\n",
1170 (unsigned int) insn
->skip_offset
);
1171 next_pc
= start_pc
+ insn
->skip_offset
;
1173 /* Pop 1 when jump not taken */
1174 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1175 next_pc
+= sizeof(struct logical_op
);
1181 /* load field ref */
1182 OP(FILTER_OP_LOAD_FIELD_REF_STRING
):
1184 struct load_op
*insn
= (struct load_op
*) pc
;
1185 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1187 dbg_printk("load field ref offset %u type string\n",
1189 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1190 estack_ax(stack
, top
)->u
.s
.str
=
1191 *(const char * const *) &filter_stack_data
[ref
->offset
];
1192 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1193 dbg_printk("Filter warning: loading a NULL string.\n");
1197 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1198 estack_ax(stack
, top
)->u
.s
.literal_type
=
1199 ESTACK_STRING_LITERAL_TYPE_NONE
;
1200 estack_ax(stack
, top
)->u
.s
.user
= 0;
1201 estack_ax(stack
, top
)->type
= REG_STRING
;
1202 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1203 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1207 OP(FILTER_OP_LOAD_FIELD_REF_SEQUENCE
):
1209 struct load_op
*insn
= (struct load_op
*) pc
;
1210 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1212 dbg_printk("load field ref offset %u type sequence\n",
1214 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1215 estack_ax(stack
, top
)->u
.s
.seq_len
=
1216 *(unsigned long *) &filter_stack_data
[ref
->offset
];
1217 estack_ax(stack
, top
)->u
.s
.str
=
1218 *(const char **) (&filter_stack_data
[ref
->offset
1219 + sizeof(unsigned long)]);
1220 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1221 dbg_printk("Filter warning: loading a NULL sequence.\n");
1225 estack_ax(stack
, top
)->u
.s
.literal_type
=
1226 ESTACK_STRING_LITERAL_TYPE_NONE
;
1227 estack_ax(stack
, top
)->u
.s
.user
= 0;
1228 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1232 OP(FILTER_OP_LOAD_FIELD_REF_S64
):
1234 struct load_op
*insn
= (struct load_op
*) pc
;
1235 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1237 dbg_printk("load field ref offset %u type s64\n",
1239 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1241 ((struct literal_numeric
*) &filter_stack_data
[ref
->offset
])->v
;
1242 estack_ax_t
= REG_S64
;
1243 dbg_printk("ref load s64 %lld\n",
1244 (long long) estack_ax_v
);
1245 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1249 OP(FILTER_OP_LOAD_FIELD_REF_DOUBLE
):
1255 /* load from immediate operand */
1256 OP(FILTER_OP_LOAD_STRING
):
1258 struct load_op
*insn
= (struct load_op
*) pc
;
1260 dbg_printk("load string %s\n", insn
->data
);
1261 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1262 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1263 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1264 estack_ax(stack
, top
)->u
.s
.literal_type
=
1265 ESTACK_STRING_LITERAL_TYPE_PLAIN
;
1266 estack_ax(stack
, top
)->u
.s
.user
= 0;
1267 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1271 OP(FILTER_OP_LOAD_STAR_GLOB_STRING
):
1273 struct load_op
*insn
= (struct load_op
*) pc
;
1275 dbg_printk("load globbing pattern %s\n", insn
->data
);
1276 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1277 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1278 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1279 estack_ax(stack
, top
)->u
.s
.literal_type
=
1280 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
;
1281 estack_ax(stack
, top
)->u
.s
.user
= 0;
1282 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1286 OP(FILTER_OP_LOAD_S64
):
1288 struct load_op
*insn
= (struct load_op
*) pc
;
1290 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1291 estack_ax_v
= ((struct literal_numeric
*) insn
->data
)->v
;
1292 estack_ax_t
= REG_S64
;
1293 dbg_printk("load s64 %lld\n",
1294 (long long) estack_ax_v
);
1295 next_pc
+= sizeof(struct load_op
)
1296 + sizeof(struct literal_numeric
);
1300 OP(FILTER_OP_LOAD_DOUBLE
):
1307 OP(FILTER_OP_CAST_TO_S64
):
1308 printk(KERN_WARNING
"LTTng: filter: unsupported non-specialized bytecode op %u\n",
1309 (unsigned int) *(filter_opcode_t
*) pc
);
1313 OP(FILTER_OP_CAST_DOUBLE_TO_S64
):
1319 OP(FILTER_OP_CAST_NOP
):
1321 next_pc
+= sizeof(struct cast_op
);
1325 /* get context ref */
1326 OP(FILTER_OP_GET_CONTEXT_REF_STRING
):
1328 struct load_op
*insn
= (struct load_op
*) pc
;
1329 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1330 struct lttng_ctx_field
*ctx_field
;
1331 union lttng_ctx_value v
;
1333 dbg_printk("get context ref offset %u type string\n",
1335 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1336 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
1337 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1338 estack_ax(stack
, top
)->u
.s
.str
= v
.str
;
1339 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1340 dbg_printk("Filter warning: loading a NULL string.\n");
1344 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1345 estack_ax(stack
, top
)->u
.s
.literal_type
=
1346 ESTACK_STRING_LITERAL_TYPE_NONE
;
1347 estack_ax(stack
, top
)->u
.s
.user
= 0;
1348 estack_ax(stack
, top
)->type
= REG_STRING
;
1349 dbg_printk("ref get context string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1350 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1354 OP(FILTER_OP_GET_CONTEXT_REF_S64
):
1356 struct load_op
*insn
= (struct load_op
*) pc
;
1357 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1358 struct lttng_ctx_field
*ctx_field
;
1359 union lttng_ctx_value v
;
1361 dbg_printk("get context ref offset %u type s64\n",
1363 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1364 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
1365 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1366 estack_ax_v
= v
.s64
;
1367 estack_ax_t
= REG_S64
;
1368 dbg_printk("ref get context s64 %lld\n",
1369 (long long) estack_ax_v
);
1370 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1374 OP(FILTER_OP_GET_CONTEXT_REF_DOUBLE
):
1380 /* load userspace field ref */
1381 OP(FILTER_OP_LOAD_FIELD_REF_USER_STRING
):
1383 struct load_op
*insn
= (struct load_op
*) pc
;
1384 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1386 dbg_printk("load field ref offset %u type user string\n",
1388 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1389 estack_ax(stack
, top
)->u
.s
.user_str
=
1390 *(const char * const *) &filter_stack_data
[ref
->offset
];
1391 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1392 dbg_printk("Filter warning: loading a NULL string.\n");
1396 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1397 estack_ax(stack
, top
)->u
.s
.literal_type
=
1398 ESTACK_STRING_LITERAL_TYPE_NONE
;
1399 estack_ax(stack
, top
)->u
.s
.user
= 1;
1400 estack_ax(stack
, top
)->type
= REG_STRING
;
1401 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1402 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1406 OP(FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
):
1408 struct load_op
*insn
= (struct load_op
*) pc
;
1409 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1411 dbg_printk("load field ref offset %u type user sequence\n",
1413 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1414 estack_ax(stack
, top
)->u
.s
.seq_len
=
1415 *(unsigned long *) &filter_stack_data
[ref
->offset
];
1416 estack_ax(stack
, top
)->u
.s
.user_str
=
1417 *(const char **) (&filter_stack_data
[ref
->offset
1418 + sizeof(unsigned long)]);
1419 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1420 dbg_printk("Filter warning: loading a NULL sequence.\n");
1424 estack_ax(stack
, top
)->u
.s
.literal_type
=
1425 ESTACK_STRING_LITERAL_TYPE_NONE
;
1426 estack_ax(stack
, top
)->u
.s
.user
= 1;
1427 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1431 OP(FILTER_OP_GET_CONTEXT_ROOT
):
1433 dbg_printk("op get context root\n");
1434 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1435 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_CONTEXT
;
1436 /* "field" only needed for variants. */
1437 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1438 estack_ax(stack
, top
)->type
= REG_PTR
;
1439 next_pc
+= sizeof(struct load_op
);
1443 OP(FILTER_OP_GET_APP_CONTEXT_ROOT
):
1449 OP(FILTER_OP_GET_PAYLOAD_ROOT
):
1451 dbg_printk("op get app payload root\n");
1452 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1453 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_PAYLOAD
;
1454 estack_ax(stack
, top
)->u
.ptr
.ptr
= filter_stack_data
;
1455 /* "field" only needed for variants. */
1456 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1457 estack_ax(stack
, top
)->type
= REG_PTR
;
1458 next_pc
+= sizeof(struct load_op
);
1462 OP(FILTER_OP_GET_SYMBOL
):
1464 dbg_printk("op get symbol\n");
1465 switch (estack_ax(stack
, top
)->u
.ptr
.type
) {
1467 printk(KERN_WARNING
"LTTng: filter: Nested fields not implemented yet.\n");
1470 case LOAD_ROOT_CONTEXT
:
1471 case LOAD_ROOT_APP_CONTEXT
:
1472 case LOAD_ROOT_PAYLOAD
:
1474 * symbol lookup is performed by
1480 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_symbol
);
1484 OP(FILTER_OP_GET_SYMBOL_FIELD
):
1487 * Used for first variant encountered in a
1488 * traversal. Variants are not implemented yet.
1494 OP(FILTER_OP_GET_INDEX_U16
):
1496 struct load_op
*insn
= (struct load_op
*) pc
;
1497 struct get_index_u16
*index
= (struct get_index_u16
*) insn
->data
;
1499 dbg_printk("op get index u16\n");
1500 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1503 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1504 estack_ax_t
= estack_ax(stack
, top
)->type
;
1505 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u16
);
1509 OP(FILTER_OP_GET_INDEX_U64
):
1511 struct load_op
*insn
= (struct load_op
*) pc
;
1512 struct get_index_u64
*index
= (struct get_index_u64
*) insn
->data
;
1514 dbg_printk("op get index u64\n");
1515 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1518 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1519 estack_ax_t
= estack_ax(stack
, top
)->type
;
1520 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u64
);
1524 OP(FILTER_OP_LOAD_FIELD
):
1526 dbg_printk("op load field\n");
1527 ret
= dynamic_load_field(estack_ax(stack
, top
));
1530 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1531 estack_ax_t
= estack_ax(stack
, top
)->type
;
1532 next_pc
+= sizeof(struct load_op
);
1536 OP(FILTER_OP_LOAD_FIELD_S8
):
1538 dbg_printk("op load field s8\n");
1540 estack_ax_v
= *(int8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1541 estack_ax_t
= REG_S64
;
1542 next_pc
+= sizeof(struct load_op
);
1545 OP(FILTER_OP_LOAD_FIELD_S16
):
1547 dbg_printk("op load field s16\n");
1549 estack_ax_v
= *(int16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1550 estack_ax_t
= REG_S64
;
1551 next_pc
+= sizeof(struct load_op
);
1554 OP(FILTER_OP_LOAD_FIELD_S32
):
1556 dbg_printk("op load field s32\n");
1558 estack_ax_v
= *(int32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1559 estack_ax_t
= REG_S64
;
1560 next_pc
+= sizeof(struct load_op
);
1563 OP(FILTER_OP_LOAD_FIELD_S64
):
1565 dbg_printk("op load field s64\n");
1567 estack_ax_v
= *(int64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1568 estack_ax_t
= REG_S64
;
1569 next_pc
+= sizeof(struct load_op
);
1572 OP(FILTER_OP_LOAD_FIELD_U8
):
1574 dbg_printk("op load field u8\n");
1576 estack_ax_v
= *(uint8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1577 estack_ax_t
= REG_S64
;
1578 next_pc
+= sizeof(struct load_op
);
1581 OP(FILTER_OP_LOAD_FIELD_U16
):
1583 dbg_printk("op load field u16\n");
1585 estack_ax_v
= *(uint16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1586 estack_ax_t
= REG_S64
;
1587 next_pc
+= sizeof(struct load_op
);
1590 OP(FILTER_OP_LOAD_FIELD_U32
):
1592 dbg_printk("op load field u32\n");
1594 estack_ax_v
= *(uint32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1595 estack_ax_t
= REG_S64
;
1596 next_pc
+= sizeof(struct load_op
);
1599 OP(FILTER_OP_LOAD_FIELD_U64
):
1601 dbg_printk("op load field u64\n");
1603 estack_ax_v
= *(uint64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1604 estack_ax_t
= REG_S64
;
1605 next_pc
+= sizeof(struct load_op
);
1608 OP(FILTER_OP_LOAD_FIELD_DOUBLE
):
1614 OP(FILTER_OP_LOAD_FIELD_STRING
):
1618 dbg_printk("op load field string\n");
1619 str
= (const char *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1620 estack_ax(stack
, top
)->u
.s
.str
= str
;
1621 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1622 dbg_printk("Filter warning: loading a NULL string.\n");
1626 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1627 estack_ax(stack
, top
)->u
.s
.literal_type
=
1628 ESTACK_STRING_LITERAL_TYPE_NONE
;
1629 estack_ax(stack
, top
)->type
= REG_STRING
;
1630 next_pc
+= sizeof(struct load_op
);
1634 OP(FILTER_OP_LOAD_FIELD_SEQUENCE
):
1638 dbg_printk("op load field string sequence\n");
1639 ptr
= estack_ax(stack
, top
)->u
.ptr
.ptr
;
1640 estack_ax(stack
, top
)->u
.s
.seq_len
= *(unsigned long *) ptr
;
1641 estack_ax(stack
, top
)->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
1642 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1643 dbg_printk("Filter warning: loading a NULL sequence.\n");
1647 estack_ax(stack
, top
)->u
.s
.literal_type
=
1648 ESTACK_STRING_LITERAL_TYPE_NONE
;
1649 estack_ax(stack
, top
)->type
= REG_STRING
;
1650 next_pc
+= sizeof(struct load_op
);
1656 /* Return _DISCARD on error. */
1658 return LTTNG_FILTER_DISCARD
;