Merge "rename SEC() to SECTION()" am: bc8df444d1 am: bab48348a4 am: 453f93e9db

Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/1895607

Change-Id: Ic84ea528924826a79c7e885eb73041b415c658bc
This commit is contained in:
Treehugger Robot 2021-11-18 07:58:35 +00:00 committed by Automerger Merge Worker
commit 458b630552
4 changed files with 21 additions and 18 deletions

View file

@ -81,10 +81,13 @@ typedef struct {
/* /*
* Map section name prefixes to program types, the section name will be: * Map section name prefixes to program types, the section name will be:
* SEC(<prefix>/<name-of-program>) * SECTION(<prefix>/<name-of-program>)
* For example: * For example:
* SEC("tracepoint/sched_switch_func") where sched_switch_funcs * SECTION("tracepoint/sched_switch_func") where sched_switch_funcs
* is the name of the program, and tracepoint is the type. * is the name of the program, and tracepoint is the type.
*
* However, be aware that you should not be directly using the SECTION() macro.
* Instead use the DEFINE_(BPF|XDP)_(PROG|MAP)... & LICENSE/CRITICAL macros.
*/ */
sectionType sectionNameTypes[] = { sectionType sectionNameTypes[] = {
{"kprobe", BPF_PROG_TYPE_KPROBE}, {"kprobe", BPF_PROG_TYPE_KPROBE},

View file

@ -12,7 +12,7 @@
* * * *
* THIS WILL LIKELY RESULT IN BRICKED DEVICES AT SOME ARBITRARY FUTURE TIME * * THIS WILL LIKELY RESULT IN BRICKED DEVICES AT SOME ARBITRARY FUTURE TIME *
* * * *
* THAT GOES ESPECIALLY FOR THE 'SEC' 'LICENSE' AND 'CRITICAL' MACRO DEFINES * * THAT GOES ESPECIALLY FOR THE 'SECTION' 'LICENSE' AND 'CRITICAL' MACROS *
* * * *
* We strongly suggest that if you need changes to bpfloader functionality * * We strongly suggest that if you need changes to bpfloader functionality *
* you get your changes reviewed and accepted into aosp/master. * * you get your changes reviewed and accepted into aosp/master. *
@ -20,7 +20,7 @@
******************************************************************************/ ******************************************************************************/
/* place things in different elf sections */ /* place things in different elf sections */
#define SEC(NAME) __attribute__((section(NAME), used)) #define SECTION(NAME) __attribute__((section(NAME), used))
/* Must be present in every program, example usage: /* Must be present in every program, example usage:
* LICENSE("GPL"); or LICENSE("Apache 2.0"); * LICENSE("GPL"); or LICENSE("Apache 2.0");
@ -42,17 +42,17 @@
* while size_of_bpf_{map/prog}_def default to 32/20 which are the v0.0 sizes. * while size_of_bpf_{map/prog}_def default to 32/20 which are the v0.0 sizes.
*/ */
#define LICENSE(NAME) \ #define LICENSE(NAME) \
unsigned int _bpfloader_min_ver SEC("bpfloader_min_ver") = DEFAULT_BPFLOADER_MIN_VER; \ unsigned int _bpfloader_min_ver SECTION("bpfloader_min_ver") = DEFAULT_BPFLOADER_MIN_VER; \
unsigned int _bpfloader_max_ver SEC("bpfloader_max_ver") = DEFAULT_BPFLOADER_MAX_VER; \ unsigned int _bpfloader_max_ver SECTION("bpfloader_max_ver") = DEFAULT_BPFLOADER_MAX_VER; \
size_t _size_of_bpf_map_def SEC("size_of_bpf_map_def") = sizeof(struct bpf_map_def); \ size_t _size_of_bpf_map_def SECTION("size_of_bpf_map_def") = sizeof(struct bpf_map_def); \
size_t _size_of_bpf_prog_def SEC("size_of_bpf_prog_def") = sizeof(struct bpf_prog_def); \ size_t _size_of_bpf_prog_def SECTION("size_of_bpf_prog_def") = sizeof(struct bpf_prog_def); \
char _license[] SEC("license") = (NAME) char _license[] SECTION("license") = (NAME)
/* flag the resulting bpf .o file as critical to system functionality, /* flag the resulting bpf .o file as critical to system functionality,
* loading all kernel version appropriate programs in it must succeed * loading all kernel version appropriate programs in it must succeed
* for bpfloader success * for bpfloader success
*/ */
#define CRITICAL(REASON) char _critical[] SEC("critical") = (REASON) #define CRITICAL(REASON) char _critical[] SECTION("critical") = (REASON)
/* /*
* Helper functions called from eBPF programs written in C. These are * Helper functions called from eBPF programs written in C. These are
@ -103,7 +103,7 @@ static int (*bpf_map_delete_elem_unsafe)(const struct bpf_map_def* map,
/* type safe macro to declare a map and related accessor functions */ /* type safe macro to declare a map and related accessor functions */
#define DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, usr, grp, md) \ #define DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, usr, grp, md) \
const struct bpf_map_def SEC("maps") the_map = { \ const struct bpf_map_def SECTION("maps") the_map = { \
.type = BPF_MAP_TYPE_##TYPE, \ .type = BPF_MAP_TYPE_##TYPE, \
.key_size = sizeof(TypeOfKey), \ .key_size = sizeof(TypeOfKey), \
.value_size = sizeof(TypeOfValue), \ .value_size = sizeof(TypeOfValue), \
@ -155,7 +155,7 @@ static unsigned long long (*bpf_get_smp_processor_id)(void) = (void*) BPF_FUNC_g
#define DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \ #define DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \
opt) \ opt) \
const struct bpf_prog_def SEC("progs") the_prog##_def = { \ const struct bpf_prog_def SECTION("progs") the_prog##_def = { \
.uid = (prog_uid), \ .uid = (prog_uid), \
.gid = (prog_gid), \ .gid = (prog_gid), \
.min_kver = (min_kv), \ .min_kver = (min_kv), \
@ -164,7 +164,7 @@ static unsigned long long (*bpf_get_smp_processor_id)(void) = (void*) BPF_FUNC_g
.bpfloader_min_ver = DEFAULT_BPFLOADER_MIN_VER, \ .bpfloader_min_ver = DEFAULT_BPFLOADER_MIN_VER, \
.bpfloader_max_ver = DEFAULT_BPFLOADER_MAX_VER, \ .bpfloader_max_ver = DEFAULT_BPFLOADER_MAX_VER, \
}; \ }; \
SEC(SECTION_NAME) \ SECTION(SECTION_NAME) \
int the_prog int the_prog
// Programs (here used in the sense of functions/sections) marked optional are allowed to fail // Programs (here used in the sense of functions/sections) marked optional are allowed to fail

View file

@ -116,10 +116,10 @@ _Static_assert(__alignof__(unsigned long long) == 8, "__alignof__ unsigned long
* uses this structure from eBPF object to create maps at boot time. * uses this structure from eBPF object to create maps at boot time.
* *
* The eBPF C program should define structure in the maps section using * The eBPF C program should define structure in the maps section using
* SEC("maps") otherwise it will be ignored by the eBPF loader. * SECTION("maps") otherwise it will be ignored by the eBPF loader.
* *
* For example: * For example:
* const struct bpf_map_def SEC("maps") mymap { .type=... , .key_size=... } * const struct bpf_map_def SECTION("maps") mymap { .type=... , .key_size=... }
* *
* See 'bpf_helpers.h' for helpful macros for eBPF program use. * See 'bpf_helpers.h' for helpful macros for eBPF program use.
*/ */

View file

@ -86,7 +86,7 @@ void mock_bpf_set_current_pid_tgid(uint64_t pid_tgid);
#endif #endif
/* place things in different elf sections */ /* place things in different elf sections */
#define SEC(NAME) __attribute__((section(NAME), used)) #define SECTION(NAME) __attribute__((section(NAME), used))
/* Example use: LICENSE("GPL"); or LICENSE("Apache 2.0"); */ /* Example use: LICENSE("GPL"); or LICENSE("Apache 2.0"); */
#define LICENSE(NAME) char _license[] SEC("license") = (NAME) #define LICENSE(NAME) char _license[] SECTION("license") = (NAME)