1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2020 Facebook */ 3 #ifndef _BPF_TESTMOD_H 4 #define _BPF_TESTMOD_H 5 6 #include <linux/types.h> 7 8 struct task_struct; 9 struct cgroup; 10 11 struct bpf_testmod_test_read_ctx { 12 char *buf; 13 loff_t off; 14 size_t len; 15 }; 16 17 struct bpf_testmod_test_write_ctx { 18 char *buf; 19 loff_t off; 20 size_t len; 21 }; 22 23 struct bpf_testmod_test_writable_ctx { 24 bool early_ret; 25 int val; 26 }; 27 28 /* BPF iter that returns *value* *n* times in a row */ 29 struct bpf_iter_testmod_seq { 30 s64 value; 31 int cnt; 32 }; 33 34 struct bpf_testmod_ops { 35 int (*test_1)(void); 36 void (*test_2)(int a, int b); 37 /* Used to test nullable arguments. */ 38 int (*test_maybe_null)(int dummy, struct task_struct *task); 39 int (*unsupported_ops)(void); 40 /* Used to test ref_acquired arguments. */ 41 int (*test_refcounted)(int dummy, struct task_struct *task); 42 /* Used to test checking of __ref arguments when it not the first argument. */ 43 int (*test_refcounted_multi)(int dummy, struct task_struct *task, 44 struct task_struct *task2); 45 /* Used to test returning referenced kptr. */ 46 struct task_struct *(*test_return_ref_kptr)(int dummy, struct task_struct *task, 47 struct cgroup *cgrp); 48 49 /* The following fields are used to test shadow copies. */ 50 char onebyte; 51 struct { 52 int a; 53 int b; 54 } unsupported; 55 int data; 56 57 /* The following pointers are used to test the maps having multiple 58 * pages of trampolines. 59 */ 60 int (*tramp_1)(int value); 61 int (*tramp_2)(int value); 62 int (*tramp_3)(int value); 63 int (*tramp_4)(int value); 64 int (*tramp_5)(int value); 65 int (*tramp_6)(int value); 66 int (*tramp_7)(int value); 67 int (*tramp_8)(int value); 68 int (*tramp_9)(int value); 69 int (*tramp_10)(int value); 70 int (*tramp_11)(int value); 71 int (*tramp_12)(int value); 72 int (*tramp_13)(int value); 73 int (*tramp_14)(int value); 74 int (*tramp_15)(int value); 75 int (*tramp_16)(int value); 76 int (*tramp_17)(int value); 77 int (*tramp_18)(int value); 78 int (*tramp_19)(int value); 79 int (*tramp_20)(int value); 80 int (*tramp_21)(int value); 81 int (*tramp_22)(int value); 82 int (*tramp_23)(int value); 83 int (*tramp_24)(int value); 84 int (*tramp_25)(int value); 85 int (*tramp_26)(int value); 86 int (*tramp_27)(int value); 87 int (*tramp_28)(int value); 88 int (*tramp_29)(int value); 89 int (*tramp_30)(int value); 90 int (*tramp_31)(int value); 91 int (*tramp_32)(int value); 92 int (*tramp_33)(int value); 93 int (*tramp_34)(int value); 94 int (*tramp_35)(int value); 95 int (*tramp_36)(int value); 96 int (*tramp_37)(int value); 97 int (*tramp_38)(int value); 98 int (*tramp_39)(int value); 99 int (*tramp_40)(int value); 100 }; 101 102 struct bpf_testmod_ops2 { 103 int (*test_1)(void); 104 }; 105 106 /* 16 bytes, so it takes two argument slots when passed by value */ 107 struct bpf_testmod_arena_pair { 108 u64 a; 109 u64 b; 110 }; 111 112 struct bpf_testmod_ops3 { 113 int (*test_1)(void); 114 int (*test_2)(void); 115 /* Used to test arena pointer arguments. */ 116 int (*test_arena)(u64 *ptr); 117 int (*test_arena_nullable)(u64 *ptr); 118 /* enough leading args to force @ptr onto the stack on x86 and arm64 */ 119 int (*test_arena_stack)(u64 a, u64 b, u64 c, u64 d, u64 e, u64 f, 120 u64 g, u64 h, u64 *ptr); 121 /* a multi-slot leading arg, so @ptr is not at the slot its arg index suggests */ 122 int (*test_arena_multislot)(struct bpf_testmod_arena_pair p, u64 *ptr); 123 }; 124 125 struct st_ops_args { 126 u64 a; 127 }; 128 129 struct bpf_testmod_st_ops { 130 int (*test_prologue)(struct st_ops_args *args); 131 int (*test_epilogue)(struct st_ops_args *args); 132 int (*test_pro_epilogue)(struct st_ops_args *args); 133 struct module *owner; 134 }; 135 136 struct bpf_testmod_multi_st_ops { 137 int (*test_1)(struct st_ops_args *args); 138 struct hlist_node node; 139 int id; 140 }; 141 142 #endif /* _BPF_TESTMOD_H */ 143