File Index
Files and directories
Sign in
FILE

htab_update.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/progs/htab_update.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (C) 2022. Huawei Technologies Co., Ltd */
 3#include <linux/bpf.h>
 4#include <bpf/bpf_helpers.h>
 5#include <bpf/bpf_tracing.h>
 6
 7char _license[] SEC("license") = "GPL";
 8
 9/* Map value type: has BTF-managed field (bpf_timer) */
10struct val {
11	struct bpf_timer t;
12	__u64 payload;
13};
14
15struct {
16	__uint(type, BPF_MAP_TYPE_HASH);
17	__uint(max_entries, 1);
18	__type(key, __u32);
19	__type(value, struct val);
20} htab SEC(".maps");
21
22int pid = 0;
23int update_err = 0;
24
25SEC("?fentry/bpf_obj_free_fields")
26int bpf_obj_free_fields(void *ctx)
27{
28	__u32 key = 0;
29	struct val value = { .payload = 1 };
30
31	if ((bpf_get_current_pid_tgid() >> 32) != pid)
32		return 0;
33
34	update_err = bpf_map_update_elem(&htab, &key, &value, BPF_ANY);
35	return 0;
36}
~/ Read-only file preview.