1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Google LLC. */
5 #include <bpf/bpf_helpers.h>
15 char sym_out[64] = {};
18 char addr_out[64] = {};
21 char str_out[64] = {};
24 char over_out[6] = {};
27 char pad_out[10] = {};
30 char noarg_out[64] = {};
35 extern const void schedule __ksym;
37 SEC("raw_tp/sys_enter")
38 int handler(const void *ctx)
40 /* Convenient values to pretty-print */
41 const __u8 ex_ipv4[] = {127, 0, 0, 1};
42 const __u8 ex_ipv6[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
43 static const char str1[] = "str1";
44 static const char longstr[] = "longstr";
46 if ((int)bpf_get_current_pid_tgid() != pid)
50 num_ret = BPF_SNPRINTF(num_out, sizeof(num_out),
51 "%d %u %x %li %llu %lX",
52 -8, 9, 150, -424242, 1337, 0xDABBAD00);
54 ip_ret = BPF_SNPRINTF(ip_out, sizeof(ip_out), "%pi4 %pI6",
56 /* Symbol lookup formatting */
57 sym_ret = BPF_SNPRINTF(sym_out, sizeof(sym_out), "%ps %pS %pB",
58 &schedule, &schedule, &schedule);
60 addr_ret = BPF_SNPRINTF(addr_out, sizeof(addr_out), "%pK %px %p",
61 0, 0xFFFF00000ADD4E55, 0xFFFF00000ADD4E55);
62 /* Strings embedding */
63 str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s %+05s",
66 over_ret = BPF_SNPRINTF(over_out, sizeof(over_out), "%%overflow");
67 /* Padding of fixed width numbers */
68 pad_ret = BPF_SNPRINTF(pad_out, sizeof(pad_out), "%5d %0900000X", 4, 4);
70 noarg_ret = BPF_SNPRINTF(noarg_out, sizeof(noarg_out), "simple case");
72 nobuf_ret = BPF_SNPRINTF(NULL, 0, "only interested in length %d", 60);
77 char _license[] SEC("license") = "GPL";