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