mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-03-12 00:45:28 +00:00
GetCurrentThreadStackLimits dynamically for Windows platform (#939)
GetCurrentThreadStackLimits dynamically for Windows platform according to suggestion in #902 And fix some compiling warnings on Windows platform
This commit is contained in:
parent
cb51dbb513
commit
78308e7bda
|
@ -1643,7 +1643,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
|
|||
vendor_sys = strstr(default_triple, "-");
|
||||
bh_assert(vendor_sys);
|
||||
bh_memcpy_s(default_arch, sizeof(default_arch), default_triple,
|
||||
vendor_sys - default_triple);
|
||||
(uint32)(vendor_sys - default_triple));
|
||||
arch1 = default_arch;
|
||||
|
||||
LLVMDisposeMessage(default_triple);
|
||||
|
@ -1668,13 +1668,15 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
|
|||
|
||||
bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi)
|
||||
< sizeof(triple_buf));
|
||||
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch1, strlen(arch1));
|
||||
bh_memcpy_s(triple_buf, (uint32)sizeof(triple_buf), arch1,
|
||||
(uint32)strlen(arch1));
|
||||
bh_memcpy_s(triple_buf + strlen(arch1),
|
||||
sizeof(triple_buf) - strlen(arch1), vendor_sys,
|
||||
strlen(vendor_sys));
|
||||
(uint32)(sizeof(triple_buf) - strlen(arch1)),
|
||||
vendor_sys, (uint32)strlen(vendor_sys));
|
||||
bh_memcpy_s(triple_buf + strlen(arch1) + strlen(vendor_sys),
|
||||
sizeof(triple_buf) - strlen(arch1) - strlen(vendor_sys),
|
||||
abi, strlen(abi));
|
||||
(uint32)(sizeof(triple_buf) - strlen(arch1)
|
||||
- strlen(vendor_sys)),
|
||||
abi, (uint32)strlen(abi));
|
||||
triple = triple_buf;
|
||||
}
|
||||
else if (arch) {
|
||||
|
@ -1707,13 +1709,15 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
|
|||
|
||||
bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi)
|
||||
< sizeof(triple_buf));
|
||||
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch, strlen(arch));
|
||||
bh_memcpy_s(triple_buf, (uint32)sizeof(triple_buf), arch,
|
||||
(uint32)strlen(arch));
|
||||
bh_memcpy_s(triple_buf + strlen(arch),
|
||||
sizeof(triple_buf) - strlen(arch), vendor_sys,
|
||||
strlen(vendor_sys));
|
||||
(uint32)(sizeof(triple_buf) - strlen(arch)), vendor_sys,
|
||||
(uint32)strlen(vendor_sys));
|
||||
bh_memcpy_s(triple_buf + strlen(arch) + strlen(vendor_sys),
|
||||
sizeof(triple_buf) - strlen(arch) - strlen(vendor_sys),
|
||||
abi, strlen(abi));
|
||||
(uint32)(sizeof(triple_buf) - strlen(arch)
|
||||
- strlen(vendor_sys)),
|
||||
abi, (uint32)strlen(abi));
|
||||
triple = triple_buf;
|
||||
}
|
||||
|
||||
|
@ -2604,4 +2608,4 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
|
|||
}
|
||||
|
||||
return const_value;
|
||||
}
|
||||
}
|
|
@ -47,6 +47,10 @@ static os_thread_data supervisor_thread_data;
|
|||
/* Thread data key */
|
||||
static DWORD thread_data_key;
|
||||
|
||||
/* The GetCurrentThreadStackLimits API from "kernel32" */
|
||||
static void(WINAPI *GetCurrentThreadStackLimits_Kernel32)(PULONG_PTR,
|
||||
PULONG_PTR) = NULL;
|
||||
|
||||
int
|
||||
os_sem_init(korp_sem *sem);
|
||||
int
|
||||
|
@ -61,6 +65,8 @@ os_sem_signal(korp_sem *sem);
|
|||
int
|
||||
os_thread_sys_init()
|
||||
{
|
||||
HMODULE module;
|
||||
|
||||
if (is_thread_sys_inited)
|
||||
return BHT_OK;
|
||||
|
||||
|
@ -84,6 +90,11 @@ os_thread_sys_init()
|
|||
if (!TlsSetValue(thread_data_key, &supervisor_thread_data))
|
||||
goto fail4;
|
||||
|
||||
if ((module = GetModuleHandle((LPSTR) "kernel32"))) {
|
||||
*(void **)&GetCurrentThreadStackLimits_Kernel32 =
|
||||
GetProcAddress(module, "GetCurrentThreadStackLimits");
|
||||
}
|
||||
|
||||
is_thread_sys_inited = true;
|
||||
return BHT_OK;
|
||||
|
||||
|
@ -556,7 +567,6 @@ 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)
|
||||
|
@ -579,7 +589,6 @@ GetCurrentThreadStackLimits_Win7(PULONG_PTR p_low_limit,
|
|||
os_printf("warning: VirtualQuery() failed\n");
|
||||
return GetLastError();
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
|
@ -591,13 +600,14 @@ 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;
|
||||
if (GetCurrentThreadStackLimits_Kernel32) {
|
||||
GetCurrentThreadStackLimits_Kernel32(&low_limit, &high_limit);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
if (0 != GetCurrentThreadStackLimits_Win7(&low_limit, &high_limit))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
|
|
@ -103,7 +103,7 @@ set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
|||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN -D_WINSOCK_DEPRECATED_NO_WARNINGS")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
|
||||
|
||||
|
|
|
@ -222,6 +222,10 @@ if (NOT MSVC)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WINSOCK_DEPRECATED_NO_WARNINGS")
|
||||
endif()
|
||||
|
||||
# message ("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
|
||||
|
||||
add_library (vmlib
|
||||
|
|
Loading…
Reference in New Issue
Block a user