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 #if !defined(__aarch64__)
8 struct syscalls_enter_open_args
{
9 unsigned long long unused
;
17 struct syscalls_exit_open_args
{
18 unsigned long long unused
;
23 struct syscalls_enter_open_at_args
{
24 unsigned long long unused
;
33 __uint(type
, BPF_MAP_TYPE_ARRAY
);
36 __uint(max_entries
, 1);
37 } enter_open_map
SEC(".maps");
40 __uint(type
, BPF_MAP_TYPE_ARRAY
);
43 __uint(max_entries
, 1);
44 } exit_open_map
SEC(".maps");
46 static __always_inline
void count(void *map
)
49 u32
*value
, init_val
= 1;
51 value
= bpf_map_lookup_elem(map
, &key
);
55 bpf_map_update_elem(map
, &key
, &init_val
, BPF_NOEXIST
);
58 #if !defined(__aarch64__)
59 SEC("tracepoint/syscalls/sys_enter_open")
60 int trace_enter_open(struct syscalls_enter_open_args
*ctx
)
62 count(&enter_open_map
);
67 SEC("tracepoint/syscalls/sys_enter_openat")
68 int trace_enter_open_at(struct syscalls_enter_open_at_args
*ctx
)
70 count(&enter_open_map
);
74 SEC("tracepoint/syscalls/sys_enter_openat2")
75 int trace_enter_open_at2(struct syscalls_enter_open_at_args
*ctx
)
77 count(&enter_open_map
);
81 #if !defined(__aarch64__)
82 SEC("tracepoint/syscalls/sys_exit_open")
83 int trace_enter_exit(struct syscalls_exit_open_args
*ctx
)
85 count(&exit_open_map
);
90 SEC("tracepoint/syscalls/sys_exit_openat")
91 int trace_enter_exit_at(struct syscalls_exit_open_args
*ctx
)
93 count(&exit_open_map
);
97 SEC("tracepoint/syscalls/sys_exit_openat2")
98 int trace_enter_exit_at2(struct syscalls_exit_open_args
*ctx
)
100 count(&exit_open_map
);