2 * lttng-filter-validator.c
4 * LTTng modules filter bytecode validator.
6 * Copyright (C) 2010-2014 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 <linux/list.h>
24 #include <linux/jhash.h>
25 #include <linux/slab.h>
27 #include "lttng-filter.h"
29 #define MERGE_POINT_TABLE_BITS 7
30 #define MERGE_POINT_TABLE_SIZE (1U << MERGE_POINT_TABLE_BITS)
32 /* merge point table node */
34 struct hlist_node node
;
36 /* Context at merge point */
38 unsigned long target_pc
;
42 struct hlist_head mp_head
[MERGE_POINT_TABLE_SIZE
];
46 int lttng_hash_match(struct mp_node
*mp_node
, unsigned long key_pc
)
48 if (mp_node
->target_pc
== key_pc
)
55 int merge_points_compare(const struct vstack
*stacka
,
56 const struct vstack
*stackb
)
60 if (stacka
->top
!= stackb
->top
)
62 len
= stacka
->top
+ 1;
63 WARN_ON_ONCE(len
< 0);
64 for (i
= 0; i
< len
; i
++) {
65 if (stacka
->e
[i
].type
!= stackb
->e
[i
].type
)
72 int merge_point_add_check(struct mp_table
*mp_table
, unsigned long target_pc
,
73 const struct vstack
*stack
)
75 struct mp_node
*mp_node
;
76 unsigned long hash
= jhash_1word(target_pc
, 0);
77 struct hlist_head
*head
;
78 struct mp_node
*lookup_node
;
81 dbg_printk("Filter: adding merge point at offset %lu, hash %lu\n",
83 mp_node
= kzalloc(sizeof(struct mp_node
), GFP_KERNEL
);
86 mp_node
->target_pc
= target_pc
;
87 memcpy(&mp_node
->stack
, stack
, sizeof(mp_node
->stack
));
89 head
= &mp_table
->mp_head
[hash
& (MERGE_POINT_TABLE_SIZE
- 1)];
90 hlist_for_each_entry(lookup_node
, head
, node
) {
91 if (lttng_hash_match(lookup_node
, target_pc
)) {
97 /* Key already present */
98 dbg_printk("Filter: compare merge points for offset %lu, hash %lu\n",
101 if (merge_points_compare(stack
, &lookup_node
->stack
)) {
102 printk(KERN_WARNING
"Merge points differ for offset %lu\n",
107 hlist_add_head(&mp_node
->node
, head
);
112 * Binary comparators use top of stack and top of stack -1.
115 int bin_op_compare_check(struct vstack
*stack
, const char *str
)
117 if (unlikely(!vstack_ax(stack
) || !vstack_bx(stack
)))
120 switch (vstack_ax(stack
)->type
) {
126 switch (vstack_bx(stack
)->type
) {
138 switch (vstack_bx(stack
)->type
) {
157 printk(KERN_WARNING
"type mismatch for '%s' binary operator\n", str
);
162 * Validate bytecode range overflow within the validation pass.
163 * Called for each instruction encountered.
166 int bytecode_validate_overflow(struct bytecode_runtime
*bytecode
,
167 void *start_pc
, void *pc
)
171 switch (*(filter_opcode_t
*) pc
) {
172 case FILTER_OP_UNKNOWN
:
175 printk(KERN_WARNING
"unknown bytecode op %u\n",
176 (unsigned int) *(filter_opcode_t
*) pc
);
181 case FILTER_OP_RETURN
:
183 if (unlikely(pc
+ sizeof(struct return_op
)
184 > start_pc
+ bytecode
->len
)) {
195 case FILTER_OP_MINUS
:
196 case FILTER_OP_RSHIFT
:
197 case FILTER_OP_LSHIFT
:
198 case FILTER_OP_BIN_AND
:
199 case FILTER_OP_BIN_OR
:
200 case FILTER_OP_BIN_XOR
:
201 case FILTER_OP_EQ_DOUBLE
:
202 case FILTER_OP_NE_DOUBLE
:
203 case FILTER_OP_GT_DOUBLE
:
204 case FILTER_OP_LT_DOUBLE
:
205 case FILTER_OP_GE_DOUBLE
:
206 case FILTER_OP_LE_DOUBLE
:
208 case FILTER_OP_EQ_DOUBLE_S64
:
209 case FILTER_OP_NE_DOUBLE_S64
:
210 case FILTER_OP_GT_DOUBLE_S64
:
211 case FILTER_OP_LT_DOUBLE_S64
:
212 case FILTER_OP_GE_DOUBLE_S64
:
213 case FILTER_OP_LE_DOUBLE_S64
:
214 case FILTER_OP_EQ_S64_DOUBLE
:
215 case FILTER_OP_NE_S64_DOUBLE
:
216 case FILTER_OP_GT_S64_DOUBLE
:
217 case FILTER_OP_LT_S64_DOUBLE
:
218 case FILTER_OP_GE_S64_DOUBLE
:
219 case FILTER_OP_LE_S64_DOUBLE
:
220 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
221 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
222 case FILTER_OP_LOAD_DOUBLE
:
223 case FILTER_OP_CAST_DOUBLE_TO_S64
:
224 case FILTER_OP_UNARY_PLUS_DOUBLE
:
225 case FILTER_OP_UNARY_MINUS_DOUBLE
:
226 case FILTER_OP_UNARY_NOT_DOUBLE
:
228 printk(KERN_WARNING
"unsupported bytecode op %u\n",
229 (unsigned int) *(filter_opcode_t
*) pc
);
240 case FILTER_OP_EQ_STRING
:
241 case FILTER_OP_NE_STRING
:
242 case FILTER_OP_GT_STRING
:
243 case FILTER_OP_LT_STRING
:
244 case FILTER_OP_GE_STRING
:
245 case FILTER_OP_LE_STRING
:
246 case FILTER_OP_EQ_S64
:
247 case FILTER_OP_NE_S64
:
248 case FILTER_OP_GT_S64
:
249 case FILTER_OP_LT_S64
:
250 case FILTER_OP_GE_S64
:
251 case FILTER_OP_LE_S64
:
253 if (unlikely(pc
+ sizeof(struct binary_op
)
254 > start_pc
+ bytecode
->len
)) {
261 case FILTER_OP_UNARY_PLUS
:
262 case FILTER_OP_UNARY_MINUS
:
263 case FILTER_OP_UNARY_NOT
:
264 case FILTER_OP_UNARY_PLUS_S64
:
265 case FILTER_OP_UNARY_MINUS_S64
:
266 case FILTER_OP_UNARY_NOT_S64
:
268 if (unlikely(pc
+ sizeof(struct unary_op
)
269 > start_pc
+ bytecode
->len
)) {
279 if (unlikely(pc
+ sizeof(struct logical_op
)
280 > start_pc
+ bytecode
->len
)) {
287 case FILTER_OP_LOAD_FIELD_REF
:
289 printk(KERN_WARNING
"Unknown field ref type\n");
293 /* get context ref */
294 case FILTER_OP_GET_CONTEXT_REF
:
296 printk(KERN_WARNING
"Unknown field ref type\n");
300 case FILTER_OP_LOAD_FIELD_REF_STRING
:
301 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
302 case FILTER_OP_LOAD_FIELD_REF_S64
:
303 case FILTER_OP_GET_CONTEXT_REF_STRING
:
304 case FILTER_OP_GET_CONTEXT_REF_S64
:
306 if (unlikely(pc
+ sizeof(struct load_op
) + sizeof(struct field_ref
)
307 > start_pc
+ bytecode
->len
)) {
313 /* load from immediate operand */
314 case FILTER_OP_LOAD_STRING
:
316 struct load_op
*insn
= (struct load_op
*) pc
;
317 uint32_t str_len
, maxlen
;
319 if (unlikely(pc
+ sizeof(struct load_op
)
320 > start_pc
+ bytecode
->len
)) {
325 maxlen
= start_pc
+ bytecode
->len
- pc
- sizeof(struct load_op
);
326 str_len
= strnlen(insn
->data
, maxlen
);
327 if (unlikely(str_len
>= maxlen
)) {
328 /* Final '\0' not found within range */
334 case FILTER_OP_LOAD_S64
:
336 if (unlikely(pc
+ sizeof(struct load_op
) + sizeof(struct literal_numeric
)
337 > start_pc
+ bytecode
->len
)) {
343 case FILTER_OP_CAST_TO_S64
:
344 case FILTER_OP_CAST_NOP
:
346 if (unlikely(pc
+ sizeof(struct cast_op
)
347 > start_pc
+ bytecode
->len
)) {
359 unsigned long delete_all_nodes(struct mp_table
*mp_table
)
361 struct mp_node
*mp_node
;
362 struct hlist_node
*tmp
;
363 unsigned long nr_nodes
= 0;
366 for (i
= 0; i
< MERGE_POINT_TABLE_SIZE
; i
++) {
367 struct hlist_head
*head
;
369 head
= &mp_table
->mp_head
[i
];
370 hlist_for_each_entry_safe(mp_node
, tmp
, head
, node
) {
384 int validate_instruction_context(struct bytecode_runtime
*bytecode
,
385 struct vstack
*stack
,
391 switch (*(filter_opcode_t
*) pc
) {
392 case FILTER_OP_UNKNOWN
:
395 printk(KERN_WARNING
"unknown bytecode op %u\n",
396 (unsigned int) *(filter_opcode_t
*) pc
);
401 case FILTER_OP_RETURN
:
411 case FILTER_OP_MINUS
:
412 case FILTER_OP_RSHIFT
:
413 case FILTER_OP_LSHIFT
:
414 case FILTER_OP_BIN_AND
:
415 case FILTER_OP_BIN_OR
:
416 case FILTER_OP_BIN_XOR
:
418 case FILTER_OP_EQ_DOUBLE
:
419 case FILTER_OP_NE_DOUBLE
:
420 case FILTER_OP_GT_DOUBLE
:
421 case FILTER_OP_LT_DOUBLE
:
422 case FILTER_OP_GE_DOUBLE
:
423 case FILTER_OP_LE_DOUBLE
:
424 case FILTER_OP_EQ_DOUBLE_S64
:
425 case FILTER_OP_NE_DOUBLE_S64
:
426 case FILTER_OP_GT_DOUBLE_S64
:
427 case FILTER_OP_LT_DOUBLE_S64
:
428 case FILTER_OP_GE_DOUBLE_S64
:
429 case FILTER_OP_LE_DOUBLE_S64
:
430 case FILTER_OP_EQ_S64_DOUBLE
:
431 case FILTER_OP_NE_S64_DOUBLE
:
432 case FILTER_OP_GT_S64_DOUBLE
:
433 case FILTER_OP_LT_S64_DOUBLE
:
434 case FILTER_OP_GE_S64_DOUBLE
:
435 case FILTER_OP_LE_S64_DOUBLE
:
436 case FILTER_OP_UNARY_PLUS_DOUBLE
:
437 case FILTER_OP_UNARY_MINUS_DOUBLE
:
438 case FILTER_OP_UNARY_NOT_DOUBLE
:
439 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
440 case FILTER_OP_LOAD_DOUBLE
:
441 case FILTER_OP_CAST_DOUBLE_TO_S64
:
442 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
444 printk(KERN_WARNING
"unsupported bytecode op %u\n",
445 (unsigned int) *(filter_opcode_t
*) pc
);
452 ret
= bin_op_compare_check(stack
, "==");
459 ret
= bin_op_compare_check(stack
, "!=");
466 ret
= bin_op_compare_check(stack
, ">");
473 ret
= bin_op_compare_check(stack
, "<");
480 ret
= bin_op_compare_check(stack
, ">=");
487 ret
= bin_op_compare_check(stack
, "<=");
493 case FILTER_OP_EQ_STRING
:
494 case FILTER_OP_NE_STRING
:
495 case FILTER_OP_GT_STRING
:
496 case FILTER_OP_LT_STRING
:
497 case FILTER_OP_GE_STRING
:
498 case FILTER_OP_LE_STRING
:
500 if (!vstack_ax(stack
) || !vstack_bx(stack
)) {
501 printk(KERN_WARNING
"Empty stack\n");
505 if (vstack_ax(stack
)->type
!= REG_STRING
506 || vstack_bx(stack
)->type
!= REG_STRING
) {
507 printk(KERN_WARNING
"Unexpected register type for string comparator\n");
514 case FILTER_OP_EQ_S64
:
515 case FILTER_OP_NE_S64
:
516 case FILTER_OP_GT_S64
:
517 case FILTER_OP_LT_S64
:
518 case FILTER_OP_GE_S64
:
519 case FILTER_OP_LE_S64
:
521 if (!vstack_ax(stack
) || !vstack_bx(stack
)) {
522 printk(KERN_WARNING
"Empty stack\n");
526 if (vstack_ax(stack
)->type
!= REG_S64
527 || vstack_bx(stack
)->type
!= REG_S64
) {
528 printk(KERN_WARNING
"Unexpected register type for s64 comparator\n");
536 case FILTER_OP_UNARY_PLUS
:
537 case FILTER_OP_UNARY_MINUS
:
538 case FILTER_OP_UNARY_NOT
:
540 if (!vstack_ax(stack
)) {
541 printk(KERN_WARNING
"Empty stack\n");
545 switch (vstack_ax(stack
)->type
) {
548 printk(KERN_WARNING
"unknown register type\n");
553 printk(KERN_WARNING
"Unary op can only be applied to numeric or floating point registers\n");
562 case FILTER_OP_UNARY_PLUS_S64
:
563 case FILTER_OP_UNARY_MINUS_S64
:
564 case FILTER_OP_UNARY_NOT_S64
:
566 if (!vstack_ax(stack
)) {
567 printk(KERN_WARNING
"Empty stack\n");
571 if (vstack_ax(stack
)->type
!= REG_S64
) {
572 printk(KERN_WARNING
"Invalid register type\n");
583 struct logical_op
*insn
= (struct logical_op
*) pc
;
585 if (!vstack_ax(stack
)) {
586 printk(KERN_WARNING
"Empty stack\n");
590 if (vstack_ax(stack
)->type
!= REG_S64
) {
591 printk(KERN_WARNING
"Logical comparator expects S64 register\n");
596 dbg_printk("Validate jumping to bytecode offset %u\n",
597 (unsigned int) insn
->skip_offset
);
598 if (unlikely(start_pc
+ insn
->skip_offset
<= pc
)) {
599 printk(KERN_WARNING
"Loops are not allowed in bytecode\n");
607 case FILTER_OP_LOAD_FIELD_REF
:
609 printk(KERN_WARNING
"Unknown field ref type\n");
613 case FILTER_OP_LOAD_FIELD_REF_STRING
:
614 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
616 struct load_op
*insn
= (struct load_op
*) pc
;
617 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
619 dbg_printk("Validate load field ref offset %u type string\n",
623 case FILTER_OP_LOAD_FIELD_REF_S64
:
625 struct load_op
*insn
= (struct load_op
*) pc
;
626 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
628 dbg_printk("Validate load field ref offset %u type s64\n",
633 /* load from immediate operand */
634 case FILTER_OP_LOAD_STRING
:
639 case FILTER_OP_LOAD_S64
:
644 case FILTER_OP_CAST_TO_S64
:
646 struct cast_op
*insn
= (struct cast_op
*) pc
;
648 if (!vstack_ax(stack
)) {
649 printk(KERN_WARNING
"Empty stack\n");
653 switch (vstack_ax(stack
)->type
) {
656 printk(KERN_WARNING
"unknown register type\n");
661 printk(KERN_WARNING
"Cast op can only be applied to numeric or floating point registers\n");
667 if (insn
->op
== FILTER_OP_CAST_DOUBLE_TO_S64
) {
668 if (vstack_ax(stack
)->type
!= REG_DOUBLE
) {
669 printk(KERN_WARNING
"Cast expects double\n");
676 case FILTER_OP_CAST_NOP
:
681 /* get context ref */
682 case FILTER_OP_GET_CONTEXT_REF
:
684 printk(KERN_WARNING
"Unknown get context ref type\n");
688 case FILTER_OP_GET_CONTEXT_REF_STRING
:
690 struct load_op
*insn
= (struct load_op
*) pc
;
691 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
693 dbg_printk("Validate get context ref offset %u type string\n",
697 case FILTER_OP_GET_CONTEXT_REF_S64
:
699 struct load_op
*insn
= (struct load_op
*) pc
;
700 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
702 dbg_printk("Validate get context ref offset %u type s64\n",
718 int validate_instruction_all_contexts(struct bytecode_runtime
*bytecode
,
719 struct mp_table
*mp_table
,
720 struct vstack
*stack
,
725 unsigned long target_pc
= pc
- start_pc
;
727 struct hlist_head
*head
;
728 struct mp_node
*mp_node
;
730 /* Validate the context resulting from the previous instruction */
731 ret
= validate_instruction_context(bytecode
, stack
, start_pc
, pc
);
735 /* Validate merge points */
736 hash
= jhash_1word(target_pc
, 0);
737 head
= &mp_table
->mp_head
[hash
& (MERGE_POINT_TABLE_SIZE
- 1)];
738 hlist_for_each_entry(mp_node
, head
, node
) {
739 if (lttng_hash_match(mp_node
, target_pc
)) {
745 dbg_printk("Filter: validate merge point at offset %lu\n",
747 if (merge_points_compare(stack
, &mp_node
->stack
)) {
748 printk(KERN_WARNING
"Merge points differ for offset %lu\n",
752 /* Once validated, we can remove the merge point */
753 dbg_printk("Filter: remove merge point at offset %lu\n",
755 hlist_del(&mp_node
->node
);
762 * >0: going to next insn.
763 * 0: success, stop iteration.
767 int exec_insn(struct bytecode_runtime
*bytecode
,
768 struct mp_table
*mp_table
,
769 struct vstack
*stack
,
774 void *next_pc
= *_next_pc
;
776 switch (*(filter_opcode_t
*) pc
) {
777 case FILTER_OP_UNKNOWN
:
780 printk(KERN_WARNING
"unknown bytecode op %u\n",
781 (unsigned int) *(filter_opcode_t
*) pc
);
786 case FILTER_OP_RETURN
:
788 if (!vstack_ax(stack
)) {
789 printk(KERN_WARNING
"Empty stack\n");
802 case FILTER_OP_MINUS
:
803 case FILTER_OP_RSHIFT
:
804 case FILTER_OP_LSHIFT
:
805 case FILTER_OP_BIN_AND
:
806 case FILTER_OP_BIN_OR
:
807 case FILTER_OP_BIN_XOR
:
809 case FILTER_OP_EQ_DOUBLE
:
810 case FILTER_OP_NE_DOUBLE
:
811 case FILTER_OP_GT_DOUBLE
:
812 case FILTER_OP_LT_DOUBLE
:
813 case FILTER_OP_GE_DOUBLE
:
814 case FILTER_OP_LE_DOUBLE
:
815 case FILTER_OP_EQ_DOUBLE_S64
:
816 case FILTER_OP_NE_DOUBLE_S64
:
817 case FILTER_OP_GT_DOUBLE_S64
:
818 case FILTER_OP_LT_DOUBLE_S64
:
819 case FILTER_OP_GE_DOUBLE_S64
:
820 case FILTER_OP_LE_DOUBLE_S64
:
821 case FILTER_OP_EQ_S64_DOUBLE
:
822 case FILTER_OP_NE_S64_DOUBLE
:
823 case FILTER_OP_GT_S64_DOUBLE
:
824 case FILTER_OP_LT_S64_DOUBLE
:
825 case FILTER_OP_GE_S64_DOUBLE
:
826 case FILTER_OP_LE_S64_DOUBLE
:
827 case FILTER_OP_UNARY_PLUS_DOUBLE
:
828 case FILTER_OP_UNARY_MINUS_DOUBLE
:
829 case FILTER_OP_UNARY_NOT_DOUBLE
:
830 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
831 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
832 case FILTER_OP_LOAD_DOUBLE
:
833 case FILTER_OP_CAST_DOUBLE_TO_S64
:
835 printk(KERN_WARNING
"unsupported bytecode op %u\n",
836 (unsigned int) *(filter_opcode_t
*) pc
);
847 case FILTER_OP_EQ_STRING
:
848 case FILTER_OP_NE_STRING
:
849 case FILTER_OP_GT_STRING
:
850 case FILTER_OP_LT_STRING
:
851 case FILTER_OP_GE_STRING
:
852 case FILTER_OP_LE_STRING
:
853 case FILTER_OP_EQ_S64
:
854 case FILTER_OP_NE_S64
:
855 case FILTER_OP_GT_S64
:
856 case FILTER_OP_LT_S64
:
857 case FILTER_OP_GE_S64
:
858 case FILTER_OP_LE_S64
:
861 if (vstack_pop(stack
)) {
865 if (!vstack_ax(stack
)) {
866 printk(KERN_WARNING
"Empty stack\n");
870 vstack_ax(stack
)->type
= REG_S64
;
871 next_pc
+= sizeof(struct binary_op
);
876 case FILTER_OP_UNARY_PLUS
:
877 case FILTER_OP_UNARY_MINUS
:
878 case FILTER_OP_UNARY_NOT
:
879 case FILTER_OP_UNARY_PLUS_S64
:
880 case FILTER_OP_UNARY_MINUS_S64
:
881 case FILTER_OP_UNARY_NOT_S64
:
884 if (!vstack_ax(stack
)) {
885 printk(KERN_WARNING
"Empty stack\n");
889 vstack_ax(stack
)->type
= REG_S64
;
890 next_pc
+= sizeof(struct unary_op
);
898 struct logical_op
*insn
= (struct logical_op
*) pc
;
901 /* Add merge point to table */
902 merge_ret
= merge_point_add_check(mp_table
,
903 insn
->skip_offset
, stack
);
908 /* Continue to next instruction */
909 /* Pop 1 when jump not taken */
910 if (vstack_pop(stack
)) {
914 next_pc
+= sizeof(struct logical_op
);
919 case FILTER_OP_LOAD_FIELD_REF
:
921 printk(KERN_WARNING
"Unknown field ref type\n");
925 /* get context ref */
926 case FILTER_OP_GET_CONTEXT_REF
:
928 printk(KERN_WARNING
"Unknown get context ref type\n");
932 case FILTER_OP_LOAD_FIELD_REF_STRING
:
933 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
934 case FILTER_OP_GET_CONTEXT_REF_STRING
:
936 if (vstack_push(stack
)) {
940 vstack_ax(stack
)->type
= REG_STRING
;
941 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
944 case FILTER_OP_LOAD_FIELD_REF_S64
:
945 case FILTER_OP_GET_CONTEXT_REF_S64
:
947 if (vstack_push(stack
)) {
951 vstack_ax(stack
)->type
= REG_S64
;
952 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
956 /* load from immediate operand */
957 case FILTER_OP_LOAD_STRING
:
959 struct load_op
*insn
= (struct load_op
*) pc
;
961 if (vstack_push(stack
)) {
965 vstack_ax(stack
)->type
= REG_STRING
;
966 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
970 case FILTER_OP_LOAD_S64
:
972 if (vstack_push(stack
)) {
976 vstack_ax(stack
)->type
= REG_S64
;
977 next_pc
+= sizeof(struct load_op
)
978 + sizeof(struct literal_numeric
);
982 case FILTER_OP_CAST_TO_S64
:
985 if (!vstack_ax(stack
)) {
986 printk(KERN_WARNING
"Empty stack\n");
990 vstack_ax(stack
)->type
= REG_S64
;
991 next_pc
+= sizeof(struct cast_op
);
994 case FILTER_OP_CAST_NOP
:
996 next_pc
+= sizeof(struct cast_op
);
1002 *_next_pc
= next_pc
;
1007 * Never called concurrently (hash seed is shared).
1009 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
)
1011 struct mp_table
*mp_table
;
1012 void *pc
, *next_pc
, *start_pc
;
1014 struct vstack stack
;
1016 vstack_init(&stack
);
1018 mp_table
= kzalloc(sizeof(*mp_table
), GFP_KERNEL
);
1020 printk(KERN_WARNING
"Error allocating hash table for bytecode validation\n");
1023 start_pc
= &bytecode
->data
[0];
1024 for (pc
= next_pc
= start_pc
; pc
- start_pc
< bytecode
->len
;
1026 ret
= bytecode_validate_overflow(bytecode
, start_pc
, pc
);
1029 printk(KERN_WARNING
"filter bytecode overflow\n");
1032 dbg_printk("Validating op %s (%u)\n",
1033 lttng_filter_print_op((unsigned int) *(filter_opcode_t
*) pc
),
1034 (unsigned int) *(filter_opcode_t
*) pc
);
1037 * For each instruction, validate the current context
1038 * (traversal of entire execution flow), and validate
1039 * all merge points targeting this instruction.
1041 ret
= validate_instruction_all_contexts(bytecode
, mp_table
,
1042 &stack
, start_pc
, pc
);
1045 ret
= exec_insn(bytecode
, mp_table
, &stack
, &next_pc
, pc
);
1050 if (delete_all_nodes(mp_table
)) {
1052 printk(KERN_WARNING
"Unexpected merge points\n");