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/compiler_attributes.h>
11 #include <wrapper/uaccess.h>
12 #include <wrapper/objtool.h>
13 #include <wrapper/types.h>
14 #include <linux/swab.h>
16 #include <lttng/lttng-bytecode.h>
17 #include <lttng/string-utils.h>
18 #include <lttng/events-internal.h>
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(const 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 int lttng_bytecode_interpret_error(
213 struct lttng_kernel_bytecode_runtime
*bytecode_runtime
__attribute__((unused
)),
214 const char *stack_data
__attribute__((unused
)),
215 struct lttng_kernel_probe_ctx
*probe_ctx
__attribute__((unused
)),
216 void *ctx
__attribute__((unused
)))
218 return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
;
221 #ifdef INTERPRETER_USE_SWITCH
224 * Fallback for compilers that do not support taking address of labels.
228 start_pc = &bytecode->data[0]; \
229 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
231 dbg_printk("LTTng: Executing op %s (%u)\n", \
232 lttng_bytecode_print_op((unsigned int) *(bytecode_opcode_t *) pc), \
233 (unsigned int) *(bytecode_opcode_t *) pc); \
234 switch (*(bytecode_opcode_t *) pc) {
236 #define OP(name) case name
246 * Dispatch-table based interpreter.
250 start_pc = &bytecode->code[0]; \
251 pc = next_pc = start_pc; \
252 if (unlikely(pc - start_pc >= bytecode->len)) \
254 goto *dispatch[*(bytecode_opcode_t *) pc];
261 goto *dispatch[*(bytecode_opcode_t *) pc];
267 #define IS_INTEGER_REGISTER(reg_type) \
268 (reg_type == REG_S64 || reg_type == REG_U64)
270 static int context_get_index(struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
271 struct load_ptr
*ptr
,
275 struct lttng_kernel_ctx_field
*ctx_field
;
276 const struct lttng_kernel_event_field
*field
;
277 struct lttng_ctx_value v
;
279 ctx_field
= <tng_static_ctx
->fields
[idx
];
280 field
= ctx_field
->event_field
;
281 ptr
->type
= LOAD_OBJECT
;
282 /* field is only used for types nested within variants. */
285 switch (field
->type
->type
) {
286 case lttng_kernel_type_integer
:
287 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
288 if (lttng_kernel_get_type_integer(field
->type
)->signedness
) {
289 ptr
->object_type
= OBJECT_TYPE_S64
;
290 ptr
->u
.s64
= v
.u
.s64
;
291 ptr
->ptr
= &ptr
->u
.s64
;
293 ptr
->object_type
= OBJECT_TYPE_U64
;
294 ptr
->u
.u64
= v
.u
.s64
; /* Cast. */
295 ptr
->ptr
= &ptr
->u
.u64
;
298 case lttng_kernel_type_enum
:
300 const struct lttng_kernel_type_enum
*enum_type
= lttng_kernel_get_type_enum(field
->type
);
301 const struct lttng_kernel_type_integer
*integer_type
= lttng_kernel_get_type_integer(enum_type
->container_type
);
303 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
304 if (integer_type
->signedness
) {
305 ptr
->object_type
= OBJECT_TYPE_SIGNED_ENUM
;
306 ptr
->u
.s64
= v
.u
.s64
;
307 ptr
->ptr
= &ptr
->u
.s64
;
309 ptr
->object_type
= OBJECT_TYPE_UNSIGNED_ENUM
;
310 ptr
->u
.u64
= v
.u
.s64
; /* Cast. */
311 ptr
->ptr
= &ptr
->u
.u64
;
315 case lttng_kernel_type_array
:
317 const struct lttng_kernel_type_array
*array_type
= lttng_kernel_get_type_array(field
->type
);
319 if (!lttng_kernel_type_is_bytewise_integer(array_type
->elem_type
)) {
320 printk(KERN_WARNING
"LTTng: bytecode: Array nesting only supports integer types.\n");
323 if (array_type
->encoding
== lttng_kernel_string_encoding_none
) {
324 printk(KERN_WARNING
"LTTng: bytecode: Only string arrays are supported for contexts.\n");
327 ptr
->object_type
= OBJECT_TYPE_STRING
;
328 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
332 case lttng_kernel_type_sequence
:
334 const struct lttng_kernel_type_sequence
*sequence_type
= lttng_kernel_get_type_sequence(field
->type
);
336 if (!lttng_kernel_type_is_bytewise_integer(sequence_type
->elem_type
)) {
337 printk(KERN_WARNING
"LTTng: bytecode: Sequence nesting only supports integer types.\n");
340 if (sequence_type
->encoding
== lttng_kernel_string_encoding_none
) {
341 printk(KERN_WARNING
"LTTng: bytecode: Only string sequences are supported for contexts.\n");
344 ptr
->object_type
= OBJECT_TYPE_STRING
;
345 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
349 case lttng_kernel_type_string
:
350 ptr
->object_type
= OBJECT_TYPE_STRING
;
351 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
354 case lttng_kernel_type_struct
:
355 printk(KERN_WARNING
"LTTng: bytecode: Structure type cannot be loaded.\n");
357 case lttng_kernel_type_variant
:
358 printk(KERN_WARNING
"LTTng: bytecode: Variant type cannot be loaded.\n");
361 printk(KERN_WARNING
"LTTng: bytecode: Unknown type: %d", (int) field
->type
->type
);
367 static int dynamic_get_index(struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
368 struct bytecode_runtime
*runtime
,
369 uint64_t index
, struct estack_entry
*stack_top
)
372 const struct bytecode_get_index_data
*gid
;
374 gid
= (const struct bytecode_get_index_data
*) &runtime
->data
[index
];
375 switch (stack_top
->u
.ptr
.type
) {
377 switch (stack_top
->u
.ptr
.object_type
) {
378 case OBJECT_TYPE_ARRAY
:
382 WARN_ON_ONCE(gid
->offset
>= gid
->array_len
);
383 /* Skip count (unsigned long) */
384 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
385 ptr
= ptr
+ gid
->offset
;
386 stack_top
->u
.ptr
.ptr
= ptr
;
387 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
388 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
389 BUG_ON(stack_top
->u
.ptr
.field
->type
->type
!= lttng_kernel_type_array
);
390 stack_top
->u
.ptr
.field
= NULL
;
393 case OBJECT_TYPE_SEQUENCE
:
398 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
399 ptr_seq_len
= *(unsigned long *) stack_top
->u
.ptr
.ptr
;
400 if (gid
->offset
>= gid
->elem
.len
* ptr_seq_len
) {
404 ptr
= ptr
+ gid
->offset
;
405 stack_top
->u
.ptr
.ptr
= ptr
;
406 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
407 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
408 BUG_ON(stack_top
->u
.ptr
.field
->type
->type
!= lttng_kernel_type_sequence
);
409 stack_top
->u
.ptr
.field
= NULL
;
412 case OBJECT_TYPE_STRUCT
:
413 printk(KERN_WARNING
"LTTng: bytecode: Nested structures are not supported yet.\n");
416 case OBJECT_TYPE_VARIANT
:
418 printk(KERN_WARNING
"LTTng: bytecode: Unexpected get index type %d",
419 (int) stack_top
->u
.ptr
.object_type
);
424 case LOAD_ROOT_CONTEXT
:
426 case LOAD_ROOT_APP_CONTEXT
:
428 ret
= context_get_index(lttng_probe_ctx
,
436 case LOAD_ROOT_PAYLOAD
:
437 stack_top
->u
.ptr
.ptr
+= gid
->offset
;
438 if (gid
->elem
.type
== OBJECT_TYPE_STRING
)
439 stack_top
->u
.ptr
.ptr
= *(const char * const *) stack_top
->u
.ptr
.ptr
;
440 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
441 stack_top
->u
.ptr
.type
= LOAD_OBJECT
;
442 stack_top
->u
.ptr
.field
= gid
->field
;
443 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
447 stack_top
->type
= REG_PTR
;
455 static int dynamic_load_field(struct estack_entry
*stack_top
)
459 switch (stack_top
->u
.ptr
.type
) {
462 case LOAD_ROOT_CONTEXT
:
463 case LOAD_ROOT_APP_CONTEXT
:
464 case LOAD_ROOT_PAYLOAD
:
466 dbg_printk("Bytecode warning: cannot load root, missing field name.\n");
470 switch (stack_top
->u
.ptr
.object_type
) {
472 dbg_printk("op load field s8\n");
473 stack_top
->u
.v
= *(int8_t *) stack_top
->u
.ptr
.ptr
;
474 stack_top
->type
= REG_S64
;
476 case OBJECT_TYPE_S16
:
480 dbg_printk("op load field s16\n");
481 tmp
= *(int16_t *) stack_top
->u
.ptr
.ptr
;
482 if (stack_top
->u
.ptr
.rev_bo
)
484 stack_top
->u
.v
= tmp
;
485 stack_top
->type
= REG_S64
;
488 case OBJECT_TYPE_S32
:
492 dbg_printk("op load field s32\n");
493 tmp
= *(int32_t *) stack_top
->u
.ptr
.ptr
;
494 if (stack_top
->u
.ptr
.rev_bo
)
496 stack_top
->u
.v
= tmp
;
497 stack_top
->type
= REG_S64
;
500 case OBJECT_TYPE_S64
:
504 dbg_printk("op load field s64\n");
505 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
506 if (stack_top
->u
.ptr
.rev_bo
)
508 stack_top
->u
.v
= tmp
;
509 stack_top
->type
= REG_S64
;
512 case OBJECT_TYPE_SIGNED_ENUM
:
516 dbg_printk("op load field signed enumeration\n");
517 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
518 if (stack_top
->u
.ptr
.rev_bo
)
520 stack_top
->u
.v
= tmp
;
521 stack_top
->type
= REG_S64
;
525 dbg_printk("op load field u8\n");
526 stack_top
->u
.v
= *(uint8_t *) stack_top
->u
.ptr
.ptr
;
527 stack_top
->type
= REG_U64
;
529 case OBJECT_TYPE_U16
:
533 dbg_printk("op load field u16\n");
534 tmp
= *(uint16_t *) stack_top
->u
.ptr
.ptr
;
535 if (stack_top
->u
.ptr
.rev_bo
)
537 stack_top
->u
.v
= tmp
;
538 stack_top
->type
= REG_U64
;
541 case OBJECT_TYPE_U32
:
545 dbg_printk("op load field u32\n");
546 tmp
= *(uint32_t *) stack_top
->u
.ptr
.ptr
;
547 if (stack_top
->u
.ptr
.rev_bo
)
549 stack_top
->u
.v
= tmp
;
550 stack_top
->type
= REG_U64
;
553 case OBJECT_TYPE_U64
:
557 dbg_printk("op load field u64\n");
558 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
559 if (stack_top
->u
.ptr
.rev_bo
)
561 stack_top
->u
.v
= tmp
;
562 stack_top
->type
= REG_U64
;
565 case OBJECT_TYPE_UNSIGNED_ENUM
:
569 dbg_printk("op load field unsigned enumeration\n");
570 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
571 if (stack_top
->u
.ptr
.rev_bo
)
573 stack_top
->u
.v
= tmp
;
574 stack_top
->type
= REG_U64
;
577 case OBJECT_TYPE_STRING
:
581 dbg_printk("op load field string\n");
582 str
= (const char *) stack_top
->u
.ptr
.ptr
;
583 stack_top
->u
.s
.str
= str
;
584 if (unlikely(!stack_top
->u
.s
.str
)) {
585 dbg_printk("Bytecode warning: loading a NULL string.\n");
589 stack_top
->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
590 stack_top
->u
.s
.literal_type
=
591 ESTACK_STRING_LITERAL_TYPE_NONE
;
592 stack_top
->type
= REG_STRING
;
595 case OBJECT_TYPE_STRING_SEQUENCE
:
599 dbg_printk("op load field string sequence\n");
600 ptr
= stack_top
->u
.ptr
.ptr
;
601 stack_top
->u
.s
.seq_len
= *(unsigned long *) ptr
;
602 stack_top
->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
603 if (unlikely(!stack_top
->u
.s
.str
)) {
604 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
608 stack_top
->u
.s
.literal_type
=
609 ESTACK_STRING_LITERAL_TYPE_NONE
;
610 stack_top
->type
= REG_STRING
;
613 case OBJECT_TYPE_DYNAMIC
:
615 * Dynamic types in context are looked up
616 * by context get index.
620 case OBJECT_TYPE_DOUBLE
:
623 case OBJECT_TYPE_SEQUENCE
:
624 case OBJECT_TYPE_ARRAY
:
625 case OBJECT_TYPE_STRUCT
:
626 case OBJECT_TYPE_VARIANT
:
627 printk(KERN_WARNING
"LTTng: bytecode: Sequences, arrays, struct and variant cannot be loaded (nested types).\n");
638 int lttng_bytecode_interpret_format_output(struct estack_entry
*ax
,
639 struct lttng_interpreter_output
*output
)
646 output
->type
= LTTNG_INTERPRETER_TYPE_S64
;
647 output
->u
.s
= ax
->u
.v
;
650 output
->type
= LTTNG_INTERPRETER_TYPE_U64
;
651 output
->u
.u
= (uint64_t) ax
->u
.v
;
654 output
->type
= LTTNG_INTERPRETER_TYPE_STRING
;
655 output
->u
.str
.str
= ax
->u
.s
.str
;
656 output
->u
.str
.len
= ax
->u
.s
.seq_len
;
659 switch (ax
->u
.ptr
.object_type
) {
661 case OBJECT_TYPE_S16
:
662 case OBJECT_TYPE_S32
:
663 case OBJECT_TYPE_S64
:
665 case OBJECT_TYPE_U16
:
666 case OBJECT_TYPE_U32
:
667 case OBJECT_TYPE_U64
:
668 case OBJECT_TYPE_DOUBLE
:
669 case OBJECT_TYPE_STRING
:
670 case OBJECT_TYPE_STRING_SEQUENCE
:
671 ret
= dynamic_load_field(ax
);
674 /* Retry after loading ptr into stack top. */
676 case OBJECT_TYPE_SEQUENCE
:
677 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
678 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
679 output
->u
.sequence
.nr_elem
= *(unsigned long *) ax
->u
.ptr
.ptr
;
680 output
->u
.sequence
.nested_type
= lttng_kernel_get_type_sequence(ax
->u
.ptr
.field
->type
)->elem_type
;
682 case OBJECT_TYPE_ARRAY
:
683 /* Skip count (unsigned long) */
684 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
685 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
686 output
->u
.sequence
.nr_elem
= lttng_kernel_get_type_array(ax
->u
.ptr
.field
->type
)->length
;
687 output
->u
.sequence
.nested_type
= lttng_kernel_get_type_array(ax
->u
.ptr
.field
->type
)->elem_type
;
689 case OBJECT_TYPE_SIGNED_ENUM
:
690 ret
= dynamic_load_field(ax
);
693 output
->type
= LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
;
694 output
->u
.s
= ax
->u
.v
;
696 case OBJECT_TYPE_UNSIGNED_ENUM
:
697 ret
= dynamic_load_field(ax
);
700 output
->type
= LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
;
701 output
->u
.u
= ax
->u
.v
;
703 case OBJECT_TYPE_STRUCT
:
704 case OBJECT_TYPE_VARIANT
:
710 case REG_STAR_GLOB_STRING
:
711 case REG_TYPE_UNKNOWN
:
721 #define DBG_USER_STR_CUTOFF 32
724 * In debug mode, print user string (truncated, if necessary).
727 void dbg_load_ref_user_str_printk(const struct estack_entry
*user_str_reg
)
731 char user_str
[DBG_USER_STR_CUTOFF
];
735 last_char
= get_char(user_str_reg
, pos
);
736 user_str
[pos
] = last_char
;
738 } while (last_char
!= '\0' && pos
< sizeof(user_str
));
741 user_str
[sizeof(user_str
) - 1] = '\0';
742 dbg_printk("load field ref user string: '%s%s'\n", user_str
,
743 last_char
!= '\0' ? "[...]" : "");
747 void dbg_load_ref_user_str_printk(const struct estack_entry
*user_str_reg
)
753 * Return LTTNG_KERNEL_BYTECODE_INTERPRETER_OK on success.
754 * Return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR on error.
756 * For FILTER bytecode: expect a struct lttng_kernel_bytecode_filter_ctx *
758 * For CAPTURE bytecode: expect a struct lttng_interpreter_output *
761 int lttng_bytecode_interpret(struct lttng_kernel_bytecode_runtime
*kernel_bytecode
,
762 const char *interpreter_stack_data
,
763 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
766 struct bytecode_runtime
*bytecode
= container_of(kernel_bytecode
, struct bytecode_runtime
, p
);
767 void *pc
, *next_pc
, *start_pc
;
770 struct estack _stack
;
771 struct estack
*stack
= &_stack
;
772 register int64_t ax
= 0, bx
= 0;
773 register enum entry_type ax_t
= REG_TYPE_UNKNOWN
, bx_t
= REG_TYPE_UNKNOWN
;
774 register int top
= INTERPRETER_STACK_EMPTY
;
775 #ifndef INTERPRETER_USE_SWITCH
776 static void *dispatch
[NR_BYTECODE_OPS
] = {
777 [ BYTECODE_OP_UNKNOWN
] = &&LABEL_BYTECODE_OP_UNKNOWN
,
779 [ BYTECODE_OP_RETURN
] = &&LABEL_BYTECODE_OP_RETURN
,
782 [ BYTECODE_OP_MUL
] = &&LABEL_BYTECODE_OP_MUL
,
783 [ BYTECODE_OP_DIV
] = &&LABEL_BYTECODE_OP_DIV
,
784 [ BYTECODE_OP_MOD
] = &&LABEL_BYTECODE_OP_MOD
,
785 [ BYTECODE_OP_PLUS
] = &&LABEL_BYTECODE_OP_PLUS
,
786 [ BYTECODE_OP_MINUS
] = &&LABEL_BYTECODE_OP_MINUS
,
787 [ BYTECODE_OP_BIT_RSHIFT
] = &&LABEL_BYTECODE_OP_BIT_RSHIFT
,
788 [ BYTECODE_OP_BIT_LSHIFT
] = &&LABEL_BYTECODE_OP_BIT_LSHIFT
,
789 [ BYTECODE_OP_BIT_AND
] = &&LABEL_BYTECODE_OP_BIT_AND
,
790 [ BYTECODE_OP_BIT_OR
] = &&LABEL_BYTECODE_OP_BIT_OR
,
791 [ BYTECODE_OP_BIT_XOR
] = &&LABEL_BYTECODE_OP_BIT_XOR
,
793 /* binary comparators */
794 [ BYTECODE_OP_EQ
] = &&LABEL_BYTECODE_OP_EQ
,
795 [ BYTECODE_OP_NE
] = &&LABEL_BYTECODE_OP_NE
,
796 [ BYTECODE_OP_GT
] = &&LABEL_BYTECODE_OP_GT
,
797 [ BYTECODE_OP_LT
] = &&LABEL_BYTECODE_OP_LT
,
798 [ BYTECODE_OP_GE
] = &&LABEL_BYTECODE_OP_GE
,
799 [ BYTECODE_OP_LE
] = &&LABEL_BYTECODE_OP_LE
,
801 /* string binary comparator */
802 [ BYTECODE_OP_EQ_STRING
] = &&LABEL_BYTECODE_OP_EQ_STRING
,
803 [ BYTECODE_OP_NE_STRING
] = &&LABEL_BYTECODE_OP_NE_STRING
,
804 [ BYTECODE_OP_GT_STRING
] = &&LABEL_BYTECODE_OP_GT_STRING
,
805 [ BYTECODE_OP_LT_STRING
] = &&LABEL_BYTECODE_OP_LT_STRING
,
806 [ BYTECODE_OP_GE_STRING
] = &&LABEL_BYTECODE_OP_GE_STRING
,
807 [ BYTECODE_OP_LE_STRING
] = &&LABEL_BYTECODE_OP_LE_STRING
,
809 /* globbing pattern binary comparator */
810 [ BYTECODE_OP_EQ_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING
,
811 [ BYTECODE_OP_NE_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING
,
813 /* s64 binary comparator */
814 [ BYTECODE_OP_EQ_S64
] = &&LABEL_BYTECODE_OP_EQ_S64
,
815 [ BYTECODE_OP_NE_S64
] = &&LABEL_BYTECODE_OP_NE_S64
,
816 [ BYTECODE_OP_GT_S64
] = &&LABEL_BYTECODE_OP_GT_S64
,
817 [ BYTECODE_OP_LT_S64
] = &&LABEL_BYTECODE_OP_LT_S64
,
818 [ BYTECODE_OP_GE_S64
] = &&LABEL_BYTECODE_OP_GE_S64
,
819 [ BYTECODE_OP_LE_S64
] = &&LABEL_BYTECODE_OP_LE_S64
,
821 /* double binary comparator */
822 [ BYTECODE_OP_EQ_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE
,
823 [ BYTECODE_OP_NE_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_DOUBLE
,
824 [ BYTECODE_OP_GT_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_DOUBLE
,
825 [ BYTECODE_OP_LT_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_DOUBLE
,
826 [ BYTECODE_OP_GE_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_DOUBLE
,
827 [ BYTECODE_OP_LE_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_DOUBLE
,
829 /* Mixed S64-double binary comparators */
830 [ BYTECODE_OP_EQ_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64
,
831 [ BYTECODE_OP_NE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64
,
832 [ BYTECODE_OP_GT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64
,
833 [ BYTECODE_OP_LT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64
,
834 [ BYTECODE_OP_GE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64
,
835 [ BYTECODE_OP_LE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64
,
837 [ BYTECODE_OP_EQ_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE
,
838 [ BYTECODE_OP_NE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE
,
839 [ BYTECODE_OP_GT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE
,
840 [ BYTECODE_OP_LT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE
,
841 [ BYTECODE_OP_GE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE
,
842 [ BYTECODE_OP_LE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE
,
845 [ BYTECODE_OP_UNARY_PLUS
] = &&LABEL_BYTECODE_OP_UNARY_PLUS
,
846 [ BYTECODE_OP_UNARY_MINUS
] = &&LABEL_BYTECODE_OP_UNARY_MINUS
,
847 [ BYTECODE_OP_UNARY_NOT
] = &&LABEL_BYTECODE_OP_UNARY_NOT
,
848 [ BYTECODE_OP_UNARY_PLUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64
,
849 [ BYTECODE_OP_UNARY_MINUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64
,
850 [ BYTECODE_OP_UNARY_NOT_S64
] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64
,
851 [ BYTECODE_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE
,
852 [ BYTECODE_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE
,
853 [ BYTECODE_OP_UNARY_NOT_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE
,
856 [ BYTECODE_OP_AND
] = &&LABEL_BYTECODE_OP_AND
,
857 [ BYTECODE_OP_OR
] = &&LABEL_BYTECODE_OP_OR
,
860 [ BYTECODE_OP_LOAD_FIELD_REF
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF
,
861 [ BYTECODE_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING
,
862 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
,
863 [ BYTECODE_OP_LOAD_FIELD_REF_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64
,
864 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
,
866 /* load from immediate operand */
867 [ BYTECODE_OP_LOAD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STRING
,
868 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING
,
869 [ BYTECODE_OP_LOAD_S64
] = &&LABEL_BYTECODE_OP_LOAD_S64
,
870 [ BYTECODE_OP_LOAD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE
,
873 [ BYTECODE_OP_CAST_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_TO_S64
,
874 [ BYTECODE_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64
,
875 [ BYTECODE_OP_CAST_NOP
] = &&LABEL_BYTECODE_OP_CAST_NOP
,
877 /* get context ref */
878 [ BYTECODE_OP_GET_CONTEXT_REF
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF
,
879 [ BYTECODE_OP_GET_CONTEXT_REF_STRING
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING
,
880 [ BYTECODE_OP_GET_CONTEXT_REF_S64
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64
,
881 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
,
883 /* load userspace field ref */
884 [ BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
,
885 [ BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
,
887 /* Instructions for recursive traversal through composed types. */
888 [ BYTECODE_OP_GET_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT
,
889 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT
,
890 [ BYTECODE_OP_GET_PAYLOAD_ROOT
] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT
,
892 [ BYTECODE_OP_GET_SYMBOL
] = &&LABEL_BYTECODE_OP_GET_SYMBOL
,
893 [ BYTECODE_OP_GET_SYMBOL_FIELD
] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD
,
894 [ BYTECODE_OP_GET_INDEX_U16
] = &&LABEL_BYTECODE_OP_GET_INDEX_U16
,
895 [ BYTECODE_OP_GET_INDEX_U64
] = &&LABEL_BYTECODE_OP_GET_INDEX_U64
,
897 [ BYTECODE_OP_LOAD_FIELD
] = &&LABEL_BYTECODE_OP_LOAD_FIELD
,
898 [ BYTECODE_OP_LOAD_FIELD_S8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8
,
899 [ BYTECODE_OP_LOAD_FIELD_S16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16
,
900 [ BYTECODE_OP_LOAD_FIELD_S32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32
,
901 [ BYTECODE_OP_LOAD_FIELD_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64
,
902 [ BYTECODE_OP_LOAD_FIELD_U8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8
,
903 [ BYTECODE_OP_LOAD_FIELD_U16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16
,
904 [ BYTECODE_OP_LOAD_FIELD_U32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32
,
905 [ BYTECODE_OP_LOAD_FIELD_U64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64
,
906 [ BYTECODE_OP_LOAD_FIELD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING
,
907 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE
,
908 [ BYTECODE_OP_LOAD_FIELD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE
,
910 [ BYTECODE_OP_UNARY_BIT_NOT
] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT
,
912 [ BYTECODE_OP_RETURN_S64
] = &&LABEL_BYTECODE_OP_RETURN_S64
,
914 #endif /* #ifndef INTERPRETER_USE_SWITCH */
918 OP(BYTECODE_OP_UNKNOWN
):
919 OP(BYTECODE_OP_LOAD_FIELD_REF
):
920 OP(BYTECODE_OP_GET_CONTEXT_REF
):
921 #ifdef INTERPRETER_USE_SWITCH
923 #endif /* INTERPRETER_USE_SWITCH */
924 printk(KERN_WARNING
"LTTng: bytecode: unknown bytecode op %u\n",
925 (unsigned int) *(bytecode_opcode_t
*) pc
);
929 OP(BYTECODE_OP_RETURN
):
930 /* LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR or LTTNG_KERNEL_BYTECODE_INTERPRETER_OK */
931 switch (estack_ax_t
) {
934 retval
= !!estack_ax_v
;
939 if (kernel_bytecode
->type
!= LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
) {
945 case REG_STAR_GLOB_STRING
:
946 case REG_TYPE_UNKNOWN
:
953 OP(BYTECODE_OP_RETURN_S64
):
954 /* LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR or LTTNG_KERNEL_BYTECODE_INTERPRETER_OK */
955 retval
= !!estack_ax_v
;
963 OP(BYTECODE_OP_PLUS
):
964 OP(BYTECODE_OP_MINUS
):
965 printk(KERN_WARNING
"LTTng: bytecode: unsupported bytecode op %u\n",
966 (unsigned int) *(bytecode_opcode_t
*) pc
);
976 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
977 (unsigned int) *(bytecode_opcode_t
*) pc
);
981 OP(BYTECODE_OP_EQ_STRING
):
985 res
= (stack_strcmp(stack
, top
, "==") == 0);
986 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
988 estack_ax_t
= REG_S64
;
989 next_pc
+= sizeof(struct binary_op
);
992 OP(BYTECODE_OP_NE_STRING
):
996 res
= (stack_strcmp(stack
, top
, "!=") != 0);
997 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
999 estack_ax_t
= REG_S64
;
1000 next_pc
+= sizeof(struct binary_op
);
1003 OP(BYTECODE_OP_GT_STRING
):
1007 res
= (stack_strcmp(stack
, top
, ">") > 0);
1008 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1010 estack_ax_t
= REG_S64
;
1011 next_pc
+= sizeof(struct binary_op
);
1014 OP(BYTECODE_OP_LT_STRING
):
1018 res
= (stack_strcmp(stack
, top
, "<") < 0);
1019 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1021 estack_ax_t
= REG_S64
;
1022 next_pc
+= sizeof(struct binary_op
);
1025 OP(BYTECODE_OP_GE_STRING
):
1029 res
= (stack_strcmp(stack
, top
, ">=") >= 0);
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_LE_STRING
):
1040 res
= (stack_strcmp(stack
, top
, "<=") <= 0);
1041 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1043 estack_ax_t
= REG_S64
;
1044 next_pc
+= sizeof(struct binary_op
);
1048 OP(BYTECODE_OP_EQ_STAR_GLOB_STRING
):
1052 res
= (stack_star_glob_match(stack
, top
, "==") == 0);
1053 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1055 estack_ax_t
= REG_S64
;
1056 next_pc
+= sizeof(struct binary_op
);
1059 OP(BYTECODE_OP_NE_STAR_GLOB_STRING
):
1063 res
= (stack_star_glob_match(stack
, top
, "!=") != 0);
1064 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1066 estack_ax_t
= REG_S64
;
1067 next_pc
+= sizeof(struct binary_op
);
1071 OP(BYTECODE_OP_EQ_S64
):
1075 res
= (estack_bx_v
== estack_ax_v
);
1076 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1078 estack_ax_t
= REG_S64
;
1079 next_pc
+= sizeof(struct binary_op
);
1082 OP(BYTECODE_OP_NE_S64
):
1086 res
= (estack_bx_v
!= estack_ax_v
);
1087 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1089 estack_ax_t
= REG_S64
;
1090 next_pc
+= sizeof(struct binary_op
);
1093 OP(BYTECODE_OP_GT_S64
):
1097 res
= (estack_bx_v
> estack_ax_v
);
1098 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1100 estack_ax_t
= REG_S64
;
1101 next_pc
+= sizeof(struct binary_op
);
1104 OP(BYTECODE_OP_LT_S64
):
1108 res
= (estack_bx_v
< estack_ax_v
);
1109 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1111 estack_ax_t
= REG_S64
;
1112 next_pc
+= sizeof(struct binary_op
);
1115 OP(BYTECODE_OP_GE_S64
):
1119 res
= (estack_bx_v
>= estack_ax_v
);
1120 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1122 estack_ax_t
= REG_S64
;
1123 next_pc
+= sizeof(struct binary_op
);
1126 OP(BYTECODE_OP_LE_S64
):
1130 res
= (estack_bx_v
<= estack_ax_v
);
1131 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1133 estack_ax_t
= REG_S64
;
1134 next_pc
+= sizeof(struct binary_op
);
1138 OP(BYTECODE_OP_EQ_DOUBLE
):
1139 OP(BYTECODE_OP_NE_DOUBLE
):
1140 OP(BYTECODE_OP_GT_DOUBLE
):
1141 OP(BYTECODE_OP_LT_DOUBLE
):
1142 OP(BYTECODE_OP_GE_DOUBLE
):
1143 OP(BYTECODE_OP_LE_DOUBLE
):
1149 /* Mixed S64-double binary comparators */
1150 OP(BYTECODE_OP_EQ_DOUBLE_S64
):
1151 OP(BYTECODE_OP_NE_DOUBLE_S64
):
1152 OP(BYTECODE_OP_GT_DOUBLE_S64
):
1153 OP(BYTECODE_OP_LT_DOUBLE_S64
):
1154 OP(BYTECODE_OP_GE_DOUBLE_S64
):
1155 OP(BYTECODE_OP_LE_DOUBLE_S64
):
1156 OP(BYTECODE_OP_EQ_S64_DOUBLE
):
1157 OP(BYTECODE_OP_NE_S64_DOUBLE
):
1158 OP(BYTECODE_OP_GT_S64_DOUBLE
):
1159 OP(BYTECODE_OP_LT_S64_DOUBLE
):
1160 OP(BYTECODE_OP_GE_S64_DOUBLE
):
1161 OP(BYTECODE_OP_LE_S64_DOUBLE
):
1166 OP(BYTECODE_OP_BIT_RSHIFT
):
1170 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1175 /* Catch undefined behavior. */
1176 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1180 res
= ((uint64_t) estack_bx_v
>> (uint32_t) estack_ax_v
);
1181 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1183 estack_ax_t
= REG_U64
;
1184 next_pc
+= sizeof(struct binary_op
);
1187 OP(BYTECODE_OP_BIT_LSHIFT
):
1191 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1196 /* Catch undefined behavior. */
1197 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1201 res
= ((uint64_t) estack_bx_v
<< (uint32_t) estack_ax_v
);
1202 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1204 estack_ax_t
= REG_U64
;
1205 next_pc
+= sizeof(struct binary_op
);
1208 OP(BYTECODE_OP_BIT_AND
):
1212 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1217 res
= ((uint64_t) estack_bx_v
& (uint64_t) estack_ax_v
);
1218 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1220 estack_ax_t
= REG_U64
;
1221 next_pc
+= sizeof(struct binary_op
);
1224 OP(BYTECODE_OP_BIT_OR
):
1228 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1233 res
= ((uint64_t) estack_bx_v
| (uint64_t) estack_ax_v
);
1234 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1236 estack_ax_t
= REG_U64
;
1237 next_pc
+= sizeof(struct binary_op
);
1240 OP(BYTECODE_OP_BIT_XOR
):
1244 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1249 res
= ((uint64_t) estack_bx_v
^ (uint64_t) estack_ax_v
);
1250 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1252 estack_ax_t
= REG_U64
;
1253 next_pc
+= sizeof(struct binary_op
);
1258 OP(BYTECODE_OP_UNARY_PLUS
):
1259 OP(BYTECODE_OP_UNARY_MINUS
):
1260 OP(BYTECODE_OP_UNARY_NOT
):
1261 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1262 (unsigned int) *(bytecode_opcode_t
*) pc
);
1267 OP(BYTECODE_OP_UNARY_BIT_NOT
):
1269 estack_ax_v
= ~(uint64_t) estack_ax_v
;
1270 estack_ax_t
= REG_S64
;
1271 next_pc
+= sizeof(struct unary_op
);
1275 OP(BYTECODE_OP_UNARY_PLUS_S64
):
1277 next_pc
+= sizeof(struct unary_op
);
1280 OP(BYTECODE_OP_UNARY_MINUS_S64
):
1282 estack_ax_v
= -estack_ax_v
;
1283 estack_ax_t
= REG_S64
;
1284 next_pc
+= sizeof(struct unary_op
);
1287 OP(BYTECODE_OP_UNARY_PLUS_DOUBLE
):
1288 OP(BYTECODE_OP_UNARY_MINUS_DOUBLE
):
1293 OP(BYTECODE_OP_UNARY_NOT_S64
):
1295 estack_ax_v
= !estack_ax_v
;
1296 estack_ax_t
= REG_S64
;
1297 next_pc
+= sizeof(struct unary_op
);
1300 OP(BYTECODE_OP_UNARY_NOT_DOUBLE
):
1307 OP(BYTECODE_OP_AND
):
1309 struct logical_op
*insn
= (struct logical_op
*) pc
;
1311 /* If AX is 0, skip and evaluate to 0 */
1312 if (unlikely(estack_ax_v
== 0)) {
1313 dbg_printk("Jumping to bytecode offset %u\n",
1314 (unsigned int) insn
->skip_offset
);
1315 next_pc
= start_pc
+ insn
->skip_offset
;
1317 /* Pop 1 when jump not taken */
1318 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1319 next_pc
+= sizeof(struct logical_op
);
1325 struct logical_op
*insn
= (struct logical_op
*) pc
;
1327 /* If AX is nonzero, skip and evaluate to 1 */
1329 if (unlikely(estack_ax_v
!= 0)) {
1331 dbg_printk("Jumping to bytecode offset %u\n",
1332 (unsigned int) insn
->skip_offset
);
1333 next_pc
= start_pc
+ insn
->skip_offset
;
1335 /* Pop 1 when jump not taken */
1336 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1337 next_pc
+= sizeof(struct logical_op
);
1343 /* load field ref */
1344 OP(BYTECODE_OP_LOAD_FIELD_REF_STRING
):
1346 struct load_op
*insn
= (struct load_op
*) pc
;
1347 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1349 dbg_printk("load field ref offset %u type string\n",
1351 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1352 estack_ax(stack
, top
)->u
.s
.str
=
1353 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1354 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1355 dbg_printk("Bytecode warning: loading a NULL string.\n");
1359 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1360 estack_ax(stack
, top
)->u
.s
.literal_type
=
1361 ESTACK_STRING_LITERAL_TYPE_NONE
;
1362 estack_ax(stack
, top
)->u
.s
.user
= 0;
1363 estack_ax(stack
, top
)->type
= REG_STRING
;
1364 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1365 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1369 OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
):
1371 struct load_op
*insn
= (struct load_op
*) pc
;
1372 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1374 dbg_printk("load field ref offset %u type sequence\n",
1376 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1377 estack_ax(stack
, top
)->u
.s
.seq_len
=
1378 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1379 estack_ax(stack
, top
)->u
.s
.str
=
1380 *(const char **) (&interpreter_stack_data
[ref
->offset
1381 + sizeof(unsigned long)]);
1382 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1383 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1387 estack_ax(stack
, top
)->u
.s
.literal_type
=
1388 ESTACK_STRING_LITERAL_TYPE_NONE
;
1389 estack_ax(stack
, top
)->u
.s
.user
= 0;
1390 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1394 OP(BYTECODE_OP_LOAD_FIELD_REF_S64
):
1396 struct load_op
*insn
= (struct load_op
*) pc
;
1397 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1399 dbg_printk("load field ref offset %u type s64\n",
1401 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1403 ((struct literal_numeric
*) &interpreter_stack_data
[ref
->offset
])->v
;
1404 estack_ax_t
= REG_S64
;
1405 dbg_printk("ref load s64 %lld\n",
1406 (long long) estack_ax_v
);
1407 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1411 OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
):
1417 /* load from immediate operand */
1418 OP(BYTECODE_OP_LOAD_STRING
):
1420 struct load_op
*insn
= (struct load_op
*) pc
;
1422 dbg_printk("load string %s\n", insn
->data
);
1423 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1424 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1425 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1426 estack_ax(stack
, top
)->u
.s
.literal_type
=
1427 ESTACK_STRING_LITERAL_TYPE_PLAIN
;
1428 estack_ax(stack
, top
)->u
.s
.user
= 0;
1429 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1433 OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING
):
1435 struct load_op
*insn
= (struct load_op
*) pc
;
1437 dbg_printk("load globbing pattern %s\n", insn
->data
);
1438 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1439 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1440 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1441 estack_ax(stack
, top
)->u
.s
.literal_type
=
1442 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
;
1443 estack_ax(stack
, top
)->u
.s
.user
= 0;
1444 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1448 OP(BYTECODE_OP_LOAD_S64
):
1450 struct load_op
*insn
= (struct load_op
*) pc
;
1452 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1453 estack_ax_v
= ((struct literal_numeric
*) insn
->data
)->v
;
1454 estack_ax_t
= REG_S64
;
1455 dbg_printk("load s64 %lld\n",
1456 (long long) estack_ax_v
);
1457 next_pc
+= sizeof(struct load_op
)
1458 + sizeof(struct literal_numeric
);
1462 OP(BYTECODE_OP_LOAD_DOUBLE
):
1469 OP(BYTECODE_OP_CAST_TO_S64
):
1470 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1471 (unsigned int) *(bytecode_opcode_t
*) pc
);
1475 OP(BYTECODE_OP_CAST_DOUBLE_TO_S64
):
1481 OP(BYTECODE_OP_CAST_NOP
):
1483 next_pc
+= sizeof(struct cast_op
);
1487 /* get context ref */
1488 OP(BYTECODE_OP_GET_CONTEXT_REF_STRING
):
1490 struct load_op
*insn
= (struct load_op
*) pc
;
1491 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1492 struct lttng_kernel_ctx_field
*ctx_field
;
1493 struct lttng_ctx_value v
;
1495 dbg_printk("get context ref offset %u type string\n",
1497 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1498 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
1499 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1500 estack_ax(stack
, top
)->u
.s
.str
= v
.u
.str
;
1501 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1502 dbg_printk("Bytecode warning: loading a NULL string.\n");
1506 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1507 estack_ax(stack
, top
)->u
.s
.literal_type
=
1508 ESTACK_STRING_LITERAL_TYPE_NONE
;
1509 estack_ax(stack
, top
)->u
.s
.user
= 0;
1510 estack_ax(stack
, top
)->type
= REG_STRING
;
1511 dbg_printk("ref get context string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1512 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1516 OP(BYTECODE_OP_GET_CONTEXT_REF_S64
):
1518 struct load_op
*insn
= (struct load_op
*) pc
;
1519 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1520 struct lttng_kernel_ctx_field
*ctx_field
;
1521 struct lttng_ctx_value v
;
1523 dbg_printk("get context ref offset %u type s64\n",
1525 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1526 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
1527 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1528 estack_ax_v
= v
.u
.s64
;
1529 estack_ax_t
= REG_S64
;
1530 dbg_printk("ref get context s64 %lld\n",
1531 (long long) estack_ax_v
);
1532 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1536 OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
):
1542 /* load userspace field ref */
1543 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
):
1545 struct load_op
*insn
= (struct load_op
*) pc
;
1546 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1548 dbg_printk("load field ref offset %u type user string\n",
1550 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1551 estack_ax(stack
, top
)->u
.s
.user_str
=
1552 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1553 if (unlikely(!estack_ax(stack
, top
)->u
.s
.user_str
)) {
1554 dbg_printk("Bytecode warning: loading a NULL string.\n");
1558 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1559 estack_ax(stack
, top
)->u
.s
.literal_type
=
1560 ESTACK_STRING_LITERAL_TYPE_NONE
;
1561 estack_ax(stack
, top
)->u
.s
.user
= 1;
1562 estack_ax(stack
, top
)->type
= REG_STRING
;
1563 dbg_load_ref_user_str_printk(estack_ax(stack
, top
));
1564 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1568 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
):
1570 struct load_op
*insn
= (struct load_op
*) pc
;
1571 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1573 dbg_printk("load field ref offset %u type user sequence\n",
1575 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1576 estack_ax(stack
, top
)->u
.s
.seq_len
=
1577 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1578 estack_ax(stack
, top
)->u
.s
.user_str
=
1579 *(const char **) (&interpreter_stack_data
[ref
->offset
1580 + sizeof(unsigned long)]);
1581 if (unlikely(!estack_ax(stack
, top
)->u
.s
.user_str
)) {
1582 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1586 estack_ax(stack
, top
)->u
.s
.literal_type
=
1587 ESTACK_STRING_LITERAL_TYPE_NONE
;
1588 estack_ax(stack
, top
)->u
.s
.user
= 1;
1589 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1593 OP(BYTECODE_OP_GET_CONTEXT_ROOT
):
1595 dbg_printk("op get context root\n");
1596 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1597 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_CONTEXT
;
1598 /* "field" only needed for variants. */
1599 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1600 estack_ax(stack
, top
)->type
= REG_PTR
;
1601 next_pc
+= sizeof(struct load_op
);
1605 OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT
):
1611 OP(BYTECODE_OP_GET_PAYLOAD_ROOT
):
1613 dbg_printk("op get app payload root\n");
1614 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1615 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_PAYLOAD
;
1616 estack_ax(stack
, top
)->u
.ptr
.ptr
= interpreter_stack_data
;
1617 /* "field" only needed for variants. */
1618 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1619 estack_ax(stack
, top
)->type
= REG_PTR
;
1620 next_pc
+= sizeof(struct load_op
);
1624 OP(BYTECODE_OP_GET_SYMBOL
):
1626 dbg_printk("op get symbol\n");
1627 switch (estack_ax(stack
, top
)->u
.ptr
.type
) {
1629 printk(KERN_WARNING
"LTTng: bytecode: Nested fields not implemented yet.\n");
1632 case LOAD_ROOT_CONTEXT
:
1633 case LOAD_ROOT_APP_CONTEXT
:
1634 case LOAD_ROOT_PAYLOAD
:
1636 * symbol lookup is performed by
1642 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_symbol
);
1646 OP(BYTECODE_OP_GET_SYMBOL_FIELD
):
1649 * Used for first variant encountered in a
1650 * traversal. Variants are not implemented yet.
1656 OP(BYTECODE_OP_GET_INDEX_U16
):
1658 struct load_op
*insn
= (struct load_op
*) pc
;
1659 struct get_index_u16
*index
= (struct get_index_u16
*) insn
->data
;
1661 dbg_printk("op get index u16\n");
1662 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1665 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1666 estack_ax_t
= estack_ax(stack
, top
)->type
;
1667 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u16
);
1671 OP(BYTECODE_OP_GET_INDEX_U64
):
1673 struct load_op
*insn
= (struct load_op
*) pc
;
1674 struct get_index_u64
*index
= (struct get_index_u64
*) insn
->data
;
1676 dbg_printk("op get index u64\n");
1677 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1680 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1681 estack_ax_t
= estack_ax(stack
, top
)->type
;
1682 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u64
);
1686 OP(BYTECODE_OP_LOAD_FIELD
):
1688 dbg_printk("op load field\n");
1689 ret
= dynamic_load_field(estack_ax(stack
, top
));
1692 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1693 estack_ax_t
= estack_ax(stack
, top
)->type
;
1694 next_pc
+= sizeof(struct load_op
);
1698 OP(BYTECODE_OP_LOAD_FIELD_S8
):
1700 dbg_printk("op load field s8\n");
1702 estack_ax_v
= *(int8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1703 estack_ax_t
= REG_S64
;
1704 next_pc
+= sizeof(struct load_op
);
1707 OP(BYTECODE_OP_LOAD_FIELD_S16
):
1709 dbg_printk("op load field s16\n");
1711 estack_ax_v
= *(int16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1712 estack_ax_t
= REG_S64
;
1713 next_pc
+= sizeof(struct load_op
);
1716 OP(BYTECODE_OP_LOAD_FIELD_S32
):
1718 dbg_printk("op load field s32\n");
1720 estack_ax_v
= *(int32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1721 estack_ax_t
= REG_S64
;
1722 next_pc
+= sizeof(struct load_op
);
1725 OP(BYTECODE_OP_LOAD_FIELD_S64
):
1727 dbg_printk("op load field s64\n");
1729 estack_ax_v
= *(int64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1730 estack_ax_t
= REG_S64
;
1731 next_pc
+= sizeof(struct load_op
);
1734 OP(BYTECODE_OP_LOAD_FIELD_U8
):
1736 dbg_printk("op load field u8\n");
1738 estack_ax_v
= *(uint8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1739 estack_ax_t
= REG_S64
;
1740 next_pc
+= sizeof(struct load_op
);
1743 OP(BYTECODE_OP_LOAD_FIELD_U16
):
1745 dbg_printk("op load field u16\n");
1747 estack_ax_v
= *(uint16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1748 estack_ax_t
= REG_S64
;
1749 next_pc
+= sizeof(struct load_op
);
1752 OP(BYTECODE_OP_LOAD_FIELD_U32
):
1754 dbg_printk("op load field u32\n");
1756 estack_ax_v
= *(uint32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1757 estack_ax_t
= REG_S64
;
1758 next_pc
+= sizeof(struct load_op
);
1761 OP(BYTECODE_OP_LOAD_FIELD_U64
):
1763 dbg_printk("op load field u64\n");
1765 estack_ax_v
= *(uint64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1766 estack_ax_t
= REG_S64
;
1767 next_pc
+= sizeof(struct load_op
);
1770 OP(BYTECODE_OP_LOAD_FIELD_DOUBLE
):
1776 OP(BYTECODE_OP_LOAD_FIELD_STRING
):
1780 dbg_printk("op load field string\n");
1781 str
= (const char *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1782 estack_ax(stack
, top
)->u
.s
.str
= str
;
1783 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1784 dbg_printk("Bytecode warning: loading a NULL string.\n");
1788 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1789 estack_ax(stack
, top
)->u
.s
.literal_type
=
1790 ESTACK_STRING_LITERAL_TYPE_NONE
;
1791 estack_ax(stack
, top
)->type
= REG_STRING
;
1792 next_pc
+= sizeof(struct load_op
);
1796 OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE
):
1800 dbg_printk("op load field string sequence\n");
1801 ptr
= estack_ax(stack
, top
)->u
.ptr
.ptr
;
1802 estack_ax(stack
, top
)->u
.s
.seq_len
= *(unsigned long *) ptr
;
1803 estack_ax(stack
, top
)->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
1804 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1805 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1809 estack_ax(stack
, top
)->u
.s
.literal_type
=
1810 ESTACK_STRING_LITERAL_TYPE_NONE
;
1811 estack_ax(stack
, top
)->type
= REG_STRING
;
1812 next_pc
+= sizeof(struct load_op
);
1818 /* No need to prepare output if an error occurred. */
1820 return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
;
1822 /* Prepare output. */
1823 switch (kernel_bytecode
->type
) {
1824 case LTTNG_KERNEL_BYTECODE_TYPE_FILTER
:
1826 struct lttng_kernel_bytecode_filter_ctx
*filter_ctx
=
1827 (struct lttng_kernel_bytecode_filter_ctx
*) caller_ctx
;
1829 filter_ctx
->result
= LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
;
1831 filter_ctx
->result
= LTTNG_KERNEL_BYTECODE_FILTER_REJECT
;
1834 case LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
:
1835 ret
= lttng_bytecode_interpret_format_output(estack_ax(stack
, top
),
1836 (struct lttng_interpreter_output
*) caller_ctx
);
1843 return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
;
1845 return LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
;
1847 LTTNG_STACK_FRAME_NON_STANDARD(lttng_bytecode_interpret
);
1850 * Return LTTNG_KERNEL_EVENT_FILTER_ACCEPT or LTTNG_KERNEL_EVENT_FILTER_REJECT.
1852 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common
*event
,
1853 const char *interpreter_stack_data
,
1854 struct lttng_kernel_probe_ctx
*probe_ctx
,
1855 void *event_filter_ctx
__attribute__((unused
)))
1857 struct lttng_kernel_bytecode_runtime
*filter_bc_runtime
;
1858 struct list_head
*filter_bytecode_runtime_head
= &event
->priv
->filter_bytecode_runtime_head
;
1859 struct lttng_kernel_bytecode_filter_ctx bytecode_filter_ctx
;
1860 bool filter_record
= false;
1862 list_for_each_entry_rcu(filter_bc_runtime
, filter_bytecode_runtime_head
, node
) {
1863 if (likely(filter_bc_runtime
->interpreter_func(filter_bc_runtime
,
1864 interpreter_stack_data
, probe_ctx
, &bytecode_filter_ctx
) == LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
)) {
1865 if (unlikely(bytecode_filter_ctx
.result
== LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
)) {
1866 filter_record
= true;
1872 return LTTNG_KERNEL_EVENT_FILTER_ACCEPT
;
1874 return LTTNG_KERNEL_EVENT_FILTER_REJECT
;