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
;
21 struct bpf_map_def
SEC("maps") enter_open_map
= {
22 .type
= BPF_MAP_TYPE_ARRAY
,
23 .key_size
= sizeof(u32
),
24 .value_size
= sizeof(u32
),
28 struct bpf_map_def
SEC("maps") exit_open_map
= {
29 .type
= BPF_MAP_TYPE_ARRAY
,
30 .key_size
= sizeof(u32
),
31 .value_size
= sizeof(u32
),
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 SEC("tracepoint/syscalls/sys_enter_open")
48 int trace_enter_open(struct syscalls_enter_open_args
*ctx
)
50 count(&enter_open_map
);
54 SEC("tracepoint/syscalls/sys_enter_openat")
55 int trace_enter_open_at(struct syscalls_enter_open_args
*ctx
)
57 count(&enter_open_map
);
61 SEC("tracepoint/syscalls/sys_exit_open")
62 int trace_enter_exit(struct syscalls_exit_open_args
*ctx
)
64 count(&exit_open_map
);
68 SEC("tracepoint/syscalls/sys_exit_openat")
69 int trace_enter_exit_at(struct syscalls_exit_open_args
*ctx
)
71 count(&exit_open_map
);