1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_misc.h"
6 
7 SEC("netfilter")
8 __description("bpf_exit with invalid return code. test1")
9 __failure __msg("R0 is not a known value")
10 __naked void with_invalid_return_code_test1(void)
11 {
12 	asm volatile ("					\
13 	r0 = *(u64*)(r1 + 0);				\
14 	exit;						\
15 "	::: __clobber_all);
16 }
17 
18 SEC("netfilter")
19 __description("bpf_exit with valid return code. test2")
20 __success
21 __naked void with_valid_return_code_test2(void)
22 {
23 	asm volatile ("					\
24 	r0 = 0;						\
25 	exit;						\
26 "	::: __clobber_all);
27 }
28 
29 SEC("netfilter")
30 __description("bpf_exit with valid return code. test3")
31 __success
32 __naked void with_valid_return_code_test3(void)
33 {
34 	asm volatile ("					\
35 	r0 = 1;						\
36 	exit;						\
37 "	::: __clobber_all);
38 }
39 
40 SEC("netfilter")
41 __description("bpf_exit with invalid return code. test4")
42 __failure __msg("R0 has value (0x2; 0x0)")
43 __naked void with_invalid_return_code_test4(void)
44 {
45 	asm volatile ("					\
46 	r0 = 2;						\
47 	exit;						\
48 "	::: __clobber_all);
49 }
50