1 /* SPDX-License-Identifier: MIT
3 * lttng-bytecode-interpreter.c
5 * LTTng modules bytecode 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/lttng-bytecode.h>
16 #include <lttng/string-utils.h>
19 * get_char should be called with page fault handler disabled if it is expected
20 * to handle user-space read.
23 char get_char(struct estack_entry
*reg
, size_t offset
)
25 if (unlikely(offset
>= reg
->u
.s
.seq_len
))
30 /* Handle invalid access as end of string. */
31 if (unlikely(!lttng_access_ok(VERIFY_READ
,
32 reg
->u
.s
.user_str
+ offset
,
35 /* Handle fault (nonzero return value) as end of string. */
36 if (unlikely(__copy_from_user_inatomic(&c
,
37 reg
->u
.s
.user_str
+ offset
,
42 return reg
->u
.s
.str
[offset
];
48 * -2: unknown escape char.
52 int parse_char(struct estack_entry
*reg
, char *c
, size_t *offset
)
57 *c
= get_char(reg
, *offset
);
73 char get_char_at_cb(size_t at
, void *data
)
75 return get_char(data
, at
);
79 int stack_star_glob_match(struct estack
*stack
, int top
, const char *cmp_type
)
81 bool has_user
= false;
83 struct estack_entry
*pattern_reg
;
84 struct estack_entry
*candidate_reg
;
86 /* Disable the page fault handler when reading from userspace. */
87 if (estack_bx(stack
, top
)->u
.s
.user
88 || estack_ax(stack
, top
)->u
.s
.user
) {
93 /* Find out which side is the pattern vs. the candidate. */
94 if (estack_ax(stack
, top
)->u
.s
.literal_type
== ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
) {
95 pattern_reg
= estack_ax(stack
, top
);
96 candidate_reg
= estack_bx(stack
, top
);
98 pattern_reg
= estack_bx(stack
, top
);
99 candidate_reg
= estack_ax(stack
, top
);
102 /* Perform the match operation. */
103 result
= !strutils_star_glob_match_char_cb(get_char_at_cb
,
104 pattern_reg
, get_char_at_cb
, candidate_reg
);
112 int stack_strcmp(struct estack
*stack
, int top
, const char *cmp_type
)
114 size_t offset_bx
= 0, offset_ax
= 0;
115 int diff
, has_user
= 0;
117 if (estack_bx(stack
, top
)->u
.s
.user
118 || estack_ax(stack
, top
)->u
.s
.user
) {
126 char char_bx
, char_ax
;
128 char_bx
= get_char(estack_bx(stack
, top
), offset_bx
);
129 char_ax
= get_char(estack_ax(stack
, top
), offset_ax
);
131 if (unlikely(char_bx
== '\0')) {
132 if (char_ax
== '\0') {
136 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
137 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
138 ret
= parse_char(estack_ax(stack
, top
),
139 &char_ax
, &offset_ax
);
149 if (unlikely(char_ax
== '\0')) {
150 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
151 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
152 ret
= parse_char(estack_bx(stack
, top
),
153 &char_bx
, &offset_bx
);
162 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
163 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
164 ret
= parse_char(estack_bx(stack
, top
),
165 &char_bx
, &offset_bx
);
169 } else if (ret
== -2) {
172 /* else compare both char */
174 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
175 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
176 ret
= parse_char(estack_ax(stack
, top
),
177 &char_ax
, &offset_ax
);
181 } else if (ret
== -2) {
198 diff
= char_bx
- char_ax
;
210 uint64_t lttng_bytecode_filter_interpret_false(void *filter_data
,
211 struct lttng_probe_ctx
*lttng_probe_ctx
,
212 const char *filter_stack_data
)
214 return LTTNG_INTERPRETER_DISCARD
;
217 uint64_t lttng_bytecode_capture_interpret_false(void *filter_data
,
218 struct lttng_probe_ctx
*lttng_probe_ctx
,
219 const char *capture_stack_data
,
220 struct lttng_interpreter_output
*output
)
222 return LTTNG_INTERPRETER_DISCARD
;
225 #ifdef INTERPRETER_USE_SWITCH
228 * Fallback for compilers that do not support taking address of labels.
232 start_pc = &bytecode->data[0]; \
233 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
235 dbg_printk("LTTng: Executing op %s (%u)\n", \
236 lttng_bytecode_print_op((unsigned int) *(bytecode_opcode_t *) pc), \
237 (unsigned int) *(bytecode_opcode_t *) pc); \
238 switch (*(bytecode_opcode_t *) pc) {
240 #define OP(name) case name
250 * Dispatch-table based interpreter.
254 start_pc = &bytecode->code[0]; \
255 pc = next_pc = start_pc; \
256 if (unlikely(pc - start_pc >= bytecode->len)) \
258 goto *dispatch[*(bytecode_opcode_t *) pc];
265 goto *dispatch[*(bytecode_opcode_t *) pc];
271 #define IS_INTEGER_REGISTER(reg_type) \
272 (reg_type == REG_S64 || reg_type == REG_U64)
274 static int context_get_index(struct lttng_probe_ctx
*lttng_probe_ctx
,
275 struct load_ptr
*ptr
,
279 struct lttng_ctx_field
*ctx_field
;
280 struct lttng_event_field
*field
;
281 union lttng_ctx_value v
;
283 ctx_field
= <tng_static_ctx
->fields
[idx
];
284 field
= &ctx_field
->event_field
;
285 ptr
->type
= LOAD_OBJECT
;
286 /* field is only used for types nested within variants. */
289 switch (field
->type
.atype
) {
291 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
292 if (field
->type
.u
.integer
.signedness
) {
293 ptr
->object_type
= OBJECT_TYPE_S64
;
295 ptr
->ptr
= &ptr
->u
.s64
;
297 ptr
->object_type
= OBJECT_TYPE_U64
;
298 ptr
->u
.u64
= v
.s64
; /* Cast. */
299 ptr
->ptr
= &ptr
->u
.u64
;
302 case atype_enum_nestable
:
304 const struct lttng_integer_type
*itype
=
305 &field
->type
.u
.enum_nestable
.container_type
->u
.integer
;
307 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
308 if (itype
->signedness
) {
309 ptr
->object_type
= OBJECT_TYPE_SIGNED_ENUM
;
311 ptr
->ptr
= &ptr
->u
.s64
;
313 ptr
->object_type
= OBJECT_TYPE_UNSIGNED_ENUM
;
314 ptr
->u
.u64
= v
.s64
; /* Cast. */
315 ptr
->ptr
= &ptr
->u
.u64
;
319 case atype_array_nestable
:
320 if (!lttng_is_bytewise_integer(field
->type
.u
.array_nestable
.elem_type
)) {
321 printk(KERN_WARNING
"LTTng: bytecode: Array nesting only supports integer types.\n");
324 if (field
->type
.u
.array_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
325 printk(KERN_WARNING
"LTTng: bytecode: Only string arrays are supported for contexts.\n");
328 ptr
->object_type
= OBJECT_TYPE_STRING
;
329 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
332 case atype_sequence_nestable
:
333 if (!lttng_is_bytewise_integer(field
->type
.u
.sequence_nestable
.elem_type
)) {
334 printk(KERN_WARNING
"LTTng: bytecode: Sequence nesting only supports integer types.\n");
337 if (field
->type
.u
.sequence_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
338 printk(KERN_WARNING
"LTTng: bytecode: Only string sequences are supported for contexts.\n");
341 ptr
->object_type
= OBJECT_TYPE_STRING
;
342 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
346 ptr
->object_type
= OBJECT_TYPE_STRING
;
347 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
350 case atype_struct_nestable
:
351 printk(KERN_WARNING
"LTTng: bytecode: Structure type cannot be loaded.\n");
353 case atype_variant_nestable
:
354 printk(KERN_WARNING
"LTTng: bytecode: Variant type cannot be loaded.\n");
357 printk(KERN_WARNING
"LTTng: bytecode: Unknown type: %d", (int) field
->type
.atype
);
363 static int dynamic_get_index(struct lttng_probe_ctx
*lttng_probe_ctx
,
364 struct bytecode_runtime
*runtime
,
365 uint64_t index
, struct estack_entry
*stack_top
)
368 const struct bytecode_get_index_data
*gid
;
370 gid
= (const struct bytecode_get_index_data
*) &runtime
->data
[index
];
371 switch (stack_top
->u
.ptr
.type
) {
373 switch (stack_top
->u
.ptr
.object_type
) {
374 case OBJECT_TYPE_ARRAY
:
378 WARN_ON_ONCE(gid
->offset
>= gid
->array_len
);
379 /* Skip count (unsigned long) */
380 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
381 ptr
= ptr
+ gid
->offset
;
382 stack_top
->u
.ptr
.ptr
= ptr
;
383 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
384 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
385 BUG_ON(stack_top
->u
.ptr
.field
->type
.atype
!= atype_array_nestable
);
386 stack_top
->u
.ptr
.field
= NULL
;
389 case OBJECT_TYPE_SEQUENCE
:
394 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
395 ptr_seq_len
= *(unsigned long *) stack_top
->u
.ptr
.ptr
;
396 if (gid
->offset
>= gid
->elem
.len
* ptr_seq_len
) {
400 ptr
= ptr
+ gid
->offset
;
401 stack_top
->u
.ptr
.ptr
= ptr
;
402 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
403 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
404 BUG_ON(stack_top
->u
.ptr
.field
->type
.atype
!= atype_sequence_nestable
);
405 stack_top
->u
.ptr
.field
= NULL
;
408 case OBJECT_TYPE_STRUCT
:
409 printk(KERN_WARNING
"LTTng: bytecode: Nested structures are not supported yet.\n");
412 case OBJECT_TYPE_VARIANT
:
414 printk(KERN_WARNING
"LTTng: bytecode: Unexpected get index type %d",
415 (int) stack_top
->u
.ptr
.object_type
);
420 case LOAD_ROOT_CONTEXT
:
421 case LOAD_ROOT_APP_CONTEXT
: /* Fall-through */
423 ret
= context_get_index(lttng_probe_ctx
,
431 case LOAD_ROOT_PAYLOAD
:
432 stack_top
->u
.ptr
.ptr
+= gid
->offset
;
433 if (gid
->elem
.type
== OBJECT_TYPE_STRING
)
434 stack_top
->u
.ptr
.ptr
= *(const char * const *) stack_top
->u
.ptr
.ptr
;
435 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
436 stack_top
->u
.ptr
.type
= LOAD_OBJECT
;
437 stack_top
->u
.ptr
.field
= gid
->field
;
438 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
442 stack_top
->type
= REG_PTR
;
450 static int dynamic_load_field(struct estack_entry
*stack_top
)
454 switch (stack_top
->u
.ptr
.type
) {
457 case LOAD_ROOT_CONTEXT
:
458 case LOAD_ROOT_APP_CONTEXT
:
459 case LOAD_ROOT_PAYLOAD
:
461 dbg_printk("Bytecode warning: cannot load root, missing field name.\n");
465 switch (stack_top
->u
.ptr
.object_type
) {
467 dbg_printk("op load field s8\n");
468 stack_top
->u
.v
= *(int8_t *) stack_top
->u
.ptr
.ptr
;
469 stack_top
->type
= REG_S64
;
471 case OBJECT_TYPE_S16
:
475 dbg_printk("op load field s16\n");
476 tmp
= *(int16_t *) stack_top
->u
.ptr
.ptr
;
477 if (stack_top
->u
.ptr
.rev_bo
)
479 stack_top
->u
.v
= tmp
;
480 stack_top
->type
= REG_S64
;
483 case OBJECT_TYPE_S32
:
487 dbg_printk("op load field s32\n");
488 tmp
= *(int32_t *) stack_top
->u
.ptr
.ptr
;
489 if (stack_top
->u
.ptr
.rev_bo
)
491 stack_top
->u
.v
= tmp
;
492 stack_top
->type
= REG_S64
;
495 case OBJECT_TYPE_S64
:
499 dbg_printk("op load field s64\n");
500 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
501 if (stack_top
->u
.ptr
.rev_bo
)
503 stack_top
->u
.v
= tmp
;
504 stack_top
->type
= REG_S64
;
507 case OBJECT_TYPE_SIGNED_ENUM
:
511 dbg_printk("op load field signed enumeration\n");
512 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
513 if (stack_top
->u
.ptr
.rev_bo
)
515 stack_top
->u
.v
= tmp
;
516 stack_top
->type
= REG_S64
;
520 dbg_printk("op load field u8\n");
521 stack_top
->u
.v
= *(uint8_t *) stack_top
->u
.ptr
.ptr
;
522 stack_top
->type
= REG_U64
;
524 case OBJECT_TYPE_U16
:
528 dbg_printk("op load field u16\n");
529 tmp
= *(uint16_t *) stack_top
->u
.ptr
.ptr
;
530 if (stack_top
->u
.ptr
.rev_bo
)
532 stack_top
->u
.v
= tmp
;
533 stack_top
->type
= REG_U64
;
536 case OBJECT_TYPE_U32
:
540 dbg_printk("op load field u32\n");
541 tmp
= *(uint32_t *) stack_top
->u
.ptr
.ptr
;
542 if (stack_top
->u
.ptr
.rev_bo
)
544 stack_top
->u
.v
= tmp
;
545 stack_top
->type
= REG_U64
;
548 case OBJECT_TYPE_U64
:
552 dbg_printk("op load field u64\n");
553 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
554 if (stack_top
->u
.ptr
.rev_bo
)
556 stack_top
->u
.v
= tmp
;
557 stack_top
->type
= REG_U64
;
560 case OBJECT_TYPE_UNSIGNED_ENUM
:
564 dbg_printk("op load field unsigned enumeration\n");
565 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
566 if (stack_top
->u
.ptr
.rev_bo
)
568 stack_top
->u
.v
= tmp
;
569 stack_top
->type
= REG_U64
;
572 case OBJECT_TYPE_STRING
:
576 dbg_printk("op load field string\n");
577 str
= (const char *) stack_top
->u
.ptr
.ptr
;
578 stack_top
->u
.s
.str
= str
;
579 if (unlikely(!stack_top
->u
.s
.str
)) {
580 dbg_printk("Bytecode warning: loading a NULL string.\n");
584 stack_top
->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
585 stack_top
->u
.s
.literal_type
=
586 ESTACK_STRING_LITERAL_TYPE_NONE
;
587 stack_top
->type
= REG_STRING
;
590 case OBJECT_TYPE_STRING_SEQUENCE
:
594 dbg_printk("op load field string sequence\n");
595 ptr
= stack_top
->u
.ptr
.ptr
;
596 stack_top
->u
.s
.seq_len
= *(unsigned long *) ptr
;
597 stack_top
->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
598 if (unlikely(!stack_top
->u
.s
.str
)) {
599 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
603 stack_top
->u
.s
.literal_type
=
604 ESTACK_STRING_LITERAL_TYPE_NONE
;
605 stack_top
->type
= REG_STRING
;
608 case OBJECT_TYPE_DYNAMIC
:
610 * Dynamic types in context are looked up
611 * by context get index.
615 case OBJECT_TYPE_DOUBLE
:
618 case OBJECT_TYPE_SEQUENCE
:
619 case OBJECT_TYPE_ARRAY
:
620 case OBJECT_TYPE_STRUCT
:
621 case OBJECT_TYPE_VARIANT
:
622 printk(KERN_WARNING
"LTTng: bytecode: Sequences, arrays, struct and variant cannot be loaded (nested types).\n");
633 int lttng_bytecode_interpret_format_output(struct estack_entry
*ax
,
634 struct lttng_interpreter_output
*output
)
641 output
->type
= LTTNG_INTERPRETER_TYPE_S64
;
642 output
->u
.s
= ax
->u
.v
;
645 output
->type
= LTTNG_INTERPRETER_TYPE_U64
;
646 output
->u
.u
= (uint64_t) ax
->u
.v
;
649 output
->type
= LTTNG_INTERPRETER_TYPE_STRING
;
650 output
->u
.str
.str
= ax
->u
.s
.str
;
651 output
->u
.str
.len
= ax
->u
.s
.seq_len
;
654 switch (ax
->u
.ptr
.object_type
) {
656 case OBJECT_TYPE_S16
:
657 case OBJECT_TYPE_S32
:
658 case OBJECT_TYPE_S64
:
660 case OBJECT_TYPE_U16
:
661 case OBJECT_TYPE_U32
:
662 case OBJECT_TYPE_U64
:
663 case OBJECT_TYPE_DOUBLE
:
664 case OBJECT_TYPE_STRING
:
665 case OBJECT_TYPE_STRING_SEQUENCE
:
666 ret
= dynamic_load_field(ax
);
669 /* Retry after loading ptr into stack top. */
671 case OBJECT_TYPE_SEQUENCE
:
672 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
673 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
674 output
->u
.sequence
.nr_elem
= *(unsigned long *) ax
->u
.ptr
.ptr
;
675 output
->u
.sequence
.nested_type
= ax
->u
.ptr
.field
->type
.u
.sequence_nestable
.elem_type
;
677 case OBJECT_TYPE_ARRAY
:
678 /* Skip count (unsigned long) */
679 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
680 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
681 output
->u
.sequence
.nr_elem
= ax
->u
.ptr
.field
->type
.u
.array_nestable
.length
;
682 output
->u
.sequence
.nested_type
= ax
->u
.ptr
.field
->type
.u
.array_nestable
.elem_type
;
684 case OBJECT_TYPE_SIGNED_ENUM
:
685 ret
= dynamic_load_field(ax
);
688 output
->type
= LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
;
689 output
->u
.s
= ax
->u
.v
;
691 case OBJECT_TYPE_UNSIGNED_ENUM
:
692 ret
= dynamic_load_field(ax
);
695 output
->type
= LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
;
696 output
->u
.u
= ax
->u
.v
;
698 case OBJECT_TYPE_STRUCT
:
699 case OBJECT_TYPE_VARIANT
:
705 case REG_STAR_GLOB_STRING
:
706 case REG_TYPE_UNKNOWN
:
711 return LTTNG_INTERPRETER_RECORD_FLAG
;
715 * Return 0 (discard), or raise the 0x1 flag (log event).
716 * Currently, other flags are kept for future extensions and have no
720 uint64_t bytecode_interpret(void *interpreter_data
,
721 struct lttng_probe_ctx
*lttng_probe_ctx
,
722 const char *interpreter_stack_data
,
723 struct lttng_interpreter_output
*output
)
725 struct bytecode_runtime
*bytecode
= interpreter_data
;
726 void *pc
, *next_pc
, *start_pc
;
729 struct estack _stack
;
730 struct estack
*stack
= &_stack
;
731 register int64_t ax
= 0, bx
= 0;
732 register enum entry_type ax_t
= REG_TYPE_UNKNOWN
, bx_t
= REG_TYPE_UNKNOWN
;
733 register int top
= INTERPRETER_STACK_EMPTY
;
734 #ifndef INTERPRETER_USE_SWITCH
735 static void *dispatch
[NR_BYTECODE_OPS
] = {
736 [ BYTECODE_OP_UNKNOWN
] = &&LABEL_BYTECODE_OP_UNKNOWN
,
738 [ BYTECODE_OP_RETURN
] = &&LABEL_BYTECODE_OP_RETURN
,
741 [ BYTECODE_OP_MUL
] = &&LABEL_BYTECODE_OP_MUL
,
742 [ BYTECODE_OP_DIV
] = &&LABEL_BYTECODE_OP_DIV
,
743 [ BYTECODE_OP_MOD
] = &&LABEL_BYTECODE_OP_MOD
,
744 [ BYTECODE_OP_PLUS
] = &&LABEL_BYTECODE_OP_PLUS
,
745 [ BYTECODE_OP_MINUS
] = &&LABEL_BYTECODE_OP_MINUS
,
746 [ BYTECODE_OP_BIT_RSHIFT
] = &&LABEL_BYTECODE_OP_BIT_RSHIFT
,
747 [ BYTECODE_OP_BIT_LSHIFT
] = &&LABEL_BYTECODE_OP_BIT_LSHIFT
,
748 [ BYTECODE_OP_BIT_AND
] = &&LABEL_BYTECODE_OP_BIT_AND
,
749 [ BYTECODE_OP_BIT_OR
] = &&LABEL_BYTECODE_OP_BIT_OR
,
750 [ BYTECODE_OP_BIT_XOR
] = &&LABEL_BYTECODE_OP_BIT_XOR
,
752 /* binary comparators */
753 [ BYTECODE_OP_EQ
] = &&LABEL_BYTECODE_OP_EQ
,
754 [ BYTECODE_OP_NE
] = &&LABEL_BYTECODE_OP_NE
,
755 [ BYTECODE_OP_GT
] = &&LABEL_BYTECODE_OP_GT
,
756 [ BYTECODE_OP_LT
] = &&LABEL_BYTECODE_OP_LT
,
757 [ BYTECODE_OP_GE
] = &&LABEL_BYTECODE_OP_GE
,
758 [ BYTECODE_OP_LE
] = &&LABEL_BYTECODE_OP_LE
,
760 /* string binary comparator */
761 [ BYTECODE_OP_EQ_STRING
] = &&LABEL_BYTECODE_OP_EQ_STRING
,
762 [ BYTECODE_OP_NE_STRING
] = &&LABEL_BYTECODE_OP_NE_STRING
,
763 [ BYTECODE_OP_GT_STRING
] = &&LABEL_BYTECODE_OP_GT_STRING
,
764 [ BYTECODE_OP_LT_STRING
] = &&LABEL_BYTECODE_OP_LT_STRING
,
765 [ BYTECODE_OP_GE_STRING
] = &&LABEL_BYTECODE_OP_GE_STRING
,
766 [ BYTECODE_OP_LE_STRING
] = &&LABEL_BYTECODE_OP_LE_STRING
,
768 /* globbing pattern binary comparator */
769 [ BYTECODE_OP_EQ_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING
,
770 [ BYTECODE_OP_NE_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING
,
772 /* s64 binary comparator */
773 [ BYTECODE_OP_EQ_S64
] = &&LABEL_BYTECODE_OP_EQ_S64
,
774 [ BYTECODE_OP_NE_S64
] = &&LABEL_BYTECODE_OP_NE_S64
,
775 [ BYTECODE_OP_GT_S64
] = &&LABEL_BYTECODE_OP_GT_S64
,
776 [ BYTECODE_OP_LT_S64
] = &&LABEL_BYTECODE_OP_LT_S64
,
777 [ BYTECODE_OP_GE_S64
] = &&LABEL_BYTECODE_OP_GE_S64
,
778 [ BYTECODE_OP_LE_S64
] = &&LABEL_BYTECODE_OP_LE_S64
,
780 /* double binary comparator */
781 [ BYTECODE_OP_EQ_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE
,
782 [ BYTECODE_OP_NE_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_DOUBLE
,
783 [ BYTECODE_OP_GT_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_DOUBLE
,
784 [ BYTECODE_OP_LT_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_DOUBLE
,
785 [ BYTECODE_OP_GE_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_DOUBLE
,
786 [ BYTECODE_OP_LE_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_DOUBLE
,
788 /* Mixed S64-double binary comparators */
789 [ BYTECODE_OP_EQ_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64
,
790 [ BYTECODE_OP_NE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64
,
791 [ BYTECODE_OP_GT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64
,
792 [ BYTECODE_OP_LT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64
,
793 [ BYTECODE_OP_GE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64
,
794 [ BYTECODE_OP_LE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64
,
796 [ BYTECODE_OP_EQ_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE
,
797 [ BYTECODE_OP_NE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE
,
798 [ BYTECODE_OP_GT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE
,
799 [ BYTECODE_OP_LT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE
,
800 [ BYTECODE_OP_GE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE
,
801 [ BYTECODE_OP_LE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE
,
804 [ BYTECODE_OP_UNARY_PLUS
] = &&LABEL_BYTECODE_OP_UNARY_PLUS
,
805 [ BYTECODE_OP_UNARY_MINUS
] = &&LABEL_BYTECODE_OP_UNARY_MINUS
,
806 [ BYTECODE_OP_UNARY_NOT
] = &&LABEL_BYTECODE_OP_UNARY_NOT
,
807 [ BYTECODE_OP_UNARY_PLUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64
,
808 [ BYTECODE_OP_UNARY_MINUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64
,
809 [ BYTECODE_OP_UNARY_NOT_S64
] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64
,
810 [ BYTECODE_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE
,
811 [ BYTECODE_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE
,
812 [ BYTECODE_OP_UNARY_NOT_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE
,
815 [ BYTECODE_OP_AND
] = &&LABEL_BYTECODE_OP_AND
,
816 [ BYTECODE_OP_OR
] = &&LABEL_BYTECODE_OP_OR
,
819 [ BYTECODE_OP_LOAD_FIELD_REF
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF
,
820 [ BYTECODE_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING
,
821 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
,
822 [ BYTECODE_OP_LOAD_FIELD_REF_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64
,
823 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
,
825 /* load from immediate operand */
826 [ BYTECODE_OP_LOAD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STRING
,
827 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING
,
828 [ BYTECODE_OP_LOAD_S64
] = &&LABEL_BYTECODE_OP_LOAD_S64
,
829 [ BYTECODE_OP_LOAD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE
,
832 [ BYTECODE_OP_CAST_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_TO_S64
,
833 [ BYTECODE_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64
,
834 [ BYTECODE_OP_CAST_NOP
] = &&LABEL_BYTECODE_OP_CAST_NOP
,
836 /* get context ref */
837 [ BYTECODE_OP_GET_CONTEXT_REF
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF
,
838 [ BYTECODE_OP_GET_CONTEXT_REF_STRING
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING
,
839 [ BYTECODE_OP_GET_CONTEXT_REF_S64
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64
,
840 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
,
842 /* load userspace field ref */
843 [ BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
,
844 [ BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
,
846 /* Instructions for recursive traversal through composed types. */
847 [ BYTECODE_OP_GET_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT
,
848 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT
,
849 [ BYTECODE_OP_GET_PAYLOAD_ROOT
] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT
,
851 [ BYTECODE_OP_GET_SYMBOL
] = &&LABEL_BYTECODE_OP_GET_SYMBOL
,
852 [ BYTECODE_OP_GET_SYMBOL_FIELD
] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD
,
853 [ BYTECODE_OP_GET_INDEX_U16
] = &&LABEL_BYTECODE_OP_GET_INDEX_U16
,
854 [ BYTECODE_OP_GET_INDEX_U64
] = &&LABEL_BYTECODE_OP_GET_INDEX_U64
,
856 [ BYTECODE_OP_LOAD_FIELD
] = &&LABEL_BYTECODE_OP_LOAD_FIELD
,
857 [ BYTECODE_OP_LOAD_FIELD_S8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8
,
858 [ BYTECODE_OP_LOAD_FIELD_S16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16
,
859 [ BYTECODE_OP_LOAD_FIELD_S32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32
,
860 [ BYTECODE_OP_LOAD_FIELD_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64
,
861 [ BYTECODE_OP_LOAD_FIELD_U8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8
,
862 [ BYTECODE_OP_LOAD_FIELD_U16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16
,
863 [ BYTECODE_OP_LOAD_FIELD_U32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32
,
864 [ BYTECODE_OP_LOAD_FIELD_U64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64
,
865 [ BYTECODE_OP_LOAD_FIELD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING
,
866 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE
,
867 [ BYTECODE_OP_LOAD_FIELD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE
,
869 [ BYTECODE_OP_UNARY_BIT_NOT
] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT
,
871 [ BYTECODE_OP_RETURN_S64
] = &&LABEL_BYTECODE_OP_RETURN_S64
,
873 #endif /* #ifndef INTERPRETER_USE_SWITCH */
877 OP(BYTECODE_OP_UNKNOWN
):
878 OP(BYTECODE_OP_LOAD_FIELD_REF
):
879 OP(BYTECODE_OP_GET_CONTEXT_REF
):
880 #ifdef INTERPRETER_USE_SWITCH
882 #endif /* INTERPRETER_USE_SWITCH */
883 printk(KERN_WARNING
"LTTng: bytecode: unknown bytecode op %u\n",
884 (unsigned int) *(bytecode_opcode_t
*) pc
);
888 OP(BYTECODE_OP_RETURN
):
889 OP(BYTECODE_OP_RETURN_S64
):
890 /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */
891 switch (estack_ax_t
) {
894 retval
= !!estack_ax_v
;
905 case REG_STAR_GLOB_STRING
:
906 case REG_TYPE_UNKNOWN
:
917 OP(BYTECODE_OP_PLUS
):
918 OP(BYTECODE_OP_MINUS
):
919 printk(KERN_WARNING
"LTTng: bytecode: unsupported bytecode op %u\n",
920 (unsigned int) *(bytecode_opcode_t
*) pc
);
930 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
931 (unsigned int) *(bytecode_opcode_t
*) pc
);
935 OP(BYTECODE_OP_EQ_STRING
):
939 res
= (stack_strcmp(stack
, top
, "==") == 0);
940 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
942 estack_ax_t
= REG_S64
;
943 next_pc
+= sizeof(struct binary_op
);
946 OP(BYTECODE_OP_NE_STRING
):
950 res
= (stack_strcmp(stack
, top
, "!=") != 0);
951 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
953 estack_ax_t
= REG_S64
;
954 next_pc
+= sizeof(struct binary_op
);
957 OP(BYTECODE_OP_GT_STRING
):
961 res
= (stack_strcmp(stack
, top
, ">") > 0);
962 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
964 estack_ax_t
= REG_S64
;
965 next_pc
+= sizeof(struct binary_op
);
968 OP(BYTECODE_OP_LT_STRING
):
972 res
= (stack_strcmp(stack
, top
, "<") < 0);
973 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
975 estack_ax_t
= REG_S64
;
976 next_pc
+= sizeof(struct binary_op
);
979 OP(BYTECODE_OP_GE_STRING
):
983 res
= (stack_strcmp(stack
, top
, ">=") >= 0);
984 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
986 estack_ax_t
= REG_S64
;
987 next_pc
+= sizeof(struct binary_op
);
990 OP(BYTECODE_OP_LE_STRING
):
994 res
= (stack_strcmp(stack
, top
, "<=") <= 0);
995 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
997 estack_ax_t
= REG_S64
;
998 next_pc
+= sizeof(struct binary_op
);
1002 OP(BYTECODE_OP_EQ_STAR_GLOB_STRING
):
1006 res
= (stack_star_glob_match(stack
, top
, "==") == 0);
1007 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1009 estack_ax_t
= REG_S64
;
1010 next_pc
+= sizeof(struct binary_op
);
1013 OP(BYTECODE_OP_NE_STAR_GLOB_STRING
):
1017 res
= (stack_star_glob_match(stack
, top
, "!=") != 0);
1018 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1020 estack_ax_t
= REG_S64
;
1021 next_pc
+= sizeof(struct binary_op
);
1025 OP(BYTECODE_OP_EQ_S64
):
1029 res
= (estack_bx_v
== estack_ax_v
);
1030 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1032 estack_ax_t
= REG_S64
;
1033 next_pc
+= sizeof(struct binary_op
);
1036 OP(BYTECODE_OP_NE_S64
):
1040 res
= (estack_bx_v
!= estack_ax_v
);
1041 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1043 estack_ax_t
= REG_S64
;
1044 next_pc
+= sizeof(struct binary_op
);
1047 OP(BYTECODE_OP_GT_S64
):
1051 res
= (estack_bx_v
> estack_ax_v
);
1052 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1054 estack_ax_t
= REG_S64
;
1055 next_pc
+= sizeof(struct binary_op
);
1058 OP(BYTECODE_OP_LT_S64
):
1062 res
= (estack_bx_v
< estack_ax_v
);
1063 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1065 estack_ax_t
= REG_S64
;
1066 next_pc
+= sizeof(struct binary_op
);
1069 OP(BYTECODE_OP_GE_S64
):
1073 res
= (estack_bx_v
>= estack_ax_v
);
1074 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1076 estack_ax_t
= REG_S64
;
1077 next_pc
+= sizeof(struct binary_op
);
1080 OP(BYTECODE_OP_LE_S64
):
1084 res
= (estack_bx_v
<= estack_ax_v
);
1085 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1087 estack_ax_t
= REG_S64
;
1088 next_pc
+= sizeof(struct binary_op
);
1092 OP(BYTECODE_OP_EQ_DOUBLE
):
1093 OP(BYTECODE_OP_NE_DOUBLE
):
1094 OP(BYTECODE_OP_GT_DOUBLE
):
1095 OP(BYTECODE_OP_LT_DOUBLE
):
1096 OP(BYTECODE_OP_GE_DOUBLE
):
1097 OP(BYTECODE_OP_LE_DOUBLE
):
1103 /* Mixed S64-double binary comparators */
1104 OP(BYTECODE_OP_EQ_DOUBLE_S64
):
1105 OP(BYTECODE_OP_NE_DOUBLE_S64
):
1106 OP(BYTECODE_OP_GT_DOUBLE_S64
):
1107 OP(BYTECODE_OP_LT_DOUBLE_S64
):
1108 OP(BYTECODE_OP_GE_DOUBLE_S64
):
1109 OP(BYTECODE_OP_LE_DOUBLE_S64
):
1110 OP(BYTECODE_OP_EQ_S64_DOUBLE
):
1111 OP(BYTECODE_OP_NE_S64_DOUBLE
):
1112 OP(BYTECODE_OP_GT_S64_DOUBLE
):
1113 OP(BYTECODE_OP_LT_S64_DOUBLE
):
1114 OP(BYTECODE_OP_GE_S64_DOUBLE
):
1115 OP(BYTECODE_OP_LE_S64_DOUBLE
):
1120 OP(BYTECODE_OP_BIT_RSHIFT
):
1124 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1129 /* Catch undefined behavior. */
1130 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1134 res
= ((uint64_t) estack_bx_v
>> (uint32_t) estack_ax_v
);
1135 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1137 estack_ax_t
= REG_U64
;
1138 next_pc
+= sizeof(struct binary_op
);
1141 OP(BYTECODE_OP_BIT_LSHIFT
):
1145 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1150 /* Catch undefined behavior. */
1151 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1155 res
= ((uint64_t) estack_bx_v
<< (uint32_t) estack_ax_v
);
1156 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1158 estack_ax_t
= REG_U64
;
1159 next_pc
+= sizeof(struct binary_op
);
1162 OP(BYTECODE_OP_BIT_AND
):
1166 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1171 res
= ((uint64_t) estack_bx_v
& (uint64_t) estack_ax_v
);
1172 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1174 estack_ax_t
= REG_U64
;
1175 next_pc
+= sizeof(struct binary_op
);
1178 OP(BYTECODE_OP_BIT_OR
):
1182 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1187 res
= ((uint64_t) estack_bx_v
| (uint64_t) estack_ax_v
);
1188 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1190 estack_ax_t
= REG_U64
;
1191 next_pc
+= sizeof(struct binary_op
);
1194 OP(BYTECODE_OP_BIT_XOR
):
1198 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1203 res
= ((uint64_t) estack_bx_v
^ (uint64_t) estack_ax_v
);
1204 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1206 estack_ax_t
= REG_U64
;
1207 next_pc
+= sizeof(struct binary_op
);
1212 OP(BYTECODE_OP_UNARY_PLUS
):
1213 OP(BYTECODE_OP_UNARY_MINUS
):
1214 OP(BYTECODE_OP_UNARY_NOT
):
1215 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1216 (unsigned int) *(bytecode_opcode_t
*) pc
);
1221 OP(BYTECODE_OP_UNARY_BIT_NOT
):
1223 estack_ax_v
= ~(uint64_t) estack_ax_v
;
1224 estack_ax_t
= REG_S64
;
1225 next_pc
+= sizeof(struct unary_op
);
1229 OP(BYTECODE_OP_UNARY_PLUS_S64
):
1231 next_pc
+= sizeof(struct unary_op
);
1234 OP(BYTECODE_OP_UNARY_MINUS_S64
):
1236 estack_ax_v
= -estack_ax_v
;
1237 estack_ax_t
= REG_S64
;
1238 next_pc
+= sizeof(struct unary_op
);
1241 OP(BYTECODE_OP_UNARY_PLUS_DOUBLE
):
1242 OP(BYTECODE_OP_UNARY_MINUS_DOUBLE
):
1247 OP(BYTECODE_OP_UNARY_NOT_S64
):
1249 estack_ax_v
= !estack_ax_v
;
1250 estack_ax_t
= REG_S64
;
1251 next_pc
+= sizeof(struct unary_op
);
1254 OP(BYTECODE_OP_UNARY_NOT_DOUBLE
):
1261 OP(BYTECODE_OP_AND
):
1263 struct logical_op
*insn
= (struct logical_op
*) pc
;
1265 /* If AX is 0, skip and evaluate to 0 */
1266 if (unlikely(estack_ax_v
== 0)) {
1267 dbg_printk("Jumping to bytecode offset %u\n",
1268 (unsigned int) insn
->skip_offset
);
1269 next_pc
= start_pc
+ insn
->skip_offset
;
1271 /* Pop 1 when jump not taken */
1272 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1273 next_pc
+= sizeof(struct logical_op
);
1279 struct logical_op
*insn
= (struct logical_op
*) pc
;
1281 /* If AX is nonzero, skip and evaluate to 1 */
1283 if (unlikely(estack_ax_v
!= 0)) {
1285 dbg_printk("Jumping to bytecode offset %u\n",
1286 (unsigned int) insn
->skip_offset
);
1287 next_pc
= start_pc
+ insn
->skip_offset
;
1289 /* Pop 1 when jump not taken */
1290 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1291 next_pc
+= sizeof(struct logical_op
);
1297 /* load field ref */
1298 OP(BYTECODE_OP_LOAD_FIELD_REF_STRING
):
1300 struct load_op
*insn
= (struct load_op
*) pc
;
1301 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1303 dbg_printk("load field ref offset %u type string\n",
1305 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1306 estack_ax(stack
, top
)->u
.s
.str
=
1307 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1308 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1309 dbg_printk("Bytecode warning: loading a NULL string.\n");
1313 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1314 estack_ax(stack
, top
)->u
.s
.literal_type
=
1315 ESTACK_STRING_LITERAL_TYPE_NONE
;
1316 estack_ax(stack
, top
)->u
.s
.user
= 0;
1317 estack_ax(stack
, top
)->type
= REG_STRING
;
1318 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1319 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1323 OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
):
1325 struct load_op
*insn
= (struct load_op
*) pc
;
1326 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1328 dbg_printk("load field ref offset %u type sequence\n",
1330 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1331 estack_ax(stack
, top
)->u
.s
.seq_len
=
1332 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1333 estack_ax(stack
, top
)->u
.s
.str
=
1334 *(const char **) (&interpreter_stack_data
[ref
->offset
1335 + sizeof(unsigned long)]);
1336 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1337 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1341 estack_ax(stack
, top
)->u
.s
.literal_type
=
1342 ESTACK_STRING_LITERAL_TYPE_NONE
;
1343 estack_ax(stack
, top
)->u
.s
.user
= 0;
1344 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1348 OP(BYTECODE_OP_LOAD_FIELD_REF_S64
):
1350 struct load_op
*insn
= (struct load_op
*) pc
;
1351 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1353 dbg_printk("load field ref offset %u type s64\n",
1355 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1357 ((struct literal_numeric
*) &interpreter_stack_data
[ref
->offset
])->v
;
1358 estack_ax_t
= REG_S64
;
1359 dbg_printk("ref load s64 %lld\n",
1360 (long long) estack_ax_v
);
1361 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1365 OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
):
1371 /* load from immediate operand */
1372 OP(BYTECODE_OP_LOAD_STRING
):
1374 struct load_op
*insn
= (struct load_op
*) pc
;
1376 dbg_printk("load string %s\n", insn
->data
);
1377 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1378 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1379 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1380 estack_ax(stack
, top
)->u
.s
.literal_type
=
1381 ESTACK_STRING_LITERAL_TYPE_PLAIN
;
1382 estack_ax(stack
, top
)->u
.s
.user
= 0;
1383 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1387 OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING
):
1389 struct load_op
*insn
= (struct load_op
*) pc
;
1391 dbg_printk("load globbing pattern %s\n", insn
->data
);
1392 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1393 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1394 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1395 estack_ax(stack
, top
)->u
.s
.literal_type
=
1396 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
;
1397 estack_ax(stack
, top
)->u
.s
.user
= 0;
1398 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1402 OP(BYTECODE_OP_LOAD_S64
):
1404 struct load_op
*insn
= (struct load_op
*) pc
;
1406 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1407 estack_ax_v
= ((struct literal_numeric
*) insn
->data
)->v
;
1408 estack_ax_t
= REG_S64
;
1409 dbg_printk("load s64 %lld\n",
1410 (long long) estack_ax_v
);
1411 next_pc
+= sizeof(struct load_op
)
1412 + sizeof(struct literal_numeric
);
1416 OP(BYTECODE_OP_LOAD_DOUBLE
):
1423 OP(BYTECODE_OP_CAST_TO_S64
):
1424 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1425 (unsigned int) *(bytecode_opcode_t
*) pc
);
1429 OP(BYTECODE_OP_CAST_DOUBLE_TO_S64
):
1435 OP(BYTECODE_OP_CAST_NOP
):
1437 next_pc
+= sizeof(struct cast_op
);
1441 /* get context ref */
1442 OP(BYTECODE_OP_GET_CONTEXT_REF_STRING
):
1444 struct load_op
*insn
= (struct load_op
*) pc
;
1445 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1446 struct lttng_ctx_field
*ctx_field
;
1447 union lttng_ctx_value v
;
1449 dbg_printk("get context ref offset %u type string\n",
1451 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1452 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
1453 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1454 estack_ax(stack
, top
)->u
.s
.str
= v
.str
;
1455 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1456 dbg_printk("Bytecode warning: loading a NULL string.\n");
1460 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1461 estack_ax(stack
, top
)->u
.s
.literal_type
=
1462 ESTACK_STRING_LITERAL_TYPE_NONE
;
1463 estack_ax(stack
, top
)->u
.s
.user
= 0;
1464 estack_ax(stack
, top
)->type
= REG_STRING
;
1465 dbg_printk("ref get context string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1466 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1470 OP(BYTECODE_OP_GET_CONTEXT_REF_S64
):
1472 struct load_op
*insn
= (struct load_op
*) pc
;
1473 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1474 struct lttng_ctx_field
*ctx_field
;
1475 union lttng_ctx_value v
;
1477 dbg_printk("get context ref offset %u type s64\n",
1479 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1480 ctx_field
->get_value(ctx_field
, lttng_probe_ctx
, &v
);
1481 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1482 estack_ax_v
= v
.s64
;
1483 estack_ax_t
= REG_S64
;
1484 dbg_printk("ref get context s64 %lld\n",
1485 (long long) estack_ax_v
);
1486 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1490 OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
):
1496 /* load userspace field ref */
1497 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
):
1499 struct load_op
*insn
= (struct load_op
*) pc
;
1500 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1502 dbg_printk("load field ref offset %u type user string\n",
1504 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1505 estack_ax(stack
, top
)->u
.s
.user_str
=
1506 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1507 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1508 dbg_printk("Bytecode warning: loading a NULL string.\n");
1512 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1513 estack_ax(stack
, top
)->u
.s
.literal_type
=
1514 ESTACK_STRING_LITERAL_TYPE_NONE
;
1515 estack_ax(stack
, top
)->u
.s
.user
= 1;
1516 estack_ax(stack
, top
)->type
= REG_STRING
;
1517 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1518 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1522 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
):
1524 struct load_op
*insn
= (struct load_op
*) pc
;
1525 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1527 dbg_printk("load field ref offset %u type user sequence\n",
1529 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1530 estack_ax(stack
, top
)->u
.s
.seq_len
=
1531 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1532 estack_ax(stack
, top
)->u
.s
.user_str
=
1533 *(const char **) (&interpreter_stack_data
[ref
->offset
1534 + sizeof(unsigned long)]);
1535 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1536 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1540 estack_ax(stack
, top
)->u
.s
.literal_type
=
1541 ESTACK_STRING_LITERAL_TYPE_NONE
;
1542 estack_ax(stack
, top
)->u
.s
.user
= 1;
1543 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1547 OP(BYTECODE_OP_GET_CONTEXT_ROOT
):
1549 dbg_printk("op get context root\n");
1550 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1551 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_CONTEXT
;
1552 /* "field" only needed for variants. */
1553 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1554 estack_ax(stack
, top
)->type
= REG_PTR
;
1555 next_pc
+= sizeof(struct load_op
);
1559 OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT
):
1565 OP(BYTECODE_OP_GET_PAYLOAD_ROOT
):
1567 dbg_printk("op get app payload root\n");
1568 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1569 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_PAYLOAD
;
1570 estack_ax(stack
, top
)->u
.ptr
.ptr
= interpreter_stack_data
;
1571 /* "field" only needed for variants. */
1572 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1573 estack_ax(stack
, top
)->type
= REG_PTR
;
1574 next_pc
+= sizeof(struct load_op
);
1578 OP(BYTECODE_OP_GET_SYMBOL
):
1580 dbg_printk("op get symbol\n");
1581 switch (estack_ax(stack
, top
)->u
.ptr
.type
) {
1583 printk(KERN_WARNING
"LTTng: bytecode: Nested fields not implemented yet.\n");
1586 case LOAD_ROOT_CONTEXT
:
1587 case LOAD_ROOT_APP_CONTEXT
:
1588 case LOAD_ROOT_PAYLOAD
:
1590 * symbol lookup is performed by
1596 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_symbol
);
1600 OP(BYTECODE_OP_GET_SYMBOL_FIELD
):
1603 * Used for first variant encountered in a
1604 * traversal. Variants are not implemented yet.
1610 OP(BYTECODE_OP_GET_INDEX_U16
):
1612 struct load_op
*insn
= (struct load_op
*) pc
;
1613 struct get_index_u16
*index
= (struct get_index_u16
*) insn
->data
;
1615 dbg_printk("op get index u16\n");
1616 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1619 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1620 estack_ax_t
= estack_ax(stack
, top
)->type
;
1621 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u16
);
1625 OP(BYTECODE_OP_GET_INDEX_U64
):
1627 struct load_op
*insn
= (struct load_op
*) pc
;
1628 struct get_index_u64
*index
= (struct get_index_u64
*) insn
->data
;
1630 dbg_printk("op get index u64\n");
1631 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1634 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1635 estack_ax_t
= estack_ax(stack
, top
)->type
;
1636 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u64
);
1640 OP(BYTECODE_OP_LOAD_FIELD
):
1642 dbg_printk("op load field\n");
1643 ret
= dynamic_load_field(estack_ax(stack
, top
));
1646 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1647 estack_ax_t
= estack_ax(stack
, top
)->type
;
1648 next_pc
+= sizeof(struct load_op
);
1652 OP(BYTECODE_OP_LOAD_FIELD_S8
):
1654 dbg_printk("op load field s8\n");
1656 estack_ax_v
= *(int8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1657 estack_ax_t
= REG_S64
;
1658 next_pc
+= sizeof(struct load_op
);
1661 OP(BYTECODE_OP_LOAD_FIELD_S16
):
1663 dbg_printk("op load field s16\n");
1665 estack_ax_v
= *(int16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1666 estack_ax_t
= REG_S64
;
1667 next_pc
+= sizeof(struct load_op
);
1670 OP(BYTECODE_OP_LOAD_FIELD_S32
):
1672 dbg_printk("op load field s32\n");
1674 estack_ax_v
= *(int32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1675 estack_ax_t
= REG_S64
;
1676 next_pc
+= sizeof(struct load_op
);
1679 OP(BYTECODE_OP_LOAD_FIELD_S64
):
1681 dbg_printk("op load field s64\n");
1683 estack_ax_v
= *(int64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1684 estack_ax_t
= REG_S64
;
1685 next_pc
+= sizeof(struct load_op
);
1688 OP(BYTECODE_OP_LOAD_FIELD_U8
):
1690 dbg_printk("op load field u8\n");
1692 estack_ax_v
= *(uint8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1693 estack_ax_t
= REG_S64
;
1694 next_pc
+= sizeof(struct load_op
);
1697 OP(BYTECODE_OP_LOAD_FIELD_U16
):
1699 dbg_printk("op load field u16\n");
1701 estack_ax_v
= *(uint16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1702 estack_ax_t
= REG_S64
;
1703 next_pc
+= sizeof(struct load_op
);
1706 OP(BYTECODE_OP_LOAD_FIELD_U32
):
1708 dbg_printk("op load field u32\n");
1710 estack_ax_v
= *(uint32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1711 estack_ax_t
= REG_S64
;
1712 next_pc
+= sizeof(struct load_op
);
1715 OP(BYTECODE_OP_LOAD_FIELD_U64
):
1717 dbg_printk("op load field u64\n");
1719 estack_ax_v
= *(uint64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1720 estack_ax_t
= REG_S64
;
1721 next_pc
+= sizeof(struct load_op
);
1724 OP(BYTECODE_OP_LOAD_FIELD_DOUBLE
):
1730 OP(BYTECODE_OP_LOAD_FIELD_STRING
):
1734 dbg_printk("op load field string\n");
1735 str
= (const char *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1736 estack_ax(stack
, top
)->u
.s
.str
= str
;
1737 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1738 dbg_printk("Bytecode warning: loading a NULL string.\n");
1742 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1743 estack_ax(stack
, top
)->u
.s
.literal_type
=
1744 ESTACK_STRING_LITERAL_TYPE_NONE
;
1745 estack_ax(stack
, top
)->type
= REG_STRING
;
1746 next_pc
+= sizeof(struct load_op
);
1750 OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE
):
1754 dbg_printk("op load field string sequence\n");
1755 ptr
= estack_ax(stack
, top
)->u
.ptr
.ptr
;
1756 estack_ax(stack
, top
)->u
.s
.seq_len
= *(unsigned long *) ptr
;
1757 estack_ax(stack
, top
)->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
1758 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1759 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1763 estack_ax(stack
, top
)->u
.s
.literal_type
=
1764 ESTACK_STRING_LITERAL_TYPE_NONE
;
1765 estack_ax(stack
, top
)->type
= REG_STRING
;
1766 next_pc
+= sizeof(struct load_op
);
1772 /* Return _DISCARD on error. */
1774 return LTTNG_INTERPRETER_DISCARD
;
1777 return lttng_bytecode_interpret_format_output(
1778 estack_ax(stack
, top
), output
);
1783 LTTNG_STACK_FRAME_NON_STANDARD(bytecode_interpret
);
1785 uint64_t lttng_bytecode_filter_interpret(void *filter_data
,
1786 struct lttng_probe_ctx
*lttng_probe_ctx
,
1787 const char *filter_stack_data
)
1789 return bytecode_interpret(filter_data
, lttng_probe_ctx
,
1790 filter_stack_data
, NULL
);
1793 uint64_t lttng_bytecode_capture_interpret(void *capture_data
,
1794 struct lttng_probe_ctx
*lttng_probe_ctx
,
1795 const char *capture_stack_data
,
1796 struct lttng_interpreter_output
*output
)
1798 return bytecode_interpret(capture_data
, lttng_probe_ctx
,
1799 capture_stack_data
, output
);