1 // SPDX-License-Identifier: GPL-2.0
4 #include <bpf/bpf_helpers.h>
11 SEC("tracepoint/syscalls/sys_enter_nanosleep")
14 /* This BPF program performs variable-offset reads and writes on a
15 * stack-allocated buffer.
21 if ((bpf_get_current_pid_tgid() >> 32) != test_pid)
24 /* Copy the input to the stack. */
25 __builtin_memcpy(stack_buf, input, 4);
27 /* The first byte in the buffer indicates the length. */
28 len = stack_buf[0] & 0xf;
29 last = (len - 1) & 0xf;
31 /* Append something to the buffer. The offset where we write is not
32 * statically known; this is a variable-offset stack write.
36 /* Index into the buffer at an unknown offset. This is a
37 * variable-offset stack read.
39 * Note that if it wasn't for the preceding variable-offset write, this
40 * read would be rejected because the stack slot cannot be verified as
41 * being initialized. With the preceding variable-offset write, the
42 * stack slot still cannot be verified, but the write inhibits the
43 * respective check on the reasoning that, if there was a
44 * variable-offset to a higher-or-equal spot, we're probably reading
47 probe_res = stack_buf[last];
51 char _license[] SEC("license") = "GPL";