Skip to content

Commit 9e87ee5

Browse files
committed
Move relevant vmlinux files to ex7.bpf.c
1 parent d0be889 commit 9e87ee5

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

examples/c-form/ex7.bpf.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,47 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
23
#include <linux/bpf.h>
34
#include <bpf/bpf_helpers.h>
45
#include <bpf/bpf_tracing.h>
56

7+
struct trace_entry {
8+
short unsigned int type;
9+
unsigned char flags;
10+
unsigned char preempt_count;
11+
int pid;
12+
};
13+
14+
struct trace_event_raw_sys_enter {
15+
struct trace_entry ent;
16+
long int id;
17+
long unsigned int args[6];
18+
char __data[0];
19+
};
620

721
struct event {
8-
__u32 pid;
9-
__u32 uid;
10-
__u64 ts;
22+
__u32 pid;
23+
__u32 uid;
24+
__u64 ts;
1125
};
1226

1327
struct {
14-
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
15-
__uint(key_size, sizeof(int));
16-
__uint(value_size, sizeof(int));
28+
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
29+
__uint(key_size, sizeof(int));
30+
__uint(value_size, sizeof(int));
1731
} events SEC(".maps");
1832

1933
SEC("tp/syscalls/sys_enter_setuid")
20-
int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx)
21-
{
22-
struct event data = {};
23-
24-
// Extract UID from the syscall arguments
25-
data.uid = (unsigned int)ctx->args[0];
26-
data.ts = bpf_ktime_get_ns();
27-
data.pid = bpf_get_current_pid_tgid() >> 32;
28-
29-
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data, sizeof(data));
30-
31-
return 0;
34+
int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) {
35+
struct event data = {};
36+
37+
// Extract UID from the syscall arguments
38+
data.uid = (unsigned int)ctx->args[0];
39+
data.ts = bpf_ktime_get_ns();
40+
data.pid = bpf_get_current_pid_tgid() >> 32;
41+
42+
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data, sizeof(data));
43+
44+
return 0;
3245
}
3346

3447
char LICENSE[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)