7#ifndef INCLUDE_ZEPHYR_SYS_ITERABLE_SECTIONS_H_ 
    8#define INCLUDE_ZEPHYR_SYS_ITERABLE_SECTIONS_H_ 
   42#define TYPE_SECTION_ITERABLE(type, varname, secname, section_postfix) \ 
   43        Z_DECL_ALIGN(type) varname \ 
   44        __in_section(_##secname, static, _CONCAT(section_postfix, _)) __used __noasan 
 
   55#define TYPE_SECTION_START(secname) _CONCAT(_##secname, _list_start) 
   65#define TYPE_SECTION_END(secname) _CONCAT(_##secname, _list_end) 
   78#define TYPE_SECTION_START_EXTERN(type, secname) \ 
   79        extern type TYPE_SECTION_START(secname)[] 
 
   92#define TYPE_SECTION_END_EXTERN(type, secname) \ 
   93        extern type TYPE_SECTION_END(secname)[] 
 
  105#define TYPE_SECTION_FOREACH(type, secname, iterator)           \ 
  106        TYPE_SECTION_START_EXTERN(type, secname);               \ 
  107        TYPE_SECTION_END_EXTERN(type, secname);         \ 
  108        for (type * iterator = TYPE_SECTION_START(secname); ({  \ 
  109                __ASSERT(iterator <= TYPE_SECTION_END(secname),\ 
  110                              "unexpected list end location");  \ 
  111                     iterator < TYPE_SECTION_END(secname);      \ 
 
  125#define TYPE_SECTION_GET(type, secname, i, dst) do { \ 
  126        TYPE_SECTION_START_EXTERN(type, secname); \ 
  127        *(dst) = &TYPE_SECTION_START(secname)[i]; \ 
 
  137#define TYPE_SECTION_COUNT(type, secname, dst) do { \ 
  138        TYPE_SECTION_START_EXTERN(type, secname); \ 
  139        TYPE_SECTION_END_EXTERN(type, secname); \ 
  140        *(dst) = ((uintptr_t)TYPE_SECTION_END(secname) - \ 
  141                  (uintptr_t)TYPE_SECTION_START(secname)) / sizeof(type); \ 
 
  149#define STRUCT_SECTION_START(struct_type) \ 
  150        TYPE_SECTION_START(struct_type) 
 
  159#define STRUCT_SECTION_START_EXTERN(struct_type) \ 
  160        TYPE_SECTION_START_EXTERN(struct struct_type, struct_type) 
 
  167#define STRUCT_SECTION_END(struct_type) \ 
  168        TYPE_SECTION_END(struct_type) 
 
  177#define STRUCT_SECTION_END_EXTERN(struct_type) \ 
  178        TYPE_SECTION_END_EXTERN(struct struct_type, struct_type) 
 
  188#define STRUCT_SECTION_ITERABLE_ALTERNATE(secname, struct_type, varname) \ 
  189        TYPE_SECTION_ITERABLE(struct struct_type, varname, secname, varname) 
 
  197#define STRUCT_SECTION_ITERABLE_ARRAY_ALTERNATE(secname, struct_type, varname, \ 
  199        TYPE_SECTION_ITERABLE(struct struct_type, varname[size], secname,      \ 
 
  216#define STRUCT_SECTION_ITERABLE(struct_type, varname) \ 
  217        STRUCT_SECTION_ITERABLE_ALTERNATE(struct_type, struct_type, varname) 
 
  224#define STRUCT_SECTION_ITERABLE_ARRAY(struct_type, varname, size)              \ 
  225        STRUCT_SECTION_ITERABLE_ARRAY_ALTERNATE(struct_type, struct_type,      \ 
 
  234#define STRUCT_SECTION_ITERABLE_NAMED(struct_type, name, varname) \ 
  235        TYPE_SECTION_ITERABLE(struct struct_type, varname, struct_type, name) 
 
  247#define STRUCT_SECTION_FOREACH_ALTERNATE(secname, struct_type, iterator) \ 
  248        TYPE_SECTION_FOREACH(struct struct_type, secname, iterator) 
 
  260#define STRUCT_SECTION_FOREACH(struct_type, iterator) \ 
  261        STRUCT_SECTION_FOREACH_ALTERNATE(struct_type, struct_type, iterator) 
 
  272#define STRUCT_SECTION_GET(struct_type, i, dst) \ 
  273        TYPE_SECTION_GET(struct struct_type, struct_type, i, dst) 
 
  281#define STRUCT_SECTION_COUNT(struct_type, dst) \ 
  282        TYPE_SECTION_COUNT(struct struct_type, struct_type, dst);