File Index
Files and directories
Sign in
FILE

task_local_storage_exit_creds.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/progs/task_local_storage_exit_creds.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2021 Facebook */
 3
 4#include "vmlinux.h"
 5#include <bpf/bpf_helpers.h>
 6#include <bpf/bpf_tracing.h>
 7
 8char _license[] SEC("license") = "GPL";
 9
10struct {
11	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
12	__uint(map_flags, BPF_F_NO_PREALLOC);
13	__type(key, int);
14	__type(value, __u64);
15} task_storage SEC(".maps");
16
17int run_count = 0;
18int valid_ptr_count = 0;
19int null_ptr_count = 0;
20
21SEC("fentry/exit_creds")
22int BPF_PROG(trace_exit_creds, struct task_struct *task)
23{
24	__u64 *ptr;
25
26	ptr = bpf_task_storage_get(&task_storage, task, 0,
27				   BPF_LOCAL_STORAGE_GET_F_CREATE);
28	if (ptr)
29		__sync_fetch_and_add(&valid_ptr_count, 1);
30	else
31		__sync_fetch_and_add(&null_ptr_count, 1);
32
33	__sync_fetch_and_add(&run_count, 1);
34	return 0;
35}
~/ Read-only file preview.