From 42d51de0b15edb27d117a9dad5fd771af6c6dc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4r?= Date: Wed, 13 Apr 2022 15:47:38 +0200 Subject: [PATCH] Fix for page fault while disabled --- lib/aos/dispatch.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/aos/dispatch.c b/lib/aos/dispatch.c index bbbded4..b87a596 100644 --- a/lib/aos/dispatch.c +++ b/lib/aos/dispatch.c @@ -208,6 +208,20 @@ void disp_yield_disabled(dispatcher_handle_t handle) for (;;); } +/** + * We must not cause page faults while disabled. So touch the stack now + * to potentially cause a page fault, so that we won't have one later. + * This assumes that we use at most sizeof(s) bytes of stack while disabled. + */ +static void allocate_stack(void) +{ + volatile char s[2048]; + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wuninitialized" + s[0]; + #pragma GCC diagnostic pop +} + /** * \brief Disable the dispatcher * @@ -219,6 +233,7 @@ void disp_yield_disabled(dispatcher_handle_t handle) */ dispatcher_handle_t disp_disable(void) { + allocate_stack(); dispatcher_handle_t handle = curdispatcher(); struct dispatcher_shared_generic* disp = get_dispatcher_shared_generic(handle); @@ -240,6 +255,7 @@ dispatcher_handle_t disp_disable(void) */ dispatcher_handle_t disp_try_disable(bool *was_enabled) { + allocate_stack(); dispatcher_handle_t handle = curdispatcher(); struct dispatcher_shared_generic* disp = get_dispatcher_shared_generic(handle);