github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/testdata/common.h (about)

     1  #pragma once
     2  
     3  typedef _Bool bool;
     4  typedef unsigned char uint8_t;
     5  typedef unsigned short uint16_t;
     6  typedef unsigned int uint32_t;
     7  typedef signed int int32_t;
     8  typedef unsigned long uint64_t;
     9  
    10  enum libbpf_tristate {
    11  	TRI_NO     = 0,
    12  	TRI_YES    = 1,
    13  	TRI_MODULE = 2,
    14  };
    15  
    16  #define __section(NAME) __attribute__((section(NAME), used))
    17  #define __uint(name, val) int(*name)[val]
    18  #define __type(name, val) typeof(val) *name
    19  #define __array(name, val) typeof(val) *name[]
    20  
    21  #define __kconfig __attribute__((section(".kconfig")))
    22  #define __ksym __attribute__((section(".ksyms")))
    23  #ifndef __weak
    24  #define __weak __attribute__((weak))
    25  #endif
    26  
    27  #define bpf_ksym_exists(sym) \
    28  	({ \
    29  		_Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); \
    30  		!!sym; \
    31  	})
    32  
    33  #define core_access __builtin_preserve_access_index
    34  
    35  #define BPF_MAP_TYPE_HASH (1)
    36  #define BPF_MAP_TYPE_ARRAY (2)
    37  #define BPF_MAP_TYPE_PROG_ARRAY (3)
    38  #define BPF_MAP_TYPE_PERF_EVENT_ARRAY (4)
    39  #define BPF_MAP_TYPE_ARRAY_OF_MAPS (12)
    40  #define BPF_MAP_TYPE_HASH_OF_MAPS (13)
    41  
    42  #define BPF_F_NO_PREALLOC (1U << 0)
    43  #define BPF_F_CURRENT_CPU (0xffffffffULL)
    44  
    45  /* From tools/lib/bpf/libbpf.h */
    46  struct bpf_map_def {
    47  	unsigned int type;
    48  	unsigned int key_size;
    49  	unsigned int value_size;
    50  	unsigned int max_entries;
    51  	unsigned int map_flags;
    52  };
    53  
    54  static void *(*map_lookup_elem)(const void *map, const void *key) = (void *)1;
    55  
    56  static long (*map_update_elem)(const void *map, const void *key, const void *value, uint64_t flags) = (void *)2;
    57  
    58  static long (*trace_printk)(const char *fmt, uint32_t fmt_size, ...) = (void *)6;
    59  
    60  static long (*tail_call)(void *ctx, void *prog_array_map, uint32_t index) = (void *)12;
    61  
    62  static int (*perf_event_output)(const void *ctx, const void *map, uint64_t index, const void *data, uint64_t size) = (void *)25;
    63  
    64  static uint32_t (*get_smp_processor_id)(void) = (void *)8;
    65  
    66  static long (*for_each_map_elem)(const void *map, void *callback_fn, void *callback_ctx, uint64_t flags) = (void *)164;