1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
7 #include <bpf/bpf_helpers.h>
8 #include <bpf/bpf_core_read.h>
10 char _license[] SEC("license") = "GPL";
25 ANON_ENUM_VAL1 = 0x10,
26 ANON_ENUM_VAL2 = 0x20,
27 ANON_ENUM_VAL3 = 0x30,
30 struct core_reloc_enumval_output {
31 bool named_val1_exists;
32 bool named_val2_exists;
33 bool named_val3_exists;
34 bool anon_val1_exists;
35 bool anon_val2_exists;
36 bool anon_val3_exists;
44 SEC("raw_tracepoint/sys_enter")
45 int test_core_enumval(void *ctx)
47 #if __has_builtin(__builtin_preserve_enum_value)
48 struct core_reloc_enumval_output *out = (void *)&data.out;
49 enum named_enum named = 0;
52 out->named_val1_exists = bpf_core_enum_value_exists(named, NAMED_ENUM_VAL1);
53 out->named_val2_exists = bpf_core_enum_value_exists(enum named_enum, NAMED_ENUM_VAL2);
54 out->named_val3_exists = bpf_core_enum_value_exists(enum named_enum, NAMED_ENUM_VAL3);
56 out->anon_val1_exists = bpf_core_enum_value_exists(anon, ANON_ENUM_VAL1);
57 out->anon_val2_exists = bpf_core_enum_value_exists(anon_enum, ANON_ENUM_VAL2);
58 out->anon_val3_exists = bpf_core_enum_value_exists(anon_enum, ANON_ENUM_VAL3);
60 out->named_val1 = bpf_core_enum_value(named, NAMED_ENUM_VAL1);
61 out->named_val2 = bpf_core_enum_value(named, NAMED_ENUM_VAL2);
62 /* NAMED_ENUM_VAL3 value is optional */
64 out->anon_val1 = bpf_core_enum_value(anon, ANON_ENUM_VAL1);
65 out->anon_val2 = bpf_core_enum_value(anon, ANON_ENUM_VAL2);
66 /* ANON_ENUM_VAL3 value is optional */