Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2
3#include <vmlinux.h>
4#include <bpf/bpf_helpers.h>
5#include "bpf_misc.h"
6
7__noinline
8long changes_pkt_data(struct __sk_buff *sk)
9{
10 return bpf_skb_pull_data(sk, 0);
11}
12
13__noinline __weak
14long does_not_change_pkt_data(struct __sk_buff *sk)
15{
16 return 0;
17}
18
19SEC("?tc")
20int main_changes_with_subprogs(struct __sk_buff *sk)
21{
22 changes_pkt_data(sk);
23 does_not_change_pkt_data(sk);
24 return 0;
25}
26
27SEC("?tc")
28int main_changes(struct __sk_buff *sk)
29{
30 bpf_skb_pull_data(sk, 0);
31 return 0;
32}
33
34SEC("?tc")
35int main_does_not_change(struct __sk_buff *sk)
36{
37 return 0;
38}
39
40__noinline
41long might_sleep(struct pt_regs *ctx __arg_ctx)
42{
43 int i;
44
45 bpf_copy_from_user(&i, sizeof(i), NULL);
46 return i;
47}
48
49__noinline __weak
50long does_not_sleep(struct pt_regs *ctx __arg_ctx)
51{
52 return 0;
53}
54
55SEC("?uprobe.s")
56int main_might_sleep_with_subprogs(struct pt_regs *ctx)
57{
58 might_sleep(ctx);
59 does_not_sleep(ctx);
60 return 0;
61}
62
63SEC("?uprobe.s")
64int main_might_sleep(struct pt_regs *ctx)
65{
66 int i;
67
68 bpf_copy_from_user(&i, sizeof(i), NULL);
69 return i;
70}
71
72SEC("?uprobe.s")
73int main_does_not_sleep(struct pt_regs *ctx)
74{
75 return 0;
76}
77
78char _license[] SEC("license") = "GPL";