1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_tracing.h>
7 #include "../test_kmods/bpf_testmod.h"
8 #include "../test_kmods/bpf_testmod_kfunc.h"
10 char _license[] SEC("license") = "GPL";
13 /* save __u64 *ctx to stack */
14 __xlated("0: *(u64 *)(r10 -8) = r1")
16 __xlated("1: r1 = *(u64 *)(r1 +0)")
17 __xlated("2: r2 = *(u64 *)(r1 +0)")
20 __xlated("5: if r2 == 0x0 goto pc+10")
22 __xlated("7: *(u64 *)(r1 +0) = r3")
24 __xlated("8: r1 = *(u64 *)(r10 -8)")
25 __xlated("9: r1 = *(u64 *)(r1 +0)")
26 __xlated("10: r6 = *(u64 *)(r1 +0)")
27 __xlated("11: r6 += 10000")
28 __xlated("12: *(u64 *)(r1 +0) = r6")
29 __xlated("13: r0 = r6")
30 __xlated("14: r0 *= 2")
32 /* 2nd part of the main prog after the first exit */
33 __xlated("16: *(u64 *)(r1 +0) = r4")
34 __xlated("17: r0 = 1")
35 /* Clear the r1 to ensure it does not have
36 * off-by-1 error and ensure it jumps back to the
37 * beginning of epilogue which initializes
38 * the r1 with the ctx ptr.
40 __xlated("18: r1 = 0")
41 __xlated("19: gotol pc-12")
42 SEC("struct_ops/test_epilogue_exit")
43 __naked int test_epilogue_exit(void)
46 "r1 = *(u64 *)(r1 +0);"
47 "r2 = *(u64 *)(r1 +0);"
52 "*(u64 *)(r1 + 0) = r3;"
54 "*(u64 *)(r1 + 0) = r4;"
61 SEC(".struct_ops.link")
62 struct bpf_testmod_st_ops epilogue_exit = {
63 .test_epilogue = (void *)test_epilogue_exit,
68 int syscall_epilogue_exit0(void *ctx)
70 struct st_ops_args args = { .a = 1 };
72 return bpf_kfunc_st_ops_test_epilogue(&args);
77 int syscall_epilogue_exit1(void *ctx)
79 struct st_ops_args args = {};
81 return bpf_kfunc_st_ops_test_epilogue(&args);