linux/tools/testing/selftests/bpf/progs/task_local_storage_exit_creds.c
<<
>>
Prefs
   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 valid_ptr_count = 0;
  18int null_ptr_count = 0;
  19
  20SEC("fentry/exit_creds")
  21int BPF_PROG(trace_exit_creds, struct task_struct *task)
  22{
  23        __u64 *ptr;
  24
  25        ptr = bpf_task_storage_get(&task_storage, task, 0,
  26                                   BPF_LOCAL_STORAGE_GET_F_CREATE);
  27        if (ptr)
  28                __sync_fetch_and_add(&valid_ptr_count, 1);
  29        else
  30                __sync_fetch_and_add(&null_ptr_count, 1);
  31        return 0;
  32}
  33