linux/tools/testing/selftests/bpf/progs/test_core_reloc_mods.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_mods_output {
  17        int a, b, c, d, e, f, g, h;
  18};
  19
  20typedef const int int_t;
  21typedef const char *char_ptr_t;
  22typedef const int arr_t[7];
  23
  24struct core_reloc_mods_substruct {
  25        int x;
  26        int y;
  27};
  28
  29typedef struct {
  30        int x;
  31        int y;
  32} core_reloc_mods_substruct_t;
  33
  34struct core_reloc_mods {
  35        int a;
  36        int_t b;
  37        char *c;
  38        char_ptr_t d;
  39        int e[3];
  40        arr_t f;
  41        struct core_reloc_mods_substruct g;
  42        core_reloc_mods_substruct_t h;
  43};
  44
  45#define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src)
  46
  47SEC("raw_tracepoint/sys_enter")
  48int test_core_mods(void *ctx)
  49{
  50        struct core_reloc_mods *in = (void *)&data.in;
  51        struct core_reloc_mods_output *out = (void *)&data.out;
  52
  53        if (CORE_READ(&out->a, &in->a) ||
  54            CORE_READ(&out->b, &in->b) ||
  55            CORE_READ(&out->c, &in->c) ||
  56            CORE_READ(&out->d, &in->d) ||
  57            CORE_READ(&out->e, &in->e[2]) ||
  58            CORE_READ(&out->f, &in->f[1]) ||
  59            CORE_READ(&out->g, &in->g.x) ||
  60            CORE_READ(&out->h, &in->h.y))
  61                return 1;
  62
  63        return 0;
  64}
  65
  66