github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/pkg/ebpftracer/c/headers/vmlinux_missing.h (about)

     1  #ifndef __VMLINUX_MISSING_H__
     2  #define __VMLINUX_MISSING_H__
     3  
     4  // NOTE: vmlinux.h contains kernel BTF types but not macros (put it here)
     5  
     6  #include <vmlinux.h>
     7  
     8  #define ULLONG_MAX (~0ULL)
     9  
    10  #define inet_daddr     sk.__sk_common.skc_daddr
    11  #define inet_rcv_saddr sk.__sk_common.skc_rcv_saddr
    12  #define inet_dport     sk.__sk_common.skc_dport
    13  #define inet_num       sk.__sk_common.skc_num
    14  
    15  #define sk_node             __sk_common.skc_node
    16  #define sk_nulls_node       __sk_common.skc_nulls_node
    17  #define sk_refcnt           __sk_common.skc_refcnt
    18  #define sk_tx_queue_mapping __sk_common.skc_tx_queue_mapping
    19  
    20  #define sk_dontcopy_begin __sk_common.skc_dontcopy_begin
    21  #define sk_dontcopy_end   __sk_common.skc_dontcopy_end
    22  #define sk_hash           __sk_common.skc_hash
    23  #define sk_portpair       __sk_common.skc_portpair
    24  #define sk_num            __sk_common.skc_num
    25  #define sk_dport          __sk_common.skc_dport
    26  #define sk_addrpair       __sk_common.skc_addrpair
    27  #define sk_daddr          __sk_common.skc_daddr
    28  #define sk_rcv_saddr      __sk_common.skc_rcv_saddr
    29  #define sk_family         __sk_common.skc_family
    30  #define sk_state          __sk_common.skc_state
    31  #define sk_reuse          __sk_common.skc_reuse
    32  #define sk_reuseport      __sk_common.skc_reuseport
    33  #define sk_ipv6only       __sk_common.skc_ipv6only
    34  #define sk_net_refcnt     __sk_common.skc_net_refcnt
    35  #define sk_bound_dev_if   __sk_common.skc_bound_dev_if
    36  #define sk_bind_node      __sk_common.skc_bind_node
    37  #define sk_prot           __sk_common.skc_prot
    38  #define sk_net            __sk_common.skc_net
    39  #define sk_v6_daddr       __sk_common.skc_v6_daddr
    40  #define sk_v6_rcv_saddr   __sk_common.skc_v6_rcv_saddr
    41  #define sk_cookie         __sk_common.skc_cookie
    42  #define sk_incoming_cpu   __sk_common.skc_incoming_cpu
    43  #define sk_flags          __sk_common.skc_flags
    44  #define sk_rxhash         __sk_common.skc_rxhash
    45  
    46  #define ICMP_ECHO     8
    47  #define ICMP_EXT_ECHO 42
    48  
    49  #define ICMPV6_ECHO_REQUEST 128
    50  
    51  #define PF_KTHREAD 0x00200000 /* I am a kernel thread */
    52  
    53  #define TASK_COMM_LEN 16
    54  
    55  #define PROC_SUPER_MAGIC 0x9fa0
    56  
    57  // include/uapi/linux/const.h
    58  #define __AC(X, Y) (X##Y)
    59  #define _AC(X, Y)  __AC(X, Y)
    60  #define _UL(x)     (_AC(x, UL))
    61  
    62  // ioctl
    63  #define _IOC_NRBITS   8
    64  #define _IOC_TYPEBITS 8
    65  
    66  #ifndef _IOC_SIZEBITS
    67      #define _IOC_SIZEBITS 14
    68  #endif
    69  
    70  #define _IOC_NRSHIFT   0
    71  #define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS)
    72  #define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS)
    73  #define _IOC_DIRSHIFT  (_IOC_SIZESHIFT + _IOC_SIZEBITS)
    74  
    75  #ifndef _IOC_WRITE
    76      #define _IOC_WRITE 1U
    77  #endif
    78  
    79  #define _IOC(dir, type, nr, size)                                                                  \
    80      (((dir) << _IOC_DIRSHIFT) | ((type) << _IOC_TYPESHIFT) | ((nr) << _IOC_NRSHIFT) |              \
    81       ((size) << _IOC_SIZESHIFT))
    82  
    83  #define _IOC_TYPECHECK(t)      (sizeof(t))
    84  #define _IOW(type, nr, size)   _IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
    85  #define PERF_EVENT_IOC_SET_BPF _IOW('$', 8, __u32)
    86  
    87  enum perf_type_id
    88  {
    89      PERF_TYPE_HARDWARE = 0,
    90      PERF_TYPE_SOFTWARE = 1,
    91      PERF_TYPE_TRACEPOINT = 2,
    92      PERF_TYPE_HW_CACHE = 3,
    93      PERF_TYPE_RAW = 4,
    94      PERF_TYPE_BREAKPOINT = 5,
    95  
    96      PERF_TYPE_MAX, /* non-ABI */
    97  };
    98  
    99  /*=============================== ARCH SPECIFIC ===========================*/
   100  #if defined(__TARGET_ARCH_x86)
   101  
   102      #define TS_COMPAT 0x0002 /* 32bit syscall active (64BIT)*/
   103  
   104      // arch/x86/include/asm/page_64_types.h
   105      #define KASAN_STACK_ORDER                                                                      \
   106          0 /* We implicitly assume here that KASAN (memory debugger) is disabled */
   107      #define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER)
   108      #define THREAD_SIZE       (PAGE_SIZE << THREAD_SIZE_ORDER)
   109  
   110      #define PAGE_SHIFT 12
   111      #define PAGE_SIZE  (_AC(1, UL) << PAGE_SHIFT)
   112      #define PAGE_MASK  (~(PAGE_SIZE - 1))
   113  
   114      #define TOP_OF_KERNEL_STACK_PADDING 0
   115  
   116  #elif defined(__TARGET_ARCH_arm64)
   117  
   118      // extern bool CONFIG_ARM64_PAGE_SHIFT __kconfig;
   119      //  arch/arm64/include/asm/page-def.h
   120      //#define PAGE_SHIFT        CONFIG_ARM64_PAGE_SHIFT
   121      //  as a temporary workaround for failing builds, use the default value of PAGE_SHIFT
   122      #define PAGE_SHIFT       12
   123      #define PAGE_SIZE        (_AC(1, UL) << PAGE_SHIFT)
   124  
   125      // arch/arm64/include/asm/thread_info.h
   126      #define _TIF_32BIT       (1 << 22)
   127  
   128      // arch/arm64/include/asm/memory.h
   129      //#define MIN_THREAD_SHIFT	(14 + KASAN_THREAD_SHIFT)
   130      #define MIN_THREAD_SHIFT 14 // default value if KASAN is disabled (which it should be usually)
   131  
   132      // this can also be PAGE_SHIFT if (MIN_THREAD_SHIFT < PAGE_SHIFT) however here 14 > 12
   133      // so we choose MIN_THREAD_SHIFT
   134      #define THREAD_SHIFT     MIN_THREAD_SHIFT
   135      #define THREAD_SIZE      (_UL(1) << THREAD_SHIFT)
   136  
   137  #endif
   138  
   139  /*=============================== ARCH SPECIFIC ===========================*/
   140  
   141  #define VM_NONE   0x00000000
   142  #define VM_READ   0x00000001
   143  #define VM_WRITE  0x00000002
   144  #define VM_EXEC   0x00000004
   145  #define VM_SHARED 0x00000008
   146  
   147  #define TC_ACT_UNSPEC     (-1)
   148  #define TC_ACT_OK         0
   149  #define TC_ACT_RECLASSIFY 1
   150  #define TC_ACT_SHOT       2
   151  #define TC_ACT_PIPE       3
   152  #define TC_ACT_STOLEN     4
   153  #define TC_ACT_QUEUED     5
   154  #define TC_ACT_REPEAT     6
   155  #define TC_ACT_REDIRECT   7
   156  
   157  #define ETH_P_IP   0x0800
   158  #define ETH_P_IPV6 0x86DD
   159  
   160  #define s6_addr   in6_u.u6_addr8
   161  #define s6_addr16 in6_u.u6_addr16
   162  #define s6_addr32 in6_u.u6_addr32
   163  
   164  #define __user
   165  
   166  #define S_IFMT   00170000
   167  #define S_IFSOCK 0140000
   168  #define S_IFLNK  0120000
   169  #define S_IFREG  0100000
   170  #define S_IFBLK  0060000
   171  #define S_IFDIR  0040000
   172  #define S_IFCHR  0020000
   173  #define S_IFIFO  0010000
   174  #define S_ISUID  0004000
   175  #define S_ISGID  0002000
   176  #define S_ISVTX  0001000
   177  
   178  #define CAP_OPT_NONE    0x0
   179  #define CAP_OPT_NOAUDIT 0b10
   180  #define CAP_OPT_INSETID 0b100
   181  
   182  static inline bool ipv6_addr_any(const struct in6_addr *a)
   183  {
   184      return (a->in6_u.u6_addr32[0] | a->in6_u.u6_addr32[1] | a->in6_u.u6_addr32[2] |
   185              a->in6_u.u6_addr32[3]) == 0;
   186  }
   187  
   188  static inline struct inet_sock *inet_sk(const struct sock *sk)
   189  {
   190      return (struct inet_sock *) sk;
   191  }
   192  
   193  #define PIPE_BUF_FLAG_CAN_MERGE 0x10 /* can merge buffers */
   194  
   195  #define get_type_size(x) bpf_core_type_size(x)
   196  #define __get_node_addr(array, node_type, index)                                                   \
   197      ((node_type *) ((void *) array + (index * get_type_size(node_type))))
   198  #define get_node_addr(array, index) __get_node_addr(array, typeof(*array), index)
   199  
   200  // NOTE: new network code
   201  
   202  // Protocol families
   203  #define PF_UNSPEC    0
   204  #define PF_LOCAL     1
   205  #define PF_UNIX      PF_LOCAL
   206  #define PF_FILE      PF_LOCAL
   207  #define PF_INET      2
   208  #define PF_BRIDGE    7
   209  #define PF_INET6     10
   210  #define PF_KEY       15
   211  #define PF_NETLINK   16
   212  #define PF_ROUTE     PF_NETLINK
   213  #define PF_PACKET    17
   214  #define PF_IB        27
   215  #define PF_MPLS      28
   216  #define PF_BLUETOOTH 31
   217  #define PF_VSOCK     40
   218  #define PF_XDP       44
   219  
   220  /* Address families.  */
   221  #define AF_UNSPEC    PF_UNSPEC
   222  #define AF_LOCAL     PF_LOCAL
   223  #define AF_UNIX      PF_UNIX
   224  #define AF_FILE      PF_FILE
   225  #define AF_INET      PF_INET
   226  #define AF_INET6     PF_INET6
   227  #define AF_KEY       PF_KEY
   228  #define AF_NETLINK   PF_NETLINK
   229  #define AF_ROUTE     PF_ROUTE
   230  #define AF_PACKET    PF_PACKET
   231  #define AF_IB        PF_IB
   232  #define AF_MPLS      PF_MPLS
   233  #define AF_BLUETOOTH PF_BLUETOOTH
   234  #define AF_VSOCK     PF_VSOCK
   235  #define AF_XDP       PF_XDP
   236  
   237  #ifndef IPPROTO_IPIP
   238      #define IPPROTO_IPIP 4
   239  #endif
   240  
   241  #ifndef IPPROTO_DCCP
   242      #define IPPROTO_DCCP 33
   243  #endif
   244  
   245  #ifndef IPPROTO_IPV6
   246      #define IPPROTO_IPV6 41
   247  #endif
   248  
   249  #ifndef IPPROTO_ICMPV6
   250      #define IPPROTO_ICMPV6 58
   251  #endif
   252  
   253  #ifndef IPPROTO_SCTP
   254      #define IPPROTO_SCTP 132
   255  #endif
   256  
   257  #ifndef IPPROTO_UDPLITE
   258      #define IPPROTO_UDPLITE 136
   259  #endif
   260  
   261  #define IPPROTO_HOPOPTS  0   // IPv6 hop-by-hop options
   262  #define IPPROTO_ROUTING  43  // IPv6 routing header
   263  #define IPPROTO_FRAGMENT 44  // IPv6 fragmentation header
   264  #define IPPROTO_ICMPV6   58  // ICMPv6
   265  #define IPPROTO_NONE     59  // IPv6 no next header
   266  #define IPPROTO_DSTOPTS  60  // IPv6 destination options
   267  #define IPPROTO_MH       135 // IPv6 mobility header
   268  
   269  #endif