2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * LTTng UST bytecode interpreter.
13 #include <lttng/urcu/pointer.h>
14 #include <lttng/ust-endian.h>
15 #include <lttng/ust-events.h>
16 #include "ust-events-internal.h"
18 #include "lttng-bytecode.h"
19 #include "string-utils.h"
24 * -2: unknown escape char.
29 int parse_char(const char **p
)
49 * Returns SIZE_MAX if the string is null-terminated, or the number of
53 size_t get_str_or_seq_len(const struct estack_entry
*entry
)
55 return entry
->u
.s
.seq_len
;
59 int stack_star_glob_match(struct estack
*stack
, int top
, const char *cmp_type
)
62 const char *candidate
;
66 /* Find out which side is the pattern vs. the candidate. */
67 if (estack_ax(stack
, top
)->u
.s
.literal_type
== ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
) {
68 pattern
= estack_ax(stack
, top
)->u
.s
.str
;
69 pattern_len
= get_str_or_seq_len(estack_ax(stack
, top
));
70 candidate
= estack_bx(stack
, top
)->u
.s
.str
;
71 candidate_len
= get_str_or_seq_len(estack_bx(stack
, top
));
73 pattern
= estack_bx(stack
, top
)->u
.s
.str
;
74 pattern_len
= get_str_or_seq_len(estack_bx(stack
, top
));
75 candidate
= estack_ax(stack
, top
)->u
.s
.str
;
76 candidate_len
= get_str_or_seq_len(estack_ax(stack
, top
));
79 /* Perform the match. Returns 0 when the result is true. */
80 return !strutils_star_glob_match(pattern
, pattern_len
, candidate
,
85 int stack_strcmp(struct estack
*stack
, int top
, const char *cmp_type
)
87 const char *p
= estack_bx(stack
, top
)->u
.s
.str
, *q
= estack_ax(stack
, top
)->u
.s
.str
;
94 if (unlikely(p
- estack_bx(stack
, top
)->u
.s
.str
>= estack_bx(stack
, top
)->u
.s
.seq_len
|| *p
== '\0')) {
95 if (q
- estack_ax(stack
, top
)->u
.s
.str
>= estack_ax(stack
, top
)->u
.s
.seq_len
|| *q
== '\0') {
98 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
99 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
100 ret
= parse_char(&q
);
107 if (unlikely(q
- estack_ax(stack
, top
)->u
.s
.str
>= estack_ax(stack
, top
)->u
.s
.seq_len
|| *q
== '\0')) {
108 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
109 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
110 ret
= parse_char(&p
);
116 if (estack_bx(stack
, top
)->u
.s
.literal_type
==
117 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
118 ret
= parse_char(&p
);
121 } else if (ret
== -2) {
124 /* else compare both char */
126 if (estack_ax(stack
, top
)->u
.s
.literal_type
==
127 ESTACK_STRING_LITERAL_TYPE_PLAIN
) {
128 ret
= parse_char(&q
);
131 } else if (ret
== -2) {
151 uint64_t lttng_bytecode_filter_interpret_false(void *filter_data
,
152 const char *filter_stack_data
)
154 return LTTNG_INTERPRETER_DISCARD
;
157 uint64_t lttng_bytecode_capture_interpret_false(void *capture_data
,
158 const char *capture_stack_data
,
159 struct lttng_interpreter_output
*output
)
161 return LTTNG_INTERPRETER_DISCARD
;
164 #ifdef INTERPRETER_USE_SWITCH
167 * Fallback for compilers that do not support taking address of labels.
171 start_pc = &bytecode->data[0]; \
172 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
174 dbg_printf("Executing op %s (%u)\n", \
175 lttng_bytecode_print_op((unsigned int) *(bytecode_opcode_t *) pc), \
176 (unsigned int) *(bytecode_opcode_t *) pc); \
177 switch (*(bytecode_opcode_t *) pc) {
179 #define OP(name) jump_target_##name: __attribute__((unused)); \
187 #define JUMP_TO(name) \
188 goto jump_target_##name
193 * Dispatch-table based interpreter.
197 start_pc = &bytecode->code[0]; \
198 pc = next_pc = start_pc; \
199 if (unlikely(pc - start_pc >= bytecode->len)) \
201 goto *dispatch[*(bytecode_opcode_t *) pc];
208 goto *dispatch[*(bytecode_opcode_t *) pc];
212 #define JUMP_TO(name) \
217 #define IS_INTEGER_REGISTER(reg_type) \
218 (reg_type == REG_U64 || reg_type == REG_S64)
220 static int context_get_index(struct lttng_ctx
*ctx
,
221 struct load_ptr
*ptr
,
225 struct lttng_ctx_field
*ctx_field
;
226 struct lttng_event_field
*field
;
227 struct lttng_ctx_value v
;
229 ctx_field
= &ctx
->fields
[idx
];
230 field
= &ctx_field
->event_field
;
231 ptr
->type
= LOAD_OBJECT
;
234 switch (field
->type
.atype
) {
236 ctx_field
->get_value(ctx_field
, &v
);
237 if (field
->type
.u
.integer
.signedness
) {
238 ptr
->object_type
= OBJECT_TYPE_S64
;
239 ptr
->u
.s64
= v
.u
.s64
;
240 ptr
->ptr
= &ptr
->u
.s64
;
242 ptr
->object_type
= OBJECT_TYPE_U64
;
243 ptr
->u
.u64
= v
.u
.s64
; /* Cast. */
244 ptr
->ptr
= &ptr
->u
.u64
;
247 case atype_enum
: /* Fall-through */
248 case atype_enum_nestable
:
250 const struct lttng_integer_type
*itype
;
252 if (field
->type
.atype
== atype_enum
) {
253 itype
= &field
->type
.u
.legacy
.basic
.enumeration
.container_type
;
255 itype
= &field
->type
.u
.enum_nestable
.container_type
->u
.integer
;
257 ctx_field
->get_value(ctx_field
, &v
);
258 if (itype
->signedness
) {
259 ptr
->object_type
= OBJECT_TYPE_SIGNED_ENUM
;
260 ptr
->u
.s64
= v
.u
.s64
;
261 ptr
->ptr
= &ptr
->u
.s64
;
263 ptr
->object_type
= OBJECT_TYPE_UNSIGNED_ENUM
;
264 ptr
->u
.u64
= v
.u
.s64
; /* Cast. */
265 ptr
->ptr
= &ptr
->u
.u64
;
270 if (field
->type
.u
.legacy
.array
.elem_type
.atype
!= atype_integer
) {
271 ERR("Array nesting only supports integer types.");
274 if (field
->type
.u
.legacy
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
) {
275 ERR("Only string arrays are supported for contexts.");
278 ptr
->object_type
= OBJECT_TYPE_STRING
;
279 ctx_field
->get_value(ctx_field
, &v
);
282 case atype_array_nestable
:
283 if (field
->type
.u
.array_nestable
.elem_type
->atype
!= atype_integer
) {
284 ERR("Array nesting only supports integer types.");
287 if (field
->type
.u
.array_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
288 ERR("Only string arrays are supported for contexts.");
291 ptr
->object_type
= OBJECT_TYPE_STRING
;
292 ctx_field
->get_value(ctx_field
, &v
);
296 if (field
->type
.u
.legacy
.sequence
.elem_type
.atype
!= atype_integer
) {
297 ERR("Sequence nesting only supports integer types.");
300 if (field
->type
.u
.legacy
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
) {
301 ERR("Only string sequences are supported for contexts.");
304 ptr
->object_type
= OBJECT_TYPE_STRING
;
305 ctx_field
->get_value(ctx_field
, &v
);
308 case atype_sequence_nestable
:
309 if (field
->type
.u
.sequence_nestable
.elem_type
->atype
!= atype_integer
) {
310 ERR("Sequence nesting only supports integer types.");
313 if (field
->type
.u
.sequence_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
) {
314 ERR("Only string sequences are supported for contexts.");
317 ptr
->object_type
= OBJECT_TYPE_STRING
;
318 ctx_field
->get_value(ctx_field
, &v
);
322 ptr
->object_type
= OBJECT_TYPE_STRING
;
323 ctx_field
->get_value(ctx_field
, &v
);
327 ptr
->object_type
= OBJECT_TYPE_DOUBLE
;
328 ctx_field
->get_value(ctx_field
, &v
);
330 ptr
->ptr
= &ptr
->u
.d
;
333 ctx_field
->get_value(ctx_field
, &v
);
335 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
337 case LTTNG_UST_DYNAMIC_TYPE_U8
:
338 case LTTNG_UST_DYNAMIC_TYPE_U16
:
339 case LTTNG_UST_DYNAMIC_TYPE_U32
:
340 case LTTNG_UST_DYNAMIC_TYPE_U64
:
341 ptr
->object_type
= OBJECT_TYPE_U64
;
342 ptr
->u
.u64
= v
.u
.u64
;
343 ptr
->ptr
= &ptr
->u
.u64
;
344 dbg_printf("context get index dynamic u64 %" PRIi64
"\n", ptr
->u
.u64
);
346 case LTTNG_UST_DYNAMIC_TYPE_S8
:
347 case LTTNG_UST_DYNAMIC_TYPE_S16
:
348 case LTTNG_UST_DYNAMIC_TYPE_S32
:
349 case LTTNG_UST_DYNAMIC_TYPE_S64
:
350 ptr
->object_type
= OBJECT_TYPE_S64
;
351 ptr
->u
.s64
= v
.u
.s64
;
352 ptr
->ptr
= &ptr
->u
.s64
;
353 dbg_printf("context get index dynamic s64 %" PRIi64
"\n", ptr
->u
.s64
);
355 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
356 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
357 ptr
->object_type
= OBJECT_TYPE_DOUBLE
;
359 ptr
->ptr
= &ptr
->u
.d
;
360 dbg_printf("context get index dynamic double %g\n", ptr
->u
.d
);
362 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
363 ptr
->object_type
= OBJECT_TYPE_STRING
;
365 dbg_printf("context get index dynamic string %s\n", (const char *) ptr
->ptr
);
368 dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v
.sel
);
373 ERR("Structure type cannot be loaded.");
376 ERR("Unknown type: %d", (int) field
->type
.atype
);
382 static int dynamic_get_index(struct lttng_ctx
*ctx
,
383 struct bytecode_runtime
*runtime
,
384 uint64_t index
, struct estack_entry
*stack_top
)
387 const struct bytecode_get_index_data
*gid
;
389 gid
= (const struct bytecode_get_index_data
*) &runtime
->data
[index
];
390 switch (stack_top
->u
.ptr
.type
) {
392 switch (stack_top
->u
.ptr
.object_type
) {
393 case OBJECT_TYPE_ARRAY
:
397 assert(gid
->offset
< gid
->array_len
);
398 /* Skip count (unsigned long) */
399 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
400 ptr
= ptr
+ gid
->offset
;
401 stack_top
->u
.ptr
.ptr
= ptr
;
402 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
403 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
404 assert(stack_top
->u
.ptr
.field
->type
.atype
== atype_array
||
405 stack_top
->u
.ptr
.field
->type
.atype
== atype_array_nestable
);
406 stack_top
->u
.ptr
.field
= NULL
;
409 case OBJECT_TYPE_SEQUENCE
:
414 ptr
= *(const char **) (stack_top
->u
.ptr
.ptr
+ sizeof(unsigned long));
415 ptr_seq_len
= *(unsigned long *) stack_top
->u
.ptr
.ptr
;
416 if (gid
->offset
>= gid
->elem
.len
* ptr_seq_len
) {
420 ptr
= ptr
+ gid
->offset
;
421 stack_top
->u
.ptr
.ptr
= ptr
;
422 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
423 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
424 assert(stack_top
->u
.ptr
.field
->type
.atype
== atype_sequence
||
425 stack_top
->u
.ptr
.field
->type
.atype
== atype_sequence_nestable
);
426 stack_top
->u
.ptr
.field
= NULL
;
429 case OBJECT_TYPE_STRUCT
:
430 ERR("Nested structures are not supported yet.");
433 case OBJECT_TYPE_VARIANT
:
435 ERR("Unexpected get index type %d",
436 (int) stack_top
->u
.ptr
.object_type
);
441 case LOAD_ROOT_CONTEXT
:
442 case LOAD_ROOT_APP_CONTEXT
: /* Fall-through */
444 ret
= context_get_index(ctx
,
452 case LOAD_ROOT_PAYLOAD
:
453 stack_top
->u
.ptr
.ptr
+= gid
->offset
;
454 if (gid
->elem
.type
== OBJECT_TYPE_STRING
)
455 stack_top
->u
.ptr
.ptr
= *(const char * const *) stack_top
->u
.ptr
.ptr
;
456 stack_top
->u
.ptr
.object_type
= gid
->elem
.type
;
457 stack_top
->u
.ptr
.type
= LOAD_OBJECT
;
458 stack_top
->u
.ptr
.field
= gid
->field
;
459 stack_top
->u
.ptr
.rev_bo
= gid
->elem
.rev_bo
;
463 stack_top
->type
= REG_PTR
;
471 static int dynamic_load_field(struct estack_entry
*stack_top
)
475 switch (stack_top
->u
.ptr
.type
) {
478 case LOAD_ROOT_CONTEXT
:
479 case LOAD_ROOT_APP_CONTEXT
:
480 case LOAD_ROOT_PAYLOAD
:
482 dbg_printf("Interpreter warning: cannot load root, missing field name.\n");
486 switch (stack_top
->u
.ptr
.object_type
) {
488 dbg_printf("op load field s8\n");
489 stack_top
->u
.v
= *(int8_t *) stack_top
->u
.ptr
.ptr
;
490 stack_top
->type
= REG_S64
;
492 case OBJECT_TYPE_S16
:
496 dbg_printf("op load field s16\n");
497 tmp
= *(int16_t *) stack_top
->u
.ptr
.ptr
;
498 if (stack_top
->u
.ptr
.rev_bo
)
500 stack_top
->u
.v
= tmp
;
501 stack_top
->type
= REG_S64
;
504 case OBJECT_TYPE_S32
:
508 dbg_printf("op load field s32\n");
509 tmp
= *(int32_t *) stack_top
->u
.ptr
.ptr
;
510 if (stack_top
->u
.ptr
.rev_bo
)
512 stack_top
->u
.v
= tmp
;
513 stack_top
->type
= REG_S64
;
516 case OBJECT_TYPE_S64
:
520 dbg_printf("op load field s64\n");
521 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
522 if (stack_top
->u
.ptr
.rev_bo
)
524 stack_top
->u
.v
= tmp
;
525 stack_top
->type
= REG_S64
;
528 case OBJECT_TYPE_SIGNED_ENUM
:
532 dbg_printf("op load field signed enumeration\n");
533 tmp
= *(int64_t *) stack_top
->u
.ptr
.ptr
;
534 if (stack_top
->u
.ptr
.rev_bo
)
536 stack_top
->u
.v
= tmp
;
537 stack_top
->type
= REG_S64
;
541 dbg_printf("op load field u8\n");
542 stack_top
->u
.v
= *(uint8_t *) stack_top
->u
.ptr
.ptr
;
543 stack_top
->type
= REG_U64
;
545 case OBJECT_TYPE_U16
:
549 dbg_printf("op load field u16\n");
550 tmp
= *(uint16_t *) stack_top
->u
.ptr
.ptr
;
551 if (stack_top
->u
.ptr
.rev_bo
)
553 stack_top
->u
.v
= tmp
;
554 stack_top
->type
= REG_U64
;
557 case OBJECT_TYPE_U32
:
561 dbg_printf("op load field u32\n");
562 tmp
= *(uint32_t *) stack_top
->u
.ptr
.ptr
;
563 if (stack_top
->u
.ptr
.rev_bo
)
565 stack_top
->u
.v
= tmp
;
566 stack_top
->type
= REG_U64
;
569 case OBJECT_TYPE_U64
:
573 dbg_printf("op load field u64\n");
574 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
575 if (stack_top
->u
.ptr
.rev_bo
)
577 stack_top
->u
.v
= tmp
;
578 stack_top
->type
= REG_U64
;
581 case OBJECT_TYPE_UNSIGNED_ENUM
:
585 dbg_printf("op load field unsigned enumeration\n");
586 tmp
= *(uint64_t *) stack_top
->u
.ptr
.ptr
;
587 if (stack_top
->u
.ptr
.rev_bo
)
589 stack_top
->u
.v
= tmp
;
590 stack_top
->type
= REG_U64
;
593 case OBJECT_TYPE_DOUBLE
:
594 memcpy(&stack_top
->u
.d
,
595 stack_top
->u
.ptr
.ptr
,
596 sizeof(struct literal_double
));
597 stack_top
->type
= REG_DOUBLE
;
599 case OBJECT_TYPE_STRING
:
603 dbg_printf("op load field string\n");
604 str
= (const char *) stack_top
->u
.ptr
.ptr
;
605 stack_top
->u
.s
.str
= str
;
606 if (unlikely(!stack_top
->u
.s
.str
)) {
607 dbg_printf("Interpreter warning: loading a NULL string.\n");
611 stack_top
->u
.s
.seq_len
= SIZE_MAX
;
612 stack_top
->u
.s
.literal_type
=
613 ESTACK_STRING_LITERAL_TYPE_NONE
;
614 stack_top
->type
= REG_STRING
;
617 case OBJECT_TYPE_STRING_SEQUENCE
:
621 dbg_printf("op load field string sequence\n");
622 ptr
= stack_top
->u
.ptr
.ptr
;
623 stack_top
->u
.s
.seq_len
= *(unsigned long *) ptr
;
624 stack_top
->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
625 stack_top
->type
= REG_STRING
;
626 if (unlikely(!stack_top
->u
.s
.str
)) {
627 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
631 stack_top
->u
.s
.literal_type
=
632 ESTACK_STRING_LITERAL_TYPE_NONE
;
635 case OBJECT_TYPE_DYNAMIC
:
637 * Dynamic types in context are looked up
638 * by context get index.
642 case OBJECT_TYPE_SEQUENCE
:
643 case OBJECT_TYPE_ARRAY
:
644 case OBJECT_TYPE_STRUCT
:
645 case OBJECT_TYPE_VARIANT
:
646 ERR("Sequences, arrays, struct and variant cannot be loaded (nested types).");
657 int lttng_bytecode_interpret_format_output(struct estack_entry
*ax
,
658 struct lttng_interpreter_output
*output
)
665 output
->type
= LTTNG_INTERPRETER_TYPE_S64
;
666 output
->u
.s
= ax
->u
.v
;
669 output
->type
= LTTNG_INTERPRETER_TYPE_U64
;
670 output
->u
.u
= (uint64_t) ax
->u
.v
;
673 output
->type
= LTTNG_INTERPRETER_TYPE_DOUBLE
;
674 output
->u
.d
= ax
->u
.d
;
677 output
->type
= LTTNG_INTERPRETER_TYPE_STRING
;
678 output
->u
.str
.str
= ax
->u
.s
.str
;
679 output
->u
.str
.len
= ax
->u
.s
.seq_len
;
682 switch (ax
->u
.ptr
.object_type
) {
684 case OBJECT_TYPE_S16
:
685 case OBJECT_TYPE_S32
:
686 case OBJECT_TYPE_S64
:
688 case OBJECT_TYPE_U16
:
689 case OBJECT_TYPE_U32
:
690 case OBJECT_TYPE_U64
:
691 case OBJECT_TYPE_DOUBLE
:
692 case OBJECT_TYPE_STRING
:
693 case OBJECT_TYPE_STRING_SEQUENCE
:
694 ret
= dynamic_load_field(ax
);
697 /* Retry after loading ptr into stack top. */
699 case OBJECT_TYPE_SEQUENCE
:
700 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
701 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
702 output
->u
.sequence
.nr_elem
= *(unsigned long *) ax
->u
.ptr
.ptr
;
703 output
->u
.sequence
.nested_type
= ax
->u
.ptr
.field
->type
.u
.sequence_nestable
.elem_type
;
705 case OBJECT_TYPE_ARRAY
:
706 /* Skip count (unsigned long) */
707 output
->type
= LTTNG_INTERPRETER_TYPE_SEQUENCE
;
708 output
->u
.sequence
.ptr
= *(const char **) (ax
->u
.ptr
.ptr
+ sizeof(unsigned long));
709 output
->u
.sequence
.nr_elem
= ax
->u
.ptr
.field
->type
.u
.array_nestable
.length
;
710 output
->u
.sequence
.nested_type
= ax
->u
.ptr
.field
->type
.u
.array_nestable
.elem_type
;
712 case OBJECT_TYPE_SIGNED_ENUM
:
713 ret
= dynamic_load_field(ax
);
716 output
->type
= LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
;
717 output
->u
.s
= ax
->u
.v
;
719 case OBJECT_TYPE_UNSIGNED_ENUM
:
720 ret
= dynamic_load_field(ax
);
723 output
->type
= LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
;
724 output
->u
.u
= ax
->u
.v
;
726 case OBJECT_TYPE_STRUCT
:
727 case OBJECT_TYPE_VARIANT
:
733 case REG_STAR_GLOB_STRING
:
739 return LTTNG_INTERPRETER_RECORD_FLAG
;
743 * For `output` equal to NULL:
744 * Return 0 (discard), or raise the 0x1 flag (log event).
745 * Currently, other flags are kept for future extensions and have no
747 * For `output` not equal to NULL:
748 * Return 0 on success, negative error value on error.
751 uint64_t bytecode_interpret(void *interpreter_data
,
752 const char *interpreter_stack_data
,
753 struct lttng_interpreter_output
*output
)
755 struct bytecode_runtime
*bytecode
= interpreter_data
;
756 struct lttng_ctx
*ctx
= lttng_ust_rcu_dereference(*bytecode
->p
.priv
->pctx
);
757 void *pc
, *next_pc
, *start_pc
;
760 struct estack _stack
;
761 struct estack
*stack
= &_stack
;
762 register int64_t ax
= 0, bx
= 0;
763 register enum entry_type ax_t
= REG_UNKNOWN
, bx_t
= REG_UNKNOWN
;
764 register int top
= INTERPRETER_STACK_EMPTY
;
765 #ifndef INTERPRETER_USE_SWITCH
766 static void *dispatch
[NR_BYTECODE_OPS
] = {
767 [ BYTECODE_OP_UNKNOWN
] = &&LABEL_BYTECODE_OP_UNKNOWN
,
769 [ BYTECODE_OP_RETURN
] = &&LABEL_BYTECODE_OP_RETURN
,
772 [ BYTECODE_OP_MUL
] = &&LABEL_BYTECODE_OP_MUL
,
773 [ BYTECODE_OP_DIV
] = &&LABEL_BYTECODE_OP_DIV
,
774 [ BYTECODE_OP_MOD
] = &&LABEL_BYTECODE_OP_MOD
,
775 [ BYTECODE_OP_PLUS
] = &&LABEL_BYTECODE_OP_PLUS
,
776 [ BYTECODE_OP_MINUS
] = &&LABEL_BYTECODE_OP_MINUS
,
777 [ BYTECODE_OP_BIT_RSHIFT
] = &&LABEL_BYTECODE_OP_BIT_RSHIFT
,
778 [ BYTECODE_OP_BIT_LSHIFT
] = &&LABEL_BYTECODE_OP_BIT_LSHIFT
,
779 [ BYTECODE_OP_BIT_AND
] = &&LABEL_BYTECODE_OP_BIT_AND
,
780 [ BYTECODE_OP_BIT_OR
] = &&LABEL_BYTECODE_OP_BIT_OR
,
781 [ BYTECODE_OP_BIT_XOR
] = &&LABEL_BYTECODE_OP_BIT_XOR
,
783 /* binary comparators */
784 [ BYTECODE_OP_EQ
] = &&LABEL_BYTECODE_OP_EQ
,
785 [ BYTECODE_OP_NE
] = &&LABEL_BYTECODE_OP_NE
,
786 [ BYTECODE_OP_GT
] = &&LABEL_BYTECODE_OP_GT
,
787 [ BYTECODE_OP_LT
] = &&LABEL_BYTECODE_OP_LT
,
788 [ BYTECODE_OP_GE
] = &&LABEL_BYTECODE_OP_GE
,
789 [ BYTECODE_OP_LE
] = &&LABEL_BYTECODE_OP_LE
,
791 /* string binary comparator */
792 [ BYTECODE_OP_EQ_STRING
] = &&LABEL_BYTECODE_OP_EQ_STRING
,
793 [ BYTECODE_OP_NE_STRING
] = &&LABEL_BYTECODE_OP_NE_STRING
,
794 [ BYTECODE_OP_GT_STRING
] = &&LABEL_BYTECODE_OP_GT_STRING
,
795 [ BYTECODE_OP_LT_STRING
] = &&LABEL_BYTECODE_OP_LT_STRING
,
796 [ BYTECODE_OP_GE_STRING
] = &&LABEL_BYTECODE_OP_GE_STRING
,
797 [ BYTECODE_OP_LE_STRING
] = &&LABEL_BYTECODE_OP_LE_STRING
,
799 /* globbing pattern binary comparator */
800 [ BYTECODE_OP_EQ_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING
,
801 [ BYTECODE_OP_NE_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING
,
803 /* s64 binary comparator */
804 [ BYTECODE_OP_EQ_S64
] = &&LABEL_BYTECODE_OP_EQ_S64
,
805 [ BYTECODE_OP_NE_S64
] = &&LABEL_BYTECODE_OP_NE_S64
,
806 [ BYTECODE_OP_GT_S64
] = &&LABEL_BYTECODE_OP_GT_S64
,
807 [ BYTECODE_OP_LT_S64
] = &&LABEL_BYTECODE_OP_LT_S64
,
808 [ BYTECODE_OP_GE_S64
] = &&LABEL_BYTECODE_OP_GE_S64
,
809 [ BYTECODE_OP_LE_S64
] = &&LABEL_BYTECODE_OP_LE_S64
,
811 /* double binary comparator */
812 [ BYTECODE_OP_EQ_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE
,
813 [ BYTECODE_OP_NE_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_DOUBLE
,
814 [ BYTECODE_OP_GT_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_DOUBLE
,
815 [ BYTECODE_OP_LT_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_DOUBLE
,
816 [ BYTECODE_OP_GE_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_DOUBLE
,
817 [ BYTECODE_OP_LE_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_DOUBLE
,
819 /* Mixed S64-double binary comparators */
820 [ BYTECODE_OP_EQ_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64
,
821 [ BYTECODE_OP_NE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64
,
822 [ BYTECODE_OP_GT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64
,
823 [ BYTECODE_OP_LT_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64
,
824 [ BYTECODE_OP_GE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64
,
825 [ BYTECODE_OP_LE_DOUBLE_S64
] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64
,
827 [ BYTECODE_OP_EQ_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE
,
828 [ BYTECODE_OP_NE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE
,
829 [ BYTECODE_OP_GT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE
,
830 [ BYTECODE_OP_LT_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE
,
831 [ BYTECODE_OP_GE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE
,
832 [ BYTECODE_OP_LE_S64_DOUBLE
] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE
,
835 [ BYTECODE_OP_UNARY_PLUS
] = &&LABEL_BYTECODE_OP_UNARY_PLUS
,
836 [ BYTECODE_OP_UNARY_MINUS
] = &&LABEL_BYTECODE_OP_UNARY_MINUS
,
837 [ BYTECODE_OP_UNARY_NOT
] = &&LABEL_BYTECODE_OP_UNARY_NOT
,
838 [ BYTECODE_OP_UNARY_PLUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64
,
839 [ BYTECODE_OP_UNARY_MINUS_S64
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64
,
840 [ BYTECODE_OP_UNARY_NOT_S64
] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64
,
841 [ BYTECODE_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE
,
842 [ BYTECODE_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE
,
843 [ BYTECODE_OP_UNARY_NOT_DOUBLE
] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE
,
846 [ BYTECODE_OP_AND
] = &&LABEL_BYTECODE_OP_AND
,
847 [ BYTECODE_OP_OR
] = &&LABEL_BYTECODE_OP_OR
,
850 [ BYTECODE_OP_LOAD_FIELD_REF
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF
,
851 [ BYTECODE_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING
,
852 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
,
853 [ BYTECODE_OP_LOAD_FIELD_REF_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64
,
854 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
,
856 /* load from immediate operand */
857 [ BYTECODE_OP_LOAD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STRING
,
858 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING
] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING
,
859 [ BYTECODE_OP_LOAD_S64
] = &&LABEL_BYTECODE_OP_LOAD_S64
,
860 [ BYTECODE_OP_LOAD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE
,
863 [ BYTECODE_OP_CAST_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_TO_S64
,
864 [ BYTECODE_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64
,
865 [ BYTECODE_OP_CAST_NOP
] = &&LABEL_BYTECODE_OP_CAST_NOP
,
867 /* get context ref */
868 [ BYTECODE_OP_GET_CONTEXT_REF
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF
,
869 [ BYTECODE_OP_GET_CONTEXT_REF_STRING
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING
,
870 [ BYTECODE_OP_GET_CONTEXT_REF_S64
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64
,
871 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
,
873 /* Instructions for recursive traversal through composed types. */
874 [ BYTECODE_OP_GET_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT
,
875 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT
] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT
,
876 [ BYTECODE_OP_GET_PAYLOAD_ROOT
] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT
,
878 [ BYTECODE_OP_GET_SYMBOL
] = &&LABEL_BYTECODE_OP_GET_SYMBOL
,
879 [ BYTECODE_OP_GET_SYMBOL_FIELD
] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD
,
880 [ BYTECODE_OP_GET_INDEX_U16
] = &&LABEL_BYTECODE_OP_GET_INDEX_U16
,
881 [ BYTECODE_OP_GET_INDEX_U64
] = &&LABEL_BYTECODE_OP_GET_INDEX_U64
,
883 [ BYTECODE_OP_LOAD_FIELD
] = &&LABEL_BYTECODE_OP_LOAD_FIELD
,
884 [ BYTECODE_OP_LOAD_FIELD_S8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8
,
885 [ BYTECODE_OP_LOAD_FIELD_S16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16
,
886 [ BYTECODE_OP_LOAD_FIELD_S32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32
,
887 [ BYTECODE_OP_LOAD_FIELD_S64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64
,
888 [ BYTECODE_OP_LOAD_FIELD_U8
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8
,
889 [ BYTECODE_OP_LOAD_FIELD_U16
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16
,
890 [ BYTECODE_OP_LOAD_FIELD_U32
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32
,
891 [ BYTECODE_OP_LOAD_FIELD_U64
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64
,
892 [ BYTECODE_OP_LOAD_FIELD_STRING
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING
,
893 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE
,
894 [ BYTECODE_OP_LOAD_FIELD_DOUBLE
] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE
,
896 [ BYTECODE_OP_UNARY_BIT_NOT
] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT
,
898 [ BYTECODE_OP_RETURN_S64
] = &&LABEL_BYTECODE_OP_RETURN_S64
,
900 #endif /* #ifndef INTERPRETER_USE_SWITCH */
904 OP(BYTECODE_OP_UNKNOWN
):
905 OP(BYTECODE_OP_LOAD_FIELD_REF
):
906 #ifdef INTERPRETER_USE_SWITCH
908 #endif /* INTERPRETER_USE_SWITCH */
909 ERR("unknown bytecode op %u",
910 (unsigned int) *(bytecode_opcode_t
*) pc
);
914 OP(BYTECODE_OP_RETURN
):
915 /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */
916 /* Handle dynamic typing. */
917 switch (estack_ax_t
) {
920 retval
= !!estack_ax_v
;
931 case REG_STAR_GLOB_STRING
:
940 OP(BYTECODE_OP_RETURN_S64
):
941 /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */
942 retval
= !!estack_ax_v
;
950 OP(BYTECODE_OP_PLUS
):
951 OP(BYTECODE_OP_MINUS
):
952 ERR("unsupported bytecode op %u",
953 (unsigned int) *(bytecode_opcode_t
*) pc
);
959 /* Dynamic typing. */
960 switch (estack_ax_t
) {
961 case REG_S64
: /* Fall-through */
963 switch (estack_bx_t
) {
964 case REG_S64
: /* Fall-through */
966 JUMP_TO(BYTECODE_OP_EQ_S64
);
968 JUMP_TO(BYTECODE_OP_EQ_DOUBLE_S64
);
969 case REG_STRING
: /* Fall-through */
970 case REG_STAR_GLOB_STRING
:
974 ERR("Unknown interpreter register type (%d)",
981 switch (estack_bx_t
) {
982 case REG_S64
: /* Fall-through */
984 JUMP_TO(BYTECODE_OP_EQ_S64_DOUBLE
);
986 JUMP_TO(BYTECODE_OP_EQ_DOUBLE
);
987 case REG_STRING
: /* Fall-through */
988 case REG_STAR_GLOB_STRING
:
992 ERR("Unknown interpreter register type (%d)",
999 switch (estack_bx_t
) {
1000 case REG_S64
: /* Fall-through */
1001 case REG_U64
: /* Fall-through */
1006 JUMP_TO(BYTECODE_OP_EQ_STRING
);
1007 case REG_STAR_GLOB_STRING
:
1008 JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING
);
1010 ERR("Unknown interpreter register type (%d)",
1016 case REG_STAR_GLOB_STRING
:
1017 switch (estack_bx_t
) {
1018 case REG_S64
: /* Fall-through */
1019 case REG_U64
: /* Fall-through */
1024 JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING
);
1025 case REG_STAR_GLOB_STRING
:
1029 ERR("Unknown interpreter register type (%d)",
1036 ERR("Unknown interpreter register type (%d)",
1044 /* Dynamic typing. */
1045 switch (estack_ax_t
) {
1046 case REG_S64
: /* Fall-through */
1048 switch (estack_bx_t
) {
1049 case REG_S64
: /* Fall-through */
1051 JUMP_TO(BYTECODE_OP_NE_S64
);
1053 JUMP_TO(BYTECODE_OP_NE_DOUBLE_S64
);
1054 case REG_STRING
: /* Fall-through */
1055 case REG_STAR_GLOB_STRING
:
1059 ERR("Unknown interpreter register type (%d)",
1066 switch (estack_bx_t
) {
1067 case REG_S64
: /* Fall-through */
1069 JUMP_TO(BYTECODE_OP_NE_S64_DOUBLE
);
1071 JUMP_TO(BYTECODE_OP_NE_DOUBLE
);
1072 case REG_STRING
: /* Fall-through */
1073 case REG_STAR_GLOB_STRING
:
1077 ERR("Unknown interpreter register type (%d)",
1084 switch (estack_bx_t
) {
1085 case REG_S64
: /* Fall-through */
1091 JUMP_TO(BYTECODE_OP_NE_STRING
);
1092 case REG_STAR_GLOB_STRING
:
1093 JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING
);
1095 ERR("Unknown interpreter register type (%d)",
1101 case REG_STAR_GLOB_STRING
:
1102 switch (estack_bx_t
) {
1103 case REG_S64
: /* Fall-through */
1109 JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING
);
1110 case REG_STAR_GLOB_STRING
:
1114 ERR("Unknown interpreter register type (%d)",
1121 ERR("Unknown interpreter register type (%d)",
1129 /* Dynamic typing. */
1130 switch (estack_ax_t
) {
1131 case REG_S64
: /* Fall-through */
1133 switch (estack_bx_t
) {
1134 case REG_S64
: /* Fall-through */
1136 JUMP_TO(BYTECODE_OP_GT_S64
);
1138 JUMP_TO(BYTECODE_OP_GT_DOUBLE_S64
);
1139 case REG_STRING
: /* Fall-through */
1140 case REG_STAR_GLOB_STRING
:
1144 ERR("Unknown interpreter register type (%d)",
1151 switch (estack_bx_t
) {
1152 case REG_S64
: /* Fall-through */
1154 JUMP_TO(BYTECODE_OP_GT_S64_DOUBLE
);
1156 JUMP_TO(BYTECODE_OP_GT_DOUBLE
);
1157 case REG_STRING
: /* Fall-through */
1158 case REG_STAR_GLOB_STRING
:
1162 ERR("Unknown interpreter register type (%d)",
1169 switch (estack_bx_t
) {
1170 case REG_S64
: /* Fall-through */
1171 case REG_U64
: /* Fall-through */
1172 case REG_DOUBLE
: /* Fall-through */
1173 case REG_STAR_GLOB_STRING
:
1177 JUMP_TO(BYTECODE_OP_GT_STRING
);
1179 ERR("Unknown interpreter register type (%d)",
1186 ERR("Unknown interpreter register type (%d)",
1194 /* Dynamic typing. */
1195 switch (estack_ax_t
) {
1196 case REG_S64
: /* Fall-through */
1198 switch (estack_bx_t
) {
1199 case REG_S64
: /* Fall-through */
1201 JUMP_TO(BYTECODE_OP_LT_S64
);
1203 JUMP_TO(BYTECODE_OP_LT_DOUBLE_S64
);
1204 case REG_STRING
: /* Fall-through */
1205 case REG_STAR_GLOB_STRING
:
1209 ERR("Unknown interpreter register type (%d)",
1216 switch (estack_bx_t
) {
1217 case REG_S64
: /* Fall-through */
1219 JUMP_TO(BYTECODE_OP_LT_S64_DOUBLE
);
1221 JUMP_TO(BYTECODE_OP_LT_DOUBLE
);
1222 case REG_STRING
: /* Fall-through */
1223 case REG_STAR_GLOB_STRING
:
1227 ERR("Unknown interpreter register type (%d)",
1234 switch (estack_bx_t
) {
1235 case REG_S64
: /* Fall-through */
1236 case REG_U64
: /* Fall-through */
1237 case REG_DOUBLE
: /* Fall-through */
1238 case REG_STAR_GLOB_STRING
:
1242 JUMP_TO(BYTECODE_OP_LT_STRING
);
1244 ERR("Unknown interpreter register type (%d)",
1251 ERR("Unknown interpreter register type (%d)",
1259 /* Dynamic typing. */
1260 switch (estack_ax_t
) {
1261 case REG_S64
: /* Fall-through */
1263 switch (estack_bx_t
) {
1264 case REG_S64
: /* Fall-through */
1266 JUMP_TO(BYTECODE_OP_GE_S64
);
1268 JUMP_TO(BYTECODE_OP_GE_DOUBLE_S64
);
1269 case REG_STRING
: /* Fall-through */
1270 case REG_STAR_GLOB_STRING
:
1274 ERR("Unknown interpreter register type (%d)",
1281 switch (estack_bx_t
) {
1282 case REG_S64
: /* Fall-through */
1284 JUMP_TO(BYTECODE_OP_GE_S64_DOUBLE
);
1286 JUMP_TO(BYTECODE_OP_GE_DOUBLE
);
1287 case REG_STRING
: /* Fall-through */
1288 case REG_STAR_GLOB_STRING
:
1292 ERR("Unknown interpreter register type (%d)",
1299 switch (estack_bx_t
) {
1300 case REG_S64
: /* Fall-through */
1301 case REG_U64
: /* Fall-through */
1302 case REG_DOUBLE
: /* Fall-through */
1303 case REG_STAR_GLOB_STRING
:
1307 JUMP_TO(BYTECODE_OP_GE_STRING
);
1309 ERR("Unknown interpreter register type (%d)",
1316 ERR("Unknown interpreter register type (%d)",
1324 /* Dynamic typing. */
1325 switch (estack_ax_t
) {
1326 case REG_S64
: /* Fall-through */
1328 switch (estack_bx_t
) {
1329 case REG_S64
: /* Fall-through */
1331 JUMP_TO(BYTECODE_OP_LE_S64
);
1333 JUMP_TO(BYTECODE_OP_LE_DOUBLE_S64
);
1334 case REG_STRING
: /* Fall-through */
1335 case REG_STAR_GLOB_STRING
:
1339 ERR("Unknown interpreter register type (%d)",
1346 switch (estack_bx_t
) {
1347 case REG_S64
: /* Fall-through */
1349 JUMP_TO(BYTECODE_OP_LE_S64_DOUBLE
);
1351 JUMP_TO(BYTECODE_OP_LE_DOUBLE
);
1352 case REG_STRING
: /* Fall-through */
1353 case REG_STAR_GLOB_STRING
:
1357 ERR("Unknown interpreter register type (%d)",
1364 switch (estack_bx_t
) {
1365 case REG_S64
: /* Fall-through */
1366 case REG_U64
: /* Fall-through */
1367 case REG_DOUBLE
: /* Fall-through */
1368 case REG_STAR_GLOB_STRING
:
1372 JUMP_TO(BYTECODE_OP_LE_STRING
);
1374 ERR("Unknown interpreter register type (%d)",
1381 ERR("Unknown interpreter register type (%d)",
1388 OP(BYTECODE_OP_EQ_STRING
):
1392 res
= (stack_strcmp(stack
, top
, "==") == 0);
1393 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1395 estack_ax_t
= REG_S64
;
1396 next_pc
+= sizeof(struct binary_op
);
1399 OP(BYTECODE_OP_NE_STRING
):
1403 res
= (stack_strcmp(stack
, top
, "!=") != 0);
1404 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1406 estack_ax_t
= REG_S64
;
1407 next_pc
+= sizeof(struct binary_op
);
1410 OP(BYTECODE_OP_GT_STRING
):
1414 res
= (stack_strcmp(stack
, top
, ">") > 0);
1415 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1417 estack_ax_t
= REG_S64
;
1418 next_pc
+= sizeof(struct binary_op
);
1421 OP(BYTECODE_OP_LT_STRING
):
1425 res
= (stack_strcmp(stack
, top
, "<") < 0);
1426 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1428 estack_ax_t
= REG_S64
;
1429 next_pc
+= sizeof(struct binary_op
);
1432 OP(BYTECODE_OP_GE_STRING
):
1436 res
= (stack_strcmp(stack
, top
, ">=") >= 0);
1437 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1439 estack_ax_t
= REG_S64
;
1440 next_pc
+= sizeof(struct binary_op
);
1443 OP(BYTECODE_OP_LE_STRING
):
1447 res
= (stack_strcmp(stack
, top
, "<=") <= 0);
1448 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1450 estack_ax_t
= REG_S64
;
1451 next_pc
+= sizeof(struct binary_op
);
1455 OP(BYTECODE_OP_EQ_STAR_GLOB_STRING
):
1459 res
= (stack_star_glob_match(stack
, top
, "==") == 0);
1460 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1462 estack_ax_t
= REG_S64
;
1463 next_pc
+= sizeof(struct binary_op
);
1466 OP(BYTECODE_OP_NE_STAR_GLOB_STRING
):
1470 res
= (stack_star_glob_match(stack
, top
, "!=") != 0);
1471 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1473 estack_ax_t
= REG_S64
;
1474 next_pc
+= sizeof(struct binary_op
);
1478 OP(BYTECODE_OP_EQ_S64
):
1482 res
= (estack_bx_v
== estack_ax_v
);
1483 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1485 estack_ax_t
= REG_S64
;
1486 next_pc
+= sizeof(struct binary_op
);
1489 OP(BYTECODE_OP_NE_S64
):
1493 res
= (estack_bx_v
!= estack_ax_v
);
1494 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1496 estack_ax_t
= REG_S64
;
1497 next_pc
+= sizeof(struct binary_op
);
1500 OP(BYTECODE_OP_GT_S64
):
1504 res
= (estack_bx_v
> estack_ax_v
);
1505 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1507 estack_ax_t
= REG_S64
;
1508 next_pc
+= sizeof(struct binary_op
);
1511 OP(BYTECODE_OP_LT_S64
):
1515 res
= (estack_bx_v
< estack_ax_v
);
1516 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1518 estack_ax_t
= REG_S64
;
1519 next_pc
+= sizeof(struct binary_op
);
1522 OP(BYTECODE_OP_GE_S64
):
1526 res
= (estack_bx_v
>= estack_ax_v
);
1527 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1529 estack_ax_t
= REG_S64
;
1530 next_pc
+= sizeof(struct binary_op
);
1533 OP(BYTECODE_OP_LE_S64
):
1537 res
= (estack_bx_v
<= estack_ax_v
);
1538 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1540 estack_ax_t
= REG_S64
;
1541 next_pc
+= sizeof(struct binary_op
);
1545 OP(BYTECODE_OP_EQ_DOUBLE
):
1549 res
= (estack_bx(stack
, top
)->u
.d
== estack_ax(stack
, top
)->u
.d
);
1550 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1552 estack_ax_t
= REG_S64
;
1553 next_pc
+= sizeof(struct binary_op
);
1556 OP(BYTECODE_OP_NE_DOUBLE
):
1560 res
= (estack_bx(stack
, top
)->u
.d
!= estack_ax(stack
, top
)->u
.d
);
1561 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1563 estack_ax_t
= REG_S64
;
1564 next_pc
+= sizeof(struct binary_op
);
1567 OP(BYTECODE_OP_GT_DOUBLE
):
1571 res
= (estack_bx(stack
, top
)->u
.d
> estack_ax(stack
, top
)->u
.d
);
1572 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1574 estack_ax_t
= REG_S64
;
1575 next_pc
+= sizeof(struct binary_op
);
1578 OP(BYTECODE_OP_LT_DOUBLE
):
1582 res
= (estack_bx(stack
, top
)->u
.d
< estack_ax(stack
, top
)->u
.d
);
1583 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1585 estack_ax_t
= REG_S64
;
1586 next_pc
+= sizeof(struct binary_op
);
1589 OP(BYTECODE_OP_GE_DOUBLE
):
1593 res
= (estack_bx(stack
, top
)->u
.d
>= estack_ax(stack
, top
)->u
.d
);
1594 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1596 estack_ax_t
= REG_S64
;
1597 next_pc
+= sizeof(struct binary_op
);
1600 OP(BYTECODE_OP_LE_DOUBLE
):
1604 res
= (estack_bx(stack
, top
)->u
.d
<= estack_ax(stack
, top
)->u
.d
);
1605 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1607 estack_ax_t
= REG_S64
;
1608 next_pc
+= sizeof(struct binary_op
);
1612 /* Mixed S64-double binary comparators */
1613 OP(BYTECODE_OP_EQ_DOUBLE_S64
):
1617 res
= (estack_bx(stack
, top
)->u
.d
== estack_ax_v
);
1618 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1620 estack_ax_t
= REG_S64
;
1621 next_pc
+= sizeof(struct binary_op
);
1624 OP(BYTECODE_OP_NE_DOUBLE_S64
):
1628 res
= (estack_bx(stack
, top
)->u
.d
!= estack_ax_v
);
1629 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1631 estack_ax_t
= REG_S64
;
1632 next_pc
+= sizeof(struct binary_op
);
1635 OP(BYTECODE_OP_GT_DOUBLE_S64
):
1639 res
= (estack_bx(stack
, top
)->u
.d
> estack_ax_v
);
1640 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1642 estack_ax_t
= REG_S64
;
1643 next_pc
+= sizeof(struct binary_op
);
1646 OP(BYTECODE_OP_LT_DOUBLE_S64
):
1650 res
= (estack_bx(stack
, top
)->u
.d
< estack_ax_v
);
1651 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1653 estack_ax_t
= REG_S64
;
1654 next_pc
+= sizeof(struct binary_op
);
1657 OP(BYTECODE_OP_GE_DOUBLE_S64
):
1661 res
= (estack_bx(stack
, top
)->u
.d
>= estack_ax_v
);
1662 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1664 estack_ax_t
= REG_S64
;
1665 next_pc
+= sizeof(struct binary_op
);
1668 OP(BYTECODE_OP_LE_DOUBLE_S64
):
1672 res
= (estack_bx(stack
, top
)->u
.d
<= estack_ax_v
);
1673 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1675 estack_ax_t
= REG_S64
;
1676 next_pc
+= sizeof(struct binary_op
);
1680 OP(BYTECODE_OP_EQ_S64_DOUBLE
):
1684 res
= (estack_bx_v
== estack_ax(stack
, top
)->u
.d
);
1685 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1687 estack_ax_t
= REG_S64
;
1688 next_pc
+= sizeof(struct binary_op
);
1691 OP(BYTECODE_OP_NE_S64_DOUBLE
):
1695 res
= (estack_bx_v
!= estack_ax(stack
, top
)->u
.d
);
1696 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1698 estack_ax_t
= REG_S64
;
1699 next_pc
+= sizeof(struct binary_op
);
1702 OP(BYTECODE_OP_GT_S64_DOUBLE
):
1706 res
= (estack_bx_v
> estack_ax(stack
, top
)->u
.d
);
1707 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1709 estack_ax_t
= REG_S64
;
1710 next_pc
+= sizeof(struct binary_op
);
1713 OP(BYTECODE_OP_LT_S64_DOUBLE
):
1717 res
= (estack_bx_v
< estack_ax(stack
, top
)->u
.d
);
1718 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1720 estack_ax_t
= REG_S64
;
1721 next_pc
+= sizeof(struct binary_op
);
1724 OP(BYTECODE_OP_GE_S64_DOUBLE
):
1728 res
= (estack_bx_v
>= estack_ax(stack
, top
)->u
.d
);
1729 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1731 estack_ax_t
= REG_S64
;
1732 next_pc
+= sizeof(struct binary_op
);
1735 OP(BYTECODE_OP_LE_S64_DOUBLE
):
1739 res
= (estack_bx_v
<= estack_ax(stack
, top
)->u
.d
);
1740 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1742 estack_ax_t
= REG_S64
;
1743 next_pc
+= sizeof(struct binary_op
);
1746 OP(BYTECODE_OP_BIT_RSHIFT
):
1750 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1755 /* Catch undefined behavior. */
1756 if (caa_unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1760 res
= ((uint64_t) estack_bx_v
>> (uint32_t) estack_ax_v
);
1761 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1763 estack_ax_t
= REG_U64
;
1764 next_pc
+= sizeof(struct binary_op
);
1767 OP(BYTECODE_OP_BIT_LSHIFT
):
1771 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1776 /* Catch undefined behavior. */
1777 if (caa_unlikely(estack_ax_v
< 0 || estack_ax_v
>= 64)) {
1781 res
= ((uint64_t) estack_bx_v
<< (uint32_t) estack_ax_v
);
1782 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1784 estack_ax_t
= REG_U64
;
1785 next_pc
+= sizeof(struct binary_op
);
1788 OP(BYTECODE_OP_BIT_AND
):
1792 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1797 res
= ((uint64_t) estack_bx_v
& (uint64_t) estack_ax_v
);
1798 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1800 estack_ax_t
= REG_U64
;
1801 next_pc
+= sizeof(struct binary_op
);
1804 OP(BYTECODE_OP_BIT_OR
):
1808 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1813 res
= ((uint64_t) estack_bx_v
| (uint64_t) estack_ax_v
);
1814 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1816 estack_ax_t
= REG_U64
;
1817 next_pc
+= sizeof(struct binary_op
);
1820 OP(BYTECODE_OP_BIT_XOR
):
1824 if (!IS_INTEGER_REGISTER(estack_ax_t
) || !IS_INTEGER_REGISTER(estack_bx_t
)) {
1829 res
= ((uint64_t) estack_bx_v
^ (uint64_t) estack_ax_v
);
1830 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1832 estack_ax_t
= REG_U64
;
1833 next_pc
+= sizeof(struct binary_op
);
1838 OP(BYTECODE_OP_UNARY_PLUS
):
1840 /* Dynamic typing. */
1841 switch (estack_ax_t
) {
1842 case REG_S64
: /* Fall-through. */
1844 JUMP_TO(BYTECODE_OP_UNARY_PLUS_S64
);
1846 JUMP_TO(BYTECODE_OP_UNARY_PLUS_DOUBLE
);
1847 case REG_STRING
: /* Fall-through */
1848 case REG_STAR_GLOB_STRING
:
1852 ERR("Unknown interpreter register type (%d)",
1858 OP(BYTECODE_OP_UNARY_MINUS
):
1860 /* Dynamic typing. */
1861 switch (estack_ax_t
) {
1862 case REG_S64
: /* Fall-through. */
1864 JUMP_TO(BYTECODE_OP_UNARY_MINUS_S64
);
1866 JUMP_TO(BYTECODE_OP_UNARY_MINUS_DOUBLE
);
1867 case REG_STRING
: /* Fall-through */
1868 case REG_STAR_GLOB_STRING
:
1872 ERR("Unknown interpreter register type (%d)",
1878 OP(BYTECODE_OP_UNARY_NOT
):
1880 /* Dynamic typing. */
1881 switch (estack_ax_t
) {
1882 case REG_S64
: /* Fall-through. */
1884 JUMP_TO(BYTECODE_OP_UNARY_NOT_S64
);
1886 JUMP_TO(BYTECODE_OP_UNARY_NOT_DOUBLE
);
1887 case REG_STRING
: /* Fall-through */
1888 case REG_STAR_GLOB_STRING
:
1892 ERR("Unknown interpreter register type (%d)",
1897 next_pc
+= sizeof(struct unary_op
);
1901 OP(BYTECODE_OP_UNARY_BIT_NOT
):
1903 /* Dynamic typing. */
1904 if (!IS_INTEGER_REGISTER(estack_ax_t
)) {
1909 estack_ax_v
= ~(uint64_t) estack_ax_v
;
1910 estack_ax_t
= REG_U64
;
1911 next_pc
+= sizeof(struct unary_op
);
1915 OP(BYTECODE_OP_UNARY_PLUS_S64
):
1916 OP(BYTECODE_OP_UNARY_PLUS_DOUBLE
):
1918 next_pc
+= sizeof(struct unary_op
);
1921 OP(BYTECODE_OP_UNARY_MINUS_S64
):
1923 estack_ax_v
= -estack_ax_v
;
1924 next_pc
+= sizeof(struct unary_op
);
1927 OP(BYTECODE_OP_UNARY_MINUS_DOUBLE
):
1929 estack_ax(stack
, top
)->u
.d
= -estack_ax(stack
, top
)->u
.d
;
1930 next_pc
+= sizeof(struct unary_op
);
1933 OP(BYTECODE_OP_UNARY_NOT_S64
):
1935 estack_ax_v
= !estack_ax_v
;
1936 estack_ax_t
= REG_S64
;
1937 next_pc
+= sizeof(struct unary_op
);
1940 OP(BYTECODE_OP_UNARY_NOT_DOUBLE
):
1942 estack_ax_v
= !estack_ax(stack
, top
)->u
.d
;
1943 estack_ax_t
= REG_S64
;
1944 next_pc
+= sizeof(struct unary_op
);
1949 OP(BYTECODE_OP_AND
):
1951 struct logical_op
*insn
= (struct logical_op
*) pc
;
1953 if (estack_ax_t
!= REG_S64
&& estack_ax_t
!= REG_U64
) {
1957 /* If AX is 0, skip and evaluate to 0 */
1958 if (unlikely(estack_ax_v
== 0)) {
1959 dbg_printf("Jumping to bytecode offset %u\n",
1960 (unsigned int) insn
->skip_offset
);
1961 next_pc
= start_pc
+ insn
->skip_offset
;
1963 /* Pop 1 when jump not taken */
1964 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1965 next_pc
+= sizeof(struct logical_op
);
1971 struct logical_op
*insn
= (struct logical_op
*) pc
;
1973 if (estack_ax_t
!= REG_S64
&& estack_ax_t
!= REG_U64
) {
1977 /* If AX is nonzero, skip and evaluate to 1 */
1978 if (unlikely(estack_ax_v
!= 0)) {
1980 dbg_printf("Jumping to bytecode offset %u\n",
1981 (unsigned int) insn
->skip_offset
);
1982 next_pc
= start_pc
+ insn
->skip_offset
;
1984 /* Pop 1 when jump not taken */
1985 estack_pop(stack
, top
, ax
, bx
, ax_t
, bx_t
);
1986 next_pc
+= sizeof(struct logical_op
);
1992 /* load field ref */
1993 OP(BYTECODE_OP_LOAD_FIELD_REF_STRING
):
1995 struct load_op
*insn
= (struct load_op
*) pc
;
1996 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
1998 dbg_printf("load field ref offset %u type string\n",
2000 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2001 estack_ax(stack
, top
)->u
.s
.str
=
2002 *(const char * const *) &interpreter_stack_data
[ref
->offset
];
2003 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2004 dbg_printf("Interpreter warning: loading a NULL string.\n");
2008 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2009 estack_ax(stack
, top
)->u
.s
.literal_type
=
2010 ESTACK_STRING_LITERAL_TYPE_NONE
;
2011 estack_ax_t
= REG_STRING
;
2012 dbg_printf("ref load string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
2013 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2017 OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE
):
2019 struct load_op
*insn
= (struct load_op
*) pc
;
2020 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2022 dbg_printf("load field ref offset %u type sequence\n",
2024 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2025 estack_ax(stack
, top
)->u
.s
.seq_len
=
2026 *(unsigned long *) &interpreter_stack_data
[ref
->offset
];
2027 estack_ax(stack
, top
)->u
.s
.str
=
2028 *(const char **) (&interpreter_stack_data
[ref
->offset
2029 + sizeof(unsigned long)]);
2030 estack_ax_t
= REG_STRING
;
2031 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2032 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
2036 estack_ax(stack
, top
)->u
.s
.literal_type
=
2037 ESTACK_STRING_LITERAL_TYPE_NONE
;
2038 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2042 OP(BYTECODE_OP_LOAD_FIELD_REF_S64
):
2044 struct load_op
*insn
= (struct load_op
*) pc
;
2045 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2047 dbg_printf("load field ref offset %u type s64\n",
2049 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2051 ((struct literal_numeric
*) &interpreter_stack_data
[ref
->offset
])->v
;
2052 estack_ax_t
= REG_S64
;
2053 dbg_printf("ref load s64 %" PRIi64
"\n", estack_ax_v
);
2054 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2058 OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE
):
2060 struct load_op
*insn
= (struct load_op
*) pc
;
2061 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2063 dbg_printf("load field ref offset %u type double\n",
2065 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2066 memcpy(&estack_ax(stack
, top
)->u
.d
, &interpreter_stack_data
[ref
->offset
],
2067 sizeof(struct literal_double
));
2068 estack_ax_t
= REG_DOUBLE
;
2069 dbg_printf("ref load double %g\n", estack_ax(stack
, top
)->u
.d
);
2070 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2074 /* load from immediate operand */
2075 OP(BYTECODE_OP_LOAD_STRING
):
2077 struct load_op
*insn
= (struct load_op
*) pc
;
2079 dbg_printf("load string %s\n", insn
->data
);
2080 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2081 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
2082 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2083 estack_ax(stack
, top
)->u
.s
.literal_type
=
2084 ESTACK_STRING_LITERAL_TYPE_PLAIN
;
2085 estack_ax_t
= REG_STRING
;
2086 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
2090 OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING
):
2092 struct load_op
*insn
= (struct load_op
*) pc
;
2094 dbg_printf("load globbing pattern %s\n", insn
->data
);
2095 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2096 estack_ax(stack
, top
)->u
.s
.str
= insn
->data
;
2097 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2098 estack_ax(stack
, top
)->u
.s
.literal_type
=
2099 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
;
2100 estack_ax_t
= REG_STAR_GLOB_STRING
;
2101 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
2105 OP(BYTECODE_OP_LOAD_S64
):
2107 struct load_op
*insn
= (struct load_op
*) pc
;
2109 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2110 estack_ax_v
= ((struct literal_numeric
*) insn
->data
)->v
;
2111 estack_ax_t
= REG_S64
;
2112 dbg_printf("load s64 %" PRIi64
"\n", estack_ax_v
);
2113 next_pc
+= sizeof(struct load_op
)
2114 + sizeof(struct literal_numeric
);
2118 OP(BYTECODE_OP_LOAD_DOUBLE
):
2120 struct load_op
*insn
= (struct load_op
*) pc
;
2122 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2123 memcpy(&estack_ax(stack
, top
)->u
.d
, insn
->data
,
2124 sizeof(struct literal_double
));
2125 estack_ax_t
= REG_DOUBLE
;
2126 dbg_printf("load double %g\n", estack_ax(stack
, top
)->u
.d
);
2127 next_pc
+= sizeof(struct load_op
)
2128 + sizeof(struct literal_double
);
2133 OP(BYTECODE_OP_CAST_TO_S64
):
2135 /* Dynamic typing. */
2136 switch (estack_ax_t
) {
2138 JUMP_TO(BYTECODE_OP_CAST_NOP
);
2140 JUMP_TO(BYTECODE_OP_CAST_DOUBLE_TO_S64
);
2142 estack_ax_t
= REG_S64
;
2143 next_pc
+= sizeof(struct cast_op
);
2144 case REG_STRING
: /* Fall-through */
2145 case REG_STAR_GLOB_STRING
:
2149 ERR("Unknown interpreter register type (%d)",
2156 OP(BYTECODE_OP_CAST_DOUBLE_TO_S64
):
2158 estack_ax_v
= (int64_t) estack_ax(stack
, top
)->u
.d
;
2159 estack_ax_t
= REG_S64
;
2160 next_pc
+= sizeof(struct cast_op
);
2164 OP(BYTECODE_OP_CAST_NOP
):
2166 next_pc
+= sizeof(struct cast_op
);
2170 /* get context ref */
2171 OP(BYTECODE_OP_GET_CONTEXT_REF
):
2173 struct load_op
*insn
= (struct load_op
*) pc
;
2174 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2175 struct lttng_ctx_field
*ctx_field
;
2176 struct lttng_ctx_value v
;
2178 dbg_printf("get context ref offset %u type dynamic\n",
2180 ctx_field
= &ctx
->fields
[ref
->offset
];
2181 ctx_field
->get_value(ctx_field
, &v
);
2182 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2184 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
2187 case LTTNG_UST_DYNAMIC_TYPE_S64
:
2188 estack_ax_v
= v
.u
.s64
;
2189 estack_ax_t
= REG_S64
;
2190 dbg_printf("ref get context dynamic s64 %" PRIi64
"\n", estack_ax_v
);
2192 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
2193 estack_ax(stack
, top
)->u
.d
= v
.u
.d
;
2194 estack_ax_t
= REG_DOUBLE
;
2195 dbg_printf("ref get context dynamic double %g\n", estack_ax(stack
, top
)->u
.d
);
2197 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
2198 estack_ax(stack
, top
)->u
.s
.str
= v
.u
.str
;
2199 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2200 dbg_printf("Interpreter warning: loading a NULL string.\n");
2204 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2205 estack_ax(stack
, top
)->u
.s
.literal_type
=
2206 ESTACK_STRING_LITERAL_TYPE_NONE
;
2207 dbg_printf("ref get context dynamic string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
2208 estack_ax_t
= REG_STRING
;
2211 dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v
.sel
);
2215 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2219 OP(BYTECODE_OP_GET_CONTEXT_REF_STRING
):
2221 struct load_op
*insn
= (struct load_op
*) pc
;
2222 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2223 struct lttng_ctx_field
*ctx_field
;
2224 struct lttng_ctx_value v
;
2226 dbg_printf("get context ref offset %u type string\n",
2228 ctx_field
= &ctx
->fields
[ref
->offset
];
2229 ctx_field
->get_value(ctx_field
, &v
);
2230 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2231 estack_ax(stack
, top
)->u
.s
.str
= v
.u
.str
;
2232 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2233 dbg_printf("Interpreter warning: loading a NULL string.\n");
2237 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2238 estack_ax(stack
, top
)->u
.s
.literal_type
=
2239 ESTACK_STRING_LITERAL_TYPE_NONE
;
2240 estack_ax_t
= REG_STRING
;
2241 dbg_printf("ref get context string %s\n", estack_ax(stack
, top
)->u
.s
.str
);
2242 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2246 OP(BYTECODE_OP_GET_CONTEXT_REF_S64
):
2248 struct load_op
*insn
= (struct load_op
*) pc
;
2249 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2250 struct lttng_ctx_field
*ctx_field
;
2251 struct lttng_ctx_value v
;
2253 dbg_printf("get context ref offset %u type s64\n",
2255 ctx_field
= &ctx
->fields
[ref
->offset
];
2256 ctx_field
->get_value(ctx_field
, &v
);
2257 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2258 estack_ax_v
= v
.u
.s64
;
2259 estack_ax_t
= REG_S64
;
2260 dbg_printf("ref get context s64 %" PRIi64
"\n", estack_ax_v
);
2261 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2265 OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE
):
2267 struct load_op
*insn
= (struct load_op
*) pc
;
2268 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
2269 struct lttng_ctx_field
*ctx_field
;
2270 struct lttng_ctx_value v
;
2272 dbg_printf("get context ref offset %u type double\n",
2274 ctx_field
= &ctx
->fields
[ref
->offset
];
2275 ctx_field
->get_value(ctx_field
, &v
);
2276 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2277 memcpy(&estack_ax(stack
, top
)->u
.d
, &v
.u
.d
, sizeof(struct literal_double
));
2278 estack_ax_t
= REG_DOUBLE
;
2279 dbg_printf("ref get context double %g\n", estack_ax(stack
, top
)->u
.d
);
2280 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
2284 OP(BYTECODE_OP_GET_CONTEXT_ROOT
):
2286 dbg_printf("op get context root\n");
2287 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2288 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_CONTEXT
;
2289 /* "field" only needed for variants. */
2290 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
2291 estack_ax_t
= REG_PTR
;
2292 next_pc
+= sizeof(struct load_op
);
2296 OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT
):
2298 dbg_printf("op get app context root\n");
2299 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2300 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_APP_CONTEXT
;
2301 /* "field" only needed for variants. */
2302 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
2303 estack_ax_t
= REG_PTR
;
2304 next_pc
+= sizeof(struct load_op
);
2308 OP(BYTECODE_OP_GET_PAYLOAD_ROOT
):
2310 dbg_printf("op get app payload root\n");
2311 estack_push(stack
, top
, ax
, bx
, ax_t
, bx_t
);
2312 estack_ax(stack
, top
)->u
.ptr
.type
= LOAD_ROOT_PAYLOAD
;
2313 estack_ax(stack
, top
)->u
.ptr
.ptr
= interpreter_stack_data
;
2314 /* "field" only needed for variants. */
2315 estack_ax(stack
, top
)->u
.ptr
.field
= NULL
;
2316 estack_ax_t
= REG_PTR
;
2317 next_pc
+= sizeof(struct load_op
);
2321 OP(BYTECODE_OP_GET_SYMBOL
):
2323 dbg_printf("op get symbol\n");
2324 switch (estack_ax(stack
, top
)->u
.ptr
.type
) {
2326 ERR("Nested fields not implemented yet.");
2329 case LOAD_ROOT_CONTEXT
:
2330 case LOAD_ROOT_APP_CONTEXT
:
2331 case LOAD_ROOT_PAYLOAD
:
2333 * symbol lookup is performed by
2339 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_symbol
);
2343 OP(BYTECODE_OP_GET_SYMBOL_FIELD
):
2346 * Used for first variant encountered in a
2347 * traversal. Variants are not implemented yet.
2353 OP(BYTECODE_OP_GET_INDEX_U16
):
2355 struct load_op
*insn
= (struct load_op
*) pc
;
2356 struct get_index_u16
*index
= (struct get_index_u16
*) insn
->data
;
2358 dbg_printf("op get index u16\n");
2359 ret
= dynamic_get_index(ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
2362 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
2363 estack_ax_t
= estack_ax(stack
, top
)->type
;
2364 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u16
);
2368 OP(BYTECODE_OP_GET_INDEX_U64
):
2370 struct load_op
*insn
= (struct load_op
*) pc
;
2371 struct get_index_u64
*index
= (struct get_index_u64
*) insn
->data
;
2373 dbg_printf("op get index u64\n");
2374 ret
= dynamic_get_index(ctx
, bytecode
, index
->index
, estack_ax(stack
, top
));
2377 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
2378 estack_ax_t
= estack_ax(stack
, top
)->type
;
2379 next_pc
+= sizeof(struct load_op
) + sizeof(struct get_index_u64
);
2383 OP(BYTECODE_OP_LOAD_FIELD
):
2385 dbg_printf("op load field\n");
2386 ret
= dynamic_load_field(estack_ax(stack
, top
));
2389 estack_ax_v
= estack_ax(stack
, top
)->u
.v
;
2390 estack_ax_t
= estack_ax(stack
, top
)->type
;
2391 next_pc
+= sizeof(struct load_op
);
2395 OP(BYTECODE_OP_LOAD_FIELD_S8
):
2397 dbg_printf("op load field s8\n");
2399 estack_ax_v
= *(int8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2400 estack_ax_t
= REG_S64
;
2401 next_pc
+= sizeof(struct load_op
);
2404 OP(BYTECODE_OP_LOAD_FIELD_S16
):
2406 dbg_printf("op load field s16\n");
2408 estack_ax_v
= *(int16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2409 estack_ax_t
= REG_S64
;
2410 next_pc
+= sizeof(struct load_op
);
2413 OP(BYTECODE_OP_LOAD_FIELD_S32
):
2415 dbg_printf("op load field s32\n");
2417 estack_ax_v
= *(int32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2418 estack_ax_t
= REG_S64
;
2419 next_pc
+= sizeof(struct load_op
);
2422 OP(BYTECODE_OP_LOAD_FIELD_S64
):
2424 dbg_printf("op load field s64\n");
2426 estack_ax_v
= *(int64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2427 estack_ax_t
= REG_S64
;
2428 next_pc
+= sizeof(struct load_op
);
2431 OP(BYTECODE_OP_LOAD_FIELD_U8
):
2433 dbg_printf("op load field u8\n");
2435 estack_ax_v
= *(uint8_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2436 estack_ax_t
= REG_U64
;
2437 next_pc
+= sizeof(struct load_op
);
2440 OP(BYTECODE_OP_LOAD_FIELD_U16
):
2442 dbg_printf("op load field u16\n");
2444 estack_ax_v
= *(uint16_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2445 estack_ax_t
= REG_U64
;
2446 next_pc
+= sizeof(struct load_op
);
2449 OP(BYTECODE_OP_LOAD_FIELD_U32
):
2451 dbg_printf("op load field u32\n");
2453 estack_ax_v
= *(uint32_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2454 estack_ax_t
= REG_U64
;
2455 next_pc
+= sizeof(struct load_op
);
2458 OP(BYTECODE_OP_LOAD_FIELD_U64
):
2460 dbg_printf("op load field u64\n");
2462 estack_ax_v
= *(uint64_t *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2463 estack_ax_t
= REG_U64
;
2464 next_pc
+= sizeof(struct load_op
);
2467 OP(BYTECODE_OP_LOAD_FIELD_DOUBLE
):
2469 dbg_printf("op load field double\n");
2471 memcpy(&estack_ax(stack
, top
)->u
.d
,
2472 estack_ax(stack
, top
)->u
.ptr
.ptr
,
2473 sizeof(struct literal_double
));
2474 estack_ax(stack
, top
)->type
= REG_DOUBLE
;
2475 next_pc
+= sizeof(struct load_op
);
2479 OP(BYTECODE_OP_LOAD_FIELD_STRING
):
2483 dbg_printf("op load field string\n");
2484 str
= (const char *) estack_ax(stack
, top
)->u
.ptr
.ptr
;
2485 estack_ax(stack
, top
)->u
.s
.str
= str
;
2486 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2487 dbg_printf("Interpreter warning: loading a NULL string.\n");
2491 estack_ax(stack
, top
)->u
.s
.seq_len
= SIZE_MAX
;
2492 estack_ax(stack
, top
)->u
.s
.literal_type
=
2493 ESTACK_STRING_LITERAL_TYPE_NONE
;
2494 estack_ax(stack
, top
)->type
= REG_STRING
;
2495 next_pc
+= sizeof(struct load_op
);
2499 OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE
):
2503 dbg_printf("op load field string sequence\n");
2504 ptr
= estack_ax(stack
, top
)->u
.ptr
.ptr
;
2505 estack_ax(stack
, top
)->u
.s
.seq_len
= *(unsigned long *) ptr
;
2506 estack_ax(stack
, top
)->u
.s
.str
= *(const char **) (ptr
+ sizeof(unsigned long));
2507 estack_ax(stack
, top
)->type
= REG_STRING
;
2508 if (unlikely(!estack_ax(stack
, top
)->u
.s
.str
)) {
2509 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
2513 estack_ax(stack
, top
)->u
.s
.literal_type
=
2514 ESTACK_STRING_LITERAL_TYPE_NONE
;
2515 next_pc
+= sizeof(struct load_op
);
2521 /* Return _DISCARD on error. */
2523 return LTTNG_INTERPRETER_DISCARD
;
2526 return lttng_bytecode_interpret_format_output(estack_ax(stack
, top
),
2533 uint64_t lttng_bytecode_filter_interpret(void *filter_data
,
2534 const char *filter_stack_data
)
2536 return bytecode_interpret(filter_data
, filter_stack_data
, NULL
);
2539 uint64_t lttng_bytecode_capture_interpret(void *capture_data
,
2540 const char *capture_stack_data
,
2541 struct lttng_interpreter_output
*output
)
2543 return bytecode_interpret(capture_data
, capture_stack_data
,
2544 (struct lttng_interpreter_output
*) output
);