Skip to content

Instantly share code, notes, and snippets.

@grantseltzer
Created February 20, 2021 23:52
Show Gist options
  • Save grantseltzer/b7fca3e0df72fe8766a748ec39158a75 to your computer and use it in GitHub Desktop.
Save grantseltzer/b7fca3e0df72fe8766a748ec39158a75 to your computer and use it in GitHub Desktop.
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
char LICENSE[] SEC("license") = "GPL";
struct process_info {
int pid;
char comm[100];
};
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
} events SEC(".maps");
long ringbuffer_flags = 0;
SEC("kprobe/sys_mmap")
int kprobe__sys_mmap(struct pt_regs *ctx)
{
__u64 id = bpf_get_current_pid_tgid();
__u32 tgid = id >> 32;
struct process_info *process;
// Reserve space on the ringbuffer for the sample
process = bpf_ringbuf_reserve(&events, sizeof(struct process_info), ringbuffer_flags);
if (!process) {
return 0;
}
process->pid = tgid;
bpf_get_current_comm(&process->comm, 100);
bpf_ringbuf_submit(process, ringbuffer_flags);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment