xref: /linux/tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c (revision 35f301dd4551fa731db4834f915e8351838f6f19)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 #include "../bpf_testmod/bpf_testmod.h"
7 #include "bpf_misc.h"
8 
9 SEC("tp_btf/bpf_testmod_test_nullable_bare")
10 __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
BPF_PROG(handle_tp_btf_nullable_bare1,struct bpf_testmod_test_read_ctx * nullable_ctx)11 int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx)
12 {
13 	return nullable_ctx->len;
14 }
15 
16 SEC("tp_btf/bpf_testmod_test_nullable_bare")
BPF_PROG(handle_tp_btf_nullable_bare2,struct bpf_testmod_test_read_ctx * nullable_ctx)17 int BPF_PROG(handle_tp_btf_nullable_bare2, struct bpf_testmod_test_read_ctx *nullable_ctx)
18 {
19 	if (nullable_ctx)
20 		return nullable_ctx->len;
21 	return 0;
22 }
23 
24 char _license[] SEC("license") = "GPL";
25