1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2017 Facebook
4 #include <uapi/linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
7 struct syscalls_enter_open_args {
8 unsigned long long unused;
15 struct syscalls_exit_open_args {
16 unsigned long long unused;
22 __uint(type, BPF_MAP_TYPE_ARRAY);
25 __uint(max_entries, 1);
26 } enter_open_map SEC(".maps");
29 __uint(type, BPF_MAP_TYPE_ARRAY);
32 __uint(max_entries, 1);
33 } exit_open_map SEC(".maps");
35 static __always_inline void count(void *map)
38 u32 *value, init_val = 1;
40 value = bpf_map_lookup_elem(map, &key);
44 bpf_map_update_elem(map, &key, &init_val, BPF_NOEXIST);
47 #if !defined(__aarch64__)
48 SEC("tracepoint/syscalls/sys_enter_open")
49 int trace_enter_open(struct syscalls_enter_open_args *ctx)
51 count(&enter_open_map);
56 SEC("tracepoint/syscalls/sys_enter_openat")
57 int trace_enter_open_at(struct syscalls_enter_open_args *ctx)
59 count(&enter_open_map);
63 SEC("tracepoint/syscalls/sys_enter_openat2")
64 int trace_enter_open_at2(struct syscalls_enter_open_args *ctx)
66 count(&enter_open_map);
70 #if !defined(__aarch64__)
71 SEC("tracepoint/syscalls/sys_exit_open")
72 int trace_enter_exit(struct syscalls_exit_open_args *ctx)
74 count(&exit_open_map);
79 SEC("tracepoint/syscalls/sys_exit_openat")
80 int trace_enter_exit_at(struct syscalls_exit_open_args *ctx)
82 count(&exit_open_map);
86 SEC("tracepoint/syscalls/sys_exit_openat2")
87 int trace_enter_exit_at2(struct syscalls_exit_open_args *ctx)
89 count(&exit_open_map);