xref: /linux/tools/testing/selftests/bpf/progs/map_excl.c (revision 4f38da1f027ea2c9f01bb71daa7a299c191b6940)
1*6c850cbcSKP Singh // SPDX-License-Identifier: GPL-2.0
2*6c850cbcSKP Singh /* Copyright (C) 2025 Google LLC. */
3*6c850cbcSKP Singh #include <linux/bpf.h>
4*6c850cbcSKP Singh #include <time.h>
5*6c850cbcSKP Singh #include <bpf/bpf_helpers.h>
6*6c850cbcSKP Singh 
7*6c850cbcSKP Singh #include "bpf_misc.h"
8*6c850cbcSKP Singh 
9*6c850cbcSKP Singh struct {
10*6c850cbcSKP Singh 	__uint(type, BPF_MAP_TYPE_ARRAY);
11*6c850cbcSKP Singh 	__type(key, __u32);
12*6c850cbcSKP Singh 	__type(value, __u32);
13*6c850cbcSKP Singh 	__uint(max_entries, 1);
14*6c850cbcSKP Singh } excl_map SEC(".maps");
15*6c850cbcSKP Singh 
16*6c850cbcSKP Singh char _license[] SEC("license") = "GPL";
17*6c850cbcSKP Singh 
18*6c850cbcSKP Singh SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
19*6c850cbcSKP Singh int should_have_access(void *ctx)
20*6c850cbcSKP Singh {
21*6c850cbcSKP Singh 	int key = 0, value = 0xdeadbeef;
22*6c850cbcSKP Singh 
23*6c850cbcSKP Singh 	bpf_map_update_elem(&excl_map, &key, &value, 0);
24*6c850cbcSKP Singh 	return 0;
25*6c850cbcSKP Singh }
26*6c850cbcSKP Singh 
27*6c850cbcSKP Singh SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
28*6c850cbcSKP Singh int should_not_have_access(void *ctx)
29*6c850cbcSKP Singh {
30*6c850cbcSKP Singh 	int key = 0, value = 0xdeadbeef;
31*6c850cbcSKP Singh 
32*6c850cbcSKP Singh 	bpf_map_update_elem(&excl_map, &key, &value, 0);
33*6c850cbcSKP Singh 	return 0;
34*6c850cbcSKP Singh }
35