123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- // clang-format off
- #include <vmlinux.h>
- #include <bpf/bpf_helpers.h>
- #include <bpf/bpf_core_read.h>
- // clang-format on
- char _license[] SEC("license") = "GPL";
- struct {
- __uint(type, BPF_MAP_TYPE_ARRAY);
- __type(key, __u32);
- __type(value, __u64);
- __uint(max_entries, 1);
- } output_map SEC(".maps");
- long set_output(__u64 value) {
- __u32 key = 0;
- return bpf_map_update_elem(&output_map, &key, &value, BPF_ANY);
- }
- struct relocated_struct_with_scalars {
- #ifndef TARGET
- __u8 a;
- #endif
- __u8 b;
- __u8 c;
- #ifdef TARGET
- __u8 d;
- #endif
- };
- __noinline int field_global() {
- struct relocated_struct_with_scalars s = {1, 2, 3};
- return set_output(__builtin_preserve_access_index(s.b));
- }
- SEC("uprobe") int field(void *ctx) { return field_global(); }
- struct relocated_struct_with_pointer {
- #ifndef TARGET
- struct relocated_struct_with_pointer *first;
- #endif
- struct relocated_struct_with_pointer *second;
- #ifdef TARGET
- struct relocated_struct_with_pointer *first;
- #endif
- };
- __noinline int pointer_global() {
- struct relocated_struct_with_pointer s = {
- (struct relocated_struct_with_pointer *)42,
- (struct relocated_struct_with_pointer *)21,
- };
- return set_output((__u64)__builtin_preserve_access_index(s.first));
- }
- SEC("uprobe") int pointer(void *ctx) { return pointer_global(); }
- __noinline int struct_flavors_global() {
- struct relocated_struct_with_scalars s = {1, 2, 3};
- #ifndef TARGET
- if (bpf_core_field_exists(s.a)) {
- return set_output(__builtin_preserve_access_index(s.a));
- #else
- if (bpf_core_field_exists(s.d)) {
- return set_output(__builtin_preserve_access_index(s.d));
- #endif
- } else {
- return set_output(__builtin_preserve_access_index(s.c));
- }
- }
- SEC("uprobe") int struct_flavors(void *ctx) { return struct_flavors_global(); }
- enum relocated_enum_unsigned_32 {
- U32_VAL =
- #ifndef TARGET
- 0xAAAAAAAA
- #else
- 0xBBBBBBBB
- #endif
- };
- __noinline int enum_unsigned_32_global() {
- return set_output(
- bpf_core_enum_value(enum relocated_enum_unsigned_32, U32_VAL));
- }
- SEC("uprobe") int enum_unsigned_32(void *ctx) {
- return enum_unsigned_32_global();
- }
- enum relocated_enum_unsigned_32_checked_variants {
- #ifndef TARGET
- U32_VAL_A = 0xAAAAAAAA,
- #endif
- U32_VAL_B = 0xBBBBBBBB,
- #ifdef TARGET
- U32_VAL_C = 0xCCCCCCCC
- #endif
- };
- __noinline int enum_unsigned_32_checked_variants_global() {
- #ifndef TARGET
- if (bpf_core_enum_value_exists(
- enum relocated_enum_unsigned_32_checked_variants, U32_VAL_A)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_32_checked_variants, U32_VAL_A));
- #else
- if (bpf_core_enum_value_exists(
- enum relocated_enum_unsigned_32_checked_variants, U32_VAL_C)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_32_checked_variants, U32_VAL_C));
- #endif
- } else {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_32_checked_variants, U32_VAL_B));
- }
- }
- SEC("uprobe") int enum_unsigned_32_checked_variants(void *ctx) {
- return enum_unsigned_32_checked_variants_global();
- }
- enum relocated_enum_signed_32 {
- S32_VAL =
- #ifndef TARGET
- -0x7AAAAAAA
- #else
- -0x7BBBBBBB
- #endif
- };
- __noinline int enum_signed_32_global() {
- return set_output(
- bpf_core_enum_value(enum relocated_enum_signed_32, S32_VAL));
- }
- SEC("uprobe") int enum_signed_32(void *ctx) { return enum_signed_32_global(); }
- enum relocated_enum_signed_32_checked_variants {
- #ifndef TARGET
- S32_VAL_A = -0x7AAAAAAA,
- #endif
- S32_VAL_B = -0x7BBBBBBB,
- #ifdef TARGET
- S32_VAL_C = -0x7CCCCCCC
- #endif
- };
- __noinline int enum_signed_32_checked_variants_global() {
- #ifndef TARGET
- if (bpf_core_enum_value_exists(enum relocated_enum_signed_32_checked_variants,
- S32_VAL_A)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_32_checked_variants, S32_VAL_A));
- #else
- if (bpf_core_enum_value_exists(enum relocated_enum_signed_32_checked_variants,
- S32_VAL_C)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_32_checked_variants, S32_VAL_C));
- #endif
- } else {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_32_checked_variants, S32_VAL_B));
- }
- }
- SEC("uprobe") int enum_signed_32_checked_variants(void *ctx) {
- return enum_signed_32_checked_variants_global();
- }
- enum relocated_enum_unsigned_64 {
- U64_VAL =
- #ifndef TARGET
- 0xAAAAAAAABBBBBBBB
- #else
- 0xCCCCCCCCDDDDDDDD
- #endif
- };
- __noinline int enum_unsigned_64_global() {
- return set_output(
- bpf_core_enum_value(enum relocated_enum_unsigned_64, U64_VAL));
- }
- SEC("uprobe") int enum_unsigned_64(void *ctx) {
- return enum_unsigned_64_global();
- }
- enum relocated_enum_unsigned_64_checked_variants {
- #ifndef TARGET
- U64_VAL_A = 0xAAAAAAAABBBBBBBB,
- #endif
- U64_VAL_B = 0xCCCCCCCCDDDDDDDD,
- #ifdef TARGET
- U64_VAL_C = 0xEEEEEEEEFFFFFFFF
- #endif
- };
- __noinline int enum_unsigned_64_checked_variants_global() {
- #ifndef TARGET
- if (bpf_core_enum_value_exists(
- enum relocated_enum_unsigned_64_checked_variants, U64_VAL_A)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_64_checked_variants, U64_VAL_A));
- #else
- if (bpf_core_enum_value_exists(
- enum relocated_enum_unsigned_64_checked_variants, U64_VAL_C)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_64_checked_variants, U64_VAL_C));
- #endif
- } else {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_unsigned_64_checked_variants, U64_VAL_B));
- }
- }
- SEC("uprobe") int enum_unsigned_64_checked_variants(void *ctx) {
- return enum_unsigned_64_checked_variants_global();
- }
- enum relocated_enum_signed_64 {
- S64_VAL =
- #ifndef TARGET
- -0xAAAAAAABBBBBBBB
- #else
- -0xCCCCCCCDDDDDDDD
- #endif
- };
- __noinline int enum_signed_64_global() {
- return set_output(
- bpf_core_enum_value(enum relocated_enum_signed_64, S64_VAL));
- }
- SEC("uprobe") int enum_signed_64(void *ctx) { return enum_signed_64_global(); }
- enum relocated_enum_signed_64_checked_variants {
- #ifndef TARGET
- S64_VAL_A = -0xAAAAAAABBBBBBB,
- #endif
- S64_VAL_B = -0xCCCCCCCDDDDDDD,
- #ifdef TARGET
- S64_VAL_C = -0xEEEEEEEFFFFFFF
- #endif
- };
- __noinline int enum_signed_64_checked_variants_global() {
- #ifndef TARGET
- if (bpf_core_enum_value_exists(enum relocated_enum_signed_64_checked_variants,
- S64_VAL_A)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_64_checked_variants, S64_VAL_A));
- #else
- if (bpf_core_enum_value_exists(enum relocated_enum_signed_64_checked_variants,
- S64_VAL_C)) {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_64_checked_variants, S64_VAL_C));
- #endif
- } else {
- return set_output(bpf_core_enum_value(
- enum relocated_enum_signed_64_checked_variants, S64_VAL_B));
- }
- }
- SEC("uprobe") int enum_signed_64_checked_variants(void *ctx) {
- return enum_signed_64_checked_variants_global();
- }
|