brintos

brintos / linux-shallow public Read only

0
0
Text · 860 B · 8669eb4 Raw
48 lines · c
1// SPDX-License-Identifier: GPL-2.02// Copyright (c) 2024 Andrea Righi <andrea.righi@canonical.com>3 4#include <linux/bpf.h>5#include <sched.h>6#include <unistd.h>7#include <bpf/bpf_helpers.h>8#include "bpf_misc.h"9 10char _license[] SEC("license") = "GPL";11 12#define TASK_COMM_LEN 1613 14struct sample {15	int pid;16	long value;17	char comm[16];18};19 20struct {21	__uint(type, BPF_MAP_TYPE_RINGBUF);22} ringbuf SEC(".maps");23 24int pid = 0;25long value = 0;26 27SEC("fentry/" SYS_PREFIX "sys_getpgid")28int test_ringbuf_n(void *ctx)29{30	int cur_pid = bpf_get_current_pid_tgid() >> 32;31	struct sample *sample;32 33	if (cur_pid != pid)34		return 0;35 36	sample = bpf_ringbuf_reserve(&ringbuf, sizeof(*sample), 0);37	if (!sample)38		return 0;39 40	sample->pid = pid;41	sample->value = value;42	bpf_get_current_comm(sample->comm, sizeof(sample->comm));43 44	bpf_ringbuf_submit(sample, 0);45 46	return 0;47}48