Remove runtime dependency on liburcu shared objects
[lttng-ust.git] / liblttng-ust / lttng-bytecode-interpreter.c
1 /*
2 * lttng-bytecode-interpreter.c
3 *
4 * LTTng UST bytecode interpreter.
5 *
6 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27 #define _LGPL_SOURCE
28 #include <stddef.h>
29 #include <stdint.h>
30 #include <byteswap.h>
31
32 #include <lttng/urcu/pointer.h>
33 #include <lttng/ust-endian.h>
34 #include <lttng/ust-events.h>
35
36 #include "lttng-bytecode.h"
37 #include "string-utils.h"
38
39
40 /*
41 * -1: wildcard found.
42 * -2: unknown escape char.
43 * 0: normal char.
44 */
45
46 static
47 int parse_char(const char **p)
48 {
49 switch (**p) {
50 case '\\':
51 (*p)++;
52 switch (**p) {
53 case '\\':
54 case '*':
55 return 0;
56 default:
57 return -2;
58 }
59 case '*':
60 return -1;
61 default:
62 return 0;
63 }
64 }
65
66 /*
67 * Returns SIZE_MAX if the string is null-terminated, or the number of
68 * characters if not.
69 */
70 static
71 size_t get_str_or_seq_len(const struct estack_entry *entry)
72 {
73 return entry->u.s.seq_len;
74 }
75
76 static
77 int stack_star_glob_match(struct estack *stack, int top, const char *cmp_type)
78 {
79 const char *pattern;
80 const char *candidate;
81 size_t pattern_len;
82 size_t candidate_len;
83
84 /* Find out which side is the pattern vs. the candidate. */
85 if (estack_ax(stack, top)->u.s.literal_type == ESTACK_STRING_LITERAL_TYPE_STAR_GLOB) {
86 pattern = estack_ax(stack, top)->u.s.str;
87 pattern_len = get_str_or_seq_len(estack_ax(stack, top));
88 candidate = estack_bx(stack, top)->u.s.str;
89 candidate_len = get_str_or_seq_len(estack_bx(stack, top));
90 } else {
91 pattern = estack_bx(stack, top)->u.s.str;
92 pattern_len = get_str_or_seq_len(estack_bx(stack, top));
93 candidate = estack_ax(stack, top)->u.s.str;
94 candidate_len = get_str_or_seq_len(estack_ax(stack, top));
95 }
96
97 /* Perform the match. Returns 0 when the result is true. */
98 return !strutils_star_glob_match(pattern, pattern_len, candidate,
99 candidate_len);
100 }
101
102 static
103 int stack_strcmp(struct estack *stack, int top, const char *cmp_type)
104 {
105 const char *p = estack_bx(stack, top)->u.s.str, *q = estack_ax(stack, top)->u.s.str;
106 int ret;
107 int diff;
108
109 for (;;) {
110 int escaped_r0 = 0;
111
112 if (unlikely(p - estack_bx(stack, top)->u.s.str >= estack_bx(stack, top)->u.s.seq_len || *p == '\0')) {
113 if (q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0') {
114 return 0;
115 } else {
116 if (estack_ax(stack, top)->u.s.literal_type ==
117 ESTACK_STRING_LITERAL_TYPE_PLAIN) {
118 ret = parse_char(&q);
119 if (ret == -1)
120 return 0;
121 }
122 return -1;
123 }
124 }
125 if (unlikely(q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0')) {
126 if (estack_bx(stack, top)->u.s.literal_type ==
127 ESTACK_STRING_LITERAL_TYPE_PLAIN) {
128 ret = parse_char(&p);
129 if (ret == -1)
130 return 0;
131 }
132 return 1;
133 }
134 if (estack_bx(stack, top)->u.s.literal_type ==
135 ESTACK_STRING_LITERAL_TYPE_PLAIN) {
136 ret = parse_char(&p);
137 if (ret == -1) {
138 return 0;
139 } else if (ret == -2) {
140 escaped_r0 = 1;
141 }
142 /* else compare both char */
143 }
144 if (estack_ax(stack, top)->u.s.literal_type ==
145 ESTACK_STRING_LITERAL_TYPE_PLAIN) {
146 ret = parse_char(&q);
147 if (ret == -1) {
148 return 0;
149 } else if (ret == -2) {
150 if (!escaped_r0)
151 return -1;
152 } else {
153 if (escaped_r0)
154 return 1;
155 }
156 } else {
157 if (escaped_r0)
158 return 1;
159 }
160 diff = *p - *q;
161 if (diff != 0)
162 break;
163 p++;
164 q++;
165 }
166 return diff;
167 }
168
169 uint64_t lttng_bytecode_filter_interpret_false(void *filter_data,
170 const char *filter_stack_data)
171 {
172 return LTTNG_INTERPRETER_DISCARD;
173 }
174
175 uint64_t lttng_bytecode_capture_interpret_false(void *capture_data,
176 const char *capture_stack_data,
177 struct lttng_interpreter_output *output)
178 {
179 return LTTNG_INTERPRETER_DISCARD;
180 }
181
182 #ifdef INTERPRETER_USE_SWITCH
183
184 /*
185 * Fallback for compilers that do not support taking address of labels.
186 */
187
188 #define START_OP \
189 start_pc = &bytecode->data[0]; \
190 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
191 pc = next_pc) { \
192 dbg_printf("Executing op %s (%u)\n", \
193 print_op((unsigned int) *(bytecode_opcode_t *) pc), \
194 (unsigned int) *(bytecode_opcode_t *) pc); \
195 switch (*(bytecode_opcode_t *) pc) {
196
197 #define OP(name) jump_target_##name: __attribute__((unused)); \
198 case name
199
200 #define PO break
201
202 #define END_OP } \
203 }
204
205 #define JUMP_TO(name) \
206 goto jump_target_##name
207
208 #else
209
210 /*
211 * Dispatch-table based interpreter.
212 */
213
214 #define START_OP \
215 start_pc = &bytecode->code[0]; \
216 pc = next_pc = start_pc; \
217 if (unlikely(pc - start_pc >= bytecode->len)) \
218 goto end; \
219 goto *dispatch[*(bytecode_opcode_t *) pc];
220
221 #define OP(name) \
222 LABEL_##name
223
224 #define PO \
225 pc = next_pc; \
226 goto *dispatch[*(bytecode_opcode_t *) pc];
227
228 #define END_OP
229
230 #define JUMP_TO(name) \
231 goto LABEL_##name
232
233 #endif
234
235 #define IS_INTEGER_REGISTER(reg_type) \
236 (reg_type == REG_U64 || reg_type == REG_S64)
237
238 static int context_get_index(struct lttng_ctx *ctx,
239 struct load_ptr *ptr,
240 uint32_t idx)
241 {
242
243 struct lttng_ctx_field *ctx_field;
244 struct lttng_event_field *field;
245 struct lttng_ctx_value v;
246
247 ctx_field = &ctx->fields[idx];
248 field = &ctx_field->event_field;
249 ptr->type = LOAD_OBJECT;
250 ptr->field = field;
251
252 switch (field->type.atype) {
253 case atype_integer:
254 ctx_field->get_value(ctx_field, &v);
255 if (field->type.u.integer.signedness) {
256 ptr->object_type = OBJECT_TYPE_S64;
257 ptr->u.s64 = v.u.s64;
258 ptr->ptr = &ptr->u.s64;
259 } else {
260 ptr->object_type = OBJECT_TYPE_U64;
261 ptr->u.u64 = v.u.s64; /* Cast. */
262 ptr->ptr = &ptr->u.u64;
263 }
264 break;
265 case atype_enum: /* Fall-through */
266 case atype_enum_nestable:
267 {
268 const struct lttng_integer_type *itype;
269
270 if (field->type.atype == atype_enum) {
271 itype = &field->type.u.legacy.basic.enumeration.container_type;
272 } else {
273 itype = &field->type.u.enum_nestable.container_type->u.integer;
274 }
275 ctx_field->get_value(ctx_field, &v);
276 if (itype->signedness) {
277 ptr->object_type = OBJECT_TYPE_SIGNED_ENUM;
278 ptr->u.s64 = v.u.s64;
279 ptr->ptr = &ptr->u.s64;
280 } else {
281 ptr->object_type = OBJECT_TYPE_UNSIGNED_ENUM;
282 ptr->u.u64 = v.u.s64; /* Cast. */
283 ptr->ptr = &ptr->u.u64;
284 }
285 break;
286 }
287 case atype_array:
288 if (field->type.u.legacy.array.elem_type.atype != atype_integer) {
289 ERR("Array nesting only supports integer types.");
290 return -EINVAL;
291 }
292 if (field->type.u.legacy.array.elem_type.u.basic.integer.encoding == lttng_encode_none) {
293 ERR("Only string arrays are supported for contexts.");
294 return -EINVAL;
295 }
296 ptr->object_type = OBJECT_TYPE_STRING;
297 ctx_field->get_value(ctx_field, &v);
298 ptr->ptr = v.u.str;
299 break;
300 case atype_array_nestable:
301 if (field->type.u.array_nestable.elem_type->atype != atype_integer) {
302 ERR("Array nesting only supports integer types.");
303 return -EINVAL;
304 }
305 if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) {
306 ERR("Only string arrays are supported for contexts.");
307 return -EINVAL;
308 }
309 ptr->object_type = OBJECT_TYPE_STRING;
310 ctx_field->get_value(ctx_field, &v);
311 ptr->ptr = v.u.str;
312 break;
313 case atype_sequence:
314 if (field->type.u.legacy.sequence.elem_type.atype != atype_integer) {
315 ERR("Sequence nesting only supports integer types.");
316 return -EINVAL;
317 }
318 if (field->type.u.legacy.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) {
319 ERR("Only string sequences are supported for contexts.");
320 return -EINVAL;
321 }
322 ptr->object_type = OBJECT_TYPE_STRING;
323 ctx_field->get_value(ctx_field, &v);
324 ptr->ptr = v.u.str;
325 break;
326 case atype_sequence_nestable:
327 if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) {
328 ERR("Sequence nesting only supports integer types.");
329 return -EINVAL;
330 }
331 if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) {
332 ERR("Only string sequences are supported for contexts.");
333 return -EINVAL;
334 }
335 ptr->object_type = OBJECT_TYPE_STRING;
336 ctx_field->get_value(ctx_field, &v);
337 ptr->ptr = v.u.str;
338 break;
339 case atype_string:
340 ptr->object_type = OBJECT_TYPE_STRING;
341 ctx_field->get_value(ctx_field, &v);
342 ptr->ptr = v.u.str;
343 break;
344 case atype_float:
345 ptr->object_type = OBJECT_TYPE_DOUBLE;
346 ctx_field->get_value(ctx_field, &v);
347 ptr->u.d = v.u.d;
348 ptr->ptr = &ptr->u.d;
349 break;
350 case atype_dynamic:
351 ctx_field->get_value(ctx_field, &v);
352 switch (v.sel) {
353 case LTTNG_UST_DYNAMIC_TYPE_NONE:
354 return -EINVAL;
355 case LTTNG_UST_DYNAMIC_TYPE_U8:
356 case LTTNG_UST_DYNAMIC_TYPE_U16:
357 case LTTNG_UST_DYNAMIC_TYPE_U32:
358 case LTTNG_UST_DYNAMIC_TYPE_U64:
359 ptr->object_type = OBJECT_TYPE_U64;
360 ptr->u.u64 = v.u.u64;
361 ptr->ptr = &ptr->u.u64;
362 dbg_printf("context get index dynamic u64 %" PRIi64 "\n", ptr->u.u64);
363 break;
364 case LTTNG_UST_DYNAMIC_TYPE_S8:
365 case LTTNG_UST_DYNAMIC_TYPE_S16:
366 case LTTNG_UST_DYNAMIC_TYPE_S32:
367 case LTTNG_UST_DYNAMIC_TYPE_S64:
368 ptr->object_type = OBJECT_TYPE_S64;
369 ptr->u.s64 = v.u.s64;
370 ptr->ptr = &ptr->u.s64;
371 dbg_printf("context get index dynamic s64 %" PRIi64 "\n", ptr->u.s64);
372 break;
373 case LTTNG_UST_DYNAMIC_TYPE_FLOAT:
374 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
375 ptr->object_type = OBJECT_TYPE_DOUBLE;
376 ptr->u.d = v.u.d;
377 ptr->ptr = &ptr->u.d;
378 dbg_printf("context get index dynamic double %g\n", ptr->u.d);
379 break;
380 case LTTNG_UST_DYNAMIC_TYPE_STRING:
381 ptr->object_type = OBJECT_TYPE_STRING;
382 ptr->ptr = v.u.str;
383 dbg_printf("context get index dynamic string %s\n", (const char *) ptr->ptr);
384 break;
385 default:
386 dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v.sel);
387 return -EINVAL;
388 }
389 break;
390 case atype_struct:
391 ERR("Structure type cannot be loaded.");
392 return -EINVAL;
393 default:
394 ERR("Unknown type: %d", (int) field->type.atype);
395 return -EINVAL;
396 }
397 return 0;
398 }
399
400 static int dynamic_get_index(struct lttng_ctx *ctx,
401 struct bytecode_runtime *runtime,
402 uint64_t index, struct estack_entry *stack_top)
403 {
404 int ret;
405 const struct bytecode_get_index_data *gid;
406
407 gid = (const struct bytecode_get_index_data *) &runtime->data[index];
408 switch (stack_top->u.ptr.type) {
409 case LOAD_OBJECT:
410 switch (stack_top->u.ptr.object_type) {
411 case OBJECT_TYPE_ARRAY:
412 {
413 const char *ptr;
414
415 assert(gid->offset < gid->array_len);
416 /* Skip count (unsigned long) */
417 ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long));
418 ptr = ptr + gid->offset;
419 stack_top->u.ptr.ptr = ptr;
420 stack_top->u.ptr.object_type = gid->elem.type;
421 stack_top->u.ptr.rev_bo = gid->elem.rev_bo;
422 assert(stack_top->u.ptr.field->type.atype == atype_array ||
423 stack_top->u.ptr.field->type.atype == atype_array_nestable);
424 stack_top->u.ptr.field = NULL;
425 break;
426 }
427 case OBJECT_TYPE_SEQUENCE:
428 {
429 const char *ptr;
430 size_t ptr_seq_len;
431
432 ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long));
433 ptr_seq_len = *(unsigned long *) stack_top->u.ptr.ptr;
434 if (gid->offset >= gid->elem.len * ptr_seq_len) {
435 ret = -EINVAL;
436 goto end;
437 }
438 ptr = ptr + gid->offset;
439 stack_top->u.ptr.ptr = ptr;
440 stack_top->u.ptr.object_type = gid->elem.type;
441 stack_top->u.ptr.rev_bo = gid->elem.rev_bo;
442 assert(stack_top->u.ptr.field->type.atype == atype_sequence ||
443 stack_top->u.ptr.field->type.atype == atype_sequence_nestable);
444 stack_top->u.ptr.field = NULL;
445 break;
446 }
447 case OBJECT_TYPE_STRUCT:
448 ERR("Nested structures are not supported yet.");
449 ret = -EINVAL;
450 goto end;
451 case OBJECT_TYPE_VARIANT:
452 default:
453 ERR("Unexpected get index type %d",
454 (int) stack_top->u.ptr.object_type);
455 ret = -EINVAL;
456 goto end;
457 }
458 break;
459 case LOAD_ROOT_CONTEXT:
460 case LOAD_ROOT_APP_CONTEXT: /* Fall-through */
461 {
462 ret = context_get_index(ctx,
463 &stack_top->u.ptr,
464 gid->ctx_index);
465 if (ret) {
466 goto end;
467 }
468 break;
469 }
470 case LOAD_ROOT_PAYLOAD:
471 stack_top->u.ptr.ptr += gid->offset;
472 if (gid->elem.type == OBJECT_TYPE_STRING)
473 stack_top->u.ptr.ptr = *(const char * const *) stack_top->u.ptr.ptr;
474 stack_top->u.ptr.object_type = gid->elem.type;
475 stack_top->u.ptr.type = LOAD_OBJECT;
476 stack_top->u.ptr.field = gid->field;
477 stack_top->u.ptr.rev_bo = gid->elem.rev_bo;
478 break;
479 }
480
481 stack_top->type = REG_PTR;
482
483 return 0;
484
485 end:
486 return ret;
487 }
488
489 static int dynamic_load_field(struct estack_entry *stack_top)
490 {
491 int ret;
492
493 switch (stack_top->u.ptr.type) {
494 case LOAD_OBJECT:
495 break;
496 case LOAD_ROOT_CONTEXT:
497 case LOAD_ROOT_APP_CONTEXT:
498 case LOAD_ROOT_PAYLOAD:
499 default:
500 dbg_printf("Interpreter warning: cannot load root, missing field name.\n");
501 ret = -EINVAL;
502 goto end;
503 }
504 switch (stack_top->u.ptr.object_type) {
505 case OBJECT_TYPE_S8:
506 dbg_printf("op load field s8\n");
507 stack_top->u.v = *(int8_t *) stack_top->u.ptr.ptr;
508 stack_top->type = REG_S64;
509 break;
510 case OBJECT_TYPE_S16:
511 {
512 int16_t tmp;
513
514 dbg_printf("op load field s16\n");
515 tmp = *(int16_t *) stack_top->u.ptr.ptr;
516 if (stack_top->u.ptr.rev_bo)
517 tmp = bswap_16(tmp);
518 stack_top->u.v = tmp;
519 stack_top->type = REG_S64;
520 break;
521 }
522 case OBJECT_TYPE_S32:
523 {
524 int32_t tmp;
525
526 dbg_printf("op load field s32\n");
527 tmp = *(int32_t *) stack_top->u.ptr.ptr;
528 if (stack_top->u.ptr.rev_bo)
529 tmp = bswap_32(tmp);
530 stack_top->u.v = tmp;
531 stack_top->type = REG_S64;
532 break;
533 }
534 case OBJECT_TYPE_S64:
535 {
536 int64_t tmp;
537
538 dbg_printf("op load field s64\n");
539 tmp = *(int64_t *) stack_top->u.ptr.ptr;
540 if (stack_top->u.ptr.rev_bo)
541 tmp = bswap_64(tmp);
542 stack_top->u.v = tmp;
543 stack_top->type = REG_S64;
544 break;
545 }
546 case OBJECT_TYPE_SIGNED_ENUM:
547 {
548 int64_t tmp;
549
550 dbg_printf("op load field signed enumeration\n");
551 tmp = *(int64_t *) stack_top->u.ptr.ptr;
552 if (stack_top->u.ptr.rev_bo)
553 tmp = bswap_64(tmp);
554 stack_top->u.v = tmp;
555 stack_top->type = REG_S64;
556 break;
557 }
558 case OBJECT_TYPE_U8:
559 dbg_printf("op load field u8\n");
560 stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr;
561 stack_top->type = REG_U64;
562 break;
563 case OBJECT_TYPE_U16:
564 {
565 uint16_t tmp;
566
567 dbg_printf("op load field u16\n");
568 tmp = *(uint16_t *) stack_top->u.ptr.ptr;
569 if (stack_top->u.ptr.rev_bo)
570 tmp = bswap_16(tmp);
571 stack_top->u.v = tmp;
572 stack_top->type = REG_U64;
573 break;
574 }
575 case OBJECT_TYPE_U32:
576 {
577 uint32_t tmp;
578
579 dbg_printf("op load field u32\n");
580 tmp = *(uint32_t *) stack_top->u.ptr.ptr;
581 if (stack_top->u.ptr.rev_bo)
582 tmp = bswap_32(tmp);
583 stack_top->u.v = tmp;
584 stack_top->type = REG_U64;
585 break;
586 }
587 case OBJECT_TYPE_U64:
588 {
589 uint64_t tmp;
590
591 dbg_printf("op load field u64\n");
592 tmp = *(uint64_t *) stack_top->u.ptr.ptr;
593 if (stack_top->u.ptr.rev_bo)
594 tmp = bswap_64(tmp);
595 stack_top->u.v = tmp;
596 stack_top->type = REG_U64;
597 break;
598 }
599 case OBJECT_TYPE_UNSIGNED_ENUM:
600 {
601 uint64_t tmp;
602
603 dbg_printf("op load field unsigned enumeration\n");
604 tmp = *(uint64_t *) stack_top->u.ptr.ptr;
605 if (stack_top->u.ptr.rev_bo)
606 tmp = bswap_64(tmp);
607 stack_top->u.v = tmp;
608 stack_top->type = REG_U64;
609 break;
610 }
611 case OBJECT_TYPE_DOUBLE:
612 memcpy(&stack_top->u.d,
613 stack_top->u.ptr.ptr,
614 sizeof(struct literal_double));
615 stack_top->type = REG_DOUBLE;
616 break;
617 case OBJECT_TYPE_STRING:
618 {
619 const char *str;
620
621 dbg_printf("op load field string\n");
622 str = (const char *) stack_top->u.ptr.ptr;
623 stack_top->u.s.str = str;
624 if (unlikely(!stack_top->u.s.str)) {
625 dbg_printf("Interpreter warning: loading a NULL string.\n");
626 ret = -EINVAL;
627 goto end;
628 }
629 stack_top->u.s.seq_len = SIZE_MAX;
630 stack_top->u.s.literal_type =
631 ESTACK_STRING_LITERAL_TYPE_NONE;
632 stack_top->type = REG_STRING;
633 break;
634 }
635 case OBJECT_TYPE_STRING_SEQUENCE:
636 {
637 const char *ptr;
638
639 dbg_printf("op load field string sequence\n");
640 ptr = stack_top->u.ptr.ptr;
641 stack_top->u.s.seq_len = *(unsigned long *) ptr;
642 stack_top->u.s.str = *(const char **) (ptr + sizeof(unsigned long));
643 stack_top->type = REG_STRING;
644 if (unlikely(!stack_top->u.s.str)) {
645 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
646 ret = -EINVAL;
647 goto end;
648 }
649 stack_top->u.s.literal_type =
650 ESTACK_STRING_LITERAL_TYPE_NONE;
651 break;
652 }
653 case OBJECT_TYPE_DYNAMIC:
654 /*
655 * Dynamic types in context are looked up
656 * by context get index.
657 */
658 ret = -EINVAL;
659 goto end;
660 case OBJECT_TYPE_SEQUENCE:
661 case OBJECT_TYPE_ARRAY:
662 case OBJECT_TYPE_STRUCT:
663 case OBJECT_TYPE_VARIANT:
664 ERR("Sequences, arrays, struct and variant cannot be loaded (nested types).");
665 ret = -EINVAL;
666 goto end;
667 }
668 return 0;
669
670 end:
671 return ret;
672 }
673
674 static
675 int lttng_bytecode_interpret_format_output(struct estack_entry *ax,
676 struct lttng_interpreter_output *output)
677 {
678 int ret;
679
680 again:
681 switch (ax->type) {
682 case REG_S64:
683 output->type = LTTNG_INTERPRETER_TYPE_S64;
684 output->u.s = ax->u.v;
685 break;
686 case REG_U64:
687 output->type = LTTNG_INTERPRETER_TYPE_U64;
688 output->u.u = (uint64_t) ax->u.v;
689 break;
690 case REG_DOUBLE:
691 output->type = LTTNG_INTERPRETER_TYPE_DOUBLE;
692 output->u.d = ax->u.d;
693 break;
694 case REG_STRING:
695 output->type = LTTNG_INTERPRETER_TYPE_STRING;
696 output->u.str.str = ax->u.s.str;
697 output->u.str.len = ax->u.s.seq_len;
698 break;
699 case REG_PTR:
700 switch (ax->u.ptr.object_type) {
701 case OBJECT_TYPE_S8:
702 case OBJECT_TYPE_S16:
703 case OBJECT_TYPE_S32:
704 case OBJECT_TYPE_S64:
705 case OBJECT_TYPE_U8:
706 case OBJECT_TYPE_U16:
707 case OBJECT_TYPE_U32:
708 case OBJECT_TYPE_U64:
709 case OBJECT_TYPE_DOUBLE:
710 case OBJECT_TYPE_STRING:
711 case OBJECT_TYPE_STRING_SEQUENCE:
712 ret = dynamic_load_field(ax);
713 if (ret)
714 return ret;
715 /* Retry after loading ptr into stack top. */
716 goto again;
717 case OBJECT_TYPE_SEQUENCE:
718 output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE;
719 output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long));
720 output->u.sequence.nr_elem = *(unsigned long *) ax->u.ptr.ptr;
721 output->u.sequence.nested_type = ax->u.ptr.field->type.u.sequence_nestable.elem_type;
722 break;
723 case OBJECT_TYPE_ARRAY:
724 /* Skip count (unsigned long) */
725 output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE;
726 output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long));
727 output->u.sequence.nr_elem = ax->u.ptr.field->type.u.array_nestable.length;
728 output->u.sequence.nested_type = ax->u.ptr.field->type.u.array_nestable.elem_type;
729 break;
730 case OBJECT_TYPE_SIGNED_ENUM:
731 ret = dynamic_load_field(ax);
732 if (ret)
733 return ret;
734 output->type = LTTNG_INTERPRETER_TYPE_SIGNED_ENUM;
735 output->u.s = ax->u.v;
736 break;
737 case OBJECT_TYPE_UNSIGNED_ENUM:
738 ret = dynamic_load_field(ax);
739 if (ret)
740 return ret;
741 output->type = LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM;
742 output->u.u = ax->u.v;
743 break;
744 case OBJECT_TYPE_STRUCT:
745 case OBJECT_TYPE_VARIANT:
746 default:
747 return -EINVAL;
748 }
749
750 break;
751 case REG_STAR_GLOB_STRING:
752 case REG_UNKNOWN:
753 default:
754 return -EINVAL;
755 }
756
757 return LTTNG_INTERPRETER_RECORD_FLAG;
758 }
759
760 /*
761 * For `output` equal to NULL:
762 * Return 0 (discard), or raise the 0x1 flag (log event).
763 * Currently, other flags are kept for future extensions and have no
764 * effect.
765 * For `output` not equal to NULL:
766 * Return 0 on success, negative error value on error.
767 */
768 static
769 uint64_t bytecode_interpret(void *interpreter_data,
770 const char *interpreter_stack_data,
771 struct lttng_interpreter_output *output)
772 {
773 struct bytecode_runtime *bytecode = interpreter_data;
774 struct lttng_ctx *ctx = lttng_ust_rcu_dereference(*bytecode->p.pctx);
775 void *pc, *next_pc, *start_pc;
776 int ret = -EINVAL;
777 uint64_t retval = 0;
778 struct estack _stack;
779 struct estack *stack = &_stack;
780 register int64_t ax = 0, bx = 0;
781 register enum entry_type ax_t = REG_UNKNOWN, bx_t = REG_UNKNOWN;
782 register int top = INTERPRETER_STACK_EMPTY;
783 #ifndef INTERPRETER_USE_SWITCH
784 static void *dispatch[NR_BYTECODE_OPS] = {
785 [ BYTECODE_OP_UNKNOWN ] = &&LABEL_BYTECODE_OP_UNKNOWN,
786
787 [ BYTECODE_OP_RETURN ] = &&LABEL_BYTECODE_OP_RETURN,
788
789 /* binary */
790 [ BYTECODE_OP_MUL ] = &&LABEL_BYTECODE_OP_MUL,
791 [ BYTECODE_OP_DIV ] = &&LABEL_BYTECODE_OP_DIV,
792 [ BYTECODE_OP_MOD ] = &&LABEL_BYTECODE_OP_MOD,
793 [ BYTECODE_OP_PLUS ] = &&LABEL_BYTECODE_OP_PLUS,
794 [ BYTECODE_OP_MINUS ] = &&LABEL_BYTECODE_OP_MINUS,
795 [ BYTECODE_OP_BIT_RSHIFT ] = &&LABEL_BYTECODE_OP_BIT_RSHIFT,
796 [ BYTECODE_OP_BIT_LSHIFT ] = &&LABEL_BYTECODE_OP_BIT_LSHIFT,
797 [ BYTECODE_OP_BIT_AND ] = &&LABEL_BYTECODE_OP_BIT_AND,
798 [ BYTECODE_OP_BIT_OR ] = &&LABEL_BYTECODE_OP_BIT_OR,
799 [ BYTECODE_OP_BIT_XOR ] = &&LABEL_BYTECODE_OP_BIT_XOR,
800
801 /* binary comparators */
802 [ BYTECODE_OP_EQ ] = &&LABEL_BYTECODE_OP_EQ,
803 [ BYTECODE_OP_NE ] = &&LABEL_BYTECODE_OP_NE,
804 [ BYTECODE_OP_GT ] = &&LABEL_BYTECODE_OP_GT,
805 [ BYTECODE_OP_LT ] = &&LABEL_BYTECODE_OP_LT,
806 [ BYTECODE_OP_GE ] = &&LABEL_BYTECODE_OP_GE,
807 [ BYTECODE_OP_LE ] = &&LABEL_BYTECODE_OP_LE,
808
809 /* string binary comparator */
810 [ BYTECODE_OP_EQ_STRING ] = &&LABEL_BYTECODE_OP_EQ_STRING,
811 [ BYTECODE_OP_NE_STRING ] = &&LABEL_BYTECODE_OP_NE_STRING,
812 [ BYTECODE_OP_GT_STRING ] = &&LABEL_BYTECODE_OP_GT_STRING,
813 [ BYTECODE_OP_LT_STRING ] = &&LABEL_BYTECODE_OP_LT_STRING,
814 [ BYTECODE_OP_GE_STRING ] = &&LABEL_BYTECODE_OP_GE_STRING,
815 [ BYTECODE_OP_LE_STRING ] = &&LABEL_BYTECODE_OP_LE_STRING,
816
817 /* globbing pattern binary comparator */
818 [ BYTECODE_OP_EQ_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING,
819 [ BYTECODE_OP_NE_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING,
820
821 /* s64 binary comparator */
822 [ BYTECODE_OP_EQ_S64 ] = &&LABEL_BYTECODE_OP_EQ_S64,
823 [ BYTECODE_OP_NE_S64 ] = &&LABEL_BYTECODE_OP_NE_S64,
824 [ BYTECODE_OP_GT_S64 ] = &&LABEL_BYTECODE_OP_GT_S64,
825 [ BYTECODE_OP_LT_S64 ] = &&LABEL_BYTECODE_OP_LT_S64,
826 [ BYTECODE_OP_GE_S64 ] = &&LABEL_BYTECODE_OP_GE_S64,
827 [ BYTECODE_OP_LE_S64 ] = &&LABEL_BYTECODE_OP_LE_S64,
828
829 /* double binary comparator */
830 [ BYTECODE_OP_EQ_DOUBLE ] = &&LABEL_BYTECODE_OP_EQ_DOUBLE,
831 [ BYTECODE_OP_NE_DOUBLE ] = &&LABEL_BYTECODE_OP_NE_DOUBLE,
832 [ BYTECODE_OP_GT_DOUBLE ] = &&LABEL_BYTECODE_OP_GT_DOUBLE,
833 [ BYTECODE_OP_LT_DOUBLE ] = &&LABEL_BYTECODE_OP_LT_DOUBLE,
834 [ BYTECODE_OP_GE_DOUBLE ] = &&LABEL_BYTECODE_OP_GE_DOUBLE,
835 [ BYTECODE_OP_LE_DOUBLE ] = &&LABEL_BYTECODE_OP_LE_DOUBLE,
836
837 /* Mixed S64-double binary comparators */
838 [ BYTECODE_OP_EQ_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64,
839 [ BYTECODE_OP_NE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64,
840 [ BYTECODE_OP_GT_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64,
841 [ BYTECODE_OP_LT_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64,
842 [ BYTECODE_OP_GE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64,
843 [ BYTECODE_OP_LE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64,
844
845 [ BYTECODE_OP_EQ_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE,
846 [ BYTECODE_OP_NE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE,
847 [ BYTECODE_OP_GT_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE,
848 [ BYTECODE_OP_LT_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE,
849 [ BYTECODE_OP_GE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE,
850 [ BYTECODE_OP_LE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE,
851
852 /* unary */
853 [ BYTECODE_OP_UNARY_PLUS ] = &&LABEL_BYTECODE_OP_UNARY_PLUS,
854 [ BYTECODE_OP_UNARY_MINUS ] = &&LABEL_BYTECODE_OP_UNARY_MINUS,
855 [ BYTECODE_OP_UNARY_NOT ] = &&LABEL_BYTECODE_OP_UNARY_NOT,
856 [ BYTECODE_OP_UNARY_PLUS_S64 ] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64,
857 [ BYTECODE_OP_UNARY_MINUS_S64 ] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64,
858 [ BYTECODE_OP_UNARY_NOT_S64 ] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64,
859 [ BYTECODE_OP_UNARY_PLUS_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE,
860 [ BYTECODE_OP_UNARY_MINUS_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE,
861 [ BYTECODE_OP_UNARY_NOT_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE,
862
863 /* logical */
864 [ BYTECODE_OP_AND ] = &&LABEL_BYTECODE_OP_AND,
865 [ BYTECODE_OP_OR ] = &&LABEL_BYTECODE_OP_OR,
866
867 /* load field ref */
868 [ BYTECODE_OP_LOAD_FIELD_REF ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF,
869 [ BYTECODE_OP_LOAD_FIELD_REF_STRING ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING,
870 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE,
871 [ BYTECODE_OP_LOAD_FIELD_REF_S64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64,
872 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE,
873
874 /* load from immediate operand */
875 [ BYTECODE_OP_LOAD_STRING ] = &&LABEL_BYTECODE_OP_LOAD_STRING,
876 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING,
877 [ BYTECODE_OP_LOAD_S64 ] = &&LABEL_BYTECODE_OP_LOAD_S64,
878 [ BYTECODE_OP_LOAD_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE,
879
880 /* cast */
881 [ BYTECODE_OP_CAST_TO_S64 ] = &&LABEL_BYTECODE_OP_CAST_TO_S64,
882 [ BYTECODE_OP_CAST_DOUBLE_TO_S64 ] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64,
883 [ BYTECODE_OP_CAST_NOP ] = &&LABEL_BYTECODE_OP_CAST_NOP,
884
885 /* get context ref */
886 [ BYTECODE_OP_GET_CONTEXT_REF ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF,
887 [ BYTECODE_OP_GET_CONTEXT_REF_STRING ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING,
888 [ BYTECODE_OP_GET_CONTEXT_REF_S64 ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64,
889 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE,
890
891 /* Instructions for recursive traversal through composed types. */
892 [ BYTECODE_OP_GET_CONTEXT_ROOT ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT,
893 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT ] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT,
894 [ BYTECODE_OP_GET_PAYLOAD_ROOT ] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT,
895
896 [ BYTECODE_OP_GET_SYMBOL ] = &&LABEL_BYTECODE_OP_GET_SYMBOL,
897 [ BYTECODE_OP_GET_SYMBOL_FIELD ] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD,
898 [ BYTECODE_OP_GET_INDEX_U16 ] = &&LABEL_BYTECODE_OP_GET_INDEX_U16,
899 [ BYTECODE_OP_GET_INDEX_U64 ] = &&LABEL_BYTECODE_OP_GET_INDEX_U64,
900
901 [ BYTECODE_OP_LOAD_FIELD ] = &&LABEL_BYTECODE_OP_LOAD_FIELD,
902 [ BYTECODE_OP_LOAD_FIELD_S8 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8,
903 [ BYTECODE_OP_LOAD_FIELD_S16 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16,
904 [ BYTECODE_OP_LOAD_FIELD_S32 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32,
905 [ BYTECODE_OP_LOAD_FIELD_S64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64,
906 [ BYTECODE_OP_LOAD_FIELD_U8 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8,
907 [ BYTECODE_OP_LOAD_FIELD_U16 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16,
908 [ BYTECODE_OP_LOAD_FIELD_U32 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32,
909 [ BYTECODE_OP_LOAD_FIELD_U64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64,
910 [ BYTECODE_OP_LOAD_FIELD_STRING ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING,
911 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE,
912 [ BYTECODE_OP_LOAD_FIELD_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE,
913
914 [ BYTECODE_OP_UNARY_BIT_NOT ] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT,
915
916 [ BYTECODE_OP_RETURN_S64 ] = &&LABEL_BYTECODE_OP_RETURN_S64,
917 };
918 #endif /* #ifndef INTERPRETER_USE_SWITCH */
919
920 START_OP
921
922 OP(BYTECODE_OP_UNKNOWN):
923 OP(BYTECODE_OP_LOAD_FIELD_REF):
924 #ifdef INTERPRETER_USE_SWITCH
925 default:
926 #endif /* INTERPRETER_USE_SWITCH */
927 ERR("unknown bytecode op %u",
928 (unsigned int) *(bytecode_opcode_t *) pc);
929 ret = -EINVAL;
930 goto end;
931
932 OP(BYTECODE_OP_RETURN):
933 /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */
934 /* Handle dynamic typing. */
935 switch (estack_ax_t) {
936 case REG_S64:
937 case REG_U64:
938 retval = !!estack_ax_v;
939 break;
940 case REG_DOUBLE:
941 case REG_STRING:
942 case REG_PTR:
943 if (!output) {
944 ret = -EINVAL;
945 goto end;
946 }
947 retval = 0;
948 break;
949 case REG_STAR_GLOB_STRING:
950 case REG_UNKNOWN:
951 default:
952 ret = -EINVAL;
953 goto end;
954 }
955 ret = 0;
956 goto end;
957
958 OP(BYTECODE_OP_RETURN_S64):
959 /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */
960 retval = !!estack_ax_v;
961 ret = 0;
962 goto end;
963
964 /* binary */
965 OP(BYTECODE_OP_MUL):
966 OP(BYTECODE_OP_DIV):
967 OP(BYTECODE_OP_MOD):
968 OP(BYTECODE_OP_PLUS):
969 OP(BYTECODE_OP_MINUS):
970 ERR("unsupported bytecode op %u",
971 (unsigned int) *(bytecode_opcode_t *) pc);
972 ret = -EINVAL;
973 goto end;
974
975 OP(BYTECODE_OP_EQ):
976 {
977 /* Dynamic typing. */
978 switch (estack_ax_t) {
979 case REG_S64: /* Fall-through */
980 case REG_U64:
981 switch (estack_bx_t) {
982 case REG_S64: /* Fall-through */
983 case REG_U64:
984 JUMP_TO(BYTECODE_OP_EQ_S64);
985 case REG_DOUBLE:
986 JUMP_TO(BYTECODE_OP_EQ_DOUBLE_S64);
987 case REG_STRING: /* Fall-through */
988 case REG_STAR_GLOB_STRING:
989 ret = -EINVAL;
990 goto end;
991 default:
992 ERR("Unknown interpreter register type (%d)",
993 (int) estack_bx_t);
994 ret = -EINVAL;
995 goto end;
996 }
997 break;
998 case REG_DOUBLE:
999 switch (estack_bx_t) {
1000 case REG_S64: /* Fall-through */
1001 case REG_U64:
1002 JUMP_TO(BYTECODE_OP_EQ_S64_DOUBLE);
1003 case REG_DOUBLE:
1004 JUMP_TO(BYTECODE_OP_EQ_DOUBLE);
1005 case REG_STRING: /* Fall-through */
1006 case REG_STAR_GLOB_STRING:
1007 ret = -EINVAL;
1008 goto end;
1009 default:
1010 ERR("Unknown interpreter register type (%d)",
1011 (int) estack_bx_t);
1012 ret = -EINVAL;
1013 goto end;
1014 }
1015 break;
1016 case REG_STRING:
1017 switch (estack_bx_t) {
1018 case REG_S64: /* Fall-through */
1019 case REG_U64: /* Fall-through */
1020 case REG_DOUBLE:
1021 ret = -EINVAL;
1022 goto end;
1023 case REG_STRING:
1024 JUMP_TO(BYTECODE_OP_EQ_STRING);
1025 case REG_STAR_GLOB_STRING:
1026 JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING);
1027 default:
1028 ERR("Unknown interpreter register type (%d)",
1029 (int) estack_bx_t);
1030 ret = -EINVAL;
1031 goto end;
1032 }
1033 break;
1034 case REG_STAR_GLOB_STRING:
1035 switch (estack_bx_t) {
1036 case REG_S64: /* Fall-through */
1037 case REG_U64: /* Fall-through */
1038 case REG_DOUBLE:
1039 ret = -EINVAL;
1040 goto end;
1041 case REG_STRING:
1042 JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING);
1043 case REG_STAR_GLOB_STRING:
1044 ret = -EINVAL;
1045 goto end;
1046 default:
1047 ERR("Unknown interpreter register type (%d)",
1048 (int) estack_bx_t);
1049 ret = -EINVAL;
1050 goto end;
1051 }
1052 break;
1053 default:
1054 ERR("Unknown interpreter register type (%d)",
1055 (int) estack_ax_t);
1056 ret = -EINVAL;
1057 goto end;
1058 }
1059 }
1060 OP(BYTECODE_OP_NE):
1061 {
1062 /* Dynamic typing. */
1063 switch (estack_ax_t) {
1064 case REG_S64: /* Fall-through */
1065 case REG_U64:
1066 switch (estack_bx_t) {
1067 case REG_S64: /* Fall-through */
1068 case REG_U64:
1069 JUMP_TO(BYTECODE_OP_NE_S64);
1070 case REG_DOUBLE:
1071 JUMP_TO(BYTECODE_OP_NE_DOUBLE_S64);
1072 case REG_STRING: /* Fall-through */
1073 case REG_STAR_GLOB_STRING:
1074 ret = -EINVAL;
1075 goto end;
1076 default:
1077 ERR("Unknown interpreter register type (%d)",
1078 (int) estack_bx_t);
1079 ret = -EINVAL;
1080 goto end;
1081 }
1082 break;
1083 case REG_DOUBLE:
1084 switch (estack_bx_t) {
1085 case REG_S64: /* Fall-through */
1086 case REG_U64:
1087 JUMP_TO(BYTECODE_OP_NE_S64_DOUBLE);
1088 case REG_DOUBLE:
1089 JUMP_TO(BYTECODE_OP_NE_DOUBLE);
1090 case REG_STRING: /* Fall-through */
1091 case REG_STAR_GLOB_STRING:
1092 ret = -EINVAL;
1093 goto end;
1094 default:
1095 ERR("Unknown interpreter register type (%d)",
1096 (int) estack_bx_t);
1097 ret = -EINVAL;
1098 goto end;
1099 }
1100 break;
1101 case REG_STRING:
1102 switch (estack_bx_t) {
1103 case REG_S64: /* Fall-through */
1104 case REG_U64:
1105 case REG_DOUBLE:
1106 ret = -EINVAL;
1107 goto end;
1108 case REG_STRING:
1109 JUMP_TO(BYTECODE_OP_NE_STRING);
1110 case REG_STAR_GLOB_STRING:
1111 JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING);
1112 default:
1113 ERR("Unknown interpreter register type (%d)",
1114 (int) estack_bx_t);
1115 ret = -EINVAL;
1116 goto end;
1117 }
1118 break;
1119 case REG_STAR_GLOB_STRING:
1120 switch (estack_bx_t) {
1121 case REG_S64: /* Fall-through */
1122 case REG_U64:
1123 case REG_DOUBLE:
1124 ret = -EINVAL;
1125 goto end;
1126 case REG_STRING:
1127 JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING);
1128 case REG_STAR_GLOB_STRING:
1129 ret = -EINVAL;
1130 goto end;
1131 default:
1132 ERR("Unknown interpreter register type (%d)",
1133 (int) estack_bx_t);
1134 ret = -EINVAL;
1135 goto end;
1136 }
1137 break;
1138 default:
1139 ERR("Unknown interpreter register type (%d)",
1140 (int) estack_ax_t);
1141 ret = -EINVAL;
1142 goto end;
1143 }
1144 }
1145 OP(BYTECODE_OP_GT):
1146 {
1147 /* Dynamic typing. */
1148 switch (estack_ax_t) {
1149 case REG_S64: /* Fall-through */
1150 case REG_U64:
1151 switch (estack_bx_t) {
1152 case REG_S64: /* Fall-through */
1153 case REG_U64:
1154 JUMP_TO(BYTECODE_OP_GT_S64);
1155 case REG_DOUBLE:
1156 JUMP_TO(BYTECODE_OP_GT_DOUBLE_S64);
1157 case REG_STRING: /* Fall-through */
1158 case REG_STAR_GLOB_STRING:
1159 ret = -EINVAL;
1160 goto end;
1161 default:
1162 ERR("Unknown interpreter register type (%d)",
1163 (int) estack_bx_t);
1164 ret = -EINVAL;
1165 goto end;
1166 }
1167 break;
1168 case REG_DOUBLE:
1169 switch (estack_bx_t) {
1170 case REG_S64: /* Fall-through */
1171 case REG_U64:
1172 JUMP_TO(BYTECODE_OP_GT_S64_DOUBLE);
1173 case REG_DOUBLE:
1174 JUMP_TO(BYTECODE_OP_GT_DOUBLE);
1175 case REG_STRING: /* Fall-through */
1176 case REG_STAR_GLOB_STRING:
1177 ret = -EINVAL;
1178 goto end;
1179 default:
1180 ERR("Unknown interpreter register type (%d)",
1181 (int) estack_bx_t);
1182 ret = -EINVAL;
1183 goto end;
1184 }
1185 break;
1186 case REG_STRING:
1187 switch (estack_bx_t) {
1188 case REG_S64: /* Fall-through */
1189 case REG_U64: /* Fall-through */
1190 case REG_DOUBLE: /* Fall-through */
1191 case REG_STAR_GLOB_STRING:
1192 ret = -EINVAL;
1193 goto end;
1194 case REG_STRING:
1195 JUMP_TO(BYTECODE_OP_GT_STRING);
1196 default:
1197 ERR("Unknown interpreter register type (%d)",
1198 (int) estack_bx_t);
1199 ret = -EINVAL;
1200 goto end;
1201 }
1202 break;
1203 default:
1204 ERR("Unknown interpreter register type (%d)",
1205 (int) estack_ax_t);
1206 ret = -EINVAL;
1207 goto end;
1208 }
1209 }
1210 OP(BYTECODE_OP_LT):
1211 {
1212 /* Dynamic typing. */
1213 switch (estack_ax_t) {
1214 case REG_S64: /* Fall-through */
1215 case REG_U64:
1216 switch (estack_bx_t) {
1217 case REG_S64: /* Fall-through */
1218 case REG_U64:
1219 JUMP_TO(BYTECODE_OP_LT_S64);
1220 case REG_DOUBLE:
1221 JUMP_TO(BYTECODE_OP_LT_DOUBLE_S64);
1222 case REG_STRING: /* Fall-through */
1223 case REG_STAR_GLOB_STRING:
1224 ret = -EINVAL;
1225 goto end;
1226 default:
1227 ERR("Unknown interpreter register type (%d)",
1228 (int) estack_bx_t);
1229 ret = -EINVAL;
1230 goto end;
1231 }
1232 break;
1233 case REG_DOUBLE:
1234 switch (estack_bx_t) {
1235 case REG_S64: /* Fall-through */
1236 case REG_U64:
1237 JUMP_TO(BYTECODE_OP_LT_S64_DOUBLE);
1238 case REG_DOUBLE:
1239 JUMP_TO(BYTECODE_OP_LT_DOUBLE);
1240 case REG_STRING: /* Fall-through */
1241 case REG_STAR_GLOB_STRING:
1242 ret = -EINVAL;
1243 goto end;
1244 default:
1245 ERR("Unknown interpreter register type (%d)",
1246 (int) estack_bx_t);
1247 ret = -EINVAL;
1248 goto end;
1249 }
1250 break;
1251 case REG_STRING:
1252 switch (estack_bx_t) {
1253 case REG_S64: /* Fall-through */
1254 case REG_U64: /* Fall-through */
1255 case REG_DOUBLE: /* Fall-through */
1256 case REG_STAR_GLOB_STRING:
1257 ret = -EINVAL;
1258 goto end;
1259 case REG_STRING:
1260 JUMP_TO(BYTECODE_OP_LT_STRING);
1261 default:
1262 ERR("Unknown interpreter register type (%d)",
1263 (int) estack_bx_t);
1264 ret = -EINVAL;
1265 goto end;
1266 }
1267 break;
1268 default:
1269 ERR("Unknown interpreter register type (%d)",
1270 (int) estack_ax_t);
1271 ret = -EINVAL;
1272 goto end;
1273 }
1274 }
1275 OP(BYTECODE_OP_GE):
1276 {
1277 /* Dynamic typing. */
1278 switch (estack_ax_t) {
1279 case REG_S64: /* Fall-through */
1280 case REG_U64:
1281 switch (estack_bx_t) {
1282 case REG_S64: /* Fall-through */
1283 case REG_U64:
1284 JUMP_TO(BYTECODE_OP_GE_S64);
1285 case REG_DOUBLE:
1286 JUMP_TO(BYTECODE_OP_GE_DOUBLE_S64);
1287 case REG_STRING: /* Fall-through */
1288 case REG_STAR_GLOB_STRING:
1289 ret = -EINVAL;
1290 goto end;
1291 default:
1292 ERR("Unknown interpreter register type (%d)",
1293 (int) estack_bx_t);
1294 ret = -EINVAL;
1295 goto end;
1296 }
1297 break;
1298 case REG_DOUBLE:
1299 switch (estack_bx_t) {
1300 case REG_S64: /* Fall-through */
1301 case REG_U64:
1302 JUMP_TO(BYTECODE_OP_GE_S64_DOUBLE);
1303 case REG_DOUBLE:
1304 JUMP_TO(BYTECODE_OP_GE_DOUBLE);
1305 case REG_STRING: /* Fall-through */
1306 case REG_STAR_GLOB_STRING:
1307 ret = -EINVAL;
1308 goto end;
1309 default:
1310 ERR("Unknown interpreter register type (%d)",
1311 (int) estack_bx_t);
1312 ret = -EINVAL;
1313 goto end;
1314 }
1315 break;
1316 case REG_STRING:
1317 switch (estack_bx_t) {
1318 case REG_S64: /* Fall-through */
1319 case REG_U64: /* Fall-through */
1320 case REG_DOUBLE: /* Fall-through */
1321 case REG_STAR_GLOB_STRING:
1322 ret = -EINVAL;
1323 goto end;
1324 case REG_STRING:
1325 JUMP_TO(BYTECODE_OP_GE_STRING);
1326 default:
1327 ERR("Unknown interpreter register type (%d)",
1328 (int) estack_bx_t);
1329 ret = -EINVAL;
1330 goto end;
1331 }
1332 break;
1333 default:
1334 ERR("Unknown interpreter register type (%d)",
1335 (int) estack_ax_t);
1336 ret = -EINVAL;
1337 goto end;
1338 }
1339 }
1340 OP(BYTECODE_OP_LE):
1341 {
1342 /* Dynamic typing. */
1343 switch (estack_ax_t) {
1344 case REG_S64: /* Fall-through */
1345 case REG_U64:
1346 switch (estack_bx_t) {
1347 case REG_S64: /* Fall-through */
1348 case REG_U64:
1349 JUMP_TO(BYTECODE_OP_LE_S64);
1350 case REG_DOUBLE:
1351 JUMP_TO(BYTECODE_OP_LE_DOUBLE_S64);
1352 case REG_STRING: /* Fall-through */
1353 case REG_STAR_GLOB_STRING:
1354 ret = -EINVAL;
1355 goto end;
1356 default:
1357 ERR("Unknown interpreter register type (%d)",
1358 (int) estack_bx_t);
1359 ret = -EINVAL;
1360 goto end;
1361 }
1362 break;
1363 case REG_DOUBLE:
1364 switch (estack_bx_t) {
1365 case REG_S64: /* Fall-through */
1366 case REG_U64:
1367 JUMP_TO(BYTECODE_OP_LE_S64_DOUBLE);
1368 case REG_DOUBLE:
1369 JUMP_TO(BYTECODE_OP_LE_DOUBLE);
1370 case REG_STRING: /* Fall-through */
1371 case REG_STAR_GLOB_STRING:
1372 ret = -EINVAL;
1373 goto end;
1374 default:
1375 ERR("Unknown interpreter register type (%d)",
1376 (int) estack_bx_t);
1377 ret = -EINVAL;
1378 goto end;
1379 }
1380 break;
1381 case REG_STRING:
1382 switch (estack_bx_t) {
1383 case REG_S64: /* Fall-through */
1384 case REG_U64: /* Fall-through */
1385 case REG_DOUBLE: /* Fall-through */
1386 case REG_STAR_GLOB_STRING:
1387 ret = -EINVAL;
1388 goto end;
1389 case REG_STRING:
1390 JUMP_TO(BYTECODE_OP_LE_STRING);
1391 default:
1392 ERR("Unknown interpreter register type (%d)",
1393 (int) estack_bx_t);
1394 ret = -EINVAL;
1395 goto end;
1396 }
1397 break;
1398 default:
1399 ERR("Unknown interpreter register type (%d)",
1400 (int) estack_ax_t);
1401 ret = -EINVAL;
1402 goto end;
1403 }
1404 }
1405
1406 OP(BYTECODE_OP_EQ_STRING):
1407 {
1408 int res;
1409
1410 res = (stack_strcmp(stack, top, "==") == 0);
1411 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1412 estack_ax_v = res;
1413 estack_ax_t = REG_S64;
1414 next_pc += sizeof(struct binary_op);
1415 PO;
1416 }
1417 OP(BYTECODE_OP_NE_STRING):
1418 {
1419 int res;
1420
1421 res = (stack_strcmp(stack, top, "!=") != 0);
1422 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1423 estack_ax_v = res;
1424 estack_ax_t = REG_S64;
1425 next_pc += sizeof(struct binary_op);
1426 PO;
1427 }
1428 OP(BYTECODE_OP_GT_STRING):
1429 {
1430 int res;
1431
1432 res = (stack_strcmp(stack, top, ">") > 0);
1433 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1434 estack_ax_v = res;
1435 estack_ax_t = REG_S64;
1436 next_pc += sizeof(struct binary_op);
1437 PO;
1438 }
1439 OP(BYTECODE_OP_LT_STRING):
1440 {
1441 int res;
1442
1443 res = (stack_strcmp(stack, top, "<") < 0);
1444 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1445 estack_ax_v = res;
1446 estack_ax_t = REG_S64;
1447 next_pc += sizeof(struct binary_op);
1448 PO;
1449 }
1450 OP(BYTECODE_OP_GE_STRING):
1451 {
1452 int res;
1453
1454 res = (stack_strcmp(stack, top, ">=") >= 0);
1455 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1456 estack_ax_v = res;
1457 estack_ax_t = REG_S64;
1458 next_pc += sizeof(struct binary_op);
1459 PO;
1460 }
1461 OP(BYTECODE_OP_LE_STRING):
1462 {
1463 int res;
1464
1465 res = (stack_strcmp(stack, top, "<=") <= 0);
1466 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1467 estack_ax_v = res;
1468 estack_ax_t = REG_S64;
1469 next_pc += sizeof(struct binary_op);
1470 PO;
1471 }
1472
1473 OP(BYTECODE_OP_EQ_STAR_GLOB_STRING):
1474 {
1475 int res;
1476
1477 res = (stack_star_glob_match(stack, top, "==") == 0);
1478 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1479 estack_ax_v = res;
1480 estack_ax_t = REG_S64;
1481 next_pc += sizeof(struct binary_op);
1482 PO;
1483 }
1484 OP(BYTECODE_OP_NE_STAR_GLOB_STRING):
1485 {
1486 int res;
1487
1488 res = (stack_star_glob_match(stack, top, "!=") != 0);
1489 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1490 estack_ax_v = res;
1491 estack_ax_t = REG_S64;
1492 next_pc += sizeof(struct binary_op);
1493 PO;
1494 }
1495
1496 OP(BYTECODE_OP_EQ_S64):
1497 {
1498 int res;
1499
1500 res = (estack_bx_v == estack_ax_v);
1501 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1502 estack_ax_v = res;
1503 estack_ax_t = REG_S64;
1504 next_pc += sizeof(struct binary_op);
1505 PO;
1506 }
1507 OP(BYTECODE_OP_NE_S64):
1508 {
1509 int res;
1510
1511 res = (estack_bx_v != estack_ax_v);
1512 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1513 estack_ax_v = res;
1514 estack_ax_t = REG_S64;
1515 next_pc += sizeof(struct binary_op);
1516 PO;
1517 }
1518 OP(BYTECODE_OP_GT_S64):
1519 {
1520 int res;
1521
1522 res = (estack_bx_v > estack_ax_v);
1523 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1524 estack_ax_v = res;
1525 estack_ax_t = REG_S64;
1526 next_pc += sizeof(struct binary_op);
1527 PO;
1528 }
1529 OP(BYTECODE_OP_LT_S64):
1530 {
1531 int res;
1532
1533 res = (estack_bx_v < estack_ax_v);
1534 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1535 estack_ax_v = res;
1536 estack_ax_t = REG_S64;
1537 next_pc += sizeof(struct binary_op);
1538 PO;
1539 }
1540 OP(BYTECODE_OP_GE_S64):
1541 {
1542 int res;
1543
1544 res = (estack_bx_v >= estack_ax_v);
1545 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1546 estack_ax_v = res;
1547 estack_ax_t = REG_S64;
1548 next_pc += sizeof(struct binary_op);
1549 PO;
1550 }
1551 OP(BYTECODE_OP_LE_S64):
1552 {
1553 int res;
1554
1555 res = (estack_bx_v <= estack_ax_v);
1556 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1557 estack_ax_v = res;
1558 estack_ax_t = REG_S64;
1559 next_pc += sizeof(struct binary_op);
1560 PO;
1561 }
1562
1563 OP(BYTECODE_OP_EQ_DOUBLE):
1564 {
1565 int res;
1566
1567 res = (estack_bx(stack, top)->u.d == estack_ax(stack, top)->u.d);
1568 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1569 estack_ax_v = res;
1570 estack_ax_t = REG_S64;
1571 next_pc += sizeof(struct binary_op);
1572 PO;
1573 }
1574 OP(BYTECODE_OP_NE_DOUBLE):
1575 {
1576 int res;
1577
1578 res = (estack_bx(stack, top)->u.d != estack_ax(stack, top)->u.d);
1579 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1580 estack_ax_v = res;
1581 estack_ax_t = REG_S64;
1582 next_pc += sizeof(struct binary_op);
1583 PO;
1584 }
1585 OP(BYTECODE_OP_GT_DOUBLE):
1586 {
1587 int res;
1588
1589 res = (estack_bx(stack, top)->u.d > estack_ax(stack, top)->u.d);
1590 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1591 estack_ax_v = res;
1592 estack_ax_t = REG_S64;
1593 next_pc += sizeof(struct binary_op);
1594 PO;
1595 }
1596 OP(BYTECODE_OP_LT_DOUBLE):
1597 {
1598 int res;
1599
1600 res = (estack_bx(stack, top)->u.d < estack_ax(stack, top)->u.d);
1601 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1602 estack_ax_v = res;
1603 estack_ax_t = REG_S64;
1604 next_pc += sizeof(struct binary_op);
1605 PO;
1606 }
1607 OP(BYTECODE_OP_GE_DOUBLE):
1608 {
1609 int res;
1610
1611 res = (estack_bx(stack, top)->u.d >= estack_ax(stack, top)->u.d);
1612 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1613 estack_ax_v = res;
1614 estack_ax_t = REG_S64;
1615 next_pc += sizeof(struct binary_op);
1616 PO;
1617 }
1618 OP(BYTECODE_OP_LE_DOUBLE):
1619 {
1620 int res;
1621
1622 res = (estack_bx(stack, top)->u.d <= estack_ax(stack, top)->u.d);
1623 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1624 estack_ax_v = res;
1625 estack_ax_t = REG_S64;
1626 next_pc += sizeof(struct binary_op);
1627 PO;
1628 }
1629
1630 /* Mixed S64-double binary comparators */
1631 OP(BYTECODE_OP_EQ_DOUBLE_S64):
1632 {
1633 int res;
1634
1635 res = (estack_bx(stack, top)->u.d == estack_ax_v);
1636 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1637 estack_ax_v = res;
1638 estack_ax_t = REG_S64;
1639 next_pc += sizeof(struct binary_op);
1640 PO;
1641 }
1642 OP(BYTECODE_OP_NE_DOUBLE_S64):
1643 {
1644 int res;
1645
1646 res = (estack_bx(stack, top)->u.d != estack_ax_v);
1647 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1648 estack_ax_v = res;
1649 estack_ax_t = REG_S64;
1650 next_pc += sizeof(struct binary_op);
1651 PO;
1652 }
1653 OP(BYTECODE_OP_GT_DOUBLE_S64):
1654 {
1655 int res;
1656
1657 res = (estack_bx(stack, top)->u.d > estack_ax_v);
1658 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1659 estack_ax_v = res;
1660 estack_ax_t = REG_S64;
1661 next_pc += sizeof(struct binary_op);
1662 PO;
1663 }
1664 OP(BYTECODE_OP_LT_DOUBLE_S64):
1665 {
1666 int res;
1667
1668 res = (estack_bx(stack, top)->u.d < estack_ax_v);
1669 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1670 estack_ax_v = res;
1671 estack_ax_t = REG_S64;
1672 next_pc += sizeof(struct binary_op);
1673 PO;
1674 }
1675 OP(BYTECODE_OP_GE_DOUBLE_S64):
1676 {
1677 int res;
1678
1679 res = (estack_bx(stack, top)->u.d >= estack_ax_v);
1680 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1681 estack_ax_v = res;
1682 estack_ax_t = REG_S64;
1683 next_pc += sizeof(struct binary_op);
1684 PO;
1685 }
1686 OP(BYTECODE_OP_LE_DOUBLE_S64):
1687 {
1688 int res;
1689
1690 res = (estack_bx(stack, top)->u.d <= estack_ax_v);
1691 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1692 estack_ax_v = res;
1693 estack_ax_t = REG_S64;
1694 next_pc += sizeof(struct binary_op);
1695 PO;
1696 }
1697
1698 OP(BYTECODE_OP_EQ_S64_DOUBLE):
1699 {
1700 int res;
1701
1702 res = (estack_bx_v == estack_ax(stack, top)->u.d);
1703 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1704 estack_ax_v = res;
1705 estack_ax_t = REG_S64;
1706 next_pc += sizeof(struct binary_op);
1707 PO;
1708 }
1709 OP(BYTECODE_OP_NE_S64_DOUBLE):
1710 {
1711 int res;
1712
1713 res = (estack_bx_v != estack_ax(stack, top)->u.d);
1714 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1715 estack_ax_v = res;
1716 estack_ax_t = REG_S64;
1717 next_pc += sizeof(struct binary_op);
1718 PO;
1719 }
1720 OP(BYTECODE_OP_GT_S64_DOUBLE):
1721 {
1722 int res;
1723
1724 res = (estack_bx_v > estack_ax(stack, top)->u.d);
1725 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1726 estack_ax_v = res;
1727 estack_ax_t = REG_S64;
1728 next_pc += sizeof(struct binary_op);
1729 PO;
1730 }
1731 OP(BYTECODE_OP_LT_S64_DOUBLE):
1732 {
1733 int res;
1734
1735 res = (estack_bx_v < estack_ax(stack, top)->u.d);
1736 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1737 estack_ax_v = res;
1738 estack_ax_t = REG_S64;
1739 next_pc += sizeof(struct binary_op);
1740 PO;
1741 }
1742 OP(BYTECODE_OP_GE_S64_DOUBLE):
1743 {
1744 int res;
1745
1746 res = (estack_bx_v >= estack_ax(stack, top)->u.d);
1747 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1748 estack_ax_v = res;
1749 estack_ax_t = REG_S64;
1750 next_pc += sizeof(struct binary_op);
1751 PO;
1752 }
1753 OP(BYTECODE_OP_LE_S64_DOUBLE):
1754 {
1755 int res;
1756
1757 res = (estack_bx_v <= estack_ax(stack, top)->u.d);
1758 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1759 estack_ax_v = res;
1760 estack_ax_t = REG_S64;
1761 next_pc += sizeof(struct binary_op);
1762 PO;
1763 }
1764 OP(BYTECODE_OP_BIT_RSHIFT):
1765 {
1766 int64_t res;
1767
1768 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1769 ret = -EINVAL;
1770 goto end;
1771 }
1772
1773 /* Catch undefined behavior. */
1774 if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
1775 ret = -EINVAL;
1776 goto end;
1777 }
1778 res = ((uint64_t) estack_bx_v >> (uint32_t) estack_ax_v);
1779 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1780 estack_ax_v = res;
1781 estack_ax_t = REG_U64;
1782 next_pc += sizeof(struct binary_op);
1783 PO;
1784 }
1785 OP(BYTECODE_OP_BIT_LSHIFT):
1786 {
1787 int64_t res;
1788
1789 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1790 ret = -EINVAL;
1791 goto end;
1792 }
1793
1794 /* Catch undefined behavior. */
1795 if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
1796 ret = -EINVAL;
1797 goto end;
1798 }
1799 res = ((uint64_t) estack_bx_v << (uint32_t) estack_ax_v);
1800 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1801 estack_ax_v = res;
1802 estack_ax_t = REG_U64;
1803 next_pc += sizeof(struct binary_op);
1804 PO;
1805 }
1806 OP(BYTECODE_OP_BIT_AND):
1807 {
1808 int64_t res;
1809
1810 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1811 ret = -EINVAL;
1812 goto end;
1813 }
1814
1815 res = ((uint64_t) estack_bx_v & (uint64_t) estack_ax_v);
1816 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1817 estack_ax_v = res;
1818 estack_ax_t = REG_U64;
1819 next_pc += sizeof(struct binary_op);
1820 PO;
1821 }
1822 OP(BYTECODE_OP_BIT_OR):
1823 {
1824 int64_t res;
1825
1826 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1827 ret = -EINVAL;
1828 goto end;
1829 }
1830
1831 res = ((uint64_t) estack_bx_v | (uint64_t) estack_ax_v);
1832 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1833 estack_ax_v = res;
1834 estack_ax_t = REG_U64;
1835 next_pc += sizeof(struct binary_op);
1836 PO;
1837 }
1838 OP(BYTECODE_OP_BIT_XOR):
1839 {
1840 int64_t res;
1841
1842 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1843 ret = -EINVAL;
1844 goto end;
1845 }
1846
1847 res = ((uint64_t) estack_bx_v ^ (uint64_t) estack_ax_v);
1848 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1849 estack_ax_v = res;
1850 estack_ax_t = REG_U64;
1851 next_pc += sizeof(struct binary_op);
1852 PO;
1853 }
1854
1855 /* unary */
1856 OP(BYTECODE_OP_UNARY_PLUS):
1857 {
1858 /* Dynamic typing. */
1859 switch (estack_ax_t) {
1860 case REG_S64: /* Fall-through. */
1861 case REG_U64:
1862 JUMP_TO(BYTECODE_OP_UNARY_PLUS_S64);
1863 case REG_DOUBLE:
1864 JUMP_TO(BYTECODE_OP_UNARY_PLUS_DOUBLE);
1865 case REG_STRING: /* Fall-through */
1866 case REG_STAR_GLOB_STRING:
1867 ret = -EINVAL;
1868 goto end;
1869 default:
1870 ERR("Unknown interpreter register type (%d)",
1871 (int) estack_ax_t);
1872 ret = -EINVAL;
1873 goto end;
1874 }
1875 }
1876 OP(BYTECODE_OP_UNARY_MINUS):
1877 {
1878 /* Dynamic typing. */
1879 switch (estack_ax_t) {
1880 case REG_S64: /* Fall-through. */
1881 case REG_U64:
1882 JUMP_TO(BYTECODE_OP_UNARY_MINUS_S64);
1883 case REG_DOUBLE:
1884 JUMP_TO(BYTECODE_OP_UNARY_MINUS_DOUBLE);
1885 case REG_STRING: /* Fall-through */
1886 case REG_STAR_GLOB_STRING:
1887 ret = -EINVAL;
1888 goto end;
1889 default:
1890 ERR("Unknown interpreter register type (%d)",
1891 (int) estack_ax_t);
1892 ret = -EINVAL;
1893 goto end;
1894 }
1895 }
1896 OP(BYTECODE_OP_UNARY_NOT):
1897 {
1898 /* Dynamic typing. */
1899 switch (estack_ax_t) {
1900 case REG_S64: /* Fall-through. */
1901 case REG_U64:
1902 JUMP_TO(BYTECODE_OP_UNARY_NOT_S64);
1903 case REG_DOUBLE:
1904 JUMP_TO(BYTECODE_OP_UNARY_NOT_DOUBLE);
1905 case REG_STRING: /* Fall-through */
1906 case REG_STAR_GLOB_STRING:
1907 ret = -EINVAL;
1908 goto end;
1909 default:
1910 ERR("Unknown interpreter register type (%d)",
1911 (int) estack_ax_t);
1912 ret = -EINVAL;
1913 goto end;
1914 }
1915 next_pc += sizeof(struct unary_op);
1916 PO;
1917 }
1918
1919 OP(BYTECODE_OP_UNARY_BIT_NOT):
1920 {
1921 /* Dynamic typing. */
1922 if (!IS_INTEGER_REGISTER(estack_ax_t)) {
1923 ret = -EINVAL;
1924 goto end;
1925 }
1926
1927 estack_ax_v = ~(uint64_t) estack_ax_v;
1928 estack_ax_t = REG_U64;
1929 next_pc += sizeof(struct unary_op);
1930 PO;
1931 }
1932
1933 OP(BYTECODE_OP_UNARY_PLUS_S64):
1934 OP(BYTECODE_OP_UNARY_PLUS_DOUBLE):
1935 {
1936 next_pc += sizeof(struct unary_op);
1937 PO;
1938 }
1939 OP(BYTECODE_OP_UNARY_MINUS_S64):
1940 {
1941 estack_ax_v = -estack_ax_v;
1942 next_pc += sizeof(struct unary_op);
1943 PO;
1944 }
1945 OP(BYTECODE_OP_UNARY_MINUS_DOUBLE):
1946 {
1947 estack_ax(stack, top)->u.d = -estack_ax(stack, top)->u.d;
1948 next_pc += sizeof(struct unary_op);
1949 PO;
1950 }
1951 OP(BYTECODE_OP_UNARY_NOT_S64):
1952 {
1953 estack_ax_v = !estack_ax_v;
1954 estack_ax_t = REG_S64;
1955 next_pc += sizeof(struct unary_op);
1956 PO;
1957 }
1958 OP(BYTECODE_OP_UNARY_NOT_DOUBLE):
1959 {
1960 estack_ax_v = !estack_ax(stack, top)->u.d;
1961 estack_ax_t = REG_S64;
1962 next_pc += sizeof(struct unary_op);
1963 PO;
1964 }
1965
1966 /* logical */
1967 OP(BYTECODE_OP_AND):
1968 {
1969 struct logical_op *insn = (struct logical_op *) pc;
1970
1971 if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) {
1972 ret = -EINVAL;
1973 goto end;
1974 }
1975 /* If AX is 0, skip and evaluate to 0 */
1976 if (unlikely(estack_ax_v == 0)) {
1977 dbg_printf("Jumping to bytecode offset %u\n",
1978 (unsigned int) insn->skip_offset);
1979 next_pc = start_pc + insn->skip_offset;
1980 } else {
1981 /* Pop 1 when jump not taken */
1982 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1983 next_pc += sizeof(struct logical_op);
1984 }
1985 PO;
1986 }
1987 OP(BYTECODE_OP_OR):
1988 {
1989 struct logical_op *insn = (struct logical_op *) pc;
1990
1991 if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) {
1992 ret = -EINVAL;
1993 goto end;
1994 }
1995 /* If AX is nonzero, skip and evaluate to 1 */
1996 if (unlikely(estack_ax_v != 0)) {
1997 estack_ax_v = 1;
1998 dbg_printf("Jumping to bytecode offset %u\n",
1999 (unsigned int) insn->skip_offset);
2000 next_pc = start_pc + insn->skip_offset;
2001 } else {
2002 /* Pop 1 when jump not taken */
2003 estack_pop(stack, top, ax, bx, ax_t, bx_t);
2004 next_pc += sizeof(struct logical_op);
2005 }
2006 PO;
2007 }
2008
2009
2010 /* load field ref */
2011 OP(BYTECODE_OP_LOAD_FIELD_REF_STRING):
2012 {
2013 struct load_op *insn = (struct load_op *) pc;
2014 struct field_ref *ref = (struct field_ref *) insn->data;
2015
2016 dbg_printf("load field ref offset %u type string\n",
2017 ref->offset);
2018 estack_push(stack, top, ax, bx, ax_t, bx_t);
2019 estack_ax(stack, top)->u.s.str =
2020 *(const char * const *) &interpreter_stack_data[ref->offset];
2021 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2022 dbg_printf("Interpreter warning: loading a NULL string.\n");
2023 ret = -EINVAL;
2024 goto end;
2025 }
2026 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2027 estack_ax(stack, top)->u.s.literal_type =
2028 ESTACK_STRING_LITERAL_TYPE_NONE;
2029 estack_ax_t = REG_STRING;
2030 dbg_printf("ref load string %s\n", estack_ax(stack, top)->u.s.str);
2031 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2032 PO;
2033 }
2034
2035 OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE):
2036 {
2037 struct load_op *insn = (struct load_op *) pc;
2038 struct field_ref *ref = (struct field_ref *) insn->data;
2039
2040 dbg_printf("load field ref offset %u type sequence\n",
2041 ref->offset);
2042 estack_push(stack, top, ax, bx, ax_t, bx_t);
2043 estack_ax(stack, top)->u.s.seq_len =
2044 *(unsigned long *) &interpreter_stack_data[ref->offset];
2045 estack_ax(stack, top)->u.s.str =
2046 *(const char **) (&interpreter_stack_data[ref->offset
2047 + sizeof(unsigned long)]);
2048 estack_ax_t = REG_STRING;
2049 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2050 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
2051 ret = -EINVAL;
2052 goto end;
2053 }
2054 estack_ax(stack, top)->u.s.literal_type =
2055 ESTACK_STRING_LITERAL_TYPE_NONE;
2056 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2057 PO;
2058 }
2059
2060 OP(BYTECODE_OP_LOAD_FIELD_REF_S64):
2061 {
2062 struct load_op *insn = (struct load_op *) pc;
2063 struct field_ref *ref = (struct field_ref *) insn->data;
2064
2065 dbg_printf("load field ref offset %u type s64\n",
2066 ref->offset);
2067 estack_push(stack, top, ax, bx, ax_t, bx_t);
2068 estack_ax_v =
2069 ((struct literal_numeric *) &interpreter_stack_data[ref->offset])->v;
2070 estack_ax_t = REG_S64;
2071 dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax_v);
2072 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2073 PO;
2074 }
2075
2076 OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE):
2077 {
2078 struct load_op *insn = (struct load_op *) pc;
2079 struct field_ref *ref = (struct field_ref *) insn->data;
2080
2081 dbg_printf("load field ref offset %u type double\n",
2082 ref->offset);
2083 estack_push(stack, top, ax, bx, ax_t, bx_t);
2084 memcpy(&estack_ax(stack, top)->u.d, &interpreter_stack_data[ref->offset],
2085 sizeof(struct literal_double));
2086 estack_ax_t = REG_DOUBLE;
2087 dbg_printf("ref load double %g\n", estack_ax(stack, top)->u.d);
2088 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2089 PO;
2090 }
2091
2092 /* load from immediate operand */
2093 OP(BYTECODE_OP_LOAD_STRING):
2094 {
2095 struct load_op *insn = (struct load_op *) pc;
2096
2097 dbg_printf("load string %s\n", insn->data);
2098 estack_push(stack, top, ax, bx, ax_t, bx_t);
2099 estack_ax(stack, top)->u.s.str = insn->data;
2100 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2101 estack_ax(stack, top)->u.s.literal_type =
2102 ESTACK_STRING_LITERAL_TYPE_PLAIN;
2103 estack_ax_t = REG_STRING;
2104 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
2105 PO;
2106 }
2107
2108 OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING):
2109 {
2110 struct load_op *insn = (struct load_op *) pc;
2111
2112 dbg_printf("load globbing pattern %s\n", insn->data);
2113 estack_push(stack, top, ax, bx, ax_t, bx_t);
2114 estack_ax(stack, top)->u.s.str = insn->data;
2115 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2116 estack_ax(stack, top)->u.s.literal_type =
2117 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB;
2118 estack_ax_t = REG_STAR_GLOB_STRING;
2119 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
2120 PO;
2121 }
2122
2123 OP(BYTECODE_OP_LOAD_S64):
2124 {
2125 struct load_op *insn = (struct load_op *) pc;
2126
2127 estack_push(stack, top, ax, bx, ax_t, bx_t);
2128 estack_ax_v = ((struct literal_numeric *) insn->data)->v;
2129 estack_ax_t = REG_S64;
2130 dbg_printf("load s64 %" PRIi64 "\n", estack_ax_v);
2131 next_pc += sizeof(struct load_op)
2132 + sizeof(struct literal_numeric);
2133 PO;
2134 }
2135
2136 OP(BYTECODE_OP_LOAD_DOUBLE):
2137 {
2138 struct load_op *insn = (struct load_op *) pc;
2139
2140 estack_push(stack, top, ax, bx, ax_t, bx_t);
2141 memcpy(&estack_ax(stack, top)->u.d, insn->data,
2142 sizeof(struct literal_double));
2143 estack_ax_t = REG_DOUBLE;
2144 dbg_printf("load double %g\n", estack_ax(stack, top)->u.d);
2145 next_pc += sizeof(struct load_op)
2146 + sizeof(struct literal_double);
2147 PO;
2148 }
2149
2150 /* cast */
2151 OP(BYTECODE_OP_CAST_TO_S64):
2152 {
2153 /* Dynamic typing. */
2154 switch (estack_ax_t) {
2155 case REG_S64:
2156 JUMP_TO(BYTECODE_OP_CAST_NOP);
2157 case REG_DOUBLE:
2158 JUMP_TO(BYTECODE_OP_CAST_DOUBLE_TO_S64);
2159 case REG_U64:
2160 estack_ax_t = REG_S64;
2161 next_pc += sizeof(struct cast_op);
2162 case REG_STRING: /* Fall-through */
2163 case REG_STAR_GLOB_STRING:
2164 ret = -EINVAL;
2165 goto end;
2166 default:
2167 ERR("Unknown interpreter register type (%d)",
2168 (int) estack_ax_t);
2169 ret = -EINVAL;
2170 goto end;
2171 }
2172 }
2173
2174 OP(BYTECODE_OP_CAST_DOUBLE_TO_S64):
2175 {
2176 estack_ax_v = (int64_t) estack_ax(stack, top)->u.d;
2177 estack_ax_t = REG_S64;
2178 next_pc += sizeof(struct cast_op);
2179 PO;
2180 }
2181
2182 OP(BYTECODE_OP_CAST_NOP):
2183 {
2184 next_pc += sizeof(struct cast_op);
2185 PO;
2186 }
2187
2188 /* get context ref */
2189 OP(BYTECODE_OP_GET_CONTEXT_REF):
2190 {
2191 struct load_op *insn = (struct load_op *) pc;
2192 struct field_ref *ref = (struct field_ref *) insn->data;
2193 struct lttng_ctx_field *ctx_field;
2194 struct lttng_ctx_value v;
2195
2196 dbg_printf("get context ref offset %u type dynamic\n",
2197 ref->offset);
2198 ctx_field = &ctx->fields[ref->offset];
2199 ctx_field->get_value(ctx_field, &v);
2200 estack_push(stack, top, ax, bx, ax_t, bx_t);
2201 switch (v.sel) {
2202 case LTTNG_UST_DYNAMIC_TYPE_NONE:
2203 ret = -EINVAL;
2204 goto end;
2205 case LTTNG_UST_DYNAMIC_TYPE_S64:
2206 estack_ax_v = v.u.s64;
2207 estack_ax_t = REG_S64;
2208 dbg_printf("ref get context dynamic s64 %" PRIi64 "\n", estack_ax_v);
2209 break;
2210 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
2211 estack_ax(stack, top)->u.d = v.u.d;
2212 estack_ax_t = REG_DOUBLE;
2213 dbg_printf("ref get context dynamic double %g\n", estack_ax(stack, top)->u.d);
2214 break;
2215 case LTTNG_UST_DYNAMIC_TYPE_STRING:
2216 estack_ax(stack, top)->u.s.str = v.u.str;
2217 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2218 dbg_printf("Interpreter warning: loading a NULL string.\n");
2219 ret = -EINVAL;
2220 goto end;
2221 }
2222 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2223 estack_ax(stack, top)->u.s.literal_type =
2224 ESTACK_STRING_LITERAL_TYPE_NONE;
2225 dbg_printf("ref get context dynamic string %s\n", estack_ax(stack, top)->u.s.str);
2226 estack_ax_t = REG_STRING;
2227 break;
2228 default:
2229 dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v.sel);
2230 ret = -EINVAL;
2231 goto end;
2232 }
2233 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2234 PO;
2235 }
2236
2237 OP(BYTECODE_OP_GET_CONTEXT_REF_STRING):
2238 {
2239 struct load_op *insn = (struct load_op *) pc;
2240 struct field_ref *ref = (struct field_ref *) insn->data;
2241 struct lttng_ctx_field *ctx_field;
2242 struct lttng_ctx_value v;
2243
2244 dbg_printf("get context ref offset %u type string\n",
2245 ref->offset);
2246 ctx_field = &ctx->fields[ref->offset];
2247 ctx_field->get_value(ctx_field, &v);
2248 estack_push(stack, top, ax, bx, ax_t, bx_t);
2249 estack_ax(stack, top)->u.s.str = v.u.str;
2250 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2251 dbg_printf("Interpreter warning: loading a NULL string.\n");
2252 ret = -EINVAL;
2253 goto end;
2254 }
2255 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2256 estack_ax(stack, top)->u.s.literal_type =
2257 ESTACK_STRING_LITERAL_TYPE_NONE;
2258 estack_ax_t = REG_STRING;
2259 dbg_printf("ref get context string %s\n", estack_ax(stack, top)->u.s.str);
2260 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2261 PO;
2262 }
2263
2264 OP(BYTECODE_OP_GET_CONTEXT_REF_S64):
2265 {
2266 struct load_op *insn = (struct load_op *) pc;
2267 struct field_ref *ref = (struct field_ref *) insn->data;
2268 struct lttng_ctx_field *ctx_field;
2269 struct lttng_ctx_value v;
2270
2271 dbg_printf("get context ref offset %u type s64\n",
2272 ref->offset);
2273 ctx_field = &ctx->fields[ref->offset];
2274 ctx_field->get_value(ctx_field, &v);
2275 estack_push(stack, top, ax, bx, ax_t, bx_t);
2276 estack_ax_v = v.u.s64;
2277 estack_ax_t = REG_S64;
2278 dbg_printf("ref get context s64 %" PRIi64 "\n", estack_ax_v);
2279 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2280 PO;
2281 }
2282
2283 OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE):
2284 {
2285 struct load_op *insn = (struct load_op *) pc;
2286 struct field_ref *ref = (struct field_ref *) insn->data;
2287 struct lttng_ctx_field *ctx_field;
2288 struct lttng_ctx_value v;
2289
2290 dbg_printf("get context ref offset %u type double\n",
2291 ref->offset);
2292 ctx_field = &ctx->fields[ref->offset];
2293 ctx_field->get_value(ctx_field, &v);
2294 estack_push(stack, top, ax, bx, ax_t, bx_t);
2295 memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double));
2296 estack_ax_t = REG_DOUBLE;
2297 dbg_printf("ref get context double %g\n", estack_ax(stack, top)->u.d);
2298 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2299 PO;
2300 }
2301
2302 OP(BYTECODE_OP_GET_CONTEXT_ROOT):
2303 {
2304 dbg_printf("op get context root\n");
2305 estack_push(stack, top, ax, bx, ax_t, bx_t);
2306 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_CONTEXT;
2307 /* "field" only needed for variants. */
2308 estack_ax(stack, top)->u.ptr.field = NULL;
2309 estack_ax_t = REG_PTR;
2310 next_pc += sizeof(struct load_op);
2311 PO;
2312 }
2313
2314 OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT):
2315 {
2316 dbg_printf("op get app context root\n");
2317 estack_push(stack, top, ax, bx, ax_t, bx_t);
2318 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_APP_CONTEXT;
2319 /* "field" only needed for variants. */
2320 estack_ax(stack, top)->u.ptr.field = NULL;
2321 estack_ax_t = REG_PTR;
2322 next_pc += sizeof(struct load_op);
2323 PO;
2324 }
2325
2326 OP(BYTECODE_OP_GET_PAYLOAD_ROOT):
2327 {
2328 dbg_printf("op get app payload root\n");
2329 estack_push(stack, top, ax, bx, ax_t, bx_t);
2330 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_PAYLOAD;
2331 estack_ax(stack, top)->u.ptr.ptr = interpreter_stack_data;
2332 /* "field" only needed for variants. */
2333 estack_ax(stack, top)->u.ptr.field = NULL;
2334 estack_ax_t = REG_PTR;
2335 next_pc += sizeof(struct load_op);
2336 PO;
2337 }
2338
2339 OP(BYTECODE_OP_GET_SYMBOL):
2340 {
2341 dbg_printf("op get symbol\n");
2342 switch (estack_ax(stack, top)->u.ptr.type) {
2343 case LOAD_OBJECT:
2344 ERR("Nested fields not implemented yet.");
2345 ret = -EINVAL;
2346 goto end;
2347 case LOAD_ROOT_CONTEXT:
2348 case LOAD_ROOT_APP_CONTEXT:
2349 case LOAD_ROOT_PAYLOAD:
2350 /*
2351 * symbol lookup is performed by
2352 * specialization.
2353 */
2354 ret = -EINVAL;
2355 goto end;
2356 }
2357 next_pc += sizeof(struct load_op) + sizeof(struct get_symbol);
2358 PO;
2359 }
2360
2361 OP(BYTECODE_OP_GET_SYMBOL_FIELD):
2362 {
2363 /*
2364 * Used for first variant encountered in a
2365 * traversal. Variants are not implemented yet.
2366 */
2367 ret = -EINVAL;
2368 goto end;
2369 }
2370
2371 OP(BYTECODE_OP_GET_INDEX_U16):
2372 {
2373 struct load_op *insn = (struct load_op *) pc;
2374 struct get_index_u16 *index = (struct get_index_u16 *) insn->data;
2375
2376 dbg_printf("op get index u16\n");
2377 ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top));
2378 if (ret)
2379 goto end;
2380 estack_ax_v = estack_ax(stack, top)->u.v;
2381 estack_ax_t = estack_ax(stack, top)->type;
2382 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u16);
2383 PO;
2384 }
2385
2386 OP(BYTECODE_OP_GET_INDEX_U64):
2387 {
2388 struct load_op *insn = (struct load_op *) pc;
2389 struct get_index_u64 *index = (struct get_index_u64 *) insn->data;
2390
2391 dbg_printf("op get index u64\n");
2392 ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top));
2393 if (ret)
2394 goto end;
2395 estack_ax_v = estack_ax(stack, top)->u.v;
2396 estack_ax_t = estack_ax(stack, top)->type;
2397 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u64);
2398 PO;
2399 }
2400
2401 OP(BYTECODE_OP_LOAD_FIELD):
2402 {
2403 dbg_printf("op load field\n");
2404 ret = dynamic_load_field(estack_ax(stack, top));
2405 if (ret)
2406 goto end;
2407 estack_ax_v = estack_ax(stack, top)->u.v;
2408 estack_ax_t = estack_ax(stack, top)->type;
2409 next_pc += sizeof(struct load_op);
2410 PO;
2411 }
2412
2413 OP(BYTECODE_OP_LOAD_FIELD_S8):
2414 {
2415 dbg_printf("op load field s8\n");
2416
2417 estack_ax_v = *(int8_t *) estack_ax(stack, top)->u.ptr.ptr;
2418 estack_ax_t = REG_S64;
2419 next_pc += sizeof(struct load_op);
2420 PO;
2421 }
2422 OP(BYTECODE_OP_LOAD_FIELD_S16):
2423 {
2424 dbg_printf("op load field s16\n");
2425
2426 estack_ax_v = *(int16_t *) estack_ax(stack, top)->u.ptr.ptr;
2427 estack_ax_t = REG_S64;
2428 next_pc += sizeof(struct load_op);
2429 PO;
2430 }
2431 OP(BYTECODE_OP_LOAD_FIELD_S32):
2432 {
2433 dbg_printf("op load field s32\n");
2434
2435 estack_ax_v = *(int32_t *) estack_ax(stack, top)->u.ptr.ptr;
2436 estack_ax_t = REG_S64;
2437 next_pc += sizeof(struct load_op);
2438 PO;
2439 }
2440 OP(BYTECODE_OP_LOAD_FIELD_S64):
2441 {
2442 dbg_printf("op load field s64\n");
2443
2444 estack_ax_v = *(int64_t *) estack_ax(stack, top)->u.ptr.ptr;
2445 estack_ax_t = REG_S64;
2446 next_pc += sizeof(struct load_op);
2447 PO;
2448 }
2449 OP(BYTECODE_OP_LOAD_FIELD_U8):
2450 {
2451 dbg_printf("op load field u8\n");
2452
2453 estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr;
2454 estack_ax_t = REG_U64;
2455 next_pc += sizeof(struct load_op);
2456 PO;
2457 }
2458 OP(BYTECODE_OP_LOAD_FIELD_U16):
2459 {
2460 dbg_printf("op load field u16\n");
2461
2462 estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr;
2463 estack_ax_t = REG_U64;
2464 next_pc += sizeof(struct load_op);
2465 PO;
2466 }
2467 OP(BYTECODE_OP_LOAD_FIELD_U32):
2468 {
2469 dbg_printf("op load field u32\n");
2470
2471 estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr;
2472 estack_ax_t = REG_U64;
2473 next_pc += sizeof(struct load_op);
2474 PO;
2475 }
2476 OP(BYTECODE_OP_LOAD_FIELD_U64):
2477 {
2478 dbg_printf("op load field u64\n");
2479
2480 estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr;
2481 estack_ax_t = REG_U64;
2482 next_pc += sizeof(struct load_op);
2483 PO;
2484 }
2485 OP(BYTECODE_OP_LOAD_FIELD_DOUBLE):
2486 {
2487 dbg_printf("op load field double\n");
2488
2489 memcpy(&estack_ax(stack, top)->u.d,
2490 estack_ax(stack, top)->u.ptr.ptr,
2491 sizeof(struct literal_double));
2492 estack_ax(stack, top)->type = REG_DOUBLE;
2493 next_pc += sizeof(struct load_op);
2494 PO;
2495 }
2496
2497 OP(BYTECODE_OP_LOAD_FIELD_STRING):
2498 {
2499 const char *str;
2500
2501 dbg_printf("op load field string\n");
2502 str = (const char *) estack_ax(stack, top)->u.ptr.ptr;
2503 estack_ax(stack, top)->u.s.str = str;
2504 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2505 dbg_printf("Interpreter warning: loading a NULL string.\n");
2506 ret = -EINVAL;
2507 goto end;
2508 }
2509 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2510 estack_ax(stack, top)->u.s.literal_type =
2511 ESTACK_STRING_LITERAL_TYPE_NONE;
2512 estack_ax(stack, top)->type = REG_STRING;
2513 next_pc += sizeof(struct load_op);
2514 PO;
2515 }
2516
2517 OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE):
2518 {
2519 const char *ptr;
2520
2521 dbg_printf("op load field string sequence\n");
2522 ptr = estack_ax(stack, top)->u.ptr.ptr;
2523 estack_ax(stack, top)->u.s.seq_len = *(unsigned long *) ptr;
2524 estack_ax(stack, top)->u.s.str = *(const char **) (ptr + sizeof(unsigned long));
2525 estack_ax(stack, top)->type = REG_STRING;
2526 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2527 dbg_printf("Interpreter warning: loading a NULL sequence.\n");
2528 ret = -EINVAL;
2529 goto end;
2530 }
2531 estack_ax(stack, top)->u.s.literal_type =
2532 ESTACK_STRING_LITERAL_TYPE_NONE;
2533 next_pc += sizeof(struct load_op);
2534 PO;
2535 }
2536
2537 END_OP
2538 end:
2539 /* Return _DISCARD on error. */
2540 if (ret)
2541 return LTTNG_INTERPRETER_DISCARD;
2542
2543 if (output) {
2544 return lttng_bytecode_interpret_format_output(estack_ax(stack, top),
2545 output);
2546 }
2547
2548 return retval;
2549 }
2550
2551 uint64_t lttng_bytecode_filter_interpret(void *filter_data,
2552 const char *filter_stack_data)
2553 {
2554 return bytecode_interpret(filter_data, filter_stack_data, NULL);
2555 }
2556
2557 uint64_t lttng_bytecode_capture_interpret(void *capture_data,
2558 const char *capture_stack_data,
2559 struct lttng_interpreter_output *output)
2560 {
2561 return bytecode_interpret(capture_data, capture_stack_data,
2562 (struct lttng_interpreter_output *) output);
2563 }
2564
2565 #undef START_OP
2566 #undef OP
2567 #undef PO
2568 #undef END_OP
This page took 0.231546 seconds and 4 git commands to generate.