diff options
author | Damjan Marion <damarion@cisco.com> | 2021-04-14 19:07:13 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2021-04-14 19:26:34 +0000 |
commit | 1d429df08123abacdb6a4757385cde76653044fa (patch) | |
tree | 21fda16efd799ea5b21a1ed8f490ec5e6709876b /src | |
parent | d22f1906e7f1800bcef072357bd8d7d20143f64b (diff) |
vlib: fix access before check issue in foreach_vlib_main macro
Type: fix
Change-Id: Iefb150a60b39d419d7dde35c80fbcba3a3a0d1e1
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vlib/threads.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/vlib/threads.h b/src/vlib/threads.h index 28a81f78712..9e83563a2e9 100644 --- a/src/vlib/threads.h +++ b/src/vlib/threads.h @@ -237,16 +237,24 @@ typedef enum void vlib_worker_thread_fork_fixup (vlib_fork_fixup_t which); +always_inline int +__foreach_vlib_main_helper (vlib_main_t *ii, vlib_main_t **p) +{ + vlib_main_t *vm; + u32 index = ii - (vlib_main_t *) 0; + + if (index >= vec_len (vlib_global_main.vlib_mains)) + return 0; + + *p = vm = vlib_global_main.vlib_mains[index]; + ASSERT (index == 0 || vm->parked_at_barrier == 1); + return 1; +} + #define foreach_vlib_main() \ - for (vlib_main_t *ii = 0, *this_vlib_main = vlib_global_main.vlib_mains[0]; \ - (ii - (vlib_main_t *) 0) < vec_len (vlib_global_main.vlib_mains); \ - ii++, this_vlib_main = \ - vlib_global_main.vlib_mains[ii - (vlib_main_t *) 0]) \ - if (CLIB_ASSERT_ENABLE && \ - !(ii == 0 || \ - (this_vlib_main && this_vlib_main->parked_at_barrier == 1))) \ - ASSERT (0); \ - else if (this_vlib_main) + for (vlib_main_t *ii = 0, *this_vlib_main; \ + __foreach_vlib_main_helper (ii, &this_vlib_main); ii++) \ + if (this_vlib_main) #define foreach_sched_policy \ _(SCHED_OTHER, OTHER, "other") \ |