2 * lttng-filter-interpreter.c
4 * LTTng UST filter interpreter.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "lttng-filter.h"
27 * -2: unknown escape char.
32 int parse_char(const char **p
)
52 int stack_strcmp(struct estack
*stack
, const char *cmp_type
)
54 const char *p
= estack_bx(stack
)->u
.s
.str
, *q
= estack_ax(stack
)->u
.s
.str
;
61 if (unlikely(p
- estack_bx(stack
)->u
.s
.str
> estack_bx(stack
)->u
.s
.seq_len
|| *p
== '\0')) {
62 if (q
- estack_ax(stack
)->u
.s
.str
> estack_ax(stack
)->u
.s
.seq_len
|| *q
== '\0')
68 if (unlikely(q
- estack_ax(stack
)->u
.s
.str
> estack_ax(stack
)->u
.s
.seq_len
|| *q
== '\0')) {
69 if (p
- estack_bx(stack
)->u
.s
.str
> estack_bx(stack
)->u
.s
.seq_len
|| *p
== '\0')
75 if (estack_bx(stack
)->u
.s
.literal
) {
79 } else if (ret
== -2) {
82 /* else compare both char */
84 if (estack_ax(stack
)->u
.s
.literal
) {
88 } else if (ret
== -2) {
108 int lttng_filter_false(void *filter_data
,
109 const char *filter_stack_data
)
114 #ifdef INTERPRETER_USE_SWITCH
117 * Fallback for compilers that do not support taking address of labels.
121 start_pc = &bytecode->data[0]; \
122 for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \
124 dbg_printf("Executing op %s (%u)\n", \
125 print_op((unsigned int) *(filter_opcode_t *) pc), \
126 (unsigned int) *(filter_opcode_t *) pc); \
127 switch (*(filter_opcode_t *) pc) {
129 #define OP(name) case name
139 * Dispatch-table based interpreter.
143 start_pc = &bytecode->data[0]; \
144 pc = next_pc = start_pc; \
145 if (unlikely(pc - start_pc >= bytecode->len)) \
147 goto *dispatch[*(filter_opcode_t *) pc];
154 goto *dispatch[*(filter_opcode_t *) pc];
160 int lttng_filter_interpret_bytecode(void *filter_data
,
161 const char *filter_stack_data
)
163 struct bytecode_runtime
*bytecode
= filter_data
;
164 void *pc
, *next_pc
, *start_pc
;
167 struct estack _stack
;
168 struct estack
*stack
= &_stack
;
169 #ifndef INTERPRETER_USE_SWITCH
170 static void *dispatch
[NR_FILTER_OPS
] = {
171 [ FILTER_OP_UNKNOWN
] = &&LABEL_FILTER_OP_UNKNOWN
,
173 [ FILTER_OP_RETURN
] = &&LABEL_FILTER_OP_RETURN
,
176 [ FILTER_OP_MUL
] = &&LABEL_FILTER_OP_MUL
,
177 [ FILTER_OP_DIV
] = &&LABEL_FILTER_OP_DIV
,
178 [ FILTER_OP_MOD
] = &&LABEL_FILTER_OP_MOD
,
179 [ FILTER_OP_PLUS
] = &&LABEL_FILTER_OP_PLUS
,
180 [ FILTER_OP_MINUS
] = &&LABEL_FILTER_OP_MINUS
,
181 [ FILTER_OP_RSHIFT
] = &&LABEL_FILTER_OP_RSHIFT
,
182 [ FILTER_OP_LSHIFT
] = &&LABEL_FILTER_OP_LSHIFT
,
183 [ FILTER_OP_BIN_AND
] = &&LABEL_FILTER_OP_BIN_AND
,
184 [ FILTER_OP_BIN_OR
] = &&LABEL_FILTER_OP_BIN_OR
,
185 [ FILTER_OP_BIN_XOR
] = &&LABEL_FILTER_OP_BIN_XOR
,
187 /* binary comparators */
188 [ FILTER_OP_EQ
] = &&LABEL_FILTER_OP_EQ
,
189 [ FILTER_OP_NE
] = &&LABEL_FILTER_OP_NE
,
190 [ FILTER_OP_GT
] = &&LABEL_FILTER_OP_GT
,
191 [ FILTER_OP_LT
] = &&LABEL_FILTER_OP_LT
,
192 [ FILTER_OP_GE
] = &&LABEL_FILTER_OP_GE
,
193 [ FILTER_OP_LE
] = &&LABEL_FILTER_OP_LE
,
195 /* string binary comparator */
196 [ FILTER_OP_EQ_STRING
] = &&LABEL_FILTER_OP_EQ_STRING
,
197 [ FILTER_OP_NE_STRING
] = &&LABEL_FILTER_OP_NE_STRING
,
198 [ FILTER_OP_GT_STRING
] = &&LABEL_FILTER_OP_GT_STRING
,
199 [ FILTER_OP_LT_STRING
] = &&LABEL_FILTER_OP_LT_STRING
,
200 [ FILTER_OP_GE_STRING
] = &&LABEL_FILTER_OP_GE_STRING
,
201 [ FILTER_OP_LE_STRING
] = &&LABEL_FILTER_OP_LE_STRING
,
203 /* s64 binary comparator */
204 [ FILTER_OP_EQ_S64
] = &&LABEL_FILTER_OP_EQ_S64
,
205 [ FILTER_OP_NE_S64
] = &&LABEL_FILTER_OP_NE_S64
,
206 [ FILTER_OP_GT_S64
] = &&LABEL_FILTER_OP_GT_S64
,
207 [ FILTER_OP_LT_S64
] = &&LABEL_FILTER_OP_LT_S64
,
208 [ FILTER_OP_GE_S64
] = &&LABEL_FILTER_OP_GE_S64
,
209 [ FILTER_OP_LE_S64
] = &&LABEL_FILTER_OP_LE_S64
,
211 /* double binary comparator */
212 [ FILTER_OP_EQ_DOUBLE
] = &&LABEL_FILTER_OP_EQ_DOUBLE
,
213 [ FILTER_OP_NE_DOUBLE
] = &&LABEL_FILTER_OP_NE_DOUBLE
,
214 [ FILTER_OP_GT_DOUBLE
] = &&LABEL_FILTER_OP_GT_DOUBLE
,
215 [ FILTER_OP_LT_DOUBLE
] = &&LABEL_FILTER_OP_LT_DOUBLE
,
216 [ FILTER_OP_GE_DOUBLE
] = &&LABEL_FILTER_OP_GE_DOUBLE
,
217 [ FILTER_OP_LE_DOUBLE
] = &&LABEL_FILTER_OP_LE_DOUBLE
,
219 /* Mixed S64-double binary comparators */
220 [ FILTER_OP_EQ_DOUBLE_S64
] = &&LABEL_FILTER_OP_EQ_DOUBLE_S64
,
221 [ FILTER_OP_NE_DOUBLE_S64
] = &&LABEL_FILTER_OP_NE_DOUBLE_S64
,
222 [ FILTER_OP_GT_DOUBLE_S64
] = &&LABEL_FILTER_OP_GT_DOUBLE_S64
,
223 [ FILTER_OP_LT_DOUBLE_S64
] = &&LABEL_FILTER_OP_LT_DOUBLE_S64
,
224 [ FILTER_OP_GE_DOUBLE_S64
] = &&LABEL_FILTER_OP_GE_DOUBLE_S64
,
225 [ FILTER_OP_LE_DOUBLE_S64
] = &&LABEL_FILTER_OP_LE_DOUBLE_S64
,
227 [ FILTER_OP_EQ_S64_DOUBLE
] = &&LABEL_FILTER_OP_EQ_S64_DOUBLE
,
228 [ FILTER_OP_NE_S64_DOUBLE
] = &&LABEL_FILTER_OP_NE_S64_DOUBLE
,
229 [ FILTER_OP_GT_S64_DOUBLE
] = &&LABEL_FILTER_OP_GT_S64_DOUBLE
,
230 [ FILTER_OP_LT_S64_DOUBLE
] = &&LABEL_FILTER_OP_LT_S64_DOUBLE
,
231 [ FILTER_OP_GE_S64_DOUBLE
] = &&LABEL_FILTER_OP_GE_S64_DOUBLE
,
232 [ FILTER_OP_LE_S64_DOUBLE
] = &&LABEL_FILTER_OP_LE_S64_DOUBLE
,
235 [ FILTER_OP_UNARY_PLUS
] = &&LABEL_FILTER_OP_UNARY_PLUS
,
236 [ FILTER_OP_UNARY_MINUS
] = &&LABEL_FILTER_OP_UNARY_MINUS
,
237 [ FILTER_OP_UNARY_NOT
] = &&LABEL_FILTER_OP_UNARY_NOT
,
238 [ FILTER_OP_UNARY_PLUS_S64
] = &&LABEL_FILTER_OP_UNARY_PLUS_S64
,
239 [ FILTER_OP_UNARY_MINUS_S64
] = &&LABEL_FILTER_OP_UNARY_MINUS_S64
,
240 [ FILTER_OP_UNARY_NOT_S64
] = &&LABEL_FILTER_OP_UNARY_NOT_S64
,
241 [ FILTER_OP_UNARY_PLUS_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_PLUS_DOUBLE
,
242 [ FILTER_OP_UNARY_MINUS_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_MINUS_DOUBLE
,
243 [ FILTER_OP_UNARY_NOT_DOUBLE
] = &&LABEL_FILTER_OP_UNARY_NOT_DOUBLE
,
246 [ FILTER_OP_AND
] = &&LABEL_FILTER_OP_AND
,
247 [ FILTER_OP_OR
] = &&LABEL_FILTER_OP_OR
,
250 [ FILTER_OP_LOAD_FIELD_REF
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF
,
251 [ FILTER_OP_LOAD_FIELD_REF_STRING
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_STRING
,
252 [ FILTER_OP_LOAD_FIELD_REF_SEQUENCE
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_SEQUENCE
,
253 [ FILTER_OP_LOAD_FIELD_REF_S64
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_S64
,
254 [ FILTER_OP_LOAD_FIELD_REF_DOUBLE
] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_DOUBLE
,
256 [ FILTER_OP_LOAD_STRING
] = &&LABEL_FILTER_OP_LOAD_STRING
,
257 [ FILTER_OP_LOAD_S64
] = &&LABEL_FILTER_OP_LOAD_S64
,
258 [ FILTER_OP_LOAD_DOUBLE
] = &&LABEL_FILTER_OP_LOAD_DOUBLE
,
261 [ FILTER_OP_CAST_TO_S64
] = &&LABEL_FILTER_OP_CAST_TO_S64
,
262 [ FILTER_OP_CAST_DOUBLE_TO_S64
] = &&LABEL_FILTER_OP_CAST_DOUBLE_TO_S64
,
263 [ FILTER_OP_CAST_NOP
] = &&LABEL_FILTER_OP_CAST_NOP
,
265 #endif /* #ifndef INTERPRETER_USE_SWITCH */
271 OP(FILTER_OP_UNKNOWN
):
272 OP(FILTER_OP_LOAD_FIELD_REF
):
273 #ifdef INTERPRETER_USE_SWITCH
275 #endif /* INTERPRETER_USE_SWITCH */
276 ERR("unknown bytecode op %u\n",
277 (unsigned int) *(filter_opcode_t
*) pc
);
281 OP(FILTER_OP_RETURN
):
282 retval
= !!estack_ax(stack
)->u
.v
;
292 OP(FILTER_OP_RSHIFT
):
293 OP(FILTER_OP_LSHIFT
):
294 OP(FILTER_OP_BIN_AND
):
295 OP(FILTER_OP_BIN_OR
):
296 OP(FILTER_OP_BIN_XOR
):
297 ERR("unsupported bytecode op %u\n",
298 (unsigned int) *(filter_opcode_t
*) pc
);
308 ERR("unsupported non-specialized bytecode op %u\n",
309 (unsigned int) *(filter_opcode_t
*) pc
);
313 OP(FILTER_OP_EQ_STRING
):
317 res
= (stack_strcmp(stack
, "==") == 0);
319 estack_ax(stack
)->u
.v
= res
;
320 estack_ax(stack
)->type
= REG_S64
;
321 next_pc
+= sizeof(struct binary_op
);
324 OP(FILTER_OP_NE_STRING
):
328 res
= (stack_strcmp(stack
, "!=") != 0);
330 estack_ax(stack
)->u
.v
= res
;
331 estack_ax(stack
)->type
= REG_S64
;
332 next_pc
+= sizeof(struct binary_op
);
335 OP(FILTER_OP_GT_STRING
):
339 res
= (stack_strcmp(stack
, ">") > 0);
341 estack_ax(stack
)->u
.v
= res
;
342 estack_ax(stack
)->type
= REG_S64
;
343 next_pc
+= sizeof(struct binary_op
);
346 OP(FILTER_OP_LT_STRING
):
350 res
= (stack_strcmp(stack
, "<") < 0);
352 estack_ax(stack
)->u
.v
= res
;
353 estack_ax(stack
)->type
= REG_S64
;
354 next_pc
+= sizeof(struct binary_op
);
357 OP(FILTER_OP_GE_STRING
):
361 res
= (stack_strcmp(stack
, ">=") >= 0);
363 estack_ax(stack
)->u
.v
= res
;
364 estack_ax(stack
)->type
= REG_S64
;
365 next_pc
+= sizeof(struct binary_op
);
368 OP(FILTER_OP_LE_STRING
):
372 res
= (stack_strcmp(stack
, "<=") <= 0);
374 estack_ax(stack
)->u
.v
= res
;
375 estack_ax(stack
)->type
= REG_S64
;
376 next_pc
+= sizeof(struct binary_op
);
380 OP(FILTER_OP_EQ_S64
):
384 res
= (estack_bx(stack
)->u
.v
== estack_ax(stack
)->u
.v
);
386 estack_ax(stack
)->u
.v
= res
;
387 estack_ax(stack
)->type
= REG_S64
;
388 next_pc
+= sizeof(struct binary_op
);
391 OP(FILTER_OP_NE_S64
):
395 res
= (estack_bx(stack
)->u
.v
!= estack_ax(stack
)->u
.v
);
397 estack_ax(stack
)->u
.v
= res
;
398 estack_ax(stack
)->type
= REG_S64
;
399 next_pc
+= sizeof(struct binary_op
);
402 OP(FILTER_OP_GT_S64
):
406 res
= (estack_bx(stack
)->u
.v
> estack_ax(stack
)->u
.v
);
408 estack_ax(stack
)->u
.v
= res
;
409 estack_ax(stack
)->type
= REG_S64
;
410 next_pc
+= sizeof(struct binary_op
);
413 OP(FILTER_OP_LT_S64
):
417 res
= (estack_bx(stack
)->u
.v
< estack_ax(stack
)->u
.v
);
419 estack_ax(stack
)->u
.v
= res
;
420 estack_ax(stack
)->type
= REG_S64
;
421 next_pc
+= sizeof(struct binary_op
);
424 OP(FILTER_OP_GE_S64
):
428 res
= (estack_bx(stack
)->u
.v
>= estack_ax(stack
)->u
.v
);
430 estack_ax(stack
)->u
.v
= res
;
431 estack_ax(stack
)->type
= REG_S64
;
432 next_pc
+= sizeof(struct binary_op
);
435 OP(FILTER_OP_LE_S64
):
439 res
= (estack_bx(stack
)->u
.v
<= estack_ax(stack
)->u
.v
);
441 estack_ax(stack
)->u
.v
= res
;
442 estack_ax(stack
)->type
= REG_S64
;
443 next_pc
+= sizeof(struct binary_op
);
447 OP(FILTER_OP_EQ_DOUBLE
):
451 res
= (estack_bx(stack
)->u
.d
== estack_ax(stack
)->u
.d
);
453 estack_ax(stack
)->u
.v
= res
;
454 estack_ax(stack
)->type
= REG_S64
;
455 next_pc
+= sizeof(struct binary_op
);
458 OP(FILTER_OP_NE_DOUBLE
):
462 res
= (estack_bx(stack
)->u
.d
!= estack_ax(stack
)->u
.d
);
464 estack_ax(stack
)->u
.v
= res
;
465 estack_ax(stack
)->type
= REG_S64
;
466 next_pc
+= sizeof(struct binary_op
);
469 OP(FILTER_OP_GT_DOUBLE
):
473 res
= (estack_bx(stack
)->u
.d
> estack_ax(stack
)->u
.d
);
475 estack_ax(stack
)->u
.v
= res
;
476 estack_ax(stack
)->type
= REG_S64
;
477 next_pc
+= sizeof(struct binary_op
);
480 OP(FILTER_OP_LT_DOUBLE
):
484 res
= (estack_bx(stack
)->u
.d
< estack_ax(stack
)->u
.d
);
486 estack_ax(stack
)->u
.v
= res
;
487 estack_ax(stack
)->type
= REG_S64
;
488 next_pc
+= sizeof(struct binary_op
);
491 OP(FILTER_OP_GE_DOUBLE
):
495 res
= (estack_bx(stack
)->u
.d
>= estack_ax(stack
)->u
.d
);
497 estack_ax(stack
)->u
.v
= res
;
498 estack_ax(stack
)->type
= REG_S64
;
499 next_pc
+= sizeof(struct binary_op
);
502 OP(FILTER_OP_LE_DOUBLE
):
506 res
= (estack_bx(stack
)->u
.d
<= estack_ax(stack
)->u
.d
);
508 estack_ax(stack
)->u
.v
= res
;
509 estack_ax(stack
)->type
= REG_S64
;
510 next_pc
+= sizeof(struct binary_op
);
514 /* Mixed S64-double binary comparators */
515 OP(FILTER_OP_EQ_DOUBLE_S64
):
519 res
= (estack_bx(stack
)->u
.d
== estack_ax(stack
)->u
.v
);
521 estack_ax(stack
)->u
.v
= res
;
522 estack_ax(stack
)->type
= REG_S64
;
523 next_pc
+= sizeof(struct binary_op
);
526 OP(FILTER_OP_NE_DOUBLE_S64
):
530 res
= (estack_bx(stack
)->u
.d
!= estack_ax(stack
)->u
.v
);
532 estack_ax(stack
)->u
.v
= res
;
533 estack_ax(stack
)->type
= REG_S64
;
534 next_pc
+= sizeof(struct binary_op
);
537 OP(FILTER_OP_GT_DOUBLE_S64
):
541 res
= (estack_bx(stack
)->u
.d
> estack_ax(stack
)->u
.v
);
543 estack_ax(stack
)->u
.v
= res
;
544 estack_ax(stack
)->type
= REG_S64
;
545 next_pc
+= sizeof(struct binary_op
);
548 OP(FILTER_OP_LT_DOUBLE_S64
):
552 res
= (estack_bx(stack
)->u
.d
< estack_ax(stack
)->u
.v
);
554 estack_ax(stack
)->u
.v
= res
;
555 estack_ax(stack
)->type
= REG_S64
;
556 next_pc
+= sizeof(struct binary_op
);
559 OP(FILTER_OP_GE_DOUBLE_S64
):
563 res
= (estack_bx(stack
)->u
.d
>= estack_ax(stack
)->u
.v
);
565 estack_ax(stack
)->u
.v
= res
;
566 estack_ax(stack
)->type
= REG_S64
;
567 next_pc
+= sizeof(struct binary_op
);
570 OP(FILTER_OP_LE_DOUBLE_S64
):
574 res
= (estack_bx(stack
)->u
.d
<= estack_ax(stack
)->u
.v
);
576 estack_ax(stack
)->u
.v
= res
;
577 estack_ax(stack
)->type
= REG_S64
;
578 next_pc
+= sizeof(struct binary_op
);
582 OP(FILTER_OP_EQ_S64_DOUBLE
):
586 res
= (estack_bx(stack
)->u
.v
== estack_ax(stack
)->u
.d
);
588 estack_ax(stack
)->u
.v
= res
;
589 estack_ax(stack
)->type
= REG_S64
;
590 next_pc
+= sizeof(struct binary_op
);
593 OP(FILTER_OP_NE_S64_DOUBLE
):
597 res
= (estack_bx(stack
)->u
.v
!= estack_ax(stack
)->u
.d
);
599 estack_ax(stack
)->u
.v
= res
;
600 estack_ax(stack
)->type
= REG_S64
;
601 next_pc
+= sizeof(struct binary_op
);
604 OP(FILTER_OP_GT_S64_DOUBLE
):
608 res
= (estack_bx(stack
)->u
.v
> estack_ax(stack
)->u
.d
);
610 estack_ax(stack
)->u
.v
= res
;
611 estack_ax(stack
)->type
= REG_S64
;
612 next_pc
+= sizeof(struct binary_op
);
615 OP(FILTER_OP_LT_S64_DOUBLE
):
619 res
= (estack_bx(stack
)->u
.v
< estack_ax(stack
)->u
.d
);
621 estack_ax(stack
)->u
.v
= res
;
622 estack_ax(stack
)->type
= REG_S64
;
623 next_pc
+= sizeof(struct binary_op
);
626 OP(FILTER_OP_GE_S64_DOUBLE
):
630 res
= (estack_bx(stack
)->u
.v
>= estack_ax(stack
)->u
.d
);
632 estack_ax(stack
)->u
.v
= res
;
633 estack_ax(stack
)->type
= REG_S64
;
634 next_pc
+= sizeof(struct binary_op
);
637 OP(FILTER_OP_LE_S64_DOUBLE
):
641 res
= (estack_bx(stack
)->u
.v
<= estack_ax(stack
)->u
.d
);
643 estack_ax(stack
)->u
.v
= res
;
644 estack_ax(stack
)->type
= REG_S64
;
645 next_pc
+= sizeof(struct binary_op
);
650 OP(FILTER_OP_UNARY_PLUS
):
651 OP(FILTER_OP_UNARY_MINUS
):
652 OP(FILTER_OP_UNARY_NOT
):
653 ERR("unsupported non-specialized bytecode op %u\n",
654 (unsigned int) *(filter_opcode_t
*) pc
);
659 OP(FILTER_OP_UNARY_PLUS_S64
):
660 OP(FILTER_OP_UNARY_PLUS_DOUBLE
):
662 next_pc
+= sizeof(struct unary_op
);
665 OP(FILTER_OP_UNARY_MINUS_S64
):
667 estack_ax(stack
)->u
.v
= -estack_ax(stack
)->u
.v
;
668 next_pc
+= sizeof(struct unary_op
);
671 OP(FILTER_OP_UNARY_MINUS_DOUBLE
):
673 estack_ax(stack
)->u
.d
= -estack_ax(stack
)->u
.d
;
674 next_pc
+= sizeof(struct unary_op
);
677 OP(FILTER_OP_UNARY_NOT_S64
):
679 estack_ax(stack
)->u
.v
= !estack_ax(stack
)->u
.v
;
680 next_pc
+= sizeof(struct unary_op
);
683 OP(FILTER_OP_UNARY_NOT_DOUBLE
):
685 estack_ax(stack
)->u
.d
= !estack_ax(stack
)->u
.d
;
686 next_pc
+= sizeof(struct unary_op
);
693 struct logical_op
*insn
= (struct logical_op
*) pc
;
695 /* If AX is 0, skip and evaluate to 0 */
696 if (unlikely(estack_ax(stack
)->u
.v
== 0)) {
697 dbg_printf("Jumping to bytecode offset %u\n",
698 (unsigned int) insn
->skip_offset
);
699 next_pc
= start_pc
+ insn
->skip_offset
;
701 /* Pop 1 when jump not taken */
703 next_pc
+= sizeof(struct logical_op
);
709 struct logical_op
*insn
= (struct logical_op
*) pc
;
711 /* If AX is nonzero, skip and evaluate to 1 */
713 if (unlikely(estack_ax(stack
)->u
.v
!= 0)) {
714 estack_ax(stack
)->u
.v
= 1;
715 dbg_printf("Jumping to bytecode offset %u\n",
716 (unsigned int) insn
->skip_offset
);
717 next_pc
= start_pc
+ insn
->skip_offset
;
719 /* Pop 1 when jump not taken */
721 next_pc
+= sizeof(struct logical_op
);
728 OP(FILTER_OP_LOAD_FIELD_REF_STRING
):
730 struct load_op
*insn
= (struct load_op
*) pc
;
731 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
733 dbg_printf("load field ref offset %u type string\n",
736 estack_ax(stack
)->u
.s
.str
=
737 *(const char * const *) &filter_stack_data
[ref
->offset
];
738 if (unlikely(!estack_ax(stack
)->u
.s
.str
)) {
739 dbg_printf("Filter warning: loading a NULL string.\n");
743 estack_ax(stack
)->type
= REG_STRING
;
744 estack_ax(stack
)->u
.s
.seq_len
= UINT_MAX
;
745 estack_ax(stack
)->u
.s
.literal
= 0;
746 dbg_printf("ref load string %s\n", estack_ax(stack
)->u
.s
.str
);
747 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
751 OP(FILTER_OP_LOAD_FIELD_REF_SEQUENCE
):
753 struct load_op
*insn
= (struct load_op
*) pc
;
754 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
756 dbg_printf("load field ref offset %u type sequence\n",
759 estack_ax(stack
)->u
.s
.seq_len
=
760 *(unsigned long *) &filter_stack_data
[ref
->offset
];
761 estack_ax(stack
)->u
.s
.str
=
762 *(const char **) (&filter_stack_data
[ref
->offset
763 + sizeof(unsigned long)]);
764 if (unlikely(!estack_ax(stack
)->u
.s
.str
)) {
765 dbg_printf("Filter warning: loading a NULL sequence.\n");
769 estack_ax(stack
)->type
= REG_STRING
;
770 estack_ax(stack
)->u
.s
.literal
= 0;
771 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
775 OP(FILTER_OP_LOAD_FIELD_REF_S64
):
777 struct load_op
*insn
= (struct load_op
*) pc
;
778 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
780 dbg_printf("load field ref offset %u type s64\n",
783 memcpy(&estack_ax(stack
)->u
.v
, &filter_stack_data
[ref
->offset
],
784 sizeof(struct literal_numeric
));
785 estack_ax(stack
)->type
= REG_S64
;
786 dbg_printf("ref load s64 %" PRIi64
"\n", estack_ax(stack
)->u
.v
);
787 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
791 OP(FILTER_OP_LOAD_FIELD_REF_DOUBLE
):
793 struct load_op
*insn
= (struct load_op
*) pc
;
794 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
796 dbg_printf("load field ref offset %u type double\n",
799 memcpy(&estack_ax(stack
)->u
.d
, &filter_stack_data
[ref
->offset
],
800 sizeof(struct literal_double
));
801 estack_ax(stack
)->type
= REG_DOUBLE
;
802 dbg_printf("ref load double %g\n", estack_ax(stack
)->u
.d
);
803 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
807 OP(FILTER_OP_LOAD_STRING
):
809 struct load_op
*insn
= (struct load_op
*) pc
;
811 dbg_printf("load string %s\n", insn
->data
);
813 estack_ax(stack
)->type
= REG_STRING
;
814 estack_ax(stack
)->u
.s
.str
= insn
->data
;
815 estack_ax(stack
)->u
.s
.seq_len
= UINT_MAX
;
816 estack_ax(stack
)->u
.s
.literal
= 1;
817 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
821 OP(FILTER_OP_LOAD_S64
):
823 struct load_op
*insn
= (struct load_op
*) pc
;
826 memcpy(&estack_ax(stack
)->u
.v
, insn
->data
,
827 sizeof(struct literal_numeric
));
828 dbg_printf("load s64 %" PRIi64
"\n", estack_ax(stack
)->u
.v
);
829 estack_ax(stack
)->type
= REG_S64
;
830 next_pc
+= sizeof(struct load_op
)
831 + sizeof(struct literal_numeric
);
835 OP(FILTER_OP_LOAD_DOUBLE
):
837 struct load_op
*insn
= (struct load_op
*) pc
;
840 memcpy(&estack_ax(stack
)->u
.d
, insn
->data
,
841 sizeof(struct literal_double
));
842 dbg_printf("load s64 %g\n", estack_ax(stack
)->u
.d
);
843 estack_ax(stack
)->type
= REG_DOUBLE
;
844 next_pc
+= sizeof(struct load_op
)
845 + sizeof(struct literal_double
);
850 OP(FILTER_OP_CAST_TO_S64
):
851 ERR("unsupported non-specialized bytecode op %u\n",
852 (unsigned int) *(filter_opcode_t
*) pc
);
856 OP(FILTER_OP_CAST_DOUBLE_TO_S64
):
858 estack_ax(stack
)->u
.v
= (int64_t) estack_ax(stack
)->u
.d
;
859 estack_ax(stack
)->type
= REG_S64
;
860 next_pc
+= sizeof(struct cast_op
);
864 OP(FILTER_OP_CAST_NOP
):
866 next_pc
+= sizeof(struct cast_op
);
872 /* return 0 (discard) on error */