1 // SPDX-License-Identifier: GPL-2.0
3 * Augment the filename syscalls with the contents of the filename pointer argument
4 * filtering only those that do not start with /etc/.
8 * perf trace -e tools/perf/examples/bpf/augmented_syscalls.c cat /etc/passwd > /dev/null
10 * It'll catch some openat syscalls related to the dynamic linked and
11 * the last one should be the one for '/etc/passwd'.
13 * This matches what is marshalled into the raw_syscall:sys_enter payload
14 * expected by the 'perf trace' beautifiers, and can be used by them unmodified,
15 * which will be done as that feature is implemented in the next csets, for now
16 * it will appear in a dump done by the default tracepoint handler in 'perf trace',
17 * that uses bpf_output__fprintf() to just dump those contents, as done with
18 * the bpf-output event associated with the __bpf_output__ map declared in
19 * tools/perf/include/bpf/stdio.h.
24 /* bpf-output associated map */
25 bpf_map(__augmented_syscalls__
, PERF_EVENT_ARRAY
, int, u32
, __NR_CPUS__
);
27 struct augmented_filename
{
33 #define augmented_filename_syscall_enter(syscall) \
34 struct augmented_enter_##syscall##_args { \
35 struct syscall_enter_##syscall##_args args; \
36 struct augmented_filename filename; \
38 int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) \
40 char etc[6] = "/etc/"; \
41 struct augmented_enter_##syscall##_args augmented_args = { .filename.reserved = 0, }; \
42 probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \
43 augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \
44 sizeof(augmented_args.filename.value), \
45 args->filename_ptr); \
46 if (__builtin_memcmp(augmented_args.filename.value, etc, 4) != 0) \
48 /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ \
49 return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, \
51 (sizeof(augmented_args) - sizeof(augmented_args.filename.value) + \
52 augmented_args.filename.size)); \
55 struct syscall_enter_openat_args
{
56 unsigned long long common_tp_fields
;
64 augmented_filename_syscall_enter(openat
);
66 struct syscall_enter_open_args
{
67 unsigned long long common_tp_fields
;
74 augmented_filename_syscall_enter(open
);