Filter: index array, sequences, implement bitwise binary operators
[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_RSHIFT ] = &&LABEL_FILTER_OP_RSHIFT,
626 [ FILTER_OP_LSHIFT ] = &&LABEL_FILTER_OP_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 #endif /* #ifndef INTERPRETER_USE_SWITCH */
745
746 START_OP
747
748 OP(FILTER_OP_UNKNOWN):
749 OP(FILTER_OP_LOAD_FIELD_REF):
750 #ifdef INTERPRETER_USE_SWITCH
751 default:
752 #endif /* INTERPRETER_USE_SWITCH */
753 ERR("unknown bytecode op %u",
754 (unsigned int) *(filter_opcode_t *) pc);
755 ret = -EINVAL;
756 goto end;
757
758 OP(FILTER_OP_RETURN):
759 /* LTTNG_FILTER_DISCARD or LTTNG_FILTER_RECORD_FLAG */
760 /* Handle dynamic typing. */
761 switch (estack_ax_t) {
762 case REG_S64:
763 retval = !!estack_ax_v;
764 break;
765 case REG_DOUBLE:
766 case REG_STRING:
767 case REG_STAR_GLOB_STRING:
768 default:
769 ret = -EINVAL;
770 goto end;
771 }
772 ret = 0;
773 goto end;
774
775 /* binary */
776 OP(FILTER_OP_MUL):
777 OP(FILTER_OP_DIV):
778 OP(FILTER_OP_MOD):
779 OP(FILTER_OP_PLUS):
780 OP(FILTER_OP_MINUS):
781 OP(FILTER_OP_RSHIFT):
782 OP(FILTER_OP_LSHIFT):
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_AND):
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_OR):
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_XOR):
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
1603 /* unary */
1604 OP(FILTER_OP_UNARY_PLUS):
1605 {
1606 /* Dynamic typing. */
1607 switch (estack_ax_t) {
1608 case REG_S64: /* Fall-through. */
1609 JUMP_TO(FILTER_OP_UNARY_PLUS_S64);
1610 case REG_DOUBLE:
1611 JUMP_TO(FILTER_OP_UNARY_PLUS_DOUBLE);
1612 case REG_STRING: /* Fall-through */
1613 case REG_STAR_GLOB_STRING:
1614 ret = -EINVAL;
1615 goto end;
1616 default:
1617 ERR("Unknown filter register type (%d)",
1618 (int) estack_ax_t);
1619 ret = -EINVAL;
1620 goto end;
1621 }
1622 }
1623 OP(FILTER_OP_UNARY_MINUS):
1624 {
1625 /* Dynamic typing. */
1626 switch (estack_ax_t) {
1627 case REG_S64:
1628 JUMP_TO(FILTER_OP_UNARY_MINUS_S64);
1629 case REG_DOUBLE:
1630 JUMP_TO(FILTER_OP_UNARY_MINUS_DOUBLE);
1631 case REG_STRING: /* Fall-through */
1632 case REG_STAR_GLOB_STRING:
1633 ret = -EINVAL;
1634 goto end;
1635 default:
1636 ERR("Unknown filter register type (%d)",
1637 (int) estack_ax_t);
1638 ret = -EINVAL;
1639 goto end;
1640 }
1641 }
1642 OP(FILTER_OP_UNARY_NOT):
1643 {
1644 /* Dynamic typing. */
1645 switch (estack_ax_t) {
1646 case REG_S64:
1647 JUMP_TO(FILTER_OP_UNARY_NOT_S64);
1648 case REG_DOUBLE:
1649 JUMP_TO(FILTER_OP_UNARY_NOT_DOUBLE);
1650 case REG_STRING: /* Fall-through */
1651 case REG_STAR_GLOB_STRING:
1652 ret = -EINVAL;
1653 goto end;
1654 default:
1655 ERR("Unknown filter register type (%d)",
1656 (int) estack_ax_t);
1657 ret = -EINVAL;
1658 goto end;
1659 }
1660 next_pc += sizeof(struct unary_op);
1661 PO;
1662 }
1663
1664 OP(FILTER_OP_UNARY_PLUS_S64):
1665 OP(FILTER_OP_UNARY_PLUS_DOUBLE):
1666 {
1667 next_pc += sizeof(struct unary_op);
1668 PO;
1669 }
1670 OP(FILTER_OP_UNARY_MINUS_S64):
1671 {
1672 estack_ax_v = -estack_ax_v;
1673 next_pc += sizeof(struct unary_op);
1674 PO;
1675 }
1676 OP(FILTER_OP_UNARY_MINUS_DOUBLE):
1677 {
1678 estack_ax(stack, top)->u.d = -estack_ax(stack, top)->u.d;
1679 next_pc += sizeof(struct unary_op);
1680 PO;
1681 }
1682 OP(FILTER_OP_UNARY_NOT_S64):
1683 {
1684 estack_ax_v = !estack_ax_v;
1685 next_pc += sizeof(struct unary_op);
1686 PO;
1687 }
1688 OP(FILTER_OP_UNARY_NOT_DOUBLE):
1689 {
1690 estack_ax_v = !estack_ax(stack, top)->u.d;
1691 estack_ax_t = REG_S64;
1692 next_pc += sizeof(struct unary_op);
1693 PO;
1694 }
1695
1696 /* logical */
1697 OP(FILTER_OP_AND):
1698 {
1699 struct logical_op *insn = (struct logical_op *) pc;
1700
1701 if (estack_ax_t != REG_S64) {
1702 ret = -EINVAL;
1703 goto end;
1704 }
1705 /* If AX is 0, skip and evaluate to 0 */
1706 if (unlikely(estack_ax_v == 0)) {
1707 dbg_printf("Jumping to bytecode offset %u\n",
1708 (unsigned int) insn->skip_offset);
1709 next_pc = start_pc + insn->skip_offset;
1710 } else {
1711 /* Pop 1 when jump not taken */
1712 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1713 next_pc += sizeof(struct logical_op);
1714 }
1715 PO;
1716 }
1717 OP(FILTER_OP_OR):
1718 {
1719 struct logical_op *insn = (struct logical_op *) pc;
1720
1721 if (estack_ax_t != REG_S64) {
1722 ret = -EINVAL;
1723 goto end;
1724 }
1725 /* If AX is nonzero, skip and evaluate to 1 */
1726 if (unlikely(estack_ax_v != 0)) {
1727 estack_ax_v = 1;
1728 dbg_printf("Jumping to bytecode offset %u\n",
1729 (unsigned int) insn->skip_offset);
1730 next_pc = start_pc + insn->skip_offset;
1731 } else {
1732 /* Pop 1 when jump not taken */
1733 estack_pop(stack, top, ax, bx, ax_t, bx_t);
1734 next_pc += sizeof(struct logical_op);
1735 }
1736 PO;
1737 }
1738
1739
1740 /* load field ref */
1741 OP(FILTER_OP_LOAD_FIELD_REF_STRING):
1742 {
1743 struct load_op *insn = (struct load_op *) pc;
1744 struct field_ref *ref = (struct field_ref *) insn->data;
1745
1746 dbg_printf("load field ref offset %u type string\n",
1747 ref->offset);
1748 estack_push(stack, top, ax, bx, ax_t, bx_t);
1749 estack_ax(stack, top)->u.s.str =
1750 *(const char * const *) &filter_stack_data[ref->offset];
1751 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1752 dbg_printf("Filter warning: loading a NULL string.\n");
1753 ret = -EINVAL;
1754 goto end;
1755 }
1756 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1757 estack_ax(stack, top)->u.s.literal_type =
1758 ESTACK_STRING_LITERAL_TYPE_NONE;
1759 estack_ax_t = REG_STRING;
1760 dbg_printf("ref load string %s\n", estack_ax(stack, top)->u.s.str);
1761 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1762 PO;
1763 }
1764
1765 OP(FILTER_OP_LOAD_FIELD_REF_SEQUENCE):
1766 {
1767 struct load_op *insn = (struct load_op *) pc;
1768 struct field_ref *ref = (struct field_ref *) insn->data;
1769
1770 dbg_printf("load field ref offset %u type sequence\n",
1771 ref->offset);
1772 estack_push(stack, top, ax, bx, ax_t, bx_t);
1773 estack_ax(stack, top)->u.s.seq_len =
1774 *(unsigned long *) &filter_stack_data[ref->offset];
1775 estack_ax(stack, top)->u.s.str =
1776 *(const char **) (&filter_stack_data[ref->offset
1777 + sizeof(unsigned long)]);
1778 estack_ax_t = REG_STRING;
1779 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1780 dbg_printf("Filter warning: loading a NULL sequence.\n");
1781 ret = -EINVAL;
1782 goto end;
1783 }
1784 estack_ax(stack, top)->u.s.literal_type =
1785 ESTACK_STRING_LITERAL_TYPE_NONE;
1786 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1787 PO;
1788 }
1789
1790 OP(FILTER_OP_LOAD_FIELD_REF_S64):
1791 {
1792 struct load_op *insn = (struct load_op *) pc;
1793 struct field_ref *ref = (struct field_ref *) insn->data;
1794
1795 dbg_printf("load field ref offset %u type s64\n",
1796 ref->offset);
1797 estack_push(stack, top, ax, bx, ax_t, bx_t);
1798 estack_ax_v =
1799 ((struct literal_numeric *) &filter_stack_data[ref->offset])->v;
1800 estack_ax_t = REG_S64;
1801 dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax_v);
1802 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1803 PO;
1804 }
1805
1806 OP(FILTER_OP_LOAD_FIELD_REF_DOUBLE):
1807 {
1808 struct load_op *insn = (struct load_op *) pc;
1809 struct field_ref *ref = (struct field_ref *) insn->data;
1810
1811 dbg_printf("load field ref offset %u type double\n",
1812 ref->offset);
1813 estack_push(stack, top, ax, bx, ax_t, bx_t);
1814 memcpy(&estack_ax(stack, top)->u.d, &filter_stack_data[ref->offset],
1815 sizeof(struct literal_double));
1816 estack_ax_t = REG_DOUBLE;
1817 dbg_printf("ref load double %g\n", estack_ax(stack, top)->u.d);
1818 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1819 PO;
1820 }
1821
1822 /* load from immediate operand */
1823 OP(FILTER_OP_LOAD_STRING):
1824 {
1825 struct load_op *insn = (struct load_op *) pc;
1826
1827 dbg_printf("load string %s\n", insn->data);
1828 estack_push(stack, top, ax, bx, ax_t, bx_t);
1829 estack_ax(stack, top)->u.s.str = insn->data;
1830 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1831 estack_ax(stack, top)->u.s.literal_type =
1832 ESTACK_STRING_LITERAL_TYPE_PLAIN;
1833 estack_ax_t = REG_STRING;
1834 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
1835 PO;
1836 }
1837
1838 OP(FILTER_OP_LOAD_STAR_GLOB_STRING):
1839 {
1840 struct load_op *insn = (struct load_op *) pc;
1841
1842 dbg_printf("load globbing pattern %s\n", insn->data);
1843 estack_push(stack, top, ax, bx, ax_t, bx_t);
1844 estack_ax(stack, top)->u.s.str = insn->data;
1845 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1846 estack_ax(stack, top)->u.s.literal_type =
1847 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB;
1848 estack_ax_t = REG_STAR_GLOB_STRING;
1849 next_pc += sizeof(struct load_op) + strlen(insn->data) + 1;
1850 PO;
1851 }
1852
1853 OP(FILTER_OP_LOAD_S64):
1854 {
1855 struct load_op *insn = (struct load_op *) pc;
1856
1857 estack_push(stack, top, ax, bx, ax_t, bx_t);
1858 estack_ax_v = ((struct literal_numeric *) insn->data)->v;
1859 estack_ax_t = REG_S64;
1860 dbg_printf("load s64 %" PRIi64 "\n", estack_ax_v);
1861 next_pc += sizeof(struct load_op)
1862 + sizeof(struct literal_numeric);
1863 PO;
1864 }
1865
1866 OP(FILTER_OP_LOAD_DOUBLE):
1867 {
1868 struct load_op *insn = (struct load_op *) pc;
1869
1870 estack_push(stack, top, ax, bx, ax_t, bx_t);
1871 memcpy(&estack_ax(stack, top)->u.d, insn->data,
1872 sizeof(struct literal_double));
1873 estack_ax_t = REG_DOUBLE;
1874 dbg_printf("load double %g\n", estack_ax(stack, top)->u.d);
1875 next_pc += sizeof(struct load_op)
1876 + sizeof(struct literal_double);
1877 PO;
1878 }
1879
1880 /* cast */
1881 OP(FILTER_OP_CAST_TO_S64):
1882 {
1883 /* Dynamic typing. */
1884 switch (estack_ax_t) {
1885 case REG_S64:
1886 JUMP_TO(FILTER_OP_CAST_NOP);
1887 case REG_DOUBLE:
1888 JUMP_TO(FILTER_OP_CAST_DOUBLE_TO_S64);
1889 case REG_STRING: /* Fall-through */
1890 case REG_STAR_GLOB_STRING:
1891 ret = -EINVAL;
1892 goto end;
1893 default:
1894 ERR("Unknown filter register type (%d)",
1895 (int) estack_ax_t);
1896 ret = -EINVAL;
1897 goto end;
1898 }
1899 }
1900
1901 OP(FILTER_OP_CAST_DOUBLE_TO_S64):
1902 {
1903 estack_ax_v = (int64_t) estack_ax(stack, top)->u.d;
1904 estack_ax_t = REG_S64;
1905 next_pc += sizeof(struct cast_op);
1906 PO;
1907 }
1908
1909 OP(FILTER_OP_CAST_NOP):
1910 {
1911 next_pc += sizeof(struct cast_op);
1912 PO;
1913 }
1914
1915 /* get context ref */
1916 OP(FILTER_OP_GET_CONTEXT_REF):
1917 {
1918 struct load_op *insn = (struct load_op *) pc;
1919 struct field_ref *ref = (struct field_ref *) insn->data;
1920 struct lttng_ctx *ctx;
1921 struct lttng_ctx_field *ctx_field;
1922 struct lttng_ctx_value v;
1923
1924 dbg_printf("get context ref offset %u type dynamic\n",
1925 ref->offset);
1926 ctx = rcu_dereference(session->ctx);
1927 ctx_field = &ctx->fields[ref->offset];
1928 ctx_field->get_value(ctx_field, &v);
1929 estack_push(stack, top, ax, bx, ax_t, bx_t);
1930 switch (v.sel) {
1931 case LTTNG_UST_DYNAMIC_TYPE_NONE:
1932 ret = -EINVAL;
1933 goto end;
1934 case LTTNG_UST_DYNAMIC_TYPE_S64:
1935 estack_ax_v = v.u.s64;
1936 estack_ax_t = REG_S64;
1937 dbg_printf("ref get context dynamic s64 %" PRIi64 "\n", estack_ax_v);
1938 break;
1939 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
1940 estack_ax(stack, top)->u.d = v.u.d;
1941 estack_ax_t = REG_DOUBLE;
1942 dbg_printf("ref get context dynamic double %g\n", estack_ax(stack, top)->u.d);
1943 break;
1944 case LTTNG_UST_DYNAMIC_TYPE_STRING:
1945 estack_ax(stack, top)->u.s.str = v.u.str;
1946 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1947 dbg_printf("Filter warning: loading a NULL string.\n");
1948 ret = -EINVAL;
1949 goto end;
1950 }
1951 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1952 estack_ax(stack, top)->u.s.literal_type =
1953 ESTACK_STRING_LITERAL_TYPE_NONE;
1954 dbg_printf("ref get context dynamic string %s\n", estack_ax(stack, top)->u.s.str);
1955 estack_ax_t = REG_STRING;
1956 break;
1957 default:
1958 dbg_printf("Filter warning: unknown dynamic type (%d).\n", (int) v.sel);
1959 ret = -EINVAL;
1960 goto end;
1961 }
1962 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1963 PO;
1964 }
1965
1966 OP(FILTER_OP_GET_CONTEXT_REF_STRING):
1967 {
1968 struct load_op *insn = (struct load_op *) pc;
1969 struct field_ref *ref = (struct field_ref *) insn->data;
1970 struct lttng_ctx *ctx;
1971 struct lttng_ctx_field *ctx_field;
1972 struct lttng_ctx_value v;
1973
1974 dbg_printf("get context ref offset %u type string\n",
1975 ref->offset);
1976 ctx = rcu_dereference(session->ctx);
1977 ctx_field = &ctx->fields[ref->offset];
1978 ctx_field->get_value(ctx_field, &v);
1979 estack_push(stack, top, ax, bx, ax_t, bx_t);
1980 estack_ax(stack, top)->u.s.str = v.u.str;
1981 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
1982 dbg_printf("Filter warning: loading a NULL string.\n");
1983 ret = -EINVAL;
1984 goto end;
1985 }
1986 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
1987 estack_ax(stack, top)->u.s.literal_type =
1988 ESTACK_STRING_LITERAL_TYPE_NONE;
1989 estack_ax_t = REG_STRING;
1990 dbg_printf("ref get context string %s\n", estack_ax(stack, top)->u.s.str);
1991 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
1992 PO;
1993 }
1994
1995 OP(FILTER_OP_GET_CONTEXT_REF_S64):
1996 {
1997 struct load_op *insn = (struct load_op *) pc;
1998 struct field_ref *ref = (struct field_ref *) insn->data;
1999 struct lttng_ctx *ctx;
2000 struct lttng_ctx_field *ctx_field;
2001 struct lttng_ctx_value v;
2002
2003 dbg_printf("get context ref offset %u type s64\n",
2004 ref->offset);
2005 ctx = rcu_dereference(session->ctx);
2006 ctx_field = &ctx->fields[ref->offset];
2007 ctx_field->get_value(ctx_field, &v);
2008 estack_push(stack, top, ax, bx, ax_t, bx_t);
2009 estack_ax_v = v.u.s64;
2010 estack_ax_t = REG_S64;
2011 dbg_printf("ref get context s64 %" PRIi64 "\n", estack_ax_v);
2012 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2013 PO;
2014 }
2015
2016 OP(FILTER_OP_GET_CONTEXT_REF_DOUBLE):
2017 {
2018 struct load_op *insn = (struct load_op *) pc;
2019 struct field_ref *ref = (struct field_ref *) insn->data;
2020 struct lttng_ctx *ctx;
2021 struct lttng_ctx_field *ctx_field;
2022 struct lttng_ctx_value v;
2023
2024 dbg_printf("get context ref offset %u type double\n",
2025 ref->offset);
2026 ctx = rcu_dereference(session->ctx);
2027 ctx_field = &ctx->fields[ref->offset];
2028 ctx_field->get_value(ctx_field, &v);
2029 estack_push(stack, top, ax, bx, ax_t, bx_t);
2030 memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double));
2031 estack_ax_t = REG_DOUBLE;
2032 dbg_printf("ref get context double %g\n", estack_ax(stack, top)->u.d);
2033 next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
2034 PO;
2035 }
2036
2037 OP(FILTER_OP_GET_CONTEXT_ROOT):
2038 {
2039 dbg_printf("op get context root\n");
2040 estack_push(stack, top, ax, bx, ax_t, bx_t);
2041 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_CONTEXT;
2042 /* "field" only needed for variants. */
2043 estack_ax(stack, top)->u.ptr.field = NULL;
2044 estack_ax_t = REG_PTR;
2045 next_pc += sizeof(struct load_op);
2046 PO;
2047 }
2048
2049 OP(FILTER_OP_GET_APP_CONTEXT_ROOT):
2050 {
2051 dbg_printf("op get app context root\n");
2052 estack_push(stack, top, ax, bx, ax_t, bx_t);
2053 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_APP_CONTEXT;
2054 /* "field" only needed for variants. */
2055 estack_ax(stack, top)->u.ptr.field = NULL;
2056 estack_ax_t = REG_PTR;
2057 next_pc += sizeof(struct load_op);
2058 PO;
2059 }
2060
2061 OP(FILTER_OP_GET_PAYLOAD_ROOT):
2062 {
2063 dbg_printf("op get app payload root\n");
2064 estack_push(stack, top, ax, bx, ax_t, bx_t);
2065 estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_PAYLOAD;
2066 estack_ax(stack, top)->u.ptr.ptr = filter_stack_data;
2067 /* "field" only needed for variants. */
2068 estack_ax(stack, top)->u.ptr.field = NULL;
2069 estack_ax_t = REG_PTR;
2070 next_pc += sizeof(struct load_op);
2071 PO;
2072 }
2073
2074 OP(FILTER_OP_GET_SYMBOL):
2075 {
2076 dbg_printf("op get symbol\n");
2077 switch (estack_ax(stack, top)->u.ptr.type) {
2078 case LOAD_OBJECT:
2079 ERR("Nested fields not implemented yet.");
2080 ret = -EINVAL;
2081 goto end;
2082 case LOAD_ROOT_CONTEXT:
2083 case LOAD_ROOT_APP_CONTEXT:
2084 case LOAD_ROOT_PAYLOAD:
2085 /*
2086 * symbol lookup is performed by
2087 * specialization.
2088 */
2089 ret = -EINVAL;
2090 goto end;
2091 }
2092 next_pc += sizeof(struct load_op) + sizeof(struct get_symbol);
2093 PO;
2094 }
2095
2096 OP(FILTER_OP_GET_SYMBOL_FIELD):
2097 {
2098 /*
2099 * Used for first variant encountered in a
2100 * traversal. Variants are not implemented yet.
2101 */
2102 ret = -EINVAL;
2103 goto end;
2104 }
2105
2106 OP(FILTER_OP_GET_INDEX_U16):
2107 {
2108 struct load_op *insn = (struct load_op *) pc;
2109 struct get_index_u16 *index = (struct get_index_u16 *) insn->data;
2110
2111 dbg_printf("op get index u16\n");
2112 ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top));
2113 if (ret)
2114 goto end;
2115 estack_ax_v = estack_ax(stack, top)->u.v;
2116 estack_ax_t = estack_ax(stack, top)->type;
2117 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u16);
2118 PO;
2119 }
2120
2121 OP(FILTER_OP_GET_INDEX_U64):
2122 {
2123 struct load_op *insn = (struct load_op *) pc;
2124 struct get_index_u64 *index = (struct get_index_u64 *) insn->data;
2125
2126 dbg_printf("op get index u64\n");
2127 ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top));
2128 if (ret)
2129 goto end;
2130 estack_ax_v = estack_ax(stack, top)->u.v;
2131 estack_ax_t = estack_ax(stack, top)->type;
2132 next_pc += sizeof(struct load_op) + sizeof(struct get_index_u64);
2133 PO;
2134 }
2135
2136 OP(FILTER_OP_LOAD_FIELD):
2137 {
2138 dbg_printf("op load field\n");
2139 ret = dynamic_load_field(estack_ax(stack, top));
2140 if (ret)
2141 goto end;
2142 estack_ax_v = estack_ax(stack, top)->u.v;
2143 estack_ax_t = estack_ax(stack, top)->type;
2144 next_pc += sizeof(struct load_op);
2145 PO;
2146 }
2147
2148 OP(FILTER_OP_LOAD_FIELD_S8):
2149 {
2150 dbg_printf("op load field s8\n");
2151
2152 estack_ax_v = *(int8_t *) estack_ax(stack, top)->u.ptr.ptr;
2153 estack_ax_t = REG_S64;
2154 next_pc += sizeof(struct load_op);
2155 PO;
2156 }
2157 OP(FILTER_OP_LOAD_FIELD_S16):
2158 {
2159 dbg_printf("op load field s16\n");
2160
2161 estack_ax_v = *(int16_t *) estack_ax(stack, top)->u.ptr.ptr;
2162 estack_ax_t = REG_S64;
2163 next_pc += sizeof(struct load_op);
2164 PO;
2165 }
2166 OP(FILTER_OP_LOAD_FIELD_S32):
2167 {
2168 dbg_printf("op load field s32\n");
2169
2170 estack_ax_v = *(int32_t *) estack_ax(stack, top)->u.ptr.ptr;
2171 estack_ax_t = REG_S64;
2172 next_pc += sizeof(struct load_op);
2173 PO;
2174 }
2175 OP(FILTER_OP_LOAD_FIELD_S64):
2176 {
2177 dbg_printf("op load field s64\n");
2178
2179 estack_ax_v = *(int64_t *) estack_ax(stack, top)->u.ptr.ptr;
2180 estack_ax_t = REG_S64;
2181 next_pc += sizeof(struct load_op);
2182 PO;
2183 }
2184 OP(FILTER_OP_LOAD_FIELD_U8):
2185 {
2186 dbg_printf("op load field u8\n");
2187
2188 estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr;
2189 estack_ax_t = REG_S64;
2190 next_pc += sizeof(struct load_op);
2191 PO;
2192 }
2193 OP(FILTER_OP_LOAD_FIELD_U16):
2194 {
2195 dbg_printf("op load field u16\n");
2196
2197 estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr;
2198 estack_ax_t = REG_S64;
2199 next_pc += sizeof(struct load_op);
2200 PO;
2201 }
2202 OP(FILTER_OP_LOAD_FIELD_U32):
2203 {
2204 dbg_printf("op load field u32\n");
2205
2206 estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr;
2207 estack_ax_t = REG_S64;
2208 next_pc += sizeof(struct load_op);
2209 PO;
2210 }
2211 OP(FILTER_OP_LOAD_FIELD_U64):
2212 {
2213 dbg_printf("op load field u64\n");
2214
2215 estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr;
2216 estack_ax_t = REG_S64;
2217 next_pc += sizeof(struct load_op);
2218 PO;
2219 }
2220 OP(FILTER_OP_LOAD_FIELD_DOUBLE):
2221 {
2222 dbg_printf("op load field double\n");
2223
2224 memcpy(&estack_ax(stack, top)->u.d,
2225 estack_ax(stack, top)->u.ptr.ptr,
2226 sizeof(struct literal_double));
2227 estack_ax(stack, top)->type = REG_DOUBLE;
2228 next_pc += sizeof(struct load_op);
2229 PO;
2230 }
2231
2232 OP(FILTER_OP_LOAD_FIELD_STRING):
2233 {
2234 const char *str;
2235
2236 dbg_printf("op load field string\n");
2237 str = (const char *) estack_ax(stack, top)->u.ptr.ptr;
2238 estack_ax(stack, top)->u.s.str = str;
2239 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2240 dbg_printf("Filter warning: loading a NULL string.\n");
2241 ret = -EINVAL;
2242 goto end;
2243 }
2244 estack_ax(stack, top)->u.s.seq_len = SIZE_MAX;
2245 estack_ax(stack, top)->u.s.literal_type =
2246 ESTACK_STRING_LITERAL_TYPE_NONE;
2247 estack_ax(stack, top)->type = REG_STRING;
2248 next_pc += sizeof(struct load_op);
2249 PO;
2250 }
2251
2252 OP(FILTER_OP_LOAD_FIELD_SEQUENCE):
2253 {
2254 const char *ptr;
2255
2256 dbg_printf("op load field string sequence\n");
2257 ptr = estack_ax(stack, top)->u.ptr.ptr;
2258 estack_ax(stack, top)->u.s.seq_len = *(unsigned long *) ptr;
2259 estack_ax(stack, top)->u.s.str = *(const char **) (ptr + sizeof(unsigned long));
2260 estack_ax(stack, top)->type = REG_STRING;
2261 if (unlikely(!estack_ax(stack, top)->u.s.str)) {
2262 dbg_printf("Filter warning: loading a NULL sequence.\n");
2263 ret = -EINVAL;
2264 goto end;
2265 }
2266 estack_ax(stack, top)->u.s.literal_type =
2267 ESTACK_STRING_LITERAL_TYPE_NONE;
2268 next_pc += sizeof(struct load_op);
2269 PO;
2270 }
2271
2272 END_OP
2273 end:
2274 /* return 0 (discard) on error */
2275 if (ret)
2276 return 0;
2277 return retval;
2278 }
2279
2280 #undef START_OP
2281 #undef OP
2282 #undef PO
2283 #undef END_OP
This page took 0.111982 seconds and 4 git commands to generate.