1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_core_read.h>
9 char _license[] SEC("license") = "GPL";
16 struct core_reloc_size_output {
35 struct core_reloc_size {
37 struct { int x; } struct_field;
38 union { int x; } union_field;
41 enum { VALUE = 123 } enum_field;
45 SEC("raw_tracepoint/sys_enter")
46 int test_core_size(void *ctx)
48 struct core_reloc_size *in = (void *)&data.in;
49 struct core_reloc_size_output *out = (void *)&data.out;
51 out->int_sz = bpf_core_field_size(in->int_field);
52 out->int_off = bpf_core_field_offset(in->int_field);
54 out->struct_sz = bpf_core_field_size(in->struct_field);
55 out->struct_off = bpf_core_field_offset(in->struct_field);
57 out->union_sz = bpf_core_field_size(in->union_field);
58 out->union_off = bpf_core_field_offset(in->union_field);
60 out->arr_sz = bpf_core_field_size(in->arr_field);
61 out->arr_off = bpf_core_field_offset(in->arr_field);
63 out->arr_elem_sz = bpf_core_field_size(struct core_reloc_size, arr_field[1]);
64 out->arr_elem_off = bpf_core_field_offset(struct core_reloc_size, arr_field[1]);
66 out->ptr_sz = bpf_core_field_size(struct core_reloc_size, ptr_field);
67 out->ptr_off = bpf_core_field_offset(struct core_reloc_size, ptr_field);
69 out->enum_sz = bpf_core_field_size(struct core_reloc_size, enum_field);
70 out->enum_off = bpf_core_field_offset(struct core_reloc_size, enum_field);
72 out->float_sz = bpf_core_field_size(struct core_reloc_size, float_field);
73 out->float_off = bpf_core_field_offset(struct core_reloc_size, float_field);