1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
8 #if defined(__TARGET_ARCH_x86) && __clang_major__ >= 18
9 const volatile int skip = 0;
11 const volatile int skip = 1;
14 volatile const short val1 = -1;
15 volatile const int val2 = -1;
18 int done1, done2, ret1, ret2;
20 SEC("?raw_tp/sys_enter")
21 int rdonly_map_prog(const void *ctx)
27 /* val1/val2 readonly map */
34 SEC("?raw_tp/sys_enter")
35 int map_val_prog(const void *ctx)
41 /* val1/val2 regular read/write map */
48 struct bpf_testmod_struct_arg_1 {
54 SEC("?fentry/bpf_testmod_test_arg_ptr_to_struct")
55 int BPF_PROG2(test_ptr_struct_arg, struct bpf_testmod_struct_arg_1 *, p)
57 /* probed memory access */
62 long long set_optlen, set_retval;
64 SEC("?cgroup/getsockopt")
65 int _getsockopt(volatile struct bpf_sockopt *ctx)
67 int old_optlen, old_retval;
69 old_optlen = ctx->optlen;
70 old_retval = ctx->retval;
75 /* sign extension for ctx member */
76 set_optlen = ctx->optlen;
77 set_retval = ctx->retval;
79 ctx->optlen = old_optlen;
80 ctx->retval = old_retval;
88 int _tc(volatile struct __sk_buff *skb)
97 /* narrowed sign extension for ctx member */
98 #if __clang_major__ >= 18
99 /* force narrow one-byte signed load. Otherwise, compiler may
100 * generate a 32-bit unsigned load followed by an s8 movsx.
102 asm volatile ("r1 = *(s8 *)(%[ctx] + %[off_mark])\n\t"
104 : [tmp_mark]"=r"(tmp_mark)
106 [off_mark]"i"(offsetof(struct __sk_buff, mark))
109 tmp_mark = (char)skb->mark;
113 skb->mark = old_mark;
118 char _license[] SEC("license") = "GPL";