Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0-only
 2/* Copyright (c) 2017 Facebook
 
 
 
 
 3 */
 4#include <uapi/linux/bpf.h>
 5#include "bpf_helpers.h"
 6
 7struct syscalls_enter_open_args {
 8	unsigned long long unused;
 9	long syscall_nr;
10	long filename_ptr;
11	long flags;
12	long mode;
13};
14
15struct syscalls_exit_open_args {
16	unsigned long long unused;
17	long syscall_nr;
18	long ret;
19};
20
21struct bpf_map_def SEC("maps") enter_open_map = {
22	.type = BPF_MAP_TYPE_ARRAY,
23	.key_size = sizeof(u32),
24	.value_size = sizeof(u32),
25	.max_entries = 1,
26};
27
28struct bpf_map_def SEC("maps") exit_open_map = {
29	.type = BPF_MAP_TYPE_ARRAY,
30	.key_size = sizeof(u32),
31	.value_size = sizeof(u32),
32	.max_entries = 1,
33};
34
35static __always_inline void count(void *map)
36{
37	u32 key = 0;
38	u32 *value, init_val = 1;
39
40	value = bpf_map_lookup_elem(map, &key);
41	if (value)
42		*value += 1;
43	else
44		bpf_map_update_elem(map, &key, &init_val, BPF_NOEXIST);
45}
46
47SEC("tracepoint/syscalls/sys_enter_open")
48int trace_enter_open(struct syscalls_enter_open_args *ctx)
49{
50	count((void *)&enter_open_map);
51	return 0;
52}
53
54SEC("tracepoint/syscalls/sys_exit_open")
55int trace_enter_exit(struct syscalls_exit_open_args *ctx)
56{
57	count((void *)&exit_open_map);
58	return 0;
59}
v4.17
 
 1/* Copyright (c) 2017 Facebook
 2 *
 3 * This program is free software; you can redistribute it and/or
 4 * modify it under the terms of version 2 of the GNU General Public
 5 * License as published by the Free Software Foundation.
 6 */
 7#include <uapi/linux/bpf.h>
 8#include "bpf_helpers.h"
 9
10struct syscalls_enter_open_args {
11	unsigned long long unused;
12	long syscall_nr;
13	long filename_ptr;
14	long flags;
15	long mode;
16};
17
18struct syscalls_exit_open_args {
19	unsigned long long unused;
20	long syscall_nr;
21	long ret;
22};
23
24struct bpf_map_def SEC("maps") enter_open_map = {
25	.type = BPF_MAP_TYPE_ARRAY,
26	.key_size = sizeof(u32),
27	.value_size = sizeof(u32),
28	.max_entries = 1,
29};
30
31struct bpf_map_def SEC("maps") exit_open_map = {
32	.type = BPF_MAP_TYPE_ARRAY,
33	.key_size = sizeof(u32),
34	.value_size = sizeof(u32),
35	.max_entries = 1,
36};
37
38static __always_inline void count(void *map)
39{
40	u32 key = 0;
41	u32 *value, init_val = 1;
42
43	value = bpf_map_lookup_elem(map, &key);
44	if (value)
45		*value += 1;
46	else
47		bpf_map_update_elem(map, &key, &init_val, BPF_NOEXIST);
48}
49
50SEC("tracepoint/syscalls/sys_enter_open")
51int trace_enter_open(struct syscalls_enter_open_args *ctx)
52{
53	count((void *)&enter_open_map);
54	return 0;
55}
56
57SEC("tracepoint/syscalls/sys_exit_open")
58int trace_enter_exit(struct syscalls_exit_open_args *ctx)
59{
60	count((void *)&exit_open_map);
61	return 0;
62}