1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3#include <vmlinux.h>
4#include <bpf/bpf_tracing.h>
5#include "../bpf_testmod/bpf_testmod.h"
6
7char _license[] SEC("license") = "GPL";
8
9pid_t tgid = 0;
10
11/* This is a test BPF program that uses struct_ops to access an argument
12 * that may be NULL. This is a test for the verifier to ensure that it can
13 * rip PTR_MAYBE_NULL correctly.
14 */
15SEC("struct_ops/test_maybe_null")
16int BPF_PROG(test_maybe_null, int dummy,
17	     struct task_struct *task)
18{
19	if (task)
20		tgid = task->tgid;
21
22	return 0;
23}
24
25SEC(".struct_ops.link")
26struct bpf_testmod_ops testmod_1 = {
27	.test_maybe_null = (void *)test_maybe_null,
28};
29
30