Skip to content

Commit 33b4a3f

Browse files
dcpleungjhedberg
authored andcommitted
kernel: add compiler barrier in k_is_pre_kernel between...
...checking whether we are in user context and accessing a kernel mode only variable. For some unknown reasons only knew to Cadence engineers, the Cadence toolchain will always read z_sys_boot_kernel at the beginning of k_is_pre_kernel() instead of after k_is_user_context() is called. So it would always result in access violation if this is called in user mode. Forcing a compiler barrier seems to fix that. So force it here. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
1 parent 91d2dcf commit 33b4a3f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/zephyr/kernel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,16 @@ static inline bool k_is_pre_kernel(void)
711711
return false;
712712
}
713713

714+
/*
715+
* Some compilers might optimize by pre-reading
716+
* z_sys_post_kernel. This is absolutely not desirable.
717+
* We are trying to avoid reading it if we are in user
718+
* context as reading z_sys_post_kernel in user context
719+
* will result in access fault. So add a compiler barrier
720+
* here to stop that kind of optimizations.
721+
*/
722+
compiler_barrier();
723+
714724
return !z_sys_post_kernel;
715725
}
716726

0 commit comments

Comments
 (0)