From 89a1c8220db3e173cc2f2060b711ebbe64ea9681 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 27 Dec 2021 10:18:44 +0800 Subject: [PATCH] Implement GetCurrentThreadStackLimits() for Windows 7 (#914) And fix compilation error of when build wamrc, fix compilation warnings --- core/iwasm/aot/aot_loader.c | 2 +- core/iwasm/compilation/aot_compiler.c | 2 -- .../platform/windows/platform_internal.h | 2 +- core/shared/platform/windows/win_thread.c | 31 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index c550a3f9..ec94ffff 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -3114,7 +3114,7 @@ aot_unload(AOTModule *module) wasm_runtime_free(module->aux_func_indexes); } if (module->aux_func_names) { - wasm_runtime_free(module->aux_func_names); + wasm_runtime_free((void *)module->aux_func_names); } #endif diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 9e839601..14543885 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -459,8 +459,6 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) } case WASM_OP_REF_FUNC: { - uint32 func_idx; - if (!comp_ctx->enable_ref_types) { goto unsupport_ref_types; } diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index 7ca79a44..db942416 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -25,9 +25,9 @@ #include #include #include +#include #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/core/shared/platform/windows/win_thread.c b/core/shared/platform/windows/win_thread.c index 3a123d6f..6972c1b2 100644 --- a/core/shared/platform/windows/win_thread.c +++ b/core/shared/platform/windows/win_thread.c @@ -556,6 +556,31 @@ os_cond_signal(korp_cond *cond) static os_thread_local_attribute uint8 *thread_stack_boundary = NULL; +#if _WIN32_WINNT < 0x0602 +static ULONG +GetCurrentThreadStackLimits_Win7(PULONG_PTR p_low_limit, + PULONG_PTR p_high_limit) +{ + MEMORY_BASIC_INFORMATION mbi; + NT_TIB *tib = (NT_TIB *)NtCurrentTeb(); + + if (!tib) { + os_printf("warning: NtCurrentTeb() failed\n"); + return -1; + } + + *p_high_limit = (ULONG_PTR)tib->StackBase; + + if (VirtualQuery(tib->StackLimit, &mbi, sizeof(mbi))) { + *p_low_limit = (ULONG_PTR)mbi.AllocationBase; + return 0; + } + + os_printf("warning: VirtualQuery() failed\n"); + return GetLastError(); +} +#endif + uint8 * os_thread_get_stack_boundary() { @@ -566,7 +591,13 @@ os_thread_get_stack_boundary() return thread_stack_boundary; page_size = os_getpagesize(); +#if _WIN32_WINNT >= 0x0602 GetCurrentThreadStackLimits(&low_limit, &high_limit); +#else + if (0 != GetCurrentThreadStackLimits_Win7(&low_limit, &high_limit)) { + return NULL; + } +#endif /* 4 pages are set unaccessible by system, we reserved one more page at least for safety */ thread_stack_boundary = (uint8 *)(uintptr_t)low_limit + page_size * 5;