#ifndef bpf_for_each /* bpf_for_each(iter_type, cur_elem, args...) provides generic construct for *usingBPFopen-codediteratorswithouthavingtowritemundaneexplicit *low-levellooplogic.Instead,itprovidesfor()-likegenericconstruct *thatcanbeusedprettynaturally.E.g.,forsomehypotheticalcgroup *iterator,you'dwrite: * *structcgroup*cg,*parent_cg=<...>; * *bpf_for_each(cgroup,cg,parent_cg,CG_ITER_CHILDREN){ *bpf_printk("Childcgroupid=%d",cg->cgroup_id); *if(cg->cgroup_id==123) *break; *} * *I.e.,itlooksalmostlikehigh-levelforeachloopinotherlanguages, *supportscontinue/break,andisverifiablebyBPFverifier. * *Foriteratingintegers,thedifferencebetweenbpf_for_each(num,i,N,M) *andbpf_for(i,N,M)isinthatbpf_for()providesadditionalproofto *verifierthatiisin[N,M)range,andinbpf_for_each()caseiis`int **`,notjust`int`.Soforintegersbpf_for()ismoreconvenient. * *Note:thismacroreliesonC99featureofallowingtodeclarevariables *insidefor()loop,boundtofor()looplifetime.ItalsoutilizesGCC *extension:__attribute__((cleanup(<func>))),supportedbybothGCCand *Clang.
*/ #define bpf_for_each(type, cur, args...) for ( \ /* initialize and define destructor */ \ struct bpf_iter_##type ___it __attribute__((aligned(8), /* enforce, just in case */, \
cleanup(bpf_iter_##type##_destroy))), \ /* ___p pointer is just to call bpf_iter_##type##_new() *once* to init ___it */ \
*___p __attribute__((unused)) = ( \
bpf_iter_##type##_new(&___it, ##args), \ /* this is a workaround for Clang bug: it currently doesn't emit BTF */ \ /* for bpf_iter_##type##_destroy() when used from cleanup() attribute */ \
(void)bpf_iter_##type##_destroy, (void *)0); \ /* iteration and termination check */ \
(((cur) = bpf_iter_##type##_next(&___it))); \
) #endif/* bpf_for_each */
#ifndef bpf_for /* bpf_for(i, start, end) implements a for()-like looping construct that sets *providedintegervariable*i*tovaluesstartingfrom*start*through, *butnotincluding,*end*.ItalsoprovestoBPFverifierthat*i*belongs *torange[start,end),sothiscanbeusedforaccessingarrayswithout *extrachecks. * *Note:*start*and*end*areassumedtobeexpressionswithnosideeffects *andwhosevaluesdonotchangethroughoutbpf_for()loopexecution.Theydo *nothavetobestaticallyknownorconstant,though. * *Note:similarlytobpf_for_each(),itreliesonC99featureofdeclaringfor() *loopboundvariablesandcleanupattribute,supportedbyGCCandClang.
*/ #define bpf_for(i, start, end) for ( \ /* initialize and define destructor */ \ struct bpf_iter_num ___it __attribute__((aligned(8), /* enforce, just in case */ \
cleanup(bpf_iter_num_destroy))), \ /* ___p pointer is necessary to call bpf_iter_num_new() *once* to init ___it */ \
*___p __attribute__((unused)) = ( \
bpf_iter_num_new(&___it, (start), (end)), \ /* this is a workaround for Clang bug: it currently doesn't emit BTF */ \ /* for bpf_iter_num_destroy() when used from cleanup() attribute */ \
(void)bpf_iter_num_destroy, (void *)0); \
({ \ /* iteration step */ \ int *___t = bpf_iter_num_next(&___it); \ /* termination and bounds check */ \
(___t && ((i) = *___t, (i) >= (start) && (i) < (end))); \
}); \
) #endif/* bpf_for */
#ifndef bpf_repeat /* bpf_repeat(N) performs N iterations without exposing iteration number * *Note:similarlytobpf_for_each(),itreliesonC99featureofdeclaringfor() *loopboundvariablesandcleanupattribute,supportedbyGCCandClang.
*/ #define bpf_repeat(N) for ( \ /* initialize and define destructor */ \ struct bpf_iter_num ___it __attribute__((aligned(8), /* enforce, just in case */ \
cleanup(bpf_iter_num_destroy))), \ /* ___p pointer is necessary to call bpf_iter_num_new() *once* to init ___it */ \
*___p __attribute__((unused)) = ( \
bpf_iter_num_new(&___it, 0, (N)), \ /* this is a workaround for Clang bug: it currently doesn't emit BTF */ \ /* for bpf_iter_num_destroy() when used from cleanup() attribute */ \
(void)bpf_iter_num_destroy, (void *)0); \
bpf_iter_num_next(&___it); \ /* nothing here */ \
) #endif/* bpf_repeat */
#endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.