34 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2020 Tessares SA <http://www.tessares.net> */3 4#include "vmlinux.h"5#include <bpf/bpf_helpers.h>6 7__u64 inKey = 0;8__u64 inValue = 0;9__u32 inPid = 0;10 11struct {12 __uint(type, BPF_MAP_TYPE_PERCPU_HASH);13 __uint(max_entries, 2);14 __type(key, __u64);15 __type(value, __u64);16} hashmap1 SEC(".maps");17 18 19SEC("tp/syscalls/sys_enter_getpgid")20int sysenter_getpgid(const void *ctx)21{22 /* Just do it for once, when called from our own test prog. This23 * ensures the map value is only updated for a single CPU.24 */25 int cur_pid = bpf_get_current_pid_tgid() >> 32;26 27 if (cur_pid == inPid)28 bpf_map_update_elem(&hashmap1, &inKey, &inValue, BPF_NOEXIST);29 30 return 0;31}32 33char _license[] SEC("license") = "GPL";34