Implement GetCurrentThreadStackLimits() for Windows 7 (#914)

And fix compilation error of when build wamrc, fix compilation warnings
This commit is contained in:
Wenyong Huang
2021-12-27 10:18:44 +08:00
committed by GitHub
parent ac3f7dcc0e
commit 89a1c8220d
4 changed files with 33 additions and 4 deletions

View File

@ -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" {

View File

@ -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;