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 9 char _license[] SEC("license") = "GPL"; 10 11 struct { 12 char in[256]; 13 char out[256]; 14 } data = {}; 15 16 enum core_reloc_primitives_enum { 17 A = 0, 18 B = 1, 19 }; 20 21 struct core_reloc_primitives { 22 char a; 23 int b; 24 enum core_reloc_primitives_enum c; 25 void *d; 26 int (*f)(const char *); 27 }; 28 29 #define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src) 30 31 SEC("raw_tracepoint/sys_enter") 32 int test_core_primitives(void *ctx) 33 { 34 struct core_reloc_primitives *in = (void *)&data.in; 35 struct core_reloc_primitives *out = (void *)&data.out; 36 37 if (CORE_READ(&out->a, &in->a) || 38 CORE_READ(&out->b, &in->b) || 39 CORE_READ(&out->c, &in->c) || 40 CORE_READ(&out->d, &in->d) || 41 CORE_READ(&out->f, &in->f)) 42 return 1; 43 44 return 0; 45 } 46 47