linux/tools/testing/selftests/bpf/progs/test_core_reloc_size.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2// Copyright (c) 2019 Facebook
   3
   4#include <linux/bpf.h>
   5#include <stdint.h>
   6#include <bpf/bpf_helpers.h>
   7#include <bpf/bpf_core_read.h>
   8
   9char _license[] SEC("license") = "GPL";
  10
  11struct {
  12        char in[256];
  13        char out[256];
  14} data = {};
  15
  16struct core_reloc_size_output {
  17        int int_sz;
  18        int struct_sz;
  19        int union_sz;
  20        int arr_sz;
  21        int arr_elem_sz;
  22        int ptr_sz;
  23        int enum_sz;
  24        int float_sz;
  25};
  26
  27struct core_reloc_size {
  28        int int_field;
  29        struct { int x; } struct_field;
  30        union { int x; } union_field;
  31        int arr_field[4];
  32        void *ptr_field;
  33        enum { VALUE = 123 } enum_field;
  34        float float_field;
  35};
  36
  37SEC("raw_tracepoint/sys_enter")
  38int test_core_size(void *ctx)
  39{
  40        struct core_reloc_size *in = (void *)&data.in;
  41        struct core_reloc_size_output *out = (void *)&data.out;
  42
  43        out->int_sz = bpf_core_field_size(in->int_field);
  44        out->struct_sz = bpf_core_field_size(in->struct_field);
  45        out->union_sz = bpf_core_field_size(in->union_field);
  46        out->arr_sz = bpf_core_field_size(in->arr_field);
  47        out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]);
  48        out->ptr_sz = bpf_core_field_size(in->ptr_field);
  49        out->enum_sz = bpf_core_field_size(in->enum_field);
  50        out->float_sz = bpf_core_field_size(in->float_field);
  51
  52        return 0;
  53}
  54
  55
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.