1 // SPDX-License-Identifier: GPL-2.0
4 #include <bpf/bpf_helpers.h>
7 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
8 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && __clang_major__ >= 18
11 __description("MOV32SX, S8")
12 __success __success_unpriv __retval(0x23)
13 __naked void mov32sx_s8(void)
23 __description("MOV32SX, S16")
24 __success __success_unpriv __retval(0xFFFFff23)
25 __naked void mov32sx_s16(void)
35 __description("MOV64SX, S8")
36 __success __success_unpriv __retval(-2)
37 __naked void mov64sx_s8(void)
47 __description("MOV64SX, S16")
48 __success __success_unpriv __retval(0xf23)
49 __naked void mov64sx_s16(void)
59 __description("MOV64SX, S32")
60 __success __success_unpriv __retval(-1)
61 __naked void mov64sx_s32(void)
72 __description("MOV32SX, S8, range_check")
73 __success __success_unpriv __retval(1)
74 __naked void mov32sx_s8_range(void)
77 call %[bpf_get_prandom_u32]; \
79 /* w1 with s8 range */ \
80 if w1 s> 0x7f goto l0_%=; \
81 if w1 s< -0x80 goto l0_%=; \
89 : __imm(bpf_get_prandom_u32)
94 __description("MOV32SX, S16, range_check")
95 __success __success_unpriv __retval(1)
96 __naked void mov32sx_s16_range(void)
99 call %[bpf_get_prandom_u32]; \
101 /* w1 with s16 range */ \
102 if w1 s> 0x7fff goto l0_%=; \
103 if w1 s< -0x80ff goto l0_%=; \
111 : __imm(bpf_get_prandom_u32)
116 __description("MOV32SX, S16, range_check 2")
117 __success __success_unpriv __retval(1)
118 __naked void mov32sx_s16_range_2(void)
124 if r2 != 0x7fffFFFF goto l0_%=; \
132 : __imm(bpf_get_prandom_u32)
137 __description("MOV64SX, S8, range_check")
138 __success __success_unpriv __retval(1)
139 __naked void mov64sx_s8_range(void)
142 call %[bpf_get_prandom_u32]; \
144 /* r1 with s8 range */ \
145 if r1 s> 0x7f goto l0_%=; \
146 if r1 s< -0x80 goto l0_%=; \
154 : __imm(bpf_get_prandom_u32)
159 __description("MOV64SX, S16, range_check")
160 __success __success_unpriv __retval(1)
161 __naked void mov64sx_s16_range(void)
164 call %[bpf_get_prandom_u32]; \
166 /* r1 with s16 range */ \
167 if r1 s> 0x7fff goto l0_%=; \
168 if r1 s< -0x8000 goto l0_%=; \
176 : __imm(bpf_get_prandom_u32)
181 __description("MOV64SX, S32, range_check")
182 __success __success_unpriv __retval(1)
183 __naked void mov64sx_s32_range(void)
186 call %[bpf_get_prandom_u32]; \
188 /* r1 with s32 range */ \
189 if r1 s> 0x7fffffff goto l0_%=; \
190 if r1 s< -0x80000000 goto l0_%=; \
198 : __imm(bpf_get_prandom_u32)
203 __description("MOV64SX, S16, R10 Sign Extension")
204 __failure __msg("R1 type=scalar expected=fp, pkt, pkt_meta, map_key, map_value, mem, ringbuf_mem, buf, trusted_ptr_")
205 __failure_unpriv __msg_unpriv("R10 sign-extension part of pointer")
206 __naked void mov64sx_s16_r10(void)
210 *(u32 *)(r10 - 8) = r1; \
214 if r2 <= r1 goto l0_%=; \
216 call %[bpf_trace_printk]; \
220 : __imm(bpf_trace_printk)
227 __description("cpuv4 is not supported by compiler or jit, use a dummy test")
236 char _license[] SEC("license") = "GPL";