github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/kfuzztest/testdata/common.h (about) 1 // Copyright 2025 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 // Common struct definitions that ressemble those sound in the kernel source 5 // under include/linux/kfuzztest.h. For testing purposes, it is only required 6 // that these have the same sizes and emitted metadata as the kernel 7 // definitions, and therefore there is no strict requirement that their fields 8 // match one-to-one. 9 #ifndef COMMON_H 10 #define COMMON_H 11 12 #include <stdint.h> 13 14 struct kfuzztest_target { 15 const char *name; 16 const char *arg_type_name; 17 uintptr_t write_input_cb; 18 } __attribute__((aligned(32))); 19 20 enum kfuzztest_constraint_type { 21 EXPECT_EQ, 22 EXPECT_NE, 23 EXPECT_LT, 24 EXPECT_LE, 25 EXPECT_GT, 26 EXPECT_GE, 27 EXPECT_IN_RANGE, 28 }; 29 30 struct kfuzztest_constraint { 31 const char *input_type; 32 const char *field_name; 33 uintptr_t value1; 34 uintptr_t value2; 35 enum kfuzztest_constraint_type type; 36 } __attribute__((aligned(64))); 37 38 enum kfuzztest_annotation_attribute { 39 ATTRIBUTE_LEN, 40 ATTRIBUTE_STRING, 41 ATTRIBUTE_ARRAY, 42 }; 43 44 struct kfuzztest_annotation { 45 const char *input_type; 46 const char *field_name; 47 const char *linked_field_name; 48 enum kfuzztest_annotation_attribute attrib; 49 } __attribute__((aligned(32))); 50 51 #define DEFINE_FUZZ_TARGET(test_name, test_arg_type) \ 52 struct kfuzztest_target __fuzz_test__##test_name \ 53 __attribute__((section(".kfuzztest_target"), __used__)) = { \ 54 .name = #test_name, \ 55 .arg_type_name = #test_arg_type, \ 56 }; \ 57 /* Avoid the compiler optimizing out the struct definition. */ \ 58 static test_arg_type arg; 59 60 #define DEFINE_CONSTRAINT(arg_type, field, val1, val2, tpe) \ 61 static struct kfuzztest_constraint __constraint_##arg_type##_##field \ 62 __attribute__((section(".kfuzztest_constraint"), \ 63 __used__)) = { \ 64 .input_type = "struct " #arg_type, \ 65 .field_name = #field, \ 66 .value1 = (uintptr_t)val1, \ 67 .value2 = (uintptr_t)val2, \ 68 .type = tpe, \ 69 } 70 71 #define DEFINE_ANNOTATION(arg_type, field, linked_field, attribute) \ 72 static struct kfuzztest_annotation __annotation_##arg_type##_##field \ 73 __attribute__((section(".kfuzztest_annotation"), \ 74 __used__)) = { \ 75 .input_type = "struct " #arg_type, \ 76 .field_name = #field, \ 77 .linked_field_name = #linked_field, \ 78 .attrib = attribute, \ 79 } 80 81 #endif /* COMMON_H */