Stream: wamr

Topic: os_mprotect issue on OSX


view this post on Zulip Alexandru Ene (May 16 2022 at 11:56):

Hi, I've been experimenting more with the pthread API on OSX and noticed that it always crashes on the second os_mprotect call from:
`static bool init_stack_guard_pages(). This happens if AOT is enabled (even if not used by the module.

A quick reading online seems to suggest that on OSX mprotect can be used for regions that have been mmapped only.
I didn't do much investigation on this but just to check that I'm not using this the wrong way around before I file a bug.

view this post on Zulip Wenyong Huang (May 17 2022 at 01:08):

Hi, the init_stack_guard_pages is required when the memory access boundary check (besides with native stack overflow check) with hardware trap feature is enabled for AOT/JIT, so as to improve the performance. Not sure whether pthread_get_stackaddr_np and pthread_get_stacksize_np in os_thread_get_stack_boundary are called and work well in OSX platform:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/common/posix/posix_thread.c#L339-L341
If not and if it returns NULL, runtime will return false in latest code:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/common/posix/posix_thread.c#L415
And not sure whether the native stack space are pages mmaped? If not, mprotect may report error.

If the feature isn't supported, please disable it:

  1. when building runtime, add cmake -DWAMR_DISABLE_HW_BOUND_CHECK=1
  2. when running wamrc, add wamrc --bounds-checks=1 to generate bound check instructions in AOT code
    Thanks.
WebAssembly Micro Runtime (WAMR). Contribute to bytecodealliance/wasm-micro-runtime development by creating an account on GitHub.
WebAssembly Micro Runtime (WAMR). Contribute to bytecodealliance/wasm-micro-runtime development by creating an account on GitHub.

view this post on Zulip Alexandru Ene (May 17 2022 at 10:52):

Ok, I'll check if there's something on my side, since i've tested this on OSX and fails on that mprotect call


Last updated: Nov 22 2024 at 16:03 UTC