Make sure that touching pages will not fail due to misconfigured protection #4067
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When threads are initialized with
wasm_runtime_init_thread_env()
, the first few pages (configured usingSTACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
) are configured to be not readable/writable (for the stack protection). The protection is then removed indestroy_stack_guard_pages()
, which is automatically called whenos_thread_wrapper
is used for creating a new thread.However, the wrapper might not always be used (and in fact, is not in some of the examples like here) when the thread is created outside of WAMR. To avoid crashes in
touch_pages
(caused by trying to write to protected memory), we'll mark the whole stack readable/writable before touching the pages.