Skip to content

Commit

Permalink
Implement GetCurrentThreadStackLimits() for Windows 7 (bytecodeallian…
Browse files Browse the repository at this point in the history
…ce#914)

And fix compilation error of when build wamrc, fix compilation warnings
  • Loading branch information
wenyongh authored Dec 27, 2021
1 parent 1cc8072 commit c08aca6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions core/iwasm/compilation/aot_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/shared/platform/windows/platform_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <stdint.h>
#include <malloc.h>
#include <process.h>
#include <winsock2.h>
#include <Windows.h>
#include <BaseTsd.h>
#include <winsock2.h>

#ifdef __cplusplus
extern "C" {
Expand Down
31 changes: 31 additions & 0 deletions core/shared/platform/windows/win_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
Expand Down

0 comments on commit c08aca6

Please sign in to comment.