32610e6ca29b009b249ecd150dcad481ef462102
[deliverable/lttng-ust.git] / liblttng-ust / lttng-filter-interpreter.c
1 /*
2 * lttng-filter-interpreter.c
3 *
4 * LTTng UST filter 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 <urcu-pointer.h>
31 #include <byteswap.h>
32
33 #include <lttng/ust-endian.h>
34 #include <lttng/ust-events.h>
35
36 #include "lttng-filter.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_filter_interpret_bytecode_false(void *filter_data,
170 const char *filter_stack_data)
171 {
172 return LTTNG_FILTER_DISCARD;
173 }
174
175 #ifdef INTERPRETER_USE_SWITCH
176
177 /*
178 * Fallback for compilers that do not support taking address of labels.
179 */
180
181 #define START_OP \
182 start_pc = &bytecode->data[0]; \
183 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
184 pc = next_pc) { \
185 dbg_printf("Executing op %s (%u)\n", \
186 print_op((unsigned int) *(filter_opcode_t *) pc), \
187 (unsigned int) *(filter_opcode_t *) pc); \
188 switch (*(filter_opcode_t *) pc) {
189
190 #define OP(name) jump_target_##name: __attribute__((unused)); \
191 case name
192
193 #define PO break
194
195 #define END_OP } \
196 }
197
198 #define JUMP_TO(name) \
199 goto jump_target_##name
200
201 #else
202
203 /*
204 * Dispatch-table based interpreter.
205 */
206
207 #define START_OP \
208 start_pc = &bytecode->code[0]; \
209 pc = next_pc = start_pc; \
210 if (unlikely(pc - start_pc >= bytecode->len)) \
211 goto end; \
212 goto *dispatch[*(filter_opcode_t *) pc];
213
214 #define OP(name) \
215 LABEL_##name
216
217 #define PO \
218 pc = next_pc; \
219 goto *dispatch[*(filter_opcode_t *) pc];
220
221 #define END_OP
222
223 #define JUMP_TO(name) \
224 goto LABEL_##name
225
226 #endif
227
228 #define IS_INTEGER_REGISTER(reg_type) \
229 (reg_type == REG_U64 || reg_type == REG_S64)
230
231 static int context_get_index(struct lttng_ctx *ctx,
232 struct load_ptr *ptr,
233 uint32_t idx)
234 {
235
236 struct lttng_ctx_field *ctx_field;
237 struct lttng_event_field *field;
238 struct lttng_ctx_value v;
239
240 ctx_field = &ctx->fields[idx];
241 field = &ctx_field->event_field;
242 ptr->type = LOAD_OBJECT;
243 ptr->field = field;
244
245 switch (field->type.atype) {
246 case atype_integer:
247 ctx_field->get_value(ctx_field, &v);
248 if (field->type.u.integer.signedness) {
249 ptr->object_type = OBJECT_TYPE_S64;
250 ptr->u.s64 = v.u.s64;
251 ptr->ptr = &ptr->u.s64;
252 } else {
253 ptr->object_type = OBJECT_TYPE_U64;
254 ptr->u.u64 = v.u.s64; /* Cast. */
255 ptr->ptr = &ptr->u.u64;
256 }
257 break;
258 case atype_enum: /* Fall-through */
259 case atype_enum_nestable:
260 {
261 const struct lttng_integer_type *itype;
262
263 if (field->type.atype == atype_enum) {
264 itype = &field->type.u.legacy.basic.enumeration.container_type;
265 } else {
266 itype = &field->type.u.enum_nestable.container_type->u.integer;
267 }
268 ctx_field->get_value(ctx_field, &v);
269 if (itype->signedness) {
270 ptr->object_type = OBJECT_TYPE_S64;
271 ptr->u.s64 = v.u.s64;
272 ptr->ptr = &ptr->u.s64;
273 } else {
274 ptr->object_type = OBJECT_TYPE_U64;
275 ptr->u.u64 = v.u.s64; /* Cast. */
276 ptr->ptr = &ptr->u.u64;
277 }
278 break;
279 }
280 case atype_array:
281 if (field->type.u.legacy.array.elem_type.atype != atype_integer) {
282 ERR("Array nesting only supports integer types.");
283 return -EINVAL;
284 }
285 if (field->type.u.legacy.array.elem_type.u.basic.integer.encoding == lttng_encode_none) {
286 ERR("Only string arrays are supported for contexts.");
287 return -EINVAL;
288 }
289 ptr->object_type = OBJECT_TYPE_STRING;
290 ctx_field->get_value(ctx_field, &v);
291 ptr->ptr = v.u.str;
292 break;
293 case atype_array_nestable:
294 if (field->type.u.array_nestable.elem_type->atype != atype_integer) {
295 ERR("Array nesting only supports integer types.");
296 return -EINVAL;
297 }
298 if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) {
299 ERR("Only string arrays are supported for contexts.");
300 return -EINVAL;
301 }
302 ptr->object_type = OBJECT_TYPE_STRING;
303 ctx_field->get_value(ctx_field, &v);
304 ptr->ptr = v.u.str;
305 break;
306 case atype_sequence:
307 if (field->type.u.legacy.sequence.elem_type.atype != atype_integer) {
308 ERR("Sequence nesting only supports integer types.");
309 return -EINVAL;
310 }
311 if (field->type.u.legacy.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) {
312 ERR("Only string sequences are supported for contexts.");
313 return -EINVAL;
314 }
315 ptr->object_type = OBJECT_TYPE_STRING;
316 ctx_field->get_value(ctx_field, &v);
317 ptr->ptr = v.u.str;
318 break;
319 case atype_sequence_nestable:
320 if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) {
321 ERR("Sequence nesting only supports integer types.");
322 return -EINVAL;
323 }
324 if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) {
325 ERR("Only string sequences are supported for contexts.");
326 return -EINVAL;
327 }
328 ptr->object_type = OBJECT_TYPE_STRING;
329 ctx_field->get_value(ctx_field, &v);
330 ptr->ptr = v.u.str;
331 break;
332 case atype_string:
333 ptr->object_type = OBJECT_TYPE_STRING;
334 ctx_field->get_value(ctx_field, &v);
335 ptr->ptr = v.u.str;
336 break;
337 case atype_float:
338 ptr->object_type = OBJECT_TYPE_DOUBLE;
339 ctx_field->get_value(ctx_field, &v);
340 ptr->u.d = v.u.d;
341 ptr->ptr = &ptr->u.d;
342 break;
343 case atype_dynamic:
344 ctx_field->get_value(ctx_field, &v);
345 switch (v.sel) {
346 case LTTNG_UST_DYNAMIC_TYPE_NONE:
347 return -EINVAL;
348 case LTTNG_UST_DYNAMIC_TYPE_S64:
349 ptr->object_type = OBJECT_TYPE_S64;
350 ptr->u.s64 = v.u.s64;
351 ptr->ptr = &ptr->u.s64;
352 dbg_printf("context get index dynamic s64 %" PRIi64 "\n", ptr->u.s64);
353 break;
354 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
355 ptr->object_type = OBJECT_TYPE_DOUBLE;
356 ptr->u.d = v.u.d;
357 ptr->ptr = &ptr->u.d;
358 dbg_printf("context get index dynamic double %g\n", ptr->u.d);
359 break;
360 case LTTNG_UST_DYNAMIC_TYPE_STRING:
361 ptr->object_type = OBJECT_TYPE_STRING;
362 ptr->ptr = v.u.str;
363 dbg_printf("context get index dynamic string %s\n", (const char *) ptr->ptr);
364 break;
365 default:
366 dbg_printf("Filter warning: unknown dynamic type (%d).\n", (int) v.sel);
367 return -EINVAL;
368 }
369 break;
370 case atype_struct:
371 ERR("Structure type cannot be loaded.");
372 return -EINVAL;
373 default:
374 ERR("Unknown type: %d", (int) field->type.atype);
375 return -EINVAL;
376 }
377 return 0;
378 }
379
380 static int dynamic_get_index(struct lttng_ctx *ctx,
381 struct bytecode_runtime *runtime,
382 uint64_t index, struct estack_entry *stack_top)
383 {
384 int ret;
385 const struct filter_get_index_data *gid;
386
387 gid = (const struct filter_get_index_data *) &runtime->data[index];
388 switch (stack_top->u.ptr.type) {
389 case LOAD_OBJECT:
390 switch (stack_top->u.ptr.object_type) {
391 case OBJECT_TYPE_ARRAY:
392 {
393 const char *ptr;
394
395 assert(gid->offset < gid->array_len);
396 /* Skip count (unsigned long) */
397 ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long));
398 ptr = ptr + gid->offset;
399 stack_top->u.ptr.ptr = ptr;
400 stack_top->u.ptr.object_type = gid->elem.type;
401 stack_top->u.ptr.rev_bo = gid->elem.rev_bo;
402 assert(stack_top->u.ptr.field->type.atype == atype_array ||
403 stack_top->u.ptr.field->type.atype == atype_array_nestable);
404 stack_top->u.ptr.field = NULL;
405 break;
406 }
407 case OBJECT_TYPE_SEQUENCE:
408 {
409 const char *ptr;
410 size_t ptr_seq_len;
411
412 ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long));
413 ptr_seq_len = *(unsigned long *) stack_top->u.ptr.ptr;
414 if (gid->offset >= gid->elem.len * ptr_seq_len) {
415 ret = -EINVAL;
416 goto end;
417 }
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_sequence ||
423 stack_top->u.ptr.field->type.atype == atype_sequence_nestable);
424 stack_top->u.ptr.field = NULL;
425 break;
426 }
427 case OBJECT_TYPE_STRUCT:
428 ERR("Nested structures are not supported yet.");
429 ret = -EINVAL;
430 goto end;
431 case OBJECT_TYPE_VARIANT:
432 default:
433 ERR("Unexpected get index type %d",
434 (int) stack_top->u.ptr.object_type);
435 ret = -EINVAL;
436 goto end;
437 }
438 break;
439 case LOAD_ROOT_CONTEXT:
440 case LOAD_ROOT_APP_CONTEXT: /* Fall-through */
441 {
442 ret = context_get_index(ctx,
443 &stack_top->u.ptr,
444 gid->ctx_index);
445 if (ret) {
446 goto end;
447 }
448 break;
449 }
450 case LOAD_ROOT_PAYLOAD:
451 stack_top->u.ptr.ptr += gid->offset;
452 if (gid->elem.type == OBJECT_TYPE_STRING)
453 stack_top->u.ptr.ptr = *(const char * const *) stack_top->u.ptr.ptr;
454 stack_top->u.ptr.object_type = gid->elem.type;
455 stack_top->u.ptr.type = LOAD_OBJECT;
456 stack_top->u.ptr.field = gid->field;
457 break;
458 }
459 return 0;
460
461 end:
462 return ret;
463 }
464
465 static int dynamic_load_field(struct estack_entry *stack_top)
466 {
467 int ret;
468
469 switch (stack_top->u.ptr.type) {
470 case LOAD_OBJECT:
471 break;
472 case LOAD_ROOT_CONTEXT:
473 case LOAD_ROOT_APP_CONTEXT:
474 case LOAD_ROOT_PAYLOAD:
475 default:
476 dbg_printf("Filter warning: cannot load root, missing field name.\n");
477 ret = -EINVAL;
478 goto end;
479 }
480 switch (stack_top->u.ptr.object_type) {
481 case OBJECT_TYPE_S8:
482 dbg_printf("op load field s8\n");
483 stack_top->u.v = *(int8_t *) stack_top->u.ptr.ptr;
484 stack_top->type = REG_S64;
485 break;
486 case OBJECT_TYPE_S16:
487 {
488 int16_t tmp;
489
490 dbg_printf("op load field s16\n");
491 tmp = *(int16_t *) stack_top->u.ptr.ptr;
492 if (stack_top->u.ptr.rev_bo)
493 tmp = bswap_16(tmp);
494 stack_top->u.v = tmp;
495 stack_top->type = REG_S64;
496 break;
497 }
498 case OBJECT_TYPE_S32:
499 {
500 int32_t tmp;
501
502 dbg_printf("op load field s32\n");
503 tmp = *(int32_t *) stack_top->u.ptr.ptr;
504 if (stack_top->u.ptr.rev_bo)
505 tmp = bswap_32(tmp);
506 stack_top->u.v = tmp;
507 stack_top->type = REG_S64;
508 break;
509 }
510 case OBJECT_TYPE_S64:
511 {
512 int64_t tmp;
513
514 dbg_printf("op load field s64\n");
515 tmp = *(int64_t *) stack_top->u.ptr.ptr;
516 if (stack_top->u.ptr.rev_bo)
517 tmp = bswap_64(tmp);
518 stack_top->u.v = tmp;
519 stack_top->type = REG_S64;
520 break;
521 }
522 case OBJECT_TYPE_U8:
523 dbg_printf("op load field u8\n");
524 stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr;
525 stack_top->type = REG_U64;
526 break;
527 case OBJECT_TYPE_U16:
528 {
529 uint16_t tmp;
530
531 dbg_printf("op load field u16\n");
532 tmp = *(uint16_t *) stack_top->u.ptr.ptr;
533 if (stack_top->u.ptr.rev_bo)
534 tmp = bswap_16(tmp);
535 stack_top->u.v = tmp;
536 stack_top->type = REG_U64;
537 break;
538 }
539 case OBJECT_TYPE_U32:
540 {
541 uint32_t tmp;
542
543 dbg_printf("op load field u32\n");
544 tmp = *(uint32_t *) stack_top->u.ptr.ptr;
545 if (stack_top->u.ptr.rev_bo)
546 tmp = bswap_32(tmp);
547 stack_top->u.v = tmp;
548 stack_top->type = REG_U64;
549 break;
550 }
551 case OBJECT_TYPE_U64:
552 {
553 uint64_t tmp;
554
555 dbg_printf("op load field u64\n");
556 tmp = *(uint64_t *) stack_top->u.ptr.ptr;
557 if (stack_top->u.ptr.rev_bo)
558 tmp = bswap_64(tmp);
559 stack_top->u.v = tmp;
560 stack_top->type = REG_U64;
561 break;
562 }
563 case OBJECT_TYPE_DOUBLE:
564 memcpy(&stack_top->u.d,
565 stack_top->u.ptr.ptr,
566 sizeof(struct literal_double));
567 stack_top->type = REG_DOUBLE;
568 break;
569 case OBJECT_TYPE_STRING:
570 {
571 const char *str;
572
573 dbg_printf("op load field string\n");
574 str = (const char *) stack_top->u.ptr.ptr;
575 stack_top->u.s.str = str;
576 if (unlikely(!stack_top->u.s.str)) {
577 dbg_printf("Filter warning: loading a NULL string.\n");
578 ret = -EINVAL;
579 goto end;
580 }
581 stack_top->u.s.seq_len = SIZE_MAX;
582 stack_top->u.s.literal_type =
583 ESTACK_STRING_LITERAL_TYPE_NONE;
584 stack_top->type = REG_STRING;
585 break;
586 }
587 case OBJECT_TYPE_STRING_SEQUENCE:
588 {
589 const char *ptr;
590
591 dbg_printf("op load field string sequence\n");
592 ptr = stack_top->u.ptr.ptr;
593 stack_top->u.s.seq_len = *(unsigned long *) ptr;
594 stack_top->u.s.str = *(const char **) (ptr + sizeof(unsigned long));
595 stack_top->type = REG_STRING;
596 if (unlikely(!stack_top->u.s.str)) {
597 dbg_printf("Filter warning: loading a NULL sequence.\n");
598 ret = -EINVAL;
599 goto end;
600 }
601 stack_top->u.s.literal_type =
602 ESTACK_STRING_LITERAL_TYPE_NONE;
603 break;
604 }
605 case OBJECT_TYPE_DYNAMIC:
606 /*
607 * Dynamic types in context are looked up
608 * by context get index.
609 */
610 ret = -EINVAL;
611 goto end;
612 case OBJECT_TYPE_SEQUENCE:
613 case OBJECT_TYPE_ARRAY:
614 case OBJECT_TYPE_STRUCT:
615 case OBJECT_TYPE_VARIANT:
616 ERR("Sequences, arrays, struct and variant cannot be loaded (nested types).");
617 ret = -EINVAL;
618 goto end;
619 }
620 return 0;
621
622 end:
623 return ret;
624 }
625
626 static
627 int lttng_bytecode_interpret_format_output(struct estack_entry *ax,
628 struct lttng_interpreter_output *output)
629 {
630 int ret;
631
632 again:
633 switch (ax->type) {
634 case REG_S64:
635 output->type = LTTNG_INTERPRETER_TYPE_S64;
636 output->u.s = ax->u.v;
637 break;
638 case REG_U64:
639 output->type = LTTNG_INTERPRETER_TYPE_U64;
640 output->u.u = (uint64_t) ax->u.v;
641 break;
642 case REG_DOUBLE:
643 output->type = LTTNG_INTERPRETER_TYPE_DOUBLE;
644 output->u.d = ax->u.d;
645 break;
646 case REG_STRING:
647 output->type = LTTNG_INTERPRETER_TYPE_STRING;
648 output->u.str.str = ax->u.s.str;
649 output->u.str.len = ax->u.s.seq_len;
650 break;
651 case REG_PTR:
652 switch (ax->u.ptr.object_type) {
653 case OBJECT_TYPE_S8:
654 case OBJECT_TYPE_S16:
655 case OBJECT_TYPE_S32:
656 case OBJECT_TYPE_S64:
657 case OBJECT_TYPE_U8:
658 case OBJECT_TYPE_U16:
659 case OBJECT_TYPE_U32:
660 case OBJECT_TYPE_U64:
661 case OBJECT_TYPE_DOUBLE:
662 case OBJECT_TYPE_STRING:
663 case OBJECT_TYPE_STRING_SEQUENCE:
664 ret = dynamic_load_field(ax);
665 if (ret)
666 return ret;
667 /* Retry after loading ptr into stack top. */
668 goto again;
669 case OBJECT_TYPE_SEQUENCE:
670 output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE;
671 output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long));
672 output->u.sequence.nr_elem = *(unsigned long *) ax->u.ptr.ptr;
673 output->u.sequence.nested_type = ax->u.ptr.field->type.u.sequence_nestable.elem_type;
674 break;
675 case OBJECT_TYPE_ARRAY:
676 /* Skip count (unsigned long) */
677 output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE;
678 output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long));
679 output->u.sequence.nr_elem = ax->u.ptr.field->type.u.array_nestable.length;
680 output->u.sequence.nested_type = ax->u.ptr.field->type.u.array_nestable.elem_type;
681 break;
682 case OBJECT_TYPE_STRUCT:
683 case OBJECT_TYPE_VARIANT:
684 default:
685 return -EINVAL;
686 }
687
688 break;
689 case REG_STAR_GLOB_STRING:
690 case REG_UNKNOWN:
691 default:
692 return -EINVAL;
693 }
694
695 return LTTNG_FILTER_RECORD_FLAG;
696 }
697
698 /*
699 * Return 0 (discard), or raise the 0x1 flag (log event).
700 * Currently, other flags are kept for future extensions and have no
701 * effect.
702 */
703 static
704 uint64_t bytecode_interpret(void *interpreter_data,
705 const char *interpreter_stack_data,
706 struct lttng_interpreter_output *output)
707 {
708 struct bytecode_runtime *bytecode = interpreter_data;
709 struct lttng_ctx *ctx = rcu_dereference(*bytecode->p.pctx);
710 void *pc, *next_pc, *start_pc;
711 int ret = -EINVAL;
712 uint64_t retval = 0;
713 struct estack _stack;
714 struct estack *stack = &_stack;
715 register int64_t ax = 0, bx = 0;
716 register enum entry_type ax_t = REG_UNKNOWN, bx_t = REG_UNKNOWN;
717 register int top = FILTER_STACK_EMPTY;
718 #ifndef INTERPRETER_USE_SWITCH
719 static void *dispatch[NR_FILTER_OPS] = {
720 [ FILTER_OP_UNKNOWN ] = &&LABEL_FILTER_OP_UNKNOWN,
721
722 [ FILTER_OP_RETURN ] = &&LABEL_FILTER_OP_RETURN,
723
724 /* binary */
725 [ FILTER_OP_MUL ] = &&LABEL_FILTER_OP_MUL,
726 [ FILTER_OP_DIV ] = &&LABEL_FILTER_OP_DIV,
727 [ FILTER_OP_MOD ] = &&LABEL_FILTER_OP_MOD,
728 [ FILTER_OP_PLUS ] = &&LABEL_FILTER_OP_PLUS,
729 [ FILTER_OP_MINUS ] = &&LABEL_FILTER_OP_MINUS,
730 [ FILTER_OP_BIT_RSHIFT ] = &&LABEL_FILTER_OP_BIT_RSHIFT,
731 [ FILTER_OP_BIT_LSHIFT ] = &&LABEL_FILTER_OP_BIT_LSHIFT,
732 [ FILTER_OP_BIT_AND ] = &&LABEL_FILTER_OP_BIT_AND,
733 [ FILTER_OP_BIT_OR ] = &&LABEL_FILTER_OP_BIT_OR,
734 [ FILTER_OP_BIT_XOR ] = &&LABEL_FILTER_OP_BIT_XOR,
735
736 /* binary comparators */
737 [ FILTER_OP_EQ ] = &&LABEL_FILTER_OP_EQ,
738 [ FILTER_OP_NE ] = &&LABEL_FILTER_OP_NE,
739 [ FILTER_OP_GT ] = &&LABEL_FILTER_OP_GT,
740 [ FILTER_OP_LT ] = &&LABEL_FILTER_OP_LT,
741 [ FILTER_OP_GE ] = &&LABEL_FILTER_OP_GE,
742 [ FILTER_OP_LE ] = &&LABEL_FILTER_OP_LE,
743
744 /* string binary comparator */
745 [ FILTER_OP_EQ_STRING ] = &&LABEL_FILTER_OP_EQ_STRING,
746 [ FILTER_OP_NE_STRING ] = &&LABEL_FILTER_OP_NE_STRING,
747 [ FILTER_OP_GT_STRING ] = &&LABEL_FILTER_OP_GT_STRING,
748 [ FILTER_OP_LT_STRING ] = &&LABEL_FILTER_OP_LT_STRING,
749 [ FILTER_OP_GE_STRING ] = &&LABEL_FILTER_OP_GE_STRING,
750 [ FILTER_OP_LE_STRING ] = &&LABEL_FILTER_OP_LE_STRING,
751
752 /* globbing pattern binary comparator */
753 [ FILTER_OP_EQ_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_EQ_STAR_GLOB_STRING,
754 [ FILTER_OP_NE_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_NE_STAR_GLOB_STRING,
755
756 /* s64 binary comparator */
757 [ FILTER_OP_EQ_S64 ] = &&LABEL_FILTER_OP_EQ_S64,
758 [ FILTER_OP_NE_S64 ] = &&LABEL_FILTER_OP_NE_S64,
759 [ FILTER_OP_GT_S64 ] = &&LABEL_FILTER_OP_GT_S64,
760 [ FILTER_OP_LT_S64 ] = &&LABEL_FILTER_OP_LT_S64,
761 [ FILTER_OP_GE_S64 ] = &&LABEL_FILTER_OP_GE_S64,
762 [ FILTER_OP_LE_S64 ] = &&LABEL_FILTER_OP_LE_S64,
763
764 /* double binary comparator */
765 [ FILTER_OP_EQ_DOUBLE ] = &&LABEL_FILTER_OP_EQ_DOUBLE,
766 [ FILTER_OP_NE_DOUBLE ] = &&LABEL_FILTER_OP_NE_DOUBLE,
767 [ FILTER_OP_GT_DOUBLE ] = &&LABEL_FILTER_OP_GT_DOUBLE,
768 [ FILTER_OP_LT_DOUBLE ] = &&LABEL_FILTER_OP_LT_DOUBLE,
769 [ FILTER_OP_GE_DOUBLE ] = &&LABEL_FILTER_OP_GE_DOUBLE,
770 [ FILTER_OP_LE_DOUBLE ] = &&LABEL_FILTER_OP_LE_DOUBLE,
771
772 /* Mixed S64-double binary comparators */
773 [ FILTER_OP_EQ_DOUBLE_S64 ] = &&LABEL_FILTER_OP_EQ_DOUBLE_S64,
774 [ FILTER_OP_NE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_NE_DOUBLE_S64,
775 [ FILTER_OP_GT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GT_DOUBLE_S64,
776 [ FILTER_OP_LT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LT_DOUBLE_S64,
777 [ FILTER_OP_GE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GE_DOUBLE_S64,
778 [ FILTER_OP_LE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LE_DOUBLE_S64,
779
780 [ FILTER_OP_EQ_S64_DOUBLE ] = &&LABEL_FILTER_OP_EQ_S64_DOUBLE,
781 [ FILTER_OP_NE_S64_DOUBLE ] = &&LABEL_FILTER_OP_NE_S64_DOUBLE,
782 [ FILTER_OP_GT_S64_DOUBLE ] = &&LABEL_FILTER_OP_GT_S64_DOUBLE,
783 [ FILTER_OP_LT_S64_DOUBLE ] = &&LABEL_FILTER_OP_LT_S64_DOUBLE,
784 [ FILTER_OP_GE_S64_DOUBLE ] = &&LABEL_FILTER_OP_GE_S64_DOUBLE,
785 [ FILTER_OP_LE_S64_DOUBLE ] = &&LABEL_FILTER_OP_LE_S64_DOUBLE,
786
787 /* unary */
788 [ FILTER_OP_UNARY_PLUS ] = &&LABEL_FILTER_OP_UNARY_PLUS,
789 [ FILTER_OP_UNARY_MINUS ] = &&LABEL_FILTER_OP_UNARY_MINUS,
790 [ FILTER_OP_UNARY_NOT ] = &&LABEL_FILTER_OP_UNARY_NOT,
791 [ FILTER_OP_UNARY_PLUS_S64 ] = &&LABEL_FILTER_OP_UNARY_PLUS_S64,
792 [ FILTER_OP_UNARY_MINUS_S64 ] = &&LABEL_FILTER_OP_UNARY_MINUS_S64,
793 [ FILTER_OP_UNARY_NOT_S64 ] = &&LABEL_FILTER_OP_UNARY_NOT_S64,
794 [ FILTER_OP_UNARY_PLUS_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_PLUS_DOUBLE,
795 [ FILTER_OP_UNARY_MINUS_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_MINUS_DOUBLE,
796 [ FILTER_OP_UNARY_NOT_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_NOT_DOUBLE,
797
798 /* logical */
799 [ FILTER_OP_AND ] = &&LABEL_FILTER_OP_AND,
800 [ FILTER_OP_OR ] = &&LABEL_FILTER_OP_OR,
801
802 /* load field ref */
803 [ FILTER_OP_LOAD_FIELD_REF ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF,
804 [ FILTER_OP_LOAD_FIELD_REF_STRING ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_STRING,
805 [ FILTER_OP_LOAD_FIELD_REF_SEQUENCE ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_SEQUENCE,
806 [ FILTER_OP_LOAD_FIELD_REF_S64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_S64,
807 [ FILTER_OP_LOAD_FIELD_REF_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_DOUBLE,
808
809 /* load from immediate operand */
810 [ FILTER_OP_LOAD_STRING ] = &&LABEL_FILTER_OP_LOAD_STRING,
811 [ FILTER_OP_LOAD_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_LOAD_STAR_GLOB_STRING,
812 [ FILTER_OP_LOAD_S64 ] = &&LABEL_FILTER_OP_LOAD_S64,
813 [ FILTER_OP_LOAD_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_DOUBLE,
814
815 /* cast */
816 [ FILTER_OP_CAST_TO_S64 ] = &&LABEL_FILTER_OP_CAST_TO_S64,
817 [ FILTER_OP_CAST_DOUBLE_TO_S64 ] = &&LABEL_FILTER_OP_CAST_DOUBLE_TO_S64,
818 [ FILTER_OP_CAST_NOP ] = &&LABEL_FILTER_OP_CAST_NOP,
819
820 /* get context ref */
821 [ FILTER_OP_GET_CONTEXT_REF ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF,
822 [ FILTER_OP_GET_CONTEXT_REF_STRING ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_STRING,
823 [ FILTER_OP_GET_CONTEXT_REF_S64 ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_S64,
824 [ FILTER_OP_GET_CONTEXT_REF_DOUBLE ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_DOUBLE,
825
826 /* Instructions for recursive traversal through composed types. */
827 [ FILTER_OP_GET_CONTEXT_ROOT ] = &&LABEL_FILTER_OP_GET_CONTEXT_ROOT,
828 [ FILTER_OP_GET_APP_CONTEXT_ROOT ] = &&LABEL_FILTER_OP_GET_APP_CONTEXT_ROOT,
829 [ FILTER_OP_GET_PAYLOAD_ROOT ] = &&LABEL_FILTER_OP_GET_PAYLOAD_ROOT,
830
831 [ FILTER_OP_GET_SYMBOL ] = &&LABEL_FILTER_OP_GET_SYMBOL,
832 [ FILTER_OP_GET_SYMBOL_FIELD ] = &&LABEL_FILTER_OP_GET_SYMBOL_FIELD,
833 [ FILTER_OP_GET_INDEX_U16 ] = &&LABEL_FILTER_OP_GET_INDEX_U16,
834 [ FILTER_OP_GET_INDEX_U64 ] = &&LABEL_FILTER_OP_GET_INDEX_U64,
835
836 [ FILTER_OP_LOAD_FIELD ] = &&LABEL_FILTER_OP_LOAD_FIELD,
837 [ FILTER_OP_LOAD_FIELD_S8 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S8,
838 [ FILTER_OP_LOAD_FIELD_S16 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S16,
839 [ FILTER_OP_LOAD_FIELD_S32 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S32,
840 [ FILTER_OP_LOAD_FIELD_S64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S64,
841 [ FILTER_OP_LOAD_FIELD_U8 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U8,
842 [ FILTER_OP_LOAD_FIELD_U16 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U16,
843 [ FILTER_OP_LOAD_FIELD_U32 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U32,
844 [ FILTER_OP_LOAD_FIELD_U64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U64,
845 [ FILTER_OP_LOAD_FIELD_STRING ] = &&LABEL_FILTER_OP_LOAD_FIELD_STRING,
846 [ FILTER_OP_LOAD_FIELD_SEQUENCE ] = &&LABEL_FILTER_OP_LOAD_FIELD_SEQUENCE,
847 [ FILTER_OP_LOAD_FIELD_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_FIELD_DOUBLE,
848
849 [ FILTER_OP_UNARY_BIT_NOT ] = &&LABEL_FILTER_OP_UNARY_BIT_NOT,
850
851 [ FILTER_OP_RETURN_S64 ] = &&LABEL_FILTER_OP_RETURN_S64,
852 };
853 #endif /* #ifndef INTERPRETER_USE_SWITCH */
854
855 START_OP
856
857 OP(FILTER_OP_UNKNOWN):
858 OP(FILTER_OP_LOAD_FIELD_REF):
859 #ifdef INTERPRETER_USE_SWITCH
860 default:
861 #endif /* INTERPRETER_USE_SWITCH */
862 ERR("unknown bytecode op %u",
863 (unsigned int) *(filter_opcode_t *) pc);
864 ret = -EINVAL;
865 goto end;
866
867 OP(FILTER_OP_RETURN):
868 /* LTTNG_FILTER_DISCARD or LTTNG_FILTER_RECORD_FLAG */
869 /* Handle dynamic typing. */
870 switch (estack_ax_t) {
871 case REG_S64:
872 case REG_U64:
873 retval = !!estack_ax_v;
874 break;
875 case REG_DOUBLE:
876 case REG_STRING:
877 case REG_PTR:
878 if (!output) {
879 ret = -EINVAL;
880 goto end;
881 }
882 retval = 0;
883 break;
884 case REG_STAR_GLOB_STRING:
885 case REG_UNKNOWN:
886 default:
887 ret = -EINVAL;
888 goto end;
889 }
890 ret = 0;
891 goto end;
892
893 OP(FILTER_OP_RETURN_S64):
894 /* LTTNG_FILTER_DISCARD or LTTNG_FILTER_RECORD_FLAG */
895 retval = !!estack_ax_v;
896 ret = 0;
897 goto end;
898
899 /* binary */
900 OP(FILTER_OP_MUL):
901 OP(FILTER_OP_DIV):
902 OP(FILTER_OP_MOD):
903 OP(FILTER_OP_PLUS):
904 OP(FILTER_OP_MINUS):
905 ERR("unsupported bytecode op %u",
906 (unsigned int) *(filter_opcode_t *) pc);
907 ret = -EINVAL;
908 goto end;
909
910 OP(FILTER_OP_EQ):
911 {
912 /* Dynamic typing. */
913 switch (estack_ax_t) {
914 case REG_S64: /* Fall-through */
915 case REG_U64:
916 switch (estack_bx_t) {
917 case REG_S64: /* Fall-through */
918 case REG_U64:
919 JUMP_TO(FILTER_OP_EQ_S64);
920 case REG_DOUBLE:
921 JUMP_TO(FILTER_OP_EQ_DOUBLE_S64);
922 case REG_STRING: /* Fall-through */
923 case REG_STAR_GLOB_STRING:
924 ret = -EINVAL;
925 goto end;
926 default:
927 ERR("Unknown filter register type (%d)",
928 (int) estack_bx_t);
929 ret = -EINVAL;
930 goto end;
931 }
932 break;
933 case REG_DOUBLE:
934 switch (estack_bx_t) {
935 case REG_S64: /* Fall-through */
936 case REG_U64:
937 JUMP_TO(FILTER_OP_EQ_S64_DOUBLE);
938 case REG_DOUBLE:
939 JUMP_TO(FILTER_OP_EQ_DOUBLE);
940 case REG_STRING: /* Fall-through */
941 case REG_STAR_GLOB_STRING:
942 ret = -EINVAL;
943 goto end;
944 default:
945 ERR("Unknown filter register type (%d)",
946 (int) estack_bx_t);
947 ret = -EINVAL;
948 goto end;
949 }
950 break;
951 case REG_STRING:
952 switch (estack_bx_t) {
953 case REG_S64: /* Fall-through */
954 case REG_U64: /* Fall-through */
955 case REG_DOUBLE:
956 ret = -EINVAL;
957 goto end;
958 case REG_STRING:
959 JUMP_TO(FILTER_OP_EQ_STRING);
960 case REG_STAR_GLOB_STRING:
961 JUMP_TO(FILTER_OP_EQ_STAR_GLOB_STRING);
962 default:
963 ERR("Unknown filter register type (%d)",
964 (int) estack_bx_t);
965 ret = -EINVAL;
966 goto end;
967 }
968 break;
969 case REG_STAR_GLOB_STRING:
970 switch (estack_bx_t) {
971 case REG_S64: /* Fall-through */
972 case REG_U64: /* Fall-through */
973 case REG_DOUBLE:
974 ret = -EINVAL;
975 goto end;
976 case REG_STRING:
977 JUMP_TO(FILTER_OP_EQ_STAR_GLOB_STRING);
978 case REG_STAR_GLOB_STRING:
979 ret = -EINVAL;
980 goto end;
981 default:
982 ERR("Unknown filter register type (%d)",
983 (int) estack_bx_t);
984 ret = -EINVAL;
985 goto end;
986 }
987 break;
988 default:
989 ERR("Unknown filter register type (%d)",
990 (int) estack_ax_t);
991 ret = -EINVAL;
992 goto end;
993 }
994 }
995 OP(FILTER_OP_NE):
996 {
997 /* Dynamic typing. */
998 switch (estack_ax_t) {
999 case REG_S64: /* Fall-through */
1000 case REG_U64:
1001 switch (estack_bx_t) {
1002 case REG_S64: /* Fall-through */
1003 case REG_U64:
1004 JUMP_TO(FILTER_OP_NE_S64);
1005 case REG_DOUBLE:
1006 JUMP_TO(FILTER_OP_NE_DOUBLE_S64);
1007 case REG_STRING: /* Fall-through */
1008 case REG_STAR_GLOB_STRING:
1009 ret = -EINVAL;
1010 goto end;
1011 default:
1012 ERR("Unknown filter register type (%d)",
1013 (int) estack_bx_t);
1014 ret = -EINVAL;
1015 goto end;
1016 }
1017 break;
1018 case REG_DOUBLE:
1019 switch (estack_bx_t) {
1020 case REG_S64: /* Fall-through */
1021 case REG_U64:
1022 JUMP_TO(FILTER_OP_NE_S64_DOUBLE);
1023 case REG_DOUBLE:
1024 JUMP_TO(FILTER_OP_NE_DOUBLE);
1025 case REG_STRING: /* Fall-through */
1026 case REG_STAR_GLOB_STRING:
1027 ret = -EINVAL;
1028 goto end;
1029 default:
1030 ERR("Unknown filter register type (%d)",
1031 (int) estack_bx_t);
1032 ret = -EINVAL;
1033 goto end;
1034 }
1035 break;
1036 case REG_STRING:
1037 switch (estack_bx_t) {
1038 case REG_S64: /* Fall-through */
1039 case REG_U64:
1040 case REG_DOUBLE:
1041 ret = -EINVAL;
1042 goto end;
1043 case REG_STRING:
1044 JUMP_TO(FILTER_OP_NE_STRING);
1045 case REG_STAR_GLOB_STRING:
1046 JUMP_TO(FILTER_OP_NE_STAR_GLOB_STRING);
1047 default:
1048 ERR("Unknown filter register type (%d)",
1049 (int) estack_bx_t);
1050 ret = -EINVAL;
1051 goto end;
1052 }
1053 break;
1054 case REG_STAR_GLOB_STRING:
1055 switch (estack_bx_t) {
1056 case REG_S64: /* Fall-through */
1057 case REG_U64:
1058 case REG_DOUBLE:
1059 ret = -EINVAL;
1060 goto end;
1061 case REG_STRING:
1062 JUMP_TO(FILTER_OP_NE_STAR_GLOB_STRING);
1063 case REG_STAR_GLOB_STRING:
1064 ret = -EINVAL;
1065 goto end;
1066 default:
1067 ERR("Unknown filter register type (%d)",
1068 (int) estack_bx_t);
1069 ret = -EINVAL;
1070 goto end;
1071 }
1072 break;
1073 default:
1074 ERR("Unknown filter register type (%d)",
1075 (int) estack_ax_t);
1076 ret = -EINVAL;
1077 goto end;
1078 }
1079 }
1080 OP(FILTER_OP_GT):
1081 {
1082 /* Dynamic typing. */
1083 switch (estack_ax_t) {
1084 case REG_S64: /* Fall-through */
1085 case REG_U64:
1086 switch (estack_bx_t) {
1087 case REG_S64: /* Fall-through */
1088 case REG_U64:
1089 JUMP_TO(FILTER_OP_GT_S64);
1090 case REG_DOUBLE:
1091 JUMP_TO(FILTER_OP_GT_DOUBLE_S64);
1092 case REG_STRING: /* Fall-through */
1093 case REG_STAR_GLOB_STRING:
1094 ret = -EINVAL;
1095 goto end;
1096 default:
1097 ERR("Unknown filter register type (%d)",
1098 (int) estack_bx_t);
1099 ret = -EINVAL;
1100 goto end;
1101 }
1102 break;
1103 case REG_DOUBLE:
1104 switch (estack_bx_t) {
1105 case REG_S64: /* Fall-through */
1106 case REG_U64:
1107 JUMP_TO(FILTER_OP_GT_S64_DOUBLE);
1108 case REG_DOUBLE:
1109 JUMP_TO(FILTER_OP_GT_DOUBLE);
1110 case REG_STRING: /* Fall-through */
1111 case REG_STAR_GLOB_STRING:
1112 ret = -EINVAL;
1113 goto end;
1114 default:
1115 ERR("Unknown filter register type (%d)",
1116 (int) estack_bx_t);
1117 ret = -EINVAL;
1118 goto end;
1119 }
1120 break;
1121 case REG_STRING:
1122 switch (estack_bx_t) {
1123 case REG_S64: /* Fall-through */
1124 case REG_U64: /* Fall-through */
1125 case REG_DOUBLE: /* Fall-through */
1126 case REG_STAR_GLOB_STRING:
1127 ret = -EINVAL;
1128 goto end;
1129 case REG_STRING:
1130 JUMP_TO(FILTER_OP_GT_STRING);
1131 default:
1132 ERR("Unknown filter register type (%d)",
1133 (int) estack_bx_t);
1134 ret = -EINVAL;
1135 goto end;
1136 }
1137 break;
1138 default:
1139 ERR("Unknown filter register type (%d)",
1140 (int) estack_ax_t);
1141 ret = -EINVAL;
1142 goto end;
1143 }
1144 }
1145 OP(FILTER_OP_LT):
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(FILTER_OP_LT_S64);
1155 case REG_DOUBLE:
1156 JUMP_TO(FILTER_OP_LT_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 filter 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(FILTER_OP_LT_S64_DOUBLE);
1173 case REG_DOUBLE:
1174 JUMP_TO(FILTER_OP_LT_DOUBLE);
1175 case REG_STRING: /* Fall-through */
1176 case REG_STAR_GLOB_STRING:
1177 ret = -EINVAL;
1178 goto end;
1179 default:
1180 ERR("Unknown filter 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(FILTER_OP_LT_STRING);
1196 default:
1197 ERR("Unknown filter register type (%d)",
1198 (int) estack_bx_t);
1199 ret = -EINVAL;
1200 goto end;
1201 }
1202 break;
1203 default:
1204 ERR("Unknown filter register type (%d)",
1205 (int) estack_ax_t);
1206 ret = -EINVAL;
1207 goto end;
1208 }
1209 }
1210 OP(FILTER_OP_GE):
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(FILTER_OP_GE_S64);
1220 case REG_DOUBLE:
1221 JUMP_TO(FILTER_OP_GE_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 filter 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(FILTER_OP_GE_S64_DOUBLE);
1238 case REG_DOUBLE:
1239 JUMP_TO(FILTER_OP_GE_DOUBLE);
1240 case REG_STRING: /* Fall-through */
1241 case REG_STAR_GLOB_STRING:
1242 ret = -EINVAL;
1243 goto end;
1244 default:
1245 ERR("Unknown filter 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(FILTER_OP_GE_STRING);
1261 default:
1262 ERR("Unknown filter register type (%d)",
1263 (int) estack_bx_t);
1264 ret = -EINVAL;
1265 goto end;
1266 }
1267 break;
1268 default:
1269 ERR("Unknown filter register type (%d)",
1270 (int) estack_ax_t);
1271 ret = -EINVAL;
1272 goto end;
1273 }
1274 }
1275 OP(FILTER_OP_LE):
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(FILTER_OP_LE_S64);
1285 case REG_DOUBLE:
1286 JUMP_TO(FILTER_OP_LE_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 filter 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(FILTER_OP_LE_S64_DOUBLE);
1303 case REG_DOUBLE:
1304 JUMP_TO(FILTER_OP_LE_DOUBLE);
1305 case REG_STRING: /* Fall-through */
1306 case REG_STAR_GLOB_STRING:
1307 ret = -EINVAL;
1308 goto end;
1309 default:
1310 ERR("Unknown filter 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(FILTER_OP_LE_STRING);
1326 default:
1327 ERR("Unknown filter register type (%d)",
1328 (int) estack_bx_t);
1329 ret = -EINVAL;
1330 goto end;
1331 }
1332 break;
1333 default:
1334 ERR("Unknown filter register type (%d)",
1335 (int) estack_ax_t);
1336 ret = -EINVAL;
1337 goto end;
1338 }
1339 }
1340
1341 OP(FILTER_OP_EQ_STRING):
1342 {
1343 int res;
1344
1345 res = (stack_strcmp(stack, top, "==") == 0);
1346 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1347 estack_ax_v = res;
1348 estack_ax_t = REG_S64;
1349 next_pc += sizeof(struct binary_op);
1350 PO;
1351 }
1352 OP(FILTER_OP_NE_STRING):
1353 {
1354 int res;
1355
1356 res = (stack_strcmp(stack, top, "!=") != 0);
1357 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1358 estack_ax_v = res;
1359 estack_ax_t = REG_S64;
1360 next_pc += sizeof(struct binary_op);
1361 PO;
1362 }
1363 OP(FILTER_OP_GT_STRING):
1364 {
1365 int res;
1366
1367 res = (stack_strcmp(stack, top, ">") > 0);
1368 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1369 estack_ax_v = res;
1370 estack_ax_t = REG_S64;
1371 next_pc += sizeof(struct binary_op);
1372 PO;
1373 }
1374 OP(FILTER_OP_LT_STRING):
1375 {
1376 int res;
1377
1378 res = (stack_strcmp(stack, top, "<") < 0);
1379 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1380 estack_ax_v = res;
1381 estack_ax_t = REG_S64;
1382 next_pc += sizeof(struct binary_op);
1383 PO;
1384 }
1385 OP(FILTER_OP_GE_STRING):
1386 {
1387 int res;
1388
1389 res = (stack_strcmp(stack, top, ">=") >= 0);
1390 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1391 estack_ax_v = res;
1392 estack_ax_t = REG_S64;
1393 next_pc += sizeof(struct binary_op);
1394 PO;
1395 }
1396 OP(FILTER_OP_LE_STRING):
1397 {
1398 int res;
1399
1400 res = (stack_strcmp(stack, top, "<=") <= 0);
1401 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1402 estack_ax_v = res;
1403 estack_ax_t = REG_S64;
1404 next_pc += sizeof(struct binary_op);
1405 PO;
1406 }
1407
1408 OP(FILTER_OP_EQ_STAR_GLOB_STRING):
1409 {
1410 int res;
1411
1412 res = (stack_star_glob_match(stack, top, "==") == 0);
1413 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1414 estack_ax_v = res;
1415 estack_ax_t = REG_S64;
1416 next_pc += sizeof(struct binary_op);
1417 PO;
1418 }
1419 OP(FILTER_OP_NE_STAR_GLOB_STRING):
1420 {
1421 int res;
1422
1423 res = (stack_star_glob_match(stack, top, "!=") != 0);
1424 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1425 estack_ax_v = res;
1426 estack_ax_t = REG_S64;
1427 next_pc += sizeof(struct binary_op);
1428 PO;
1429 }
1430
1431 OP(FILTER_OP_EQ_S64):
1432 {
1433 int res;
1434
1435 res = (estack_bx_v == estack_ax_v);
1436 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1437 estack_ax_v = res;
1438 estack_ax_t = REG_S64;
1439 next_pc += sizeof(struct binary_op);
1440 PO;
1441 }
1442 OP(FILTER_OP_NE_S64):
1443 {
1444 int res;
1445
1446 res = (estack_bx_v != estack_ax_v);
1447 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1448 estack_ax_v = res;
1449 estack_ax_t = REG_S64;
1450 next_pc += sizeof(struct binary_op);
1451 PO;
1452 }
1453 OP(FILTER_OP_GT_S64):
1454 {
1455 int res;
1456
1457 res = (estack_bx_v > estack_ax_v);
1458 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1459 estack_ax_v = res;
1460 estack_ax_t = REG_S64;
1461 next_pc += sizeof(struct binary_op);
1462 PO;
1463 }
1464 OP(FILTER_OP_LT_S64):
1465 {
1466 int res;
1467
1468 res = (estack_bx_v < estack_ax_v);
1469 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1470 estack_ax_v = res;
1471 estack_ax_t = REG_S64;
1472 next_pc += sizeof(struct binary_op);
1473 PO;
1474 }
1475 OP(FILTER_OP_GE_S64):
1476 {
1477 int res;
1478
1479 res = (estack_bx_v >= estack_ax_v);
1480 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1481 estack_ax_v = res;
1482 estack_ax_t = REG_S64;
1483 next_pc += sizeof(struct binary_op);
1484 PO;
1485 }
1486 OP(FILTER_OP_LE_S64):
1487 {
1488 int res;
1489
1490 res = (estack_bx_v <= estack_ax_v);
1491 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1492 estack_ax_v = res;
1493 estack_ax_t = REG_S64;
1494 next_pc += sizeof(struct binary_op);
1495 PO;
1496 }
1497
1498 OP(FILTER_OP_EQ_DOUBLE):
1499 {
1500 int res;
1501
1502 res = (estack_bx(stack, top)->u.d == estack_ax(stack, top)->u.d);
1503 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1504 estack_ax_v = res;
1505 estack_ax_t = REG_S64;
1506 next_pc += sizeof(struct binary_op);
1507 PO;
1508 }
1509 OP(FILTER_OP_NE_DOUBLE):
1510 {
1511 int res;
1512
1513 res = (estack_bx(stack, top)->u.d != estack_ax(stack, top)->u.d);
1514 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1515 estack_ax_v = res;
1516 estack_ax_t = REG_S64;
1517 next_pc += sizeof(struct binary_op);
1518 PO;
1519 }
1520 OP(FILTER_OP_GT_DOUBLE):
1521 {
1522 int res;
1523
1524 res = (estack_bx(stack, top)->u.d > estack_ax(stack, top)->u.d);
1525 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1526 estack_ax_v = res;
1527 estack_ax_t = REG_S64;
1528 next_pc += sizeof(struct binary_op);
1529 PO;
1530 }
1531 OP(FILTER_OP_LT_DOUBLE):
1532 {
1533 int res;
1534
1535 res = (estack_bx(stack, top)->u.d < estack_ax(stack, top)->u.d);
1536 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1537 estack_ax_v = res;
1538 estack_ax_t = REG_S64;
1539 next_pc += sizeof(struct binary_op);
1540 PO;
1541 }
1542 OP(FILTER_OP_GE_DOUBLE):
1543 {
1544 int res;
1545
1546 res = (estack_bx(stack, top)->u.d >= estack_ax(stack, top)->u.d);
1547 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1548 estack_ax_v = res;
1549 estack_ax_t = REG_S64;
1550 next_pc += sizeof(struct binary_op);
1551 PO;
1552 }
1553 OP(FILTER_OP_LE_DOUBLE):
1554 {
1555 int res;
1556
1557 res = (estack_bx(stack, top)->u.d <= estack_ax(stack, top)->u.d);
1558 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1559 estack_ax_v = res;
1560 estack_ax_t = REG_S64;
1561 next_pc += sizeof(struct binary_op);
1562 PO;
1563 }
1564
1565 /* Mixed S64-double binary comparators */
1566 OP(FILTER_OP_EQ_DOUBLE_S64):
1567 {
1568 int res;
1569
1570 res = (estack_bx(stack, top)->u.d == estack_ax_v);
1571 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1572 estack_ax_v = res;
1573 estack_ax_t = REG_S64;
1574 next_pc += sizeof(struct binary_op);
1575 PO;
1576 }
1577 OP(FILTER_OP_NE_DOUBLE_S64):
1578 {
1579 int res;
1580
1581 res = (estack_bx(stack, top)->u.d != estack_ax_v);
1582 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1583 estack_ax_v = res;
1584 estack_ax_t = REG_S64;
1585 next_pc += sizeof(struct binary_op);
1586 PO;
1587 }
1588 OP(FILTER_OP_GT_DOUBLE_S64):
1589 {
1590 int res;
1591
1592 res = (estack_bx(stack, top)->u.d > estack_ax_v);
1593 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1594 estack_ax_v = res;
1595 estack_ax_t = REG_S64;
1596 next_pc += sizeof(struct binary_op);
1597 PO;
1598 }
1599 OP(FILTER_OP_LT_DOUBLE_S64):
1600 {
1601 int res;
1602
1603 res = (estack_bx(stack, top)->u.d < estack_ax_v);
1604 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1605 estack_ax_v = res;
1606 estack_ax_t = REG_S64;
1607 next_pc += sizeof(struct binary_op);
1608 PO;
1609 }
1610 OP(FILTER_OP_GE_DOUBLE_S64):
1611 {
1612 int res;
1613
1614 res = (estack_bx(stack, top)->u.d >= estack_ax_v);
1615 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1616 estack_ax_v = res;
1617 estack_ax_t = REG_S64;
1618 next_pc += sizeof(struct binary_op);
1619 PO;
1620 }
1621 OP(FILTER_OP_LE_DOUBLE_S64):
1622 {
1623 int res;
1624
1625 res = (estack_bx(stack, top)->u.d <= estack_ax_v);
1626 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1627 estack_ax_v = res;
1628 estack_ax_t = REG_S64;
1629 next_pc += sizeof(struct binary_op);
1630 PO;
1631 }
1632
1633 OP(FILTER_OP_EQ_S64_DOUBLE):
1634 {
1635 int res;
1636
1637 res = (estack_bx_v == estack_ax(stack, top)->u.d);
1638 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1639 estack_ax_v = res;
1640 estack_ax_t = REG_S64;
1641 next_pc += sizeof(struct binary_op);
1642 PO;
1643 }
1644 OP(FILTER_OP_NE_S64_DOUBLE):
1645 {
1646 int res;
1647
1648 res = (estack_bx_v != estack_ax(stack, top)->u.d);
1649 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1650 estack_ax_v = res;
1651 estack_ax_t = REG_S64;
1652 next_pc += sizeof(struct binary_op);
1653 PO;
1654 }
1655 OP(FILTER_OP_GT_S64_DOUBLE):
1656 {
1657 int res;
1658
1659 res = (estack_bx_v > estack_ax(stack, top)->u.d);
1660 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1661 estack_ax_v = res;
1662 estack_ax_t = REG_S64;
1663 next_pc += sizeof(struct binary_op);
1664 PO;
1665 }
1666 OP(FILTER_OP_LT_S64_DOUBLE):
1667 {
1668 int res;
1669
1670 res = (estack_bx_v < estack_ax(stack, top)->u.d);
1671 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1672 estack_ax_v = res;
1673 estack_ax_t = REG_S64;
1674 next_pc += sizeof(struct binary_op);
1675 PO;
1676 }
1677 OP(FILTER_OP_GE_S64_DOUBLE):
1678 {
1679 int res;
1680
1681 res = (estack_bx_v >= estack_ax(stack, top)->u.d);
1682 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1683 estack_ax_v = res;
1684 estack_ax_t = REG_S64;
1685 next_pc += sizeof(struct binary_op);
1686 PO;
1687 }
1688 OP(FILTER_OP_LE_S64_DOUBLE):
1689 {
1690 int res;
1691
1692 res = (estack_bx_v <= estack_ax(stack, top)->u.d);
1693 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1694 estack_ax_v = res;
1695 estack_ax_t = REG_S64;
1696 next_pc += sizeof(struct binary_op);
1697 PO;
1698 }
1699 OP(FILTER_OP_BIT_RSHIFT):
1700 {
1701 int64_t res;
1702
1703 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1704 ret = -EINVAL;
1705 goto end;
1706 }
1707
1708 /* Catch undefined behavior. */
1709 if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
1710 ret = -EINVAL;
1711 goto end;
1712 }
1713 res = ((uint64_t) estack_bx_v >> (uint32_t) estack_ax_v);
1714 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1715 estack_ax_v = res;
1716 estack_ax_t = REG_U64;
1717 next_pc += sizeof(struct binary_op);
1718 PO;
1719 }
1720 OP(FILTER_OP_BIT_LSHIFT):
1721 {
1722 int64_t res;
1723
1724 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1725 ret = -EINVAL;
1726 goto end;
1727 }
1728
1729 /* Catch undefined behavior. */
1730 if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) {
1731 ret = -EINVAL;
1732 goto end;
1733 }
1734 res = ((uint64_t) estack_bx_v << (uint32_t) estack_ax_v);
1735 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1736 estack_ax_v = res;
1737 estack_ax_t = REG_U64;
1738 next_pc += sizeof(struct binary_op);
1739 PO;
1740 }
1741 OP(FILTER_OP_BIT_AND):
1742 {
1743 int64_t res;
1744
1745 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1746 ret = -EINVAL;
1747 goto end;
1748 }
1749
1750 res = ((uint64_t) estack_bx_v & (uint64_t) estack_ax_v);
1751 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1752 estack_ax_v = res;
1753 estack_ax_t = REG_U64;
1754 next_pc += sizeof(struct binary_op);
1755 PO;
1756 }
1757 OP(FILTER_OP_BIT_OR):
1758 {
1759 int64_t res;
1760
1761 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1762 ret = -EINVAL;
1763 goto end;
1764 }
1765
1766 res = ((uint64_t) estack_bx_v | (uint64_t) estack_ax_v);
1767 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1768 estack_ax_v = res;
1769 estack_ax_t = REG_U64;
1770 next_pc += sizeof(struct binary_op);
1771 PO;
1772 }
1773 OP(FILTER_OP_BIT_XOR):
1774 {
1775 int64_t res;
1776
1777 if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) {
1778 ret = -EINVAL;
1779 goto end;
1780 }
1781
1782 res = ((uint64_t) estack_bx_v ^ (uint64_t) estack_ax_v);
1783 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1784 estack_ax_v = res;
1785 estack_ax_t = REG_U64;
1786 next_pc += sizeof(struct binary_op);
1787 PO;
1788 }
1789
1790 /* unary */
1791 OP(FILTER_OP_UNARY_PLUS):
1792 {
1793 /* Dynamic typing. */
1794 switch (estack_ax_t) {
1795 case REG_S64: /* Fall-through. */
1796 case REG_U64:
1797 JUMP_TO(FILTER_OP_UNARY_PLUS_S64);
1798 case REG_DOUBLE:
1799 JUMP_TO(FILTER_OP_UNARY_PLUS_DOUBLE);
1800 case REG_STRING: /* Fall-through */
1801 case REG_STAR_GLOB_STRING:
1802 ret = -EINVAL;
1803 goto end;
1804 default:
1805 ERR("Unknown filter register type (%d)",
1806 (int) estack_ax_t);
1807 ret = -EINVAL;
1808 goto end;
1809 }
1810 }
1811 OP(FILTER_OP_UNARY_MINUS):
1812 {
1813 /* Dynamic typing. */
1814 switch (estack_ax_t) {
1815 case REG_S64: /* Fall-through. */
1816 case REG_U64:
1817 JUMP_TO(FILTER_OP_UNARY_MINUS_S64);
1818 case REG_DOUBLE:
1819 JUMP_TO(FILTER_OP_UNARY_MINUS_DOUBLE);
1820 case REG_STRING: /* Fall-through */
1821 case REG_STAR_GLOB_STRING:
1822 ret = -EINVAL;
1823 goto end;
1824 default:
1825 ERR("Unknown filter register type (%d)",
1826 (int) estack_ax_t);
1827 ret = -EINVAL;
1828 goto end;
1829 }
1830 }
1831 OP(FILTER_OP_UNARY_NOT):
1832 {
1833 /* Dynamic typing. */
1834 switch (estack_ax_t) {
1835 case REG_S64: /* Fall-through. */
1836 case REG_U64:
1837 JUMP_TO(FILTER_OP_UNARY_NOT_S64);
1838 case REG_DOUBLE:
1839 JUMP_TO(FILTER_OP_UNARY_NOT_DOUBLE);
1840 case REG_STRING: /* Fall-through */
1841 case REG_STAR_GLOB_STRING:
1842 ret = -EINVAL;
1843 goto end;
1844 default:
1845 ERR("Unknown filter register type (%d)",
1846 (int) estack_ax_t);
1847 ret = -EINVAL;
1848 goto end;
1849 }
1850 next_pc += sizeof(struct unary_op);
1851 PO;
1852 }
1853
1854 OP(FILTER_OP_UNARY_BIT_NOT):
1855 {
1856 /* Dynamic typing. */
1857 if (!IS_INTEGER_REGISTER(estack_ax_t)) {
1858 ret = -EINVAL;
1859 goto end;
1860 }
1861
1862 estack_ax_v = ~(uint64_t) estack_ax_v;
1863 estack_ax_t = REG_U64;
1864 next_pc += sizeof(struct unary_op);
1865 PO;
1866 }
1867
1868 OP(FILTER_OP_UNARY_PLUS_S64):
1869 OP(FILTER_OP_UNARY_PLUS_DOUBLE):
1870 {
1871 next_pc += sizeof(struct unary_op);
1872 PO;
1873 }
1874 OP(FILTER_OP_UNARY_MINUS_S64):
1875 {
1876 estack_ax_v = -estack_ax_v;
1877 next_pc += sizeof(struct unary_op);
1878 PO;
1879 }
1880 OP(FILTER_OP_UNARY_MINUS_DOUBLE):
1881 {
1882 estack_ax(stack, top)->u.d = -estack_ax(stack, top)->u.d;
1883 next_pc += sizeof(struct unary_op);
1884 PO;
1885 }
1886 OP(FILTER_OP_UNARY_NOT_S64):
1887 {
1888 estack_ax_v = !estack_ax_v;
1889 estack_ax_t = REG_S64;
1890 next_pc += sizeof(struct unary_op);
1891 PO;
1892 }
1893 OP(FILTER_OP_UNARY_NOT_DOUBLE):
1894 {
1895 estack_ax_v = !estack_ax(stack, top)->u.d;
1896 estack_ax_t = REG_S64;
1897 next_pc += sizeof(struct unary_op);
1898 PO;
1899 }
1900
1901 /* logical */
1902 OP(FILTER_OP_AND):
1903 {
1904 struct logical_op *insn = (struct logical_op *) pc;
1905
1906 if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) {
1907 ret = -EINVAL;
1908 goto end;
1909 }
1910 /* If AX is 0, skip and evaluate to 0 */
1911 if (unlikely(estack_ax_v == 0)) {
1912 dbg_printf("Jumping to bytecode offset %u\n",
1913 (unsigned int) insn->skip_offset);
1914 next_pc = start_pc + insn->skip_offset;
1915 } else {
1916 /* Pop 1 when jump not taken */
1917 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1918 next_pc += sizeof(struct logical_op);
1919 }
1920 PO;
1921 }
1922 OP(FILTER_OP_OR):
1923 {
1924 struct logical_op *insn = (struct logical_op *) pc;
1925
1926 if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) {
1927 ret = -EINVAL;
1928 goto end;
1929 }
1930 /* If AX is nonzero, skip and evaluate to 1 */
1931 if (unlikely(estack_ax_v != 0)) {
1932 estack_ax_v = 1;
1933 dbg_printf("Jumping to bytecode offset %u\n",
1934 (unsigned int) insn->skip_offset);
1935 next_pc = start_pc + insn->skip_offset;
1936 } else {
1937 /* Pop 1 when jump not taken */
1938 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1939 next_pc += sizeof(struct logical_op);
1940 }
1941 PO;
1942 }
1943
1944
1945 /* load field ref */
1946 OP(FILTER_OP_LOAD_FIELD_REF_STRING):
1947 {
1948 struct load_op *insn = (struct load_op *) pc;
1949 struct field_ref *ref = (struct field_ref *) insn->data;
1950
1951 dbg_printf("load field ref offset %u type string\n",
1952 ref->offset);
1953 estack_push(stack, top, ax, bx, ax_t, bx_t);
1954 estack_ax(stack, top)->u.s.str =
1955 *(const char * const *) &interpreter_stack_data[ref->offset];
1956 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1957 dbg_printf("Filter warning: loading a NULL string.\n");
1958 ret = -EINVAL;
1959 goto end;
1960 }
1961 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1962 estack_ax(stack, top)->u.s.literal_type =
1963 ESTACK_STRING_LITERAL_TYPE_NONE;
1964 estack_ax_t = REG_STRING;
1965 dbg_printf("ref load string %s\n", estack_ax(stack, top)->u.s.str);
1966 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1967 PO;
1968 }
1969
1970 OP(FILTER_OP_LOAD_FIELD_REF_SEQUENCE):
1971 {
1972 struct load_op *insn = (struct load_op *) pc;
1973 struct field_ref *ref = (struct field_ref *) insn->data;
1974
1975 dbg_printf("load field ref offset %u type sequence\n",
1976 ref->offset);
1977 estack_push(stack, top, ax, bx, ax_t, bx_t);
1978 estack_ax(stack, top)->u.s.seq_len =
1979 *(unsigned long *) &interpreter_stack_data[ref->offset];
1980 estack_ax(stack, top)->u.s.str =
1981 *(const char **) (&interpreter_stack_data[ref->offset
1982 + sizeof(unsigned long)]);
1983 estack_ax_t = REG_STRING;
1984 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1985 dbg_printf("Filter warning: loading a NULL sequence.\n");
1986 ret = -EINVAL;
1987 goto end;
1988 }
1989 estack_ax(stack, top)->u.s.literal_type =
1990 ESTACK_STRING_LITERAL_TYPE_NONE;
1991 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1992 PO;
1993 }
1994
1995 OP(FILTER_OP_LOAD_FIELD_REF_S64):
1996 {
1997 struct load_op *insn = (struct load_op *) pc;
1998 struct field_ref *ref = (struct field_ref *) insn->data;
1999
2000 dbg_printf("load field ref offset %u type s64\n",
2001 ref->offset);
2002 estack_push(stack, top, ax, bx, ax_t, bx_t);
2003 estack_ax_v =
2004 ((struct literal_numeric *) &interpreter_stack_data[ref->offset])->v;
2005 estack_ax_t = REG_S64;
2006 dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax_v);
2007 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2008 PO;
2009 }
2010
2011 OP(FILTER_OP_LOAD_FIELD_REF_DOUBLE):
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 double\n",
2017 ref->offset);
2018 estack_push(stack, top, ax, bx, ax_t, bx_t);
2019 memcpy(&estack_ax(stack, top)->u.d, &interpreter_stack_data[ref->offset],
2020 sizeof(struct literal_double));
2021 estack_ax_t = REG_DOUBLE;
2022 dbg_printf("ref load double %g\n", estack_ax(stack, top)->u.d);
2023 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2024 PO;
2025 }
2026
2027 /* load from immediate operand */
2028 OP(FILTER_OP_LOAD_STRING):
2029 {
2030 struct load_op *insn = (struct load_op *) pc;
2031
2032 dbg_printf("load string %s\n", insn->data);
2033 estack_push(stack, top, ax, bx, ax_t, bx_t);
2034 estack_ax(stack, top)->u.s.str = insn->data;
2035 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2036 estack_ax(stack, top)->u.s.literal_type =
2037 ESTACK_STRING_LITERAL_TYPE_PLAIN;
2038 estack_ax_t = REG_STRING;
2039 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
2040 PO;
2041 }
2042
2043 OP(FILTER_OP_LOAD_STAR_GLOB_STRING):
2044 {
2045 struct load_op *insn = (struct load_op *) pc;
2046
2047 dbg_printf("load globbing pattern %s\n", insn->data);
2048 estack_push(stack, top, ax, bx, ax_t, bx_t);
2049 estack_ax(stack, top)->u.s.str = insn->data;
2050 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2051 estack_ax(stack, top)->u.s.literal_type =
2052 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB;
2053 estack_ax_t = REG_STAR_GLOB_STRING;
2054 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
2055 PO;
2056 }
2057
2058 OP(FILTER_OP_LOAD_S64):
2059 {
2060 struct load_op *insn = (struct load_op *) pc;
2061
2062 estack_push(stack, top, ax, bx, ax_t, bx_t);
2063 estack_ax_v = ((struct literal_numeric *) insn->data)->v;
2064 estack_ax_t = REG_S64;
2065 dbg_printf("load s64 %" PRIi64 "\n", estack_ax_v);
2066 next_pc += sizeof(struct load_op)
2067 + sizeof(struct literal_numeric);
2068 PO;
2069 }
2070
2071 OP(FILTER_OP_LOAD_DOUBLE):
2072 {
2073 struct load_op *insn = (struct load_op *) pc;
2074
2075 estack_push(stack, top, ax, bx, ax_t, bx_t);
2076 memcpy(&estack_ax(stack, top)->u.d, insn->data,
2077 sizeof(struct literal_double));
2078 estack_ax_t = REG_DOUBLE;
2079 dbg_printf("load double %g\n", estack_ax(stack, top)->u.d);
2080 next_pc += sizeof(struct load_op)
2081 + sizeof(struct literal_double);
2082 PO;
2083 }
2084
2085 /* cast */
2086 OP(FILTER_OP_CAST_TO_S64):
2087 {
2088 /* Dynamic typing. */
2089 switch (estack_ax_t) {
2090 case REG_S64:
2091 JUMP_TO(FILTER_OP_CAST_NOP);
2092 case REG_DOUBLE:
2093 JUMP_TO(FILTER_OP_CAST_DOUBLE_TO_S64);
2094 case REG_U64:
2095 estack_ax_t = REG_S64;
2096 next_pc += sizeof(struct cast_op);
2097 case REG_STRING: /* Fall-through */
2098 case REG_STAR_GLOB_STRING:
2099 ret = -EINVAL;
2100 goto end;
2101 default:
2102 ERR("Unknown filter register type (%d)",
2103 (int) estack_ax_t);
2104 ret = -EINVAL;
2105 goto end;
2106 }
2107 }
2108
2109 OP(FILTER_OP_CAST_DOUBLE_TO_S64):
2110 {
2111 estack_ax_v = (int64_t) estack_ax(stack, top)->u.d;
2112 estack_ax_t = REG_S64;
2113 next_pc += sizeof(struct cast_op);
2114 PO;
2115 }
2116
2117 OP(FILTER_OP_CAST_NOP):
2118 {
2119 next_pc += sizeof(struct cast_op);
2120 PO;
2121 }
2122
2123 /* get context ref */
2124 OP(FILTER_OP_GET_CONTEXT_REF):
2125 {
2126 struct load_op *insn = (struct load_op *) pc;
2127 struct field_ref *ref = (struct field_ref *) insn->data;
2128 struct lttng_ctx_field *ctx_field;
2129 struct lttng_ctx_value v;
2130
2131 dbg_printf("get context ref offset %u type dynamic\n",
2132 ref->offset);
2133 ctx_field = &ctx->fields[ref->offset];
2134 ctx_field->get_value(ctx_field, &v);
2135 estack_push(stack, top, ax, bx, ax_t, bx_t);
2136 switch (v.sel) {
2137 case LTTNG_UST_DYNAMIC_TYPE_NONE:
2138 ret = -EINVAL;
2139 goto end;
2140 case LTTNG_UST_DYNAMIC_TYPE_S64:
2141 estack_ax_v = v.u.s64;
2142 estack_ax_t = REG_S64;
2143 dbg_printf("ref get context dynamic s64 %" PRIi64 "\n", estack_ax_v);
2144 break;
2145 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
2146 estack_ax(stack, top)->u.d = v.u.d;
2147 estack_ax_t = REG_DOUBLE;
2148 dbg_printf("ref get context dynamic double %g\n", estack_ax(stack, top)->u.d);
2149 break;
2150 case LTTNG_UST_DYNAMIC_TYPE_STRING:
2151 estack_ax(stack, top)->u.s.str = v.u.str;
2152 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2153 dbg_printf("Filter warning: loading a NULL string.\n");
2154 ret = -EINVAL;
2155 goto end;
2156 }
2157 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2158 estack_ax(stack, top)->u.s.literal_type =
2159 ESTACK_STRING_LITERAL_TYPE_NONE;
2160 dbg_printf("ref get context dynamic string %s\n", estack_ax(stack, top)->u.s.str);
2161 estack_ax_t = REG_STRING;
2162 break;
2163 default:
2164 dbg_printf("Filter warning: unknown dynamic type (%d).\n", (int) v.sel);
2165 ret = -EINVAL;
2166 goto end;
2167 }
2168 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2169 PO;
2170 }
2171
2172 OP(FILTER_OP_GET_CONTEXT_REF_STRING):
2173 {
2174 struct load_op *insn = (struct load_op *) pc;
2175 struct field_ref *ref = (struct field_ref *) insn->data;
2176 struct lttng_ctx_field *ctx_field;
2177 struct lttng_ctx_value v;
2178
2179 dbg_printf("get context ref offset %u type string\n",
2180 ref->offset);
2181 ctx_field = &ctx->fields[ref->offset];
2182 ctx_field->get_value(ctx_field, &v);
2183 estack_push(stack, top, ax, bx, ax_t, bx_t);
2184 estack_ax(stack, top)->u.s.str = v.u.str;
2185 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2186 dbg_printf("Filter warning: loading a NULL string.\n");
2187 ret = -EINVAL;
2188 goto end;
2189 }
2190 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2191 estack_ax(stack, top)->u.s.literal_type =
2192 ESTACK_STRING_LITERAL_TYPE_NONE;
2193 estack_ax_t = REG_STRING;
2194 dbg_printf("ref get context string %s\n", estack_ax(stack, top)->u.s.str);
2195 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2196 PO;
2197 }
2198
2199 OP(FILTER_OP_GET_CONTEXT_REF_S64):
2200 {
2201 struct load_op *insn = (struct load_op *) pc;
2202 struct field_ref *ref = (struct field_ref *) insn->data;
2203 struct lttng_ctx_field *ctx_field;
2204 struct lttng_ctx_value v;
2205
2206 dbg_printf("get context ref offset %u type s64\n",
2207 ref->offset);
2208 ctx_field = &ctx->fields[ref->offset];
2209 ctx_field->get_value(ctx_field, &v);
2210 estack_push(stack, top, ax, bx, ax_t, bx_t);
2211 estack_ax_v = v.u.s64;
2212 estack_ax_t = REG_S64;
2213 dbg_printf("ref get context s64 %" PRIi64 "\n", estack_ax_v);
2214 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2215 PO;
2216 }
2217
2218 OP(FILTER_OP_GET_CONTEXT_REF_DOUBLE):
2219 {
2220 struct load_op *insn = (struct load_op *) pc;
2221 struct field_ref *ref = (struct field_ref *) insn->data;
2222 struct lttng_ctx_field *ctx_field;
2223 struct lttng_ctx_value v;
2224
2225 dbg_printf("get context ref offset %u type double\n",
2226 ref->offset);
2227 ctx_field = &ctx->fields[ref->offset];
2228 ctx_field->get_value(ctx_field, &v);
2229 estack_push(stack, top, ax, bx, ax_t, bx_t);
2230 memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double));
2231 estack_ax_t = REG_DOUBLE;
2232 dbg_printf("ref get context double %g\n", estack_ax(stack, top)->u.d);
2233 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2234 PO;
2235 }
2236
2237 OP(FILTER_OP_GET_CONTEXT_ROOT):
2238 {
2239 dbg_printf("op get context root\n");
2240 estack_push(stack, top, ax, bx, ax_t, bx_t);
2241 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_CONTEXT;
2242 /* "field" only needed for variants. */
2243 estack_ax(stack, top)->u.ptr.field = NULL;
2244 estack_ax_t = REG_PTR;
2245 next_pc += sizeof(struct load_op);
2246 PO;
2247 }
2248
2249 OP(FILTER_OP_GET_APP_CONTEXT_ROOT):
2250 {
2251 dbg_printf("op get app context root\n");
2252 estack_push(stack, top, ax, bx, ax_t, bx_t);
2253 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_APP_CONTEXT;
2254 /* "field" only needed for variants. */
2255 estack_ax(stack, top)->u.ptr.field = NULL;
2256 estack_ax_t = REG_PTR;
2257 next_pc += sizeof(struct load_op);
2258 PO;
2259 }
2260
2261 OP(FILTER_OP_GET_PAYLOAD_ROOT):
2262 {
2263 dbg_printf("op get app payload root\n");
2264 estack_push(stack, top, ax, bx, ax_t, bx_t);
2265 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_PAYLOAD;
2266 estack_ax(stack, top)->u.ptr.ptr = interpreter_stack_data;
2267 /* "field" only needed for variants. */
2268 estack_ax(stack, top)->u.ptr.field = NULL;
2269 estack_ax_t = REG_PTR;
2270 next_pc += sizeof(struct load_op);
2271 PO;
2272 }
2273
2274 OP(FILTER_OP_GET_SYMBOL):
2275 {
2276 dbg_printf("op get symbol\n");
2277 switch (estack_ax(stack, top)->u.ptr.type) {
2278 case LOAD_OBJECT:
2279 ERR("Nested fields not implemented yet.");
2280 ret = -EINVAL;
2281 goto end;
2282 case LOAD_ROOT_CONTEXT:
2283 case LOAD_ROOT_APP_CONTEXT:
2284 case LOAD_ROOT_PAYLOAD:
2285 /*
2286 * symbol lookup is performed by
2287 * specialization.
2288 */
2289 ret = -EINVAL;
2290 goto end;
2291 }
2292 next_pc += sizeof(struct load_op) + sizeof(struct get_symbol);
2293 PO;
2294 }
2295
2296 OP(FILTER_OP_GET_SYMBOL_FIELD):
2297 {
2298 /*
2299 * Used for first variant encountered in a
2300 * traversal. Variants are not implemented yet.
2301 */
2302 ret = -EINVAL;
2303 goto end;
2304 }
2305
2306 OP(FILTER_OP_GET_INDEX_U16):
2307 {
2308 struct load_op *insn = (struct load_op *) pc;
2309 struct get_index_u16 *index = (struct get_index_u16 *) insn->data;
2310
2311 dbg_printf("op get index u16\n");
2312 ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top));
2313 if (ret)
2314 goto end;
2315 estack_ax_v = estack_ax(stack, top)->u.v;
2316 estack_ax_t = estack_ax(stack, top)->type;
2317 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u16);
2318 PO;
2319 }
2320
2321 OP(FILTER_OP_GET_INDEX_U64):
2322 {
2323 struct load_op *insn = (struct load_op *) pc;
2324 struct get_index_u64 *index = (struct get_index_u64 *) insn->data;
2325
2326 dbg_printf("op get index u64\n");
2327 ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top));
2328 if (ret)
2329 goto end;
2330 estack_ax_v = estack_ax(stack, top)->u.v;
2331 estack_ax_t = estack_ax(stack, top)->type;
2332 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u64);
2333 PO;
2334 }
2335
2336 OP(FILTER_OP_LOAD_FIELD):
2337 {
2338 dbg_printf("op load field\n");
2339 ret = dynamic_load_field(estack_ax(stack, top));
2340 if (ret)
2341 goto end;
2342 estack_ax_v = estack_ax(stack, top)->u.v;
2343 estack_ax_t = estack_ax(stack, top)->type;
2344 next_pc += sizeof(struct load_op);
2345 PO;
2346 }
2347
2348 OP(FILTER_OP_LOAD_FIELD_S8):
2349 {
2350 dbg_printf("op load field s8\n");
2351
2352 estack_ax_v = *(int8_t *) estack_ax(stack, top)->u.ptr.ptr;
2353 estack_ax_t = REG_S64;
2354 next_pc += sizeof(struct load_op);
2355 PO;
2356 }
2357 OP(FILTER_OP_LOAD_FIELD_S16):
2358 {
2359 dbg_printf("op load field s16\n");
2360
2361 estack_ax_v = *(int16_t *) estack_ax(stack, top)->u.ptr.ptr;
2362 estack_ax_t = REG_S64;
2363 next_pc += sizeof(struct load_op);
2364 PO;
2365 }
2366 OP(FILTER_OP_LOAD_FIELD_S32):
2367 {
2368 dbg_printf("op load field s32\n");
2369
2370 estack_ax_v = *(int32_t *) estack_ax(stack, top)->u.ptr.ptr;
2371 estack_ax_t = REG_S64;
2372 next_pc += sizeof(struct load_op);
2373 PO;
2374 }
2375 OP(FILTER_OP_LOAD_FIELD_S64):
2376 {
2377 dbg_printf("op load field s64\n");
2378
2379 estack_ax_v = *(int64_t *) estack_ax(stack, top)->u.ptr.ptr;
2380 estack_ax_t = REG_S64;
2381 next_pc += sizeof(struct load_op);
2382 PO;
2383 }
2384 OP(FILTER_OP_LOAD_FIELD_U8):
2385 {
2386 dbg_printf("op load field u8\n");
2387
2388 estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr;
2389 estack_ax_t = REG_U64;
2390 next_pc += sizeof(struct load_op);
2391 PO;
2392 }
2393 OP(FILTER_OP_LOAD_FIELD_U16):
2394 {
2395 dbg_printf("op load field u16\n");
2396
2397 estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr;
2398 estack_ax_t = REG_U64;
2399 next_pc += sizeof(struct load_op);
2400 PO;
2401 }
2402 OP(FILTER_OP_LOAD_FIELD_U32):
2403 {
2404 dbg_printf("op load field u32\n");
2405
2406 estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr;
2407 estack_ax_t = REG_U64;
2408 next_pc += sizeof(struct load_op);
2409 PO;
2410 }
2411 OP(FILTER_OP_LOAD_FIELD_U64):
2412 {
2413 dbg_printf("op load field u64\n");
2414
2415 estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr;
2416 estack_ax_t = REG_U64;
2417 next_pc += sizeof(struct load_op);
2418 PO;
2419 }
2420 OP(FILTER_OP_LOAD_FIELD_DOUBLE):
2421 {
2422 dbg_printf("op load field double\n");
2423
2424 memcpy(&estack_ax(stack, top)->u.d,
2425 estack_ax(stack, top)->u.ptr.ptr,
2426 sizeof(struct literal_double));
2427 estack_ax(stack, top)->type = REG_DOUBLE;
2428 next_pc += sizeof(struct load_op);
2429 PO;
2430 }
2431
2432 OP(FILTER_OP_LOAD_FIELD_STRING):
2433 {
2434 const char *str;
2435
2436 dbg_printf("op load field string\n");
2437 str = (const char *) estack_ax(stack, top)->u.ptr.ptr;
2438 estack_ax(stack, top)->u.s.str = str;
2439 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2440 dbg_printf("Filter warning: loading a NULL string.\n");
2441 ret = -EINVAL;
2442 goto end;
2443 }
2444 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2445 estack_ax(stack, top)->u.s.literal_type =
2446 ESTACK_STRING_LITERAL_TYPE_NONE;
2447 estack_ax(stack, top)->type = REG_STRING;
2448 next_pc += sizeof(struct load_op);
2449 PO;
2450 }
2451
2452 OP(FILTER_OP_LOAD_FIELD_SEQUENCE):
2453 {
2454 const char *ptr;
2455
2456 dbg_printf("op load field string sequence\n");
2457 ptr = estack_ax(stack, top)->u.ptr.ptr;
2458 estack_ax(stack, top)->u.s.seq_len = *(unsigned long *) ptr;
2459 estack_ax(stack, top)->u.s.str = *(const char **) (ptr + sizeof(unsigned long));
2460 estack_ax(stack, top)->type = REG_STRING;
2461 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2462 dbg_printf("Filter warning: loading a NULL sequence.\n");
2463 ret = -EINVAL;
2464 goto end;
2465 }
2466 estack_ax(stack, top)->u.s.literal_type =
2467 ESTACK_STRING_LITERAL_TYPE_NONE;
2468 next_pc += sizeof(struct load_op);
2469 PO;
2470 }
2471
2472 END_OP
2473 end:
2474 /* Return _DISCARD on error. */
2475 if (ret)
2476 return LTTNG_FILTER_DISCARD;
2477
2478 if (output) {
2479 return lttng_bytecode_interpret_format_output(estack_ax(stack, top),
2480 output);
2481 }
2482
2483 return retval;
2484 }
2485
2486 uint64_t lttng_filter_interpret_bytecode(void *filter_data,
2487 const char *filter_stack_data)
2488 {
2489 return bytecode_interpret(filter_data, filter_stack_data, NULL);
2490 }
2491
2492 #undef START_OP
2493 #undef OP
2494 #undef PO
2495 #undef END_OP
This page took 0.140899 seconds and 4 git commands to generate.