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