Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
0002 #ifndef __BPF_CORE_READ_H__
0003 #define __BPF_CORE_READ_H__
0004 
0005 /*
0006  * enum bpf_field_info_kind is passed as a second argument into
0007  * __builtin_preserve_field_info() built-in to get a specific aspect of
0008  * a field, captured as a first argument. __builtin_preserve_field_info(field,
0009  * info_kind) returns __u32 integer and produces BTF field relocation, which
0010  * is understood and processed by libbpf during BPF object loading. See
0011  * selftests/bpf for examples.
0012  */
0013 enum bpf_field_info_kind {
0014     BPF_FIELD_BYTE_OFFSET = 0,  /* field byte offset */
0015     BPF_FIELD_BYTE_SIZE = 1,
0016     BPF_FIELD_EXISTS = 2,       /* field existence in target kernel */
0017     BPF_FIELD_SIGNED = 3,
0018     BPF_FIELD_LSHIFT_U64 = 4,
0019     BPF_FIELD_RSHIFT_U64 = 5,
0020 };
0021 
0022 /* second argument to __builtin_btf_type_id() built-in */
0023 enum bpf_type_id_kind {
0024     BPF_TYPE_ID_LOCAL = 0,      /* BTF type ID in local program */
0025     BPF_TYPE_ID_TARGET = 1,     /* BTF type ID in target kernel */
0026 };
0027 
0028 /* second argument to __builtin_preserve_type_info() built-in */
0029 enum bpf_type_info_kind {
0030     BPF_TYPE_EXISTS = 0,        /* type existence in target kernel */
0031     BPF_TYPE_SIZE = 1,      /* type size in target kernel */
0032     BPF_TYPE_MATCHES = 2,       /* type match in target kernel */
0033 };
0034 
0035 /* second argument to __builtin_preserve_enum_value() built-in */
0036 enum bpf_enum_value_kind {
0037     BPF_ENUMVAL_EXISTS = 0,     /* enum value existence in kernel */
0038     BPF_ENUMVAL_VALUE = 1,      /* enum value value relocation */
0039 };
0040 
0041 #define __CORE_RELO(src, field, info)                         \
0042     __builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
0043 
0044 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0045 #define __CORE_BITFIELD_PROBE_READ(dst, src, fld)                 \
0046     bpf_probe_read_kernel(                            \
0047             (void *)dst,                      \
0048             __CORE_RELO(src, fld, BYTE_SIZE),             \
0049             (const void *)src + __CORE_RELO(src, fld, BYTE_OFFSET))
0050 #else
0051 /* semantics of LSHIFT_64 assumes loading values into low-ordered bytes, so
0052  * for big-endian we need to adjust destination pointer accordingly, based on
0053  * field byte size
0054  */
0055 #define __CORE_BITFIELD_PROBE_READ(dst, src, fld)                 \
0056     bpf_probe_read_kernel(                            \
0057             (void *)dst + (8 - __CORE_RELO(src, fld, BYTE_SIZE)), \
0058             __CORE_RELO(src, fld, BYTE_SIZE),             \
0059             (const void *)src + __CORE_RELO(src, fld, BYTE_OFFSET))
0060 #endif
0061 
0062 /*
0063  * Extract bitfield, identified by s->field, and return its value as u64.
0064  * All this is done in relocatable manner, so bitfield changes such as
0065  * signedness, bit size, offset changes, this will be handled automatically.
0066  * This version of macro is using bpf_probe_read_kernel() to read underlying
0067  * integer storage. Macro functions as an expression and its return type is
0068  * bpf_probe_read_kernel()'s return value: 0, on success, <0 on error.
0069  */
0070 #define BPF_CORE_READ_BITFIELD_PROBED(s, field) ({                \
0071     unsigned long long val = 0;                       \
0072                                           \
0073     __CORE_BITFIELD_PROBE_READ(&val, s, field);               \
0074     val <<= __CORE_RELO(s, field, LSHIFT_U64);                \
0075     if (__CORE_RELO(s, field, SIGNED))                    \
0076         val = ((long long)val) >> __CORE_RELO(s, field, RSHIFT_U64);  \
0077     else                                      \
0078         val = val >> __CORE_RELO(s, field, RSHIFT_U64);           \
0079     val;                                      \
0080 })
0081 
0082 /*
0083  * Extract bitfield, identified by s->field, and return its value as u64.
0084  * This version of macro is using direct memory reads and should be used from
0085  * BPF program types that support such functionality (e.g., typed raw
0086  * tracepoints).
0087  */
0088 #define BPF_CORE_READ_BITFIELD(s, field) ({                   \
0089     const void *p = (const void *)s + __CORE_RELO(s, field, BYTE_OFFSET); \
0090     unsigned long long val;                           \
0091                                           \
0092     /* This is a so-called barrier_var() operation that makes specified   \
0093      * variable "a black box" for optimizing compiler.            \
0094      * It forces compiler to perform BYTE_OFFSET relocation on p and use  \
0095      * its calculated value in the switch below, instead of applying      \
0096      * the same relocation 4 times for each individual memory load.       \
0097      */                                   \
0098     asm volatile("" : "=r"(p) : "0"(p));                      \
0099                                           \
0100     switch (__CORE_RELO(s, field, BYTE_SIZE)) {               \
0101     case 1: val = *(const unsigned char *)p; break;               \
0102     case 2: val = *(const unsigned short *)p; break;              \
0103     case 4: val = *(const unsigned int *)p; break;                \
0104     case 8: val = *(const unsigned long long *)p; break;              \
0105     }                                     \
0106     val <<= __CORE_RELO(s, field, LSHIFT_U64);                \
0107     if (__CORE_RELO(s, field, SIGNED))                    \
0108         val = ((long long)val) >> __CORE_RELO(s, field, RSHIFT_U64);  \
0109     else                                      \
0110         val = val >> __CORE_RELO(s, field, RSHIFT_U64);           \
0111     val;                                      \
0112 })
0113 
0114 #define ___bpf_field_ref1(field)    (field)
0115 #define ___bpf_field_ref2(type, field)  (((typeof(type) *)0)->field)
0116 #define ___bpf_field_ref(args...)                       \
0117     ___bpf_apply(___bpf_field_ref, ___bpf_narg(args))(args)
0118 
0119 /*
0120  * Convenience macro to check that field actually exists in target kernel's.
0121  * Returns:
0122  *    1, if matching field is present in target kernel;
0123  *    0, if no matching field found.
0124  *
0125  * Supports two forms:
0126  *   - field reference through variable access:
0127  *     bpf_core_field_exists(p->my_field);
0128  *   - field reference through type and field names:
0129  *     bpf_core_field_exists(struct my_type, my_field).
0130  */
0131 #define bpf_core_field_exists(field...)                     \
0132     __builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_EXISTS)
0133 
0134 /*
0135  * Convenience macro to get the byte size of a field. Works for integers,
0136  * struct/unions, pointers, arrays, and enums.
0137  *
0138  * Supports two forms:
0139  *   - field reference through variable access:
0140  *     bpf_core_field_size(p->my_field);
0141  *   - field reference through type and field names:
0142  *     bpf_core_field_size(struct my_type, my_field).
0143  */
0144 #define bpf_core_field_size(field...)                       \
0145     __builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_BYTE_SIZE)
0146 
0147 /*
0148  * Convenience macro to get field's byte offset.
0149  *
0150  * Supports two forms:
0151  *   - field reference through variable access:
0152  *     bpf_core_field_offset(p->my_field);
0153  *   - field reference through type and field names:
0154  *     bpf_core_field_offset(struct my_type, my_field).
0155  */
0156 #define bpf_core_field_offset(field...)                     \
0157     __builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_BYTE_OFFSET)
0158 
0159 /*
0160  * Convenience macro to get BTF type ID of a specified type, using a local BTF
0161  * information. Return 32-bit unsigned integer with type ID from program's own
0162  * BTF. Always succeeds.
0163  */
0164 #define bpf_core_type_id_local(type)                        \
0165     __builtin_btf_type_id(*(typeof(type) *)0, BPF_TYPE_ID_LOCAL)
0166 
0167 /*
0168  * Convenience macro to get BTF type ID of a target kernel's type that matches
0169  * specified local type.
0170  * Returns:
0171  *    - valid 32-bit unsigned type ID in kernel BTF;
0172  *    - 0, if no matching type was found in a target kernel BTF.
0173  */
0174 #define bpf_core_type_id_kernel(type)                       \
0175     __builtin_btf_type_id(*(typeof(type) *)0, BPF_TYPE_ID_TARGET)
0176 
0177 /*
0178  * Convenience macro to check that provided named type
0179  * (struct/union/enum/typedef) exists in a target kernel.
0180  * Returns:
0181  *    1, if such type is present in target kernel's BTF;
0182  *    0, if no matching type is found.
0183  */
0184 #define bpf_core_type_exists(type)                      \
0185     __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_EXISTS)
0186 
0187 /*
0188  * Convenience macro to check that provided named type
0189  * (struct/union/enum/typedef) "matches" that in a target kernel.
0190  * Returns:
0191  *    1, if the type matches in the target kernel's BTF;
0192  *    0, if the type does not match any in the target kernel
0193  */
0194 #define bpf_core_type_matches(type)                     \
0195     __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_MATCHES)
0196 
0197 /*
0198  * Convenience macro to get the byte size of a provided named type
0199  * (struct/union/enum/typedef) in a target kernel.
0200  * Returns:
0201  *    >= 0 size (in bytes), if type is present in target kernel's BTF;
0202  *    0, if no matching type is found.
0203  */
0204 #define bpf_core_type_size(type)                        \
0205     __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_SIZE)
0206 
0207 /*
0208  * Convenience macro to check that provided enumerator value is defined in
0209  * a target kernel.
0210  * Returns:
0211  *    1, if specified enum type and its enumerator value are present in target
0212  *    kernel's BTF;
0213  *    0, if no matching enum and/or enum value within that enum is found.
0214  */
0215 #define bpf_core_enum_value_exists(enum_type, enum_value)           \
0216     __builtin_preserve_enum_value(*(typeof(enum_type) *)enum_value, BPF_ENUMVAL_EXISTS)
0217 
0218 /*
0219  * Convenience macro to get the integer value of an enumerator value in
0220  * a target kernel.
0221  * Returns:
0222  *    64-bit value, if specified enum type and its enumerator value are
0223  *    present in target kernel's BTF;
0224  *    0, if no matching enum and/or enum value within that enum is found.
0225  */
0226 #define bpf_core_enum_value(enum_type, enum_value)              \
0227     __builtin_preserve_enum_value(*(typeof(enum_type) *)enum_value, BPF_ENUMVAL_VALUE)
0228 
0229 /*
0230  * bpf_core_read() abstracts away bpf_probe_read_kernel() call and captures
0231  * offset relocation for source address using __builtin_preserve_access_index()
0232  * built-in, provided by Clang.
0233  *
0234  * __builtin_preserve_access_index() takes as an argument an expression of
0235  * taking an address of a field within struct/union. It makes compiler emit
0236  * a relocation, which records BTF type ID describing root struct/union and an
0237  * accessor string which describes exact embedded field that was used to take
0238  * an address. See detailed description of this relocation format and
0239  * semantics in comments to struct bpf_field_reloc in libbpf_internal.h.
0240  *
0241  * This relocation allows libbpf to adjust BPF instruction to use correct
0242  * actual field offset, based on target kernel BTF type that matches original
0243  * (local) BTF, used to record relocation.
0244  */
0245 #define bpf_core_read(dst, sz, src)                     \
0246     bpf_probe_read_kernel(dst, sz, (const void *)__builtin_preserve_access_index(src))
0247 
0248 /* NOTE: see comments for BPF_CORE_READ_USER() about the proper types use. */
0249 #define bpf_core_read_user(dst, sz, src)                    \
0250     bpf_probe_read_user(dst, sz, (const void *)__builtin_preserve_access_index(src))
0251 /*
0252  * bpf_core_read_str() is a thin wrapper around bpf_probe_read_str()
0253  * additionally emitting BPF CO-RE field relocation for specified source
0254  * argument.
0255  */
0256 #define bpf_core_read_str(dst, sz, src)                     \
0257     bpf_probe_read_kernel_str(dst, sz, (const void *)__builtin_preserve_access_index(src))
0258 
0259 /* NOTE: see comments for BPF_CORE_READ_USER() about the proper types use. */
0260 #define bpf_core_read_user_str(dst, sz, src)                    \
0261     bpf_probe_read_user_str(dst, sz, (const void *)__builtin_preserve_access_index(src))
0262 
0263 #define ___concat(a, b) a ## b
0264 #define ___apply(fn, n) ___concat(fn, n)
0265 #define ___nth(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, __11, N, ...) N
0266 
0267 /*
0268  * return number of provided arguments; used for switch-based variadic macro
0269  * definitions (see ___last, ___arrow, etc below)
0270  */
0271 #define ___narg(...) ___nth(_, ##__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
0272 /*
0273  * return 0 if no arguments are passed, N - otherwise; used for
0274  * recursively-defined macros to specify termination (0) case, and generic
0275  * (N) case (e.g., ___read_ptrs, ___core_read)
0276  */
0277 #define ___empty(...) ___nth(_, ##__VA_ARGS__, N, N, N, N, N, N, N, N, N, N, 0)
0278 
0279 #define ___last1(x) x
0280 #define ___last2(a, x) x
0281 #define ___last3(a, b, x) x
0282 #define ___last4(a, b, c, x) x
0283 #define ___last5(a, b, c, d, x) x
0284 #define ___last6(a, b, c, d, e, x) x
0285 #define ___last7(a, b, c, d, e, f, x) x
0286 #define ___last8(a, b, c, d, e, f, g, x) x
0287 #define ___last9(a, b, c, d, e, f, g, h, x) x
0288 #define ___last10(a, b, c, d, e, f, g, h, i, x) x
0289 #define ___last(...) ___apply(___last, ___narg(__VA_ARGS__))(__VA_ARGS__)
0290 
0291 #define ___nolast2(a, _) a
0292 #define ___nolast3(a, b, _) a, b
0293 #define ___nolast4(a, b, c, _) a, b, c
0294 #define ___nolast5(a, b, c, d, _) a, b, c, d
0295 #define ___nolast6(a, b, c, d, e, _) a, b, c, d, e
0296 #define ___nolast7(a, b, c, d, e, f, _) a, b, c, d, e, f
0297 #define ___nolast8(a, b, c, d, e, f, g, _) a, b, c, d, e, f, g
0298 #define ___nolast9(a, b, c, d, e, f, g, h, _) a, b, c, d, e, f, g, h
0299 #define ___nolast10(a, b, c, d, e, f, g, h, i, _) a, b, c, d, e, f, g, h, i
0300 #define ___nolast(...) ___apply(___nolast, ___narg(__VA_ARGS__))(__VA_ARGS__)
0301 
0302 #define ___arrow1(a) a
0303 #define ___arrow2(a, b) a->b
0304 #define ___arrow3(a, b, c) a->b->c
0305 #define ___arrow4(a, b, c, d) a->b->c->d
0306 #define ___arrow5(a, b, c, d, e) a->b->c->d->e
0307 #define ___arrow6(a, b, c, d, e, f) a->b->c->d->e->f
0308 #define ___arrow7(a, b, c, d, e, f, g) a->b->c->d->e->f->g
0309 #define ___arrow8(a, b, c, d, e, f, g, h) a->b->c->d->e->f->g->h
0310 #define ___arrow9(a, b, c, d, e, f, g, h, i) a->b->c->d->e->f->g->h->i
0311 #define ___arrow10(a, b, c, d, e, f, g, h, i, j) a->b->c->d->e->f->g->h->i->j
0312 #define ___arrow(...) ___apply(___arrow, ___narg(__VA_ARGS__))(__VA_ARGS__)
0313 
0314 #define ___type(...) typeof(___arrow(__VA_ARGS__))
0315 
0316 #define ___read(read_fn, dst, src_type, src, accessor)              \
0317     read_fn((void *)(dst), sizeof(*(dst)), &((src_type)(src))->accessor)
0318 
0319 /* "recursively" read a sequence of inner pointers using local __t var */
0320 #define ___rd_first(fn, src, a) ___read(fn, &__t, ___type(src), src, a);
0321 #define ___rd_last(fn, ...)                         \
0322     ___read(fn, &__t, ___type(___nolast(__VA_ARGS__)), __t, ___last(__VA_ARGS__));
0323 #define ___rd_p1(fn, ...) const void *__t; ___rd_first(fn, __VA_ARGS__)
0324 #define ___rd_p2(fn, ...) ___rd_p1(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0325 #define ___rd_p3(fn, ...) ___rd_p2(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0326 #define ___rd_p4(fn, ...) ___rd_p3(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0327 #define ___rd_p5(fn, ...) ___rd_p4(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0328 #define ___rd_p6(fn, ...) ___rd_p5(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0329 #define ___rd_p7(fn, ...) ___rd_p6(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0330 #define ___rd_p8(fn, ...) ___rd_p7(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0331 #define ___rd_p9(fn, ...) ___rd_p8(fn, ___nolast(__VA_ARGS__)) ___rd_last(fn, __VA_ARGS__)
0332 #define ___read_ptrs(fn, src, ...)                      \
0333     ___apply(___rd_p, ___narg(__VA_ARGS__))(fn, src, __VA_ARGS__)
0334 
0335 #define ___core_read0(fn, fn_ptr, dst, src, a)                  \
0336     ___read(fn, dst, ___type(src), src, a);
0337 #define ___core_readN(fn, fn_ptr, dst, src, ...)                \
0338     ___read_ptrs(fn_ptr, src, ___nolast(__VA_ARGS__))           \
0339     ___read(fn, dst, ___type(src, ___nolast(__VA_ARGS__)), __t,     \
0340         ___last(__VA_ARGS__));
0341 #define ___core_read(fn, fn_ptr, dst, src, a, ...)              \
0342     ___apply(___core_read, ___empty(__VA_ARGS__))(fn, fn_ptr, dst,      \
0343                               src, a, ##__VA_ARGS__)
0344 
0345 /*
0346  * BPF_CORE_READ_INTO() is a more performance-conscious variant of
0347  * BPF_CORE_READ(), in which final field is read into user-provided storage.
0348  * See BPF_CORE_READ() below for more details on general usage.
0349  */
0350 #define BPF_CORE_READ_INTO(dst, src, a, ...) ({                 \
0351     ___core_read(bpf_core_read, bpf_core_read,              \
0352              dst, (src), a, ##__VA_ARGS__)              \
0353 })
0354 
0355 /*
0356  * Variant of BPF_CORE_READ_INTO() for reading from user-space memory.
0357  *
0358  * NOTE: see comments for BPF_CORE_READ_USER() about the proper types use.
0359  */
0360 #define BPF_CORE_READ_USER_INTO(dst, src, a, ...) ({                \
0361     ___core_read(bpf_core_read_user, bpf_core_read_user,            \
0362              dst, (src), a, ##__VA_ARGS__)              \
0363 })
0364 
0365 /* Non-CO-RE variant of BPF_CORE_READ_INTO() */
0366 #define BPF_PROBE_READ_INTO(dst, src, a, ...) ({                \
0367     ___core_read(bpf_probe_read, bpf_probe_read,                \
0368              dst, (src), a, ##__VA_ARGS__)              \
0369 })
0370 
0371 /* Non-CO-RE variant of BPF_CORE_READ_USER_INTO().
0372  *
0373  * As no CO-RE relocations are emitted, source types can be arbitrary and are
0374  * not restricted to kernel types only.
0375  */
0376 #define BPF_PROBE_READ_USER_INTO(dst, src, a, ...) ({               \
0377     ___core_read(bpf_probe_read_user, bpf_probe_read_user,          \
0378              dst, (src), a, ##__VA_ARGS__)              \
0379 })
0380 
0381 /*
0382  * BPF_CORE_READ_STR_INTO() does same "pointer chasing" as
0383  * BPF_CORE_READ() for intermediate pointers, but then executes (and returns
0384  * corresponding error code) bpf_core_read_str() for final string read.
0385  */
0386 #define BPF_CORE_READ_STR_INTO(dst, src, a, ...) ({             \
0387     ___core_read(bpf_core_read_str, bpf_core_read,              \
0388              dst, (src), a, ##__VA_ARGS__)              \
0389 })
0390 
0391 /*
0392  * Variant of BPF_CORE_READ_STR_INTO() for reading from user-space memory.
0393  *
0394  * NOTE: see comments for BPF_CORE_READ_USER() about the proper types use.
0395  */
0396 #define BPF_CORE_READ_USER_STR_INTO(dst, src, a, ...) ({            \
0397     ___core_read(bpf_core_read_user_str, bpf_core_read_user,        \
0398              dst, (src), a, ##__VA_ARGS__)              \
0399 })
0400 
0401 /* Non-CO-RE variant of BPF_CORE_READ_STR_INTO() */
0402 #define BPF_PROBE_READ_STR_INTO(dst, src, a, ...) ({                \
0403     ___core_read(bpf_probe_read_str, bpf_probe_read,            \
0404              dst, (src), a, ##__VA_ARGS__)              \
0405 })
0406 
0407 /*
0408  * Non-CO-RE variant of BPF_CORE_READ_USER_STR_INTO().
0409  *
0410  * As no CO-RE relocations are emitted, source types can be arbitrary and are
0411  * not restricted to kernel types only.
0412  */
0413 #define BPF_PROBE_READ_USER_STR_INTO(dst, src, a, ...) ({           \
0414     ___core_read(bpf_probe_read_user_str, bpf_probe_read_user,      \
0415              dst, (src), a, ##__VA_ARGS__)              \
0416 })
0417 
0418 /*
0419  * BPF_CORE_READ() is used to simplify BPF CO-RE relocatable read, especially
0420  * when there are few pointer chasing steps.
0421  * E.g., what in non-BPF world (or in BPF w/ BCC) would be something like:
0422  *  int x = s->a.b.c->d.e->f->g;
0423  * can be succinctly achieved using BPF_CORE_READ as:
0424  *  int x = BPF_CORE_READ(s, a.b.c, d.e, f, g);
0425  *
0426  * BPF_CORE_READ will decompose above statement into 4 bpf_core_read (BPF
0427  * CO-RE relocatable bpf_probe_read_kernel() wrapper) calls, logically
0428  * equivalent to:
0429  * 1. const void *__t = s->a.b.c;
0430  * 2. __t = __t->d.e;
0431  * 3. __t = __t->f;
0432  * 4. return __t->g;
0433  *
0434  * Equivalence is logical, because there is a heavy type casting/preservation
0435  * involved, as well as all the reads are happening through
0436  * bpf_probe_read_kernel() calls using __builtin_preserve_access_index() to
0437  * emit CO-RE relocations.
0438  *
0439  * N.B. Only up to 9 "field accessors" are supported, which should be more
0440  * than enough for any practical purpose.
0441  */
0442 #define BPF_CORE_READ(src, a, ...) ({                       \
0443     ___type((src), a, ##__VA_ARGS__) __r;                   \
0444     BPF_CORE_READ_INTO(&__r, (src), a, ##__VA_ARGS__);          \
0445     __r;                                    \
0446 })
0447 
0448 /*
0449  * Variant of BPF_CORE_READ() for reading from user-space memory.
0450  *
0451  * NOTE: all the source types involved are still *kernel types* and need to
0452  * exist in kernel (or kernel module) BTF, otherwise CO-RE relocation will
0453  * fail. Custom user types are not relocatable with CO-RE.
0454  * The typical situation in which BPF_CORE_READ_USER() might be used is to
0455  * read kernel UAPI types from the user-space memory passed in as a syscall
0456  * input argument.
0457  */
0458 #define BPF_CORE_READ_USER(src, a, ...) ({                  \
0459     ___type((src), a, ##__VA_ARGS__) __r;                   \
0460     BPF_CORE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__);         \
0461     __r;                                    \
0462 })
0463 
0464 /* Non-CO-RE variant of BPF_CORE_READ() */
0465 #define BPF_PROBE_READ(src, a, ...) ({                      \
0466     ___type((src), a, ##__VA_ARGS__) __r;                   \
0467     BPF_PROBE_READ_INTO(&__r, (src), a, ##__VA_ARGS__);         \
0468     __r;                                    \
0469 })
0470 
0471 /*
0472  * Non-CO-RE variant of BPF_CORE_READ_USER().
0473  *
0474  * As no CO-RE relocations are emitted, source types can be arbitrary and are
0475  * not restricted to kernel types only.
0476  */
0477 #define BPF_PROBE_READ_USER(src, a, ...) ({                 \
0478     ___type((src), a, ##__VA_ARGS__) __r;                   \
0479     BPF_PROBE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__);        \
0480     __r;                                    \
0481 })
0482 
0483 #endif
0484