hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/samples/bpf/tracex5_kern.c
....@@ -10,20 +10,21 @@
1010 #include <uapi/linux/seccomp.h>
1111 #include <uapi/linux/unistd.h>
1212 #include "syscall_nrs.h"
13
-#include "bpf_helpers.h"
13
+#include <bpf/bpf_helpers.h>
14
+#include <bpf/bpf_tracing.h>
1415
1516 #define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F
1617
17
-struct bpf_map_def SEC("maps") progs = {
18
- .type = BPF_MAP_TYPE_PROG_ARRAY,
19
- .key_size = sizeof(u32),
20
- .value_size = sizeof(u32),
18
+struct {
19
+ __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
20
+ __uint(key_size, sizeof(u32));
21
+ __uint(value_size, sizeof(u32));
2122 #ifdef __mips__
22
- .max_entries = 6000, /* MIPS n64 syscalls start at 5000 */
23
+ __uint(max_entries, 6000); /* MIPS n64 syscalls start at 5000 */
2324 #else
24
- .max_entries = 1024,
25
+ __uint(max_entries, 1024);
2526 #endif
26
-};
27
+} progs SEC(".maps");
2728
2829 SEC("kprobe/__seccomp_filter")
2930 int bpf_prog1(struct pt_regs *ctx)
....@@ -46,7 +47,7 @@
4647 {
4748 struct seccomp_data sd;
4849
49
- bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
50
+ bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
5051 if (sd.args[2] == 512) {
5152 char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
5253 bpf_trace_printk(fmt, sizeof(fmt),
....@@ -59,7 +60,7 @@
5960 {
6061 struct seccomp_data sd;
6162
62
- bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
63
+ bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
6364 if (sd.args[2] > 128 && sd.args[2] <= 1024) {
6465 char fmt[] = "read(fd=%d, buf=%p, size=%d)\n";
6566 bpf_trace_printk(fmt, sizeof(fmt),
....@@ -68,12 +69,25 @@
6869 return 0;
6970 }
7071
71
-PROG(SYS__NR_mmap)(struct pt_regs *ctx)
72
+#ifdef __NR_mmap2
73
+PROG(SYS__NR_mmap2)(struct pt_regs *ctx)
7274 {
73
- char fmt[] = "mmap\n";
75
+ char fmt[] = "mmap2\n";
76
+
7477 bpf_trace_printk(fmt, sizeof(fmt));
7578 return 0;
7679 }
80
+#endif
81
+
82
+#ifdef __NR_mmap
83
+PROG(SYS__NR_mmap)(struct pt_regs *ctx)
84
+{
85
+ char fmt[] = "mmap\n";
86
+
87
+ bpf_trace_printk(fmt, sizeof(fmt));
88
+ return 0;
89
+}
90
+#endif
7791
7892 char _license[] SEC("license") = "GPL";
7993 u32 _version SEC("version") = LINUX_VERSION_CODE;