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
;
297 ptr
->rev_bo
= lttng_kernel_get_type_integer(field
->type
)->reverse_byte_order
;
299 case lttng_kernel_type_enum
:
301 const struct lttng_kernel_type_enum
*enum_type
= lttng_kernel_get_type_enum(field
->type
);
302 const struct lttng_kernel_type_integer
*integer_type
= lttng_kernel_get_type_integer(enum_type
->container_type
);
304 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
305 if (integer_type
->signedness
) {
306 ptr
->object_type
= OBJECT_TYPE_SIGNED_ENUM
;
307 ptr
->u
.s64
= v
.u
.s64
;
308 ptr
->ptr
= &ptr
->u
.s64
;
310 ptr
->object_type
= OBJECT_TYPE_UNSIGNED_ENUM
;
311 ptr
->u
.u64
= v
.u
.s64
; /* Cast. */
312 ptr
->ptr
= &ptr
->u
.u64
;
314 ptr
->rev_bo
= integer_type
->reverse_byte_order
;
317 case lttng_kernel_type_array
:
319 const struct lttng_kernel_type_array
*array_type
= lttng_kernel_get_type_array(field
->type
);
321 if (!lttng_kernel_type_is_bytewise_integer(array_type
->elem_type
)) {
322 printk(KERN_WARNING
"LTTng: bytecode: Array nesting only supports integer types.\n");
325 if (array_type
->encoding
== lttng_kernel_string_encoding_none
) {
326 printk(KERN_WARNING
"LTTng: bytecode: Only string arrays are supported for contexts.\n");
329 ptr
->object_type
= OBJECT_TYPE_STRING
;
330 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
334 case lttng_kernel_type_sequence
:
336 const struct lttng_kernel_type_sequence
*sequence_type
= lttng_kernel_get_type_sequence(field
->type
);
338 if (!lttng_kernel_type_is_bytewise_integer(sequence_type
->elem_type
)) {
339 printk(KERN_WARNING
"LTTng: bytecode: Sequence nesting only supports integer types.\n");
342 if (sequence_type
->encoding
== lttng_kernel_string_encoding_none
) {
343 printk(KERN_WARNING
"LTTng: bytecode: Only string sequences are supported for contexts.\n");
346 ptr
->object_type
= OBJECT_TYPE_STRING
;
347 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
351 case lttng_kernel_type_string
:
352 ptr
->object_type
= OBJECT_TYPE_STRING
;
353 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
356 case lttng_kernel_type_struct
:
357 printk(KERN_WARNING
"LTTng: bytecode: Structure type cannot be loaded.\n");
359 case lttng_kernel_type_variant
:
360 printk(KERN_WARNING
"LTTng: bytecode: Variant type cannot be loaded.\n");
363 printk(KERN_WARNING
"LTTng: bytecode: Unknown type: %d", (int) field
->type
->type
);
369 static int dynamic_get_index(struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
370 struct bytecode_runtime
*runtime
,
371 uint64_t index
, struct estack_entry
*stack_top
)
374 const struct bytecode_get_index_data
*gid
;
376 gid
= (const struct bytecode_get_index_data
*) &runtime
->data
[index
];
377 switch (stack_top
->u
.ptr
.type
) {
379 switch (stack_top
->u
.ptr
.object_type
) {
380 case OBJECT_TYPE_ARRAY
:
384 WARN_ON_ONCE(gid
->offset
>= gid
->array_len
);
385 /* Skip count (unsigned long) */
386 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
387 ptr
= ptr
+ gid
->offset
;
388 stack_top
->u
.ptr
.ptr
= ptr
;
389 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
390 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
391 BUG_ON(stack_top
->u
.ptr
.field
->type
->type
!= lttng_kernel_type_array
);
392 stack_top
->u
.ptr
.field
= NULL
;
395 case OBJECT_TYPE_SEQUENCE
:
400 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
401 ptr_seq_len
= *(unsigned long *) stack_top
->u
.ptr
.ptr
;
402 if (gid
->offset
>= gid
->elem
.len
* ptr_seq_len
) {
406 ptr
= ptr
+ gid
->offset
;
407 stack_top
->u
.ptr
.ptr
= ptr
;
408 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
409 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
410 BUG_ON(stack_top
->u
.ptr
.field
->type
->type
!= lttng_kernel_type_sequence
);
411 stack_top
->u
.ptr
.field
= NULL
;
414 case OBJECT_TYPE_STRUCT
:
415 printk(KERN_WARNING
"LTTng: bytecode: Nested structures are not supported yet.\n");
418 case OBJECT_TYPE_VARIANT
:
420 printk(KERN_WARNING
"LTTng: bytecode: Unexpected get index type %d",
421 (int) stack_top
->u
.ptr
.object_type
);
426 case LOAD_ROOT_CONTEXT
:
428 case LOAD_ROOT_APP_CONTEXT
:
430 ret
= context_get_index(lttng_probe_ctx
,
438 case LOAD_ROOT_PAYLOAD
:
439 stack_top
->u
.ptr
.ptr
+= gid
->offset
;
440 if (gid
->elem
.type
== OBJECT_TYPE_STRING
)
441 stack_top
->u
.ptr
.ptr
= *(const char * const *) stack_top
->u
.ptr
.ptr
;
442 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
443 stack_top
->u
.ptr
.type
= LOAD_OBJECT
;
444 stack_top
->u
.ptr
.field
= gid
->field
;
445 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
449 stack_top
->type
= REG_PTR
;
457 static int dynamic_load_field(struct estack_entry
*stack_top
)
461 switch (stack_top
->u
.ptr
.type
) {
464 case LOAD_ROOT_CONTEXT
:
465 case LOAD_ROOT_APP_CONTEXT
:
466 case LOAD_ROOT_PAYLOAD
:
468 dbg_printk("Bytecode warning: cannot load root, missing field name.\n");
472 switch (stack_top
->u
.ptr
.object_type
) {
474 dbg_printk("op load field s8\n");
475 stack_top
->u
.v
= *(int8_t *) stack_top
->u
.ptr
.ptr
;
476 stack_top
->type
= REG_S64
;
478 case OBJECT_TYPE_S16
:
482 dbg_printk("op load field s16\n");
483 tmp
= *(int16_t *) stack_top
->u
.ptr
.ptr
;
484 if (stack_top
->u
.ptr
.rev_bo
)
486 stack_top
->u
.v
= tmp
;
487 stack_top
->type
= REG_S64
;
490 case OBJECT_TYPE_S32
:
494 dbg_printk("op load field s32\n");
495 tmp
= *(int32_t *) stack_top
->u
.ptr
.ptr
;
496 if (stack_top
->u
.ptr
.rev_bo
)
498 stack_top
->u
.v
= tmp
;
499 stack_top
->type
= REG_S64
;
502 case OBJECT_TYPE_S64
:
506 dbg_printk("op load field s64\n");
507 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
508 if (stack_top
->u
.ptr
.rev_bo
)
510 stack_top
->u
.v
= tmp
;
511 stack_top
->type
= REG_S64
;
514 case OBJECT_TYPE_SIGNED_ENUM
:
518 dbg_printk("op load field signed enumeration\n");
519 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
520 if (stack_top
->u
.ptr
.rev_bo
)
522 stack_top
->u
.v
= tmp
;
523 stack_top
->type
= REG_S64
;
527 dbg_printk("op load field u8\n");
528 stack_top
->u
.v
= *(uint8_t *) stack_top
->u
.ptr
.ptr
;
529 stack_top
->type
= REG_U64
;
531 case OBJECT_TYPE_U16
:
535 dbg_printk("op load field u16\n");
536 tmp
= *(uint16_t *) stack_top
->u
.ptr
.ptr
;
537 if (stack_top
->u
.ptr
.rev_bo
)
539 stack_top
->u
.v
= tmp
;
540 stack_top
->type
= REG_U64
;
543 case OBJECT_TYPE_U32
:
547 dbg_printk("op load field u32\n");
548 tmp
= *(uint32_t *) stack_top
->u
.ptr
.ptr
;
549 if (stack_top
->u
.ptr
.rev_bo
)
551 stack_top
->u
.v
= tmp
;
552 stack_top
->type
= REG_U64
;
555 case OBJECT_TYPE_U64
:
559 dbg_printk("op load field u64\n");
560 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
561 if (stack_top
->u
.ptr
.rev_bo
)
563 stack_top
->u
.v
= tmp
;
564 stack_top
->type
= REG_U64
;
567 case OBJECT_TYPE_UNSIGNED_ENUM
:
571 dbg_printk("op load field unsigned enumeration\n");
572 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
573 if (stack_top
->u
.ptr
.rev_bo
)
575 stack_top
->u
.v
= tmp
;
576 stack_top
->type
= REG_U64
;
579 case OBJECT_TYPE_STRING
:
583 dbg_printk("op load field string\n");
584 str
= (const char *) stack_top
->u
.ptr
.ptr
;
585 stack_top
->u
.s
.str
= str
;
586 if (unlikely(!stack_top
->u
.s
.str
)) {
587 dbg_printk("Bytecode warning: loading a NULL string.\n");
591 stack_top
->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
592 stack_top
->u
.s
.literal_type
=
593 ESTACK_STRING_LITERAL_TYPE_NONE
;
594 stack_top
->type
= REG_STRING
;
597 case OBJECT_TYPE_STRING_SEQUENCE
:
601 dbg_printk("op load field string sequence\n");
602 ptr
= stack_top
->u
.ptr
.ptr
;
603 stack_top
->u
.s
.seq_len
= *(unsigned long *) ptr
;
604 stack_top
->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
605 if (unlikely(!stack_top
->u
.s
.str
)) {
606 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
610 stack_top
->u
.s
.literal_type
=
611 ESTACK_STRING_LITERAL_TYPE_NONE
;
612 stack_top
->type
= REG_STRING
;
615 case OBJECT_TYPE_DYNAMIC
:
617 * Dynamic types in context are looked up
618 * by context get index.
622 case OBJECT_TYPE_DOUBLE
:
625 case OBJECT_TYPE_SEQUENCE
:
626 case OBJECT_TYPE_ARRAY
:
627 case OBJECT_TYPE_STRUCT
:
628 case OBJECT_TYPE_VARIANT
:
629 printk(KERN_WARNING
"LTTng: bytecode: Sequences, arrays, struct and variant cannot be loaded (nested types).\n");
640 int lttng_bytecode_interpret_format_output(struct estack_entry
*ax
,
641 struct lttng_interpreter_output
*output
)
648 output
->type
= LTTNG_INTERPRETER_TYPE_S64
;
649 output
->u
.s
= ax
->u
.v
;
652 output
->type
= LTTNG_INTERPRETER_TYPE_U64
;
653 output
->u
.u
= (uint64_t) ax
->u
.v
;
656 output
->type
= LTTNG_INTERPRETER_TYPE_STRING
;
657 output
->u
.str
.str
= ax
->u
.s
.str
;
658 output
->u
.str
.len
= ax
->u
.s
.seq_len
;
661 switch (ax
->u
.ptr
.object_type
) {
663 case OBJECT_TYPE_S16
:
664 case OBJECT_TYPE_S32
:
665 case OBJECT_TYPE_S64
:
667 case OBJECT_TYPE_U16
:
668 case OBJECT_TYPE_U32
:
669 case OBJECT_TYPE_U64
:
670 case OBJECT_TYPE_DOUBLE
:
671 case OBJECT_TYPE_STRING
:
672 case OBJECT_TYPE_STRING_SEQUENCE
:
673 ret
= dynamic_load_field(ax
);
676 /* Retry after loading ptr into stack top. */
678 case OBJECT_TYPE_SEQUENCE
:
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
= *(unsigned long *) ax
->u
.ptr
.ptr
;
682 output
->u
.sequence
.nested_type
= lttng_kernel_get_type_sequence(ax
->u
.ptr
.field
->type
)->elem_type
;
684 case OBJECT_TYPE_ARRAY
:
685 /* Skip count (unsigned long) */
686 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
687 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
688 output
->u
.sequence
.nr_elem
= lttng_kernel_get_type_array(ax
->u
.ptr
.field
->type
)->length
;
689 output
->u
.sequence
.nested_type
= lttng_kernel_get_type_array(ax
->u
.ptr
.field
->type
)->elem_type
;
691 case OBJECT_TYPE_SIGNED_ENUM
:
692 ret
= dynamic_load_field(ax
);
695 output
->type
= LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
;
696 output
->u
.s
= ax
->u
.v
;
698 case OBJECT_TYPE_UNSIGNED_ENUM
:
699 ret
= dynamic_load_field(ax
);
702 output
->type
= LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
;
703 output
->u
.u
= ax
->u
.v
;
705 case OBJECT_TYPE_STRUCT
:
706 case OBJECT_TYPE_VARIANT
:
712 case REG_STAR_GLOB_STRING
:
713 case REG_TYPE_UNKNOWN
:
723 #define DBG_USER_STR_CUTOFF 32
726 * In debug mode, print user string (truncated, if necessary).
729 void dbg_load_ref_user_str_printk(const struct estack_entry
*user_str_reg
)
733 char user_str
[DBG_USER_STR_CUTOFF
];
737 last_char
= get_char(user_str_reg
, pos
);
738 user_str
[pos
] = last_char
;
740 } while (last_char
!= '\0' && pos
< sizeof(user_str
));
743 user_str
[sizeof(user_str
) - 1] = '\0';
744 dbg_printk("load field ref user string: '%s%s'\n", user_str
,
745 last_char
!= '\0' ? "[...]" : "");
749 void dbg_load_ref_user_str_printk(const struct estack_entry
*user_str_reg
)
755 * Return LTTNG_KERNEL_BYTECODE_INTERPRETER_OK on success.
756 * Return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR on error.
758 * For FILTER bytecode: expect a struct lttng_kernel_bytecode_filter_ctx *
760 * For CAPTURE bytecode: expect a struct lttng_interpreter_output *
763 int lttng_bytecode_interpret(struct lttng_kernel_bytecode_runtime
*kernel_bytecode
,
764 const char *interpreter_stack_data
,
765 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
768 struct bytecode_runtime
*bytecode
= container_of(kernel_bytecode
, struct bytecode_runtime
, p
);
769 void *pc
, *next_pc
, *start_pc
;
772 struct estack _stack
;
773 struct estack
*stack
= &_stack
;
774 register int64_t ax
= 0, bx
= 0;
775 register enum entry_type ax_t
= REG_TYPE_UNKNOWN
, bx_t
= REG_TYPE_UNKNOWN
;
776 register int top
= INTERPRETER_STACK_EMPTY
;
777 #ifndef INTERPRETER_USE_SWITCH
778 static void *dispatch
[NR_BYTECODE_OPS
] = {
779 [ BYTECODE_OP_UNKNOWN
] = &&LABEL_BYTECODE_OP_UNKNOWN
,
781 [ BYTECODE_OP_RETURN
] = &&LABEL_BYTECODE_OP_RETURN
,
784 [ BYTECODE_OP_MUL
] = &&LABEL_BYTECODE_OP_MUL
,
785 [ BYTECODE_OP_DIV
] = &&LABEL_BYTECODE_OP_DIV
,
786 [ BYTECODE_OP_MOD
] = &&LABEL_BYTECODE_OP_MOD
,
787 [ BYTECODE_OP_PLUS
] = &&LABEL_BYTECODE_OP_PLUS
,
788 [ BYTECODE_OP_MINUS
] = &&LABEL_BYTECODE_OP_MINUS
,
789 [ BYTECODE_OP_BIT_RSHIFT
] = &&LABEL_BYTECODE_OP_BIT_RSHIFT
,
790 [ BYTECODE_OP_BIT_LSHIFT
] = &&LABEL_BYTECODE_OP_BIT_LSHIFT
,
791 [ BYTECODE_OP_BIT_AND
] = &&LABEL_BYTECODE_OP_BIT_AND
,
792 [ BYTECODE_OP_BIT_OR
] = &&LABEL_BYTECODE_OP_BIT_OR
,
793 [ BYTECODE_OP_BIT_XOR
] = &&LABEL_BYTECODE_OP_BIT_XOR
,
795 /* binary comparators */
796 [ BYTECODE_OP_EQ
] = &&LABEL_BYTECODE_OP_EQ
,
797 [ BYTECODE_OP_NE
] = &&LABEL_BYTECODE_OP_NE
,
798 [ BYTECODE_OP_GT
] = &&LABEL_BYTECODE_OP_GT
,
799 [ BYTECODE_OP_LT
] = &&LABEL_BYTECODE_OP_LT
,
800 [ BYTECODE_OP_GE
] = &&LABEL_BYTECODE_OP_GE
,
801 [ BYTECODE_OP_LE
] = &&LABEL_BYTECODE_OP_LE
,
803 /* string binary comparator */
804 [ BYTECODE_OP_EQ_STRING
] = &&LABEL_BYTECODE_OP_EQ_STRING
,
805 [ BYTECODE_OP_NE_STRING
] = &&LABEL_BYTECODE_OP_NE_STRING
,
806 [ BYTECODE_OP_GT_STRING
] = &&LABEL_BYTECODE_OP_GT_STRING
,
807 [ BYTECODE_OP_LT_STRING
] = &&LABEL_BYTECODE_OP_LT_STRING
,
808 [ BYTECODE_OP_GE_STRING
] = &&LABEL_BYTECODE_OP_GE_STRING
,
809 [ BYTECODE_OP_LE_STRING
] = &&LABEL_BYTECODE_OP_LE_STRING
,
811 /* globbing pattern binary comparator */
812 [ BYTECODE_OP_EQ_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING
,
813 [ BYTECODE_OP_NE_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING
,
815 /* s64 binary comparator */
816 [ BYTECODE_OP_EQ_S64
] = &&LABEL_BYTECODE_OP_EQ_S64
,
817 [ BYTECODE_OP_NE_S64
] = &&LABEL_BYTECODE_OP_NE_S64
,
818 [ BYTECODE_OP_GT_S64
] = &&LABEL_BYTECODE_OP_GT_S64
,
819 [ BYTECODE_OP_LT_S64
] = &&LABEL_BYTECODE_OP_LT_S64
,
820 [ BYTECODE_OP_GE_S64
] = &&LABEL_BYTECODE_OP_GE_S64
,
821 [ BYTECODE_OP_LE_S64
] = &&LABEL_BYTECODE_OP_LE_S64
,
823 /* double binary comparator */
824 [ BYTECODE_OP_EQ_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE
,
825 [ BYTECODE_OP_NE_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_DOUBLE
,
826 [ BYTECODE_OP_GT_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_DOUBLE
,
827 [ BYTECODE_OP_LT_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_DOUBLE
,
828 [ BYTECODE_OP_GE_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_DOUBLE
,
829 [ BYTECODE_OP_LE_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_DOUBLE
,
831 /* Mixed S64-double binary comparators */
832 [ BYTECODE_OP_EQ_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64
,
833 [ BYTECODE_OP_NE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64
,
834 [ BYTECODE_OP_GT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64
,
835 [ BYTECODE_OP_LT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64
,
836 [ BYTECODE_OP_GE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64
,
837 [ BYTECODE_OP_LE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64
,
839 [ BYTECODE_OP_EQ_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE
,
840 [ BYTECODE_OP_NE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE
,
841 [ BYTECODE_OP_GT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE
,
842 [ BYTECODE_OP_LT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE
,
843 [ BYTECODE_OP_GE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE
,
844 [ BYTECODE_OP_LE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE
,
847 [ BYTECODE_OP_UNARY_PLUS
] = &&LABEL_BYTECODE_OP_UNARY_PLUS
,
848 [ BYTECODE_OP_UNARY_MINUS
] = &&LABEL_BYTECODE_OP_UNARY_MINUS
,
849 [ BYTECODE_OP_UNARY_NOT
] = &&LABEL_BYTECODE_OP_UNARY_NOT
,
850 [ BYTECODE_OP_UNARY_PLUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64
,
851 [ BYTECODE_OP_UNARY_MINUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64
,
852 [ BYTECODE_OP_UNARY_NOT_S64
] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64
,
853 [ BYTECODE_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE
,
854 [ BYTECODE_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE
,
855 [ BYTECODE_OP_UNARY_NOT_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE
,
858 [ BYTECODE_OP_AND
] = &&LABEL_BYTECODE_OP_AND
,
859 [ BYTECODE_OP_OR
] = &&LABEL_BYTECODE_OP_OR
,
862 [ BYTECODE_OP_LOAD_FIELD_REF
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF
,
863 [ BYTECODE_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING
,
864 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
,
865 [ BYTECODE_OP_LOAD_FIELD_REF_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64
,
866 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
,
868 /* load from immediate operand */
869 [ BYTECODE_OP_LOAD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STRING
,
870 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING
,
871 [ BYTECODE_OP_LOAD_S64
] = &&LABEL_BYTECODE_OP_LOAD_S64
,
872 [ BYTECODE_OP_LOAD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE
,
875 [ BYTECODE_OP_CAST_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_TO_S64
,
876 [ BYTECODE_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64
,
877 [ BYTECODE_OP_CAST_NOP
] = &&LABEL_BYTECODE_OP_CAST_NOP
,
879 /* get context ref */
880 [ BYTECODE_OP_GET_CONTEXT_REF
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF
,
881 [ BYTECODE_OP_GET_CONTEXT_REF_STRING
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING
,
882 [ BYTECODE_OP_GET_CONTEXT_REF_S64
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64
,
883 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
,
885 /* load userspace field ref */
886 [ BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
,
887 [ BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
,
889 /* Instructions for recursive traversal through composed types. */
890 [ BYTECODE_OP_GET_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT
,
891 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT
,
892 [ BYTECODE_OP_GET_PAYLOAD_ROOT
] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT
,
894 [ BYTECODE_OP_GET_SYMBOL
] = &&LABEL_BYTECODE_OP_GET_SYMBOL
,
895 [ BYTECODE_OP_GET_SYMBOL_FIELD
] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD
,
896 [ BYTECODE_OP_GET_INDEX_U16
] = &&LABEL_BYTECODE_OP_GET_INDEX_U16
,
897 [ BYTECODE_OP_GET_INDEX_U64
] = &&LABEL_BYTECODE_OP_GET_INDEX_U64
,
899 [ BYTECODE_OP_LOAD_FIELD
] = &&LABEL_BYTECODE_OP_LOAD_FIELD
,
900 [ BYTECODE_OP_LOAD_FIELD_S8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8
,
901 [ BYTECODE_OP_LOAD_FIELD_S16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16
,
902 [ BYTECODE_OP_LOAD_FIELD_S32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32
,
903 [ BYTECODE_OP_LOAD_FIELD_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64
,
904 [ BYTECODE_OP_LOAD_FIELD_U8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8
,
905 [ BYTECODE_OP_LOAD_FIELD_U16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16
,
906 [ BYTECODE_OP_LOAD_FIELD_U32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32
,
907 [ BYTECODE_OP_LOAD_FIELD_U64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64
,
908 [ BYTECODE_OP_LOAD_FIELD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING
,
909 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE
,
910 [ BYTECODE_OP_LOAD_FIELD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE
,
912 [ BYTECODE_OP_UNARY_BIT_NOT
] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT
,
914 [ BYTECODE_OP_RETURN_S64
] = &&LABEL_BYTECODE_OP_RETURN_S64
,
916 #endif /* #ifndef INTERPRETER_USE_SWITCH */
920 OP(BYTECODE_OP_UNKNOWN
):
921 OP(BYTECODE_OP_LOAD_FIELD_REF
):
922 OP(BYTECODE_OP_GET_CONTEXT_REF
):
923 #ifdef INTERPRETER_USE_SWITCH
925 #endif /* INTERPRETER_USE_SWITCH */
926 printk(KERN_WARNING
"LTTng: bytecode: unknown bytecode op %u\n",
927 (unsigned int) *(bytecode_opcode_t
*) pc
);
931 OP(BYTECODE_OP_RETURN
):
932 /* LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR or LTTNG_KERNEL_BYTECODE_INTERPRETER_OK */
933 switch (estack_ax_t
) {
936 retval
= !!estack_ax_v
;
941 if (kernel_bytecode
->type
!= LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
) {
947 case REG_STAR_GLOB_STRING
:
948 case REG_TYPE_UNKNOWN
:
955 OP(BYTECODE_OP_RETURN_S64
):
956 /* LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR or LTTNG_KERNEL_BYTECODE_INTERPRETER_OK */
957 retval
= !!estack_ax_v
;
965 OP(BYTECODE_OP_PLUS
):
966 OP(BYTECODE_OP_MINUS
):
967 printk(KERN_WARNING
"LTTng: bytecode: unsupported bytecode op %u\n",
968 (unsigned int) *(bytecode_opcode_t
*) pc
);
978 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
979 (unsigned int) *(bytecode_opcode_t
*) pc
);
983 OP(BYTECODE_OP_EQ_STRING
):
987 res
= (stack_strcmp(stack
, top
, "==") == 0);
988 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
990 estack_ax_t
= REG_S64
;
991 next_pc
+= sizeof(struct binary_op
);
994 OP(BYTECODE_OP_NE_STRING
):
998 res
= (stack_strcmp(stack
, top
, "!=") != 0);
999 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1001 estack_ax_t
= REG_S64
;
1002 next_pc
+= sizeof(struct binary_op
);
1005 OP(BYTECODE_OP_GT_STRING
):
1009 res
= (stack_strcmp(stack
, top
, ">") > 0);
1010 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1012 estack_ax_t
= REG_S64
;
1013 next_pc
+= sizeof(struct binary_op
);
1016 OP(BYTECODE_OP_LT_STRING
):
1020 res
= (stack_strcmp(stack
, top
, "<") < 0);
1021 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1023 estack_ax_t
= REG_S64
;
1024 next_pc
+= sizeof(struct binary_op
);
1027 OP(BYTECODE_OP_GE_STRING
):
1031 res
= (stack_strcmp(stack
, top
, ">=") >= 0);
1032 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1034 estack_ax_t
= REG_S64
;
1035 next_pc
+= sizeof(struct binary_op
);
1038 OP(BYTECODE_OP_LE_STRING
):
1042 res
= (stack_strcmp(stack
, top
, "<=") <= 0);
1043 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1045 estack_ax_t
= REG_S64
;
1046 next_pc
+= sizeof(struct binary_op
);
1050 OP(BYTECODE_OP_EQ_STAR_GLOB_STRING
):
1054 res
= (stack_star_glob_match(stack
, top
, "==") == 0);
1055 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1057 estack_ax_t
= REG_S64
;
1058 next_pc
+= sizeof(struct binary_op
);
1061 OP(BYTECODE_OP_NE_STAR_GLOB_STRING
):
1065 res
= (stack_star_glob_match(stack
, top
, "!=") != 0);
1066 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1068 estack_ax_t
= REG_S64
;
1069 next_pc
+= sizeof(struct binary_op
);
1073 OP(BYTECODE_OP_EQ_S64
):
1077 res
= (estack_bx_v
== estack_ax_v
);
1078 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1080 estack_ax_t
= REG_S64
;
1081 next_pc
+= sizeof(struct binary_op
);
1084 OP(BYTECODE_OP_NE_S64
):
1088 res
= (estack_bx_v
!= estack_ax_v
);
1089 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1091 estack_ax_t
= REG_S64
;
1092 next_pc
+= sizeof(struct binary_op
);
1095 OP(BYTECODE_OP_GT_S64
):
1099 res
= (estack_bx_v
> estack_ax_v
);
1100 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1102 estack_ax_t
= REG_S64
;
1103 next_pc
+= sizeof(struct binary_op
);
1106 OP(BYTECODE_OP_LT_S64
):
1110 res
= (estack_bx_v
< estack_ax_v
);
1111 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1113 estack_ax_t
= REG_S64
;
1114 next_pc
+= sizeof(struct binary_op
);
1117 OP(BYTECODE_OP_GE_S64
):
1121 res
= (estack_bx_v
>= estack_ax_v
);
1122 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1124 estack_ax_t
= REG_S64
;
1125 next_pc
+= sizeof(struct binary_op
);
1128 OP(BYTECODE_OP_LE_S64
):
1132 res
= (estack_bx_v
<= estack_ax_v
);
1133 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1135 estack_ax_t
= REG_S64
;
1136 next_pc
+= sizeof(struct binary_op
);
1140 OP(BYTECODE_OP_EQ_DOUBLE
):
1141 OP(BYTECODE_OP_NE_DOUBLE
):
1142 OP(BYTECODE_OP_GT_DOUBLE
):
1143 OP(BYTECODE_OP_LT_DOUBLE
):
1144 OP(BYTECODE_OP_GE_DOUBLE
):
1145 OP(BYTECODE_OP_LE_DOUBLE
):
1151 /* Mixed S64-double binary comparators */
1152 OP(BYTECODE_OP_EQ_DOUBLE_S64
):
1153 OP(BYTECODE_OP_NE_DOUBLE_S64
):
1154 OP(BYTECODE_OP_GT_DOUBLE_S64
):
1155 OP(BYTECODE_OP_LT_DOUBLE_S64
):
1156 OP(BYTECODE_OP_GE_DOUBLE_S64
):
1157 OP(BYTECODE_OP_LE_DOUBLE_S64
):
1158 OP(BYTECODE_OP_EQ_S64_DOUBLE
):
1159 OP(BYTECODE_OP_NE_S64_DOUBLE
):
1160 OP(BYTECODE_OP_GT_S64_DOUBLE
):
1161 OP(BYTECODE_OP_LT_S64_DOUBLE
):
1162 OP(BYTECODE_OP_GE_S64_DOUBLE
):
1163 OP(BYTECODE_OP_LE_S64_DOUBLE
):
1168 OP(BYTECODE_OP_BIT_RSHIFT
):
1172 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1177 /* Catch undefined behavior. */
1178 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1182 res
= ((uint64_t) estack_bx_v
>> (uint32_t) estack_ax_v
);
1183 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1185 estack_ax_t
= REG_U64
;
1186 next_pc
+= sizeof(struct binary_op
);
1189 OP(BYTECODE_OP_BIT_LSHIFT
):
1193 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1198 /* Catch undefined behavior. */
1199 if (unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1203 res
= ((uint64_t) estack_bx_v
<< (uint32_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
);
1210 OP(BYTECODE_OP_BIT_AND
):
1214 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1219 res
= ((uint64_t) estack_bx_v
& (uint64_t) estack_ax_v
);
1220 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1222 estack_ax_t
= REG_U64
;
1223 next_pc
+= sizeof(struct binary_op
);
1226 OP(BYTECODE_OP_BIT_OR
):
1230 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1235 res
= ((uint64_t) estack_bx_v
| (uint64_t) estack_ax_v
);
1236 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1238 estack_ax_t
= REG_U64
;
1239 next_pc
+= sizeof(struct binary_op
);
1242 OP(BYTECODE_OP_BIT_XOR
):
1246 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1251 res
= ((uint64_t) estack_bx_v
^ (uint64_t) estack_ax_v
);
1252 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1254 estack_ax_t
= REG_U64
;
1255 next_pc
+= sizeof(struct binary_op
);
1260 OP(BYTECODE_OP_UNARY_PLUS
):
1261 OP(BYTECODE_OP_UNARY_MINUS
):
1262 OP(BYTECODE_OP_UNARY_NOT
):
1263 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1264 (unsigned int) *(bytecode_opcode_t
*) pc
);
1269 OP(BYTECODE_OP_UNARY_BIT_NOT
):
1271 estack_ax_v
= ~(uint64_t) estack_ax_v
;
1272 estack_ax_t
= REG_S64
;
1273 next_pc
+= sizeof(struct unary_op
);
1277 OP(BYTECODE_OP_UNARY_PLUS_S64
):
1279 next_pc
+= sizeof(struct unary_op
);
1282 OP(BYTECODE_OP_UNARY_MINUS_S64
):
1284 estack_ax_v
= -estack_ax_v
;
1285 estack_ax_t
= REG_S64
;
1286 next_pc
+= sizeof(struct unary_op
);
1289 OP(BYTECODE_OP_UNARY_PLUS_DOUBLE
):
1290 OP(BYTECODE_OP_UNARY_MINUS_DOUBLE
):
1295 OP(BYTECODE_OP_UNARY_NOT_S64
):
1297 estack_ax_v
= !estack_ax_v
;
1298 estack_ax_t
= REG_S64
;
1299 next_pc
+= sizeof(struct unary_op
);
1302 OP(BYTECODE_OP_UNARY_NOT_DOUBLE
):
1309 OP(BYTECODE_OP_AND
):
1311 struct logical_op
*insn
= (struct logical_op
*) pc
;
1313 /* If AX is 0, skip and evaluate to 0 */
1314 if (unlikely(estack_ax_v
== 0)) {
1315 dbg_printk("Jumping to bytecode offset %u\n",
1316 (unsigned int) insn
->skip_offset
);
1317 next_pc
= start_pc
+ insn
->skip_offset
;
1319 /* Pop 1 when jump not taken */
1320 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1321 next_pc
+= sizeof(struct logical_op
);
1327 struct logical_op
*insn
= (struct logical_op
*) pc
;
1329 /* If AX is nonzero, skip and evaluate to 1 */
1331 if (unlikely(estack_ax_v
!= 0)) {
1333 dbg_printk("Jumping to bytecode offset %u\n",
1334 (unsigned int) insn
->skip_offset
);
1335 next_pc
= start_pc
+ insn
->skip_offset
;
1337 /* Pop 1 when jump not taken */
1338 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1339 next_pc
+= sizeof(struct logical_op
);
1345 /* load field ref */
1346 OP(BYTECODE_OP_LOAD_FIELD_REF_STRING
):
1348 struct load_op
*insn
= (struct load_op
*) pc
;
1349 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1351 dbg_printk("load field ref offset %u type string\n",
1353 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1354 estack_ax(stack
, top
)->u
.s
.str
=
1355 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1356 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1357 dbg_printk("Bytecode warning: loading a NULL string.\n");
1361 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1362 estack_ax(stack
, top
)->u
.s
.literal_type
=
1363 ESTACK_STRING_LITERAL_TYPE_NONE
;
1364 estack_ax(stack
, top
)->u
.s
.user
= 0;
1365 estack_ax(stack
, top
)->type
= REG_STRING
;
1366 dbg_printk("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1367 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1371 OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
):
1373 struct load_op
*insn
= (struct load_op
*) pc
;
1374 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1376 dbg_printk("load field ref offset %u type sequence\n",
1378 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1379 estack_ax(stack
, top
)->u
.s
.seq_len
=
1380 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1381 estack_ax(stack
, top
)->u
.s
.str
=
1382 *(const char **) (&interpreter_stack_data
[ref
->offset
1383 + sizeof(unsigned long)]);
1384 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1385 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1389 estack_ax(stack
, top
)->u
.s
.literal_type
=
1390 ESTACK_STRING_LITERAL_TYPE_NONE
;
1391 estack_ax(stack
, top
)->u
.s
.user
= 0;
1392 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1396 OP(BYTECODE_OP_LOAD_FIELD_REF_S64
):
1398 struct load_op
*insn
= (struct load_op
*) pc
;
1399 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1401 dbg_printk("load field ref offset %u type s64\n",
1403 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1405 ((struct literal_numeric
*) &interpreter_stack_data
[ref
->offset
])->v
;
1406 estack_ax_t
= REG_S64
;
1407 dbg_printk("ref load s64 %lld\n",
1408 (long long) estack_ax_v
);
1409 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1413 OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
):
1419 /* load from immediate operand */
1420 OP(BYTECODE_OP_LOAD_STRING
):
1422 struct load_op
*insn
= (struct load_op
*) pc
;
1424 dbg_printk("load string %s\n", insn
->data
);
1425 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1426 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1427 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1428 estack_ax(stack
, top
)->u
.s
.literal_type
=
1429 ESTACK_STRING_LITERAL_TYPE_PLAIN
;
1430 estack_ax(stack
, top
)->u
.s
.user
= 0;
1431 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1435 OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING
):
1437 struct load_op
*insn
= (struct load_op
*) pc
;
1439 dbg_printk("load globbing pattern %s\n", insn
->data
);
1440 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1441 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
1442 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1443 estack_ax(stack
, top
)->u
.s
.literal_type
=
1444 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
;
1445 estack_ax(stack
, top
)->u
.s
.user
= 0;
1446 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
1450 OP(BYTECODE_OP_LOAD_S64
):
1452 struct load_op
*insn
= (struct load_op
*) pc
;
1454 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1455 estack_ax_v
= ((struct literal_numeric
*) insn
->data
)->v
;
1456 estack_ax_t
= REG_S64
;
1457 dbg_printk("load s64 %lld\n",
1458 (long long) estack_ax_v
);
1459 next_pc
+= sizeof(struct load_op
)
1460 + sizeof(struct literal_numeric
);
1464 OP(BYTECODE_OP_LOAD_DOUBLE
):
1471 OP(BYTECODE_OP_CAST_TO_S64
):
1472 printk(KERN_WARNING
"LTTng: bytecode: unsupported non-specialized bytecode op %u\n",
1473 (unsigned int) *(bytecode_opcode_t
*) pc
);
1477 OP(BYTECODE_OP_CAST_DOUBLE_TO_S64
):
1483 OP(BYTECODE_OP_CAST_NOP
):
1485 next_pc
+= sizeof(struct cast_op
);
1489 /* get context ref */
1490 OP(BYTECODE_OP_GET_CONTEXT_REF_STRING
):
1492 struct load_op
*insn
= (struct load_op
*) pc
;
1493 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1494 struct lttng_kernel_ctx_field
*ctx_field
;
1495 struct lttng_ctx_value v
;
1497 dbg_printk("get context ref offset %u type string\n",
1499 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1500 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
1501 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1502 estack_ax(stack
, top
)->u
.s
.str
= v
.u
.str
;
1503 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1504 dbg_printk("Bytecode warning: loading a NULL string.\n");
1508 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1509 estack_ax(stack
, top
)->u
.s
.literal_type
=
1510 ESTACK_STRING_LITERAL_TYPE_NONE
;
1511 estack_ax(stack
, top
)->u
.s
.user
= 0;
1512 estack_ax(stack
, top
)->type
= REG_STRING
;
1513 dbg_printk("ref get context string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
1514 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1518 OP(BYTECODE_OP_GET_CONTEXT_REF_S64
):
1520 struct load_op
*insn
= (struct load_op
*) pc
;
1521 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1522 struct lttng_kernel_ctx_field
*ctx_field
;
1523 struct lttng_ctx_value v
;
1525 dbg_printk("get context ref offset %u type s64\n",
1527 ctx_field
= <tng_static_ctx
->fields
[ref
->offset
];
1528 ctx_field
->get_value(ctx_field
->priv
, lttng_probe_ctx
, &v
);
1529 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1530 estack_ax_v
= v
.u
.s64
;
1531 estack_ax_t
= REG_S64
;
1532 dbg_printk("ref get context s64 %lld\n",
1533 (long long) estack_ax_v
);
1534 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1538 OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
):
1544 /* load userspace field ref */
1545 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_STRING
):
1547 struct load_op
*insn
= (struct load_op
*) pc
;
1548 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1550 dbg_printk("load field ref offset %u type user string\n",
1552 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1553 estack_ax(stack
, top
)->u
.s
.user_str
=
1554 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
1555 if (unlikely(!estack_ax(stack
, top
)->u
.s
.user_str
)) {
1556 dbg_printk("Bytecode warning: loading a NULL string.\n");
1560 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1561 estack_ax(stack
, top
)->u
.s
.literal_type
=
1562 ESTACK_STRING_LITERAL_TYPE_NONE
;
1563 estack_ax(stack
, top
)->u
.s
.user
= 1;
1564 estack_ax(stack
, top
)->type
= REG_STRING
;
1565 dbg_load_ref_user_str_printk(estack_ax(stack
, top
));
1566 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1570 OP(BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE
):
1572 struct load_op
*insn
= (struct load_op
*) pc
;
1573 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1575 dbg_printk("load field ref offset %u type user sequence\n",
1577 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1578 estack_ax(stack
, top
)->u
.s
.seq_len
=
1579 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
1580 estack_ax(stack
, top
)->u
.s
.user_str
=
1581 *(const char **) (&interpreter_stack_data
[ref
->offset
1582 + sizeof(unsigned long)]);
1583 if (unlikely(!estack_ax(stack
, top
)->u
.s
.user_str
)) {
1584 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1588 estack_ax(stack
, top
)->u
.s
.literal_type
=
1589 ESTACK_STRING_LITERAL_TYPE_NONE
;
1590 estack_ax(stack
, top
)->u
.s
.user
= 1;
1591 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
1595 OP(BYTECODE_OP_GET_CONTEXT_ROOT
):
1597 dbg_printk("op get context root\n");
1598 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1599 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_CONTEXT
;
1600 /* "field" only needed for variants. */
1601 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1602 estack_ax(stack
, top
)->type
= REG_PTR
;
1603 next_pc
+= sizeof(struct load_op
);
1607 OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT
):
1613 OP(BYTECODE_OP_GET_PAYLOAD_ROOT
):
1615 dbg_printk("op get app payload root\n");
1616 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1617 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_PAYLOAD
;
1618 estack_ax(stack
, top
)->u
.ptr
.ptr
= interpreter_stack_data
;
1619 /* "field" only needed for variants. */
1620 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
1621 estack_ax(stack
, top
)->type
= REG_PTR
;
1622 next_pc
+= sizeof(struct load_op
);
1626 OP(BYTECODE_OP_GET_SYMBOL
):
1628 dbg_printk("op get symbol\n");
1629 switch (estack_ax(stack
, top
)->u
.ptr
.type
) {
1631 printk(KERN_WARNING
"LTTng: bytecode: Nested fields not implemented yet.\n");
1634 case LOAD_ROOT_CONTEXT
:
1635 case LOAD_ROOT_APP_CONTEXT
:
1636 case LOAD_ROOT_PAYLOAD
:
1638 * symbol lookup is performed by
1644 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_symbol
);
1648 OP(BYTECODE_OP_GET_SYMBOL_FIELD
):
1651 * Used for first variant encountered in a
1652 * traversal. Variants are not implemented yet.
1658 OP(BYTECODE_OP_GET_INDEX_U16
):
1660 struct load_op
*insn
= (struct load_op
*) pc
;
1661 struct get_index_u16
*index
= (struct get_index_u16
*) insn
->data
;
1663 dbg_printk("op get index u16\n");
1664 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1667 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1668 estack_ax_t
= estack_ax(stack
, top
)->type
;
1669 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u16
);
1673 OP(BYTECODE_OP_GET_INDEX_U64
):
1675 struct load_op
*insn
= (struct load_op
*) pc
;
1676 struct get_index_u64
*index
= (struct get_index_u64
*) insn
->data
;
1678 dbg_printk("op get index u64\n");
1679 ret
= dynamic_get_index(lttng_probe_ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
1682 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1683 estack_ax_t
= estack_ax(stack
, top
)->type
;
1684 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u64
);
1688 OP(BYTECODE_OP_LOAD_FIELD
):
1690 dbg_printk("op load field\n");
1691 ret
= dynamic_load_field(estack_ax(stack
, top
));
1694 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
1695 estack_ax_t
= estack_ax(stack
, top
)->type
;
1696 next_pc
+= sizeof(struct load_op
);
1700 OP(BYTECODE_OP_LOAD_FIELD_S8
):
1702 dbg_printk("op load field s8\n");
1704 estack_ax_v
= *(int8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1705 estack_ax_t
= REG_S64
;
1706 next_pc
+= sizeof(struct load_op
);
1709 OP(BYTECODE_OP_LOAD_FIELD_S16
):
1711 dbg_printk("op load field s16\n");
1713 estack_ax_v
= *(int16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1714 estack_ax_t
= REG_S64
;
1715 next_pc
+= sizeof(struct load_op
);
1718 OP(BYTECODE_OP_LOAD_FIELD_S32
):
1720 dbg_printk("op load field s32\n");
1722 estack_ax_v
= *(int32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1723 estack_ax_t
= REG_S64
;
1724 next_pc
+= sizeof(struct load_op
);
1727 OP(BYTECODE_OP_LOAD_FIELD_S64
):
1729 dbg_printk("op load field s64\n");
1731 estack_ax_v
= *(int64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1732 estack_ax_t
= REG_S64
;
1733 next_pc
+= sizeof(struct load_op
);
1736 OP(BYTECODE_OP_LOAD_FIELD_U8
):
1738 dbg_printk("op load field u8\n");
1740 estack_ax_v
= *(uint8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1741 estack_ax_t
= REG_S64
;
1742 next_pc
+= sizeof(struct load_op
);
1745 OP(BYTECODE_OP_LOAD_FIELD_U16
):
1747 dbg_printk("op load field u16\n");
1749 estack_ax_v
= *(uint16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1750 estack_ax_t
= REG_S64
;
1751 next_pc
+= sizeof(struct load_op
);
1754 OP(BYTECODE_OP_LOAD_FIELD_U32
):
1756 dbg_printk("op load field u32\n");
1758 estack_ax_v
= *(uint32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1759 estack_ax_t
= REG_S64
;
1760 next_pc
+= sizeof(struct load_op
);
1763 OP(BYTECODE_OP_LOAD_FIELD_U64
):
1765 dbg_printk("op load field u64\n");
1767 estack_ax_v
= *(uint64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1768 estack_ax_t
= REG_S64
;
1769 next_pc
+= sizeof(struct load_op
);
1772 OP(BYTECODE_OP_LOAD_FIELD_DOUBLE
):
1778 OP(BYTECODE_OP_LOAD_FIELD_STRING
):
1782 dbg_printk("op load field string\n");
1783 str
= (const char *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
1784 estack_ax(stack
, top
)->u
.s
.str
= str
;
1785 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1786 dbg_printk("Bytecode warning: loading a NULL string.\n");
1790 estack_ax(stack
, top
)->u
.s
.seq_len
= LTTNG_SIZE_MAX
;
1791 estack_ax(stack
, top
)->u
.s
.literal_type
=
1792 ESTACK_STRING_LITERAL_TYPE_NONE
;
1793 estack_ax(stack
, top
)->type
= REG_STRING
;
1794 next_pc
+= sizeof(struct load_op
);
1798 OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE
):
1802 dbg_printk("op load field string sequence\n");
1803 ptr
= estack_ax(stack
, top
)->u
.ptr
.ptr
;
1804 estack_ax(stack
, top
)->u
.s
.seq_len
= *(unsigned long *) ptr
;
1805 estack_ax(stack
, top
)->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
1806 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
1807 dbg_printk("Bytecode warning: loading a NULL sequence.\n");
1811 estack_ax(stack
, top
)->u
.s
.literal_type
=
1812 ESTACK_STRING_LITERAL_TYPE_NONE
;
1813 estack_ax(stack
, top
)->type
= REG_STRING
;
1814 next_pc
+= sizeof(struct load_op
);
1820 /* No need to prepare output if an error occurred. */
1822 return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
;
1824 /* Prepare output. */
1825 switch (kernel_bytecode
->type
) {
1826 case LTTNG_KERNEL_BYTECODE_TYPE_FILTER
:
1828 struct lttng_kernel_bytecode_filter_ctx
*filter_ctx
=
1829 (struct lttng_kernel_bytecode_filter_ctx
*) caller_ctx
;
1831 filter_ctx
->result
= LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
;
1833 filter_ctx
->result
= LTTNG_KERNEL_BYTECODE_FILTER_REJECT
;
1836 case LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
:
1837 ret
= lttng_bytecode_interpret_format_output(estack_ax(stack
, top
),
1838 (struct lttng_interpreter_output
*) caller_ctx
);
1845 return LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
;
1847 return LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
;
1849 LTTNG_STACK_FRAME_NON_STANDARD(lttng_bytecode_interpret
);
1852 * Return LTTNG_KERNEL_EVENT_FILTER_ACCEPT or LTTNG_KERNEL_EVENT_FILTER_REJECT.
1854 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common
*event
,
1855 const char *interpreter_stack_data
,
1856 struct lttng_kernel_probe_ctx
*probe_ctx
,
1857 void *event_filter_ctx
__attribute__((unused
)))
1859 struct lttng_kernel_bytecode_runtime
*filter_bc_runtime
;
1860 struct list_head
*filter_bytecode_runtime_head
= &event
->priv
->filter_bytecode_runtime_head
;
1861 struct lttng_kernel_bytecode_filter_ctx bytecode_filter_ctx
;
1862 bool filter_record
= false;
1864 list_for_each_entry_rcu(filter_bc_runtime
, filter_bytecode_runtime_head
, node
) {
1865 if (likely(filter_bc_runtime
->interpreter_func(filter_bc_runtime
,
1866 interpreter_stack_data
, probe_ctx
, &bytecode_filter_ctx
) == LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
)) {
1867 if (unlikely(bytecode_filter_ctx
.result
== LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
)) {
1868 filter_record
= true;
1874 return LTTNG_KERNEL_EVENT_FILTER_ACCEPT
;
1876 return LTTNG_KERNEL_EVENT_FILTER_REJECT
;