|
@@ -9,10 +9,6 @@
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
-#if defined(__APPLE__)
|
|
|
|
|
-#include <Availability.h>
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
#include "wasm_export.h"
|
|
#include "wasm_export.h"
|
|
|
#include "bh_platform.h"
|
|
#include "bh_platform.h"
|
|
|
|
|
|
|
@@ -45,9 +41,12 @@ host_consume_stack_and_call_indirect(wasm_exec_env_t exec_env, uint32_t funcidx,
|
|
|
void *boundary = os_thread_get_stack_boundary();
|
|
void *boundary = os_thread_get_stack_boundary();
|
|
|
void *fp = __builtin_frame_address(0);
|
|
void *fp = __builtin_frame_address(0);
|
|
|
ptrdiff_t diff = fp - boundary;
|
|
ptrdiff_t diff = fp - boundary;
|
|
|
- if ((unsigned char *)fp < (unsigned char *)boundary + 1024 * 5) {
|
|
|
|
|
- wasm_runtime_set_exception(wasm_runtime_get_module_inst(exec_env),
|
|
|
|
|
- "native stack overflow 2");
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * because this function performs recursive calls depending on
|
|
|
|
|
+ * the user input, we don't have an apriori knowledge how much stack
|
|
|
|
|
+ * we need. perform the overflow check on each iteration.
|
|
|
|
|
+ */
|
|
|
|
|
+ if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
if (diff > stack) {
|
|
if (diff > stack) {
|
|
@@ -63,27 +62,13 @@ host_consume_stack_and_call_indirect(wasm_exec_env_t exec_env, uint32_t funcidx,
|
|
|
|
|
|
|
|
__attribute__((noinline)) static uint32_t
|
|
__attribute__((noinline)) static uint32_t
|
|
|
consume_stack1(wasm_exec_env_t exec_env, void *base, uint32_t stack)
|
|
consume_stack1(wasm_exec_env_t exec_env, void *base, uint32_t stack)
|
|
|
|
|
+#if defined(__clang__)
|
|
|
__attribute__((disable_tail_calls))
|
|
__attribute__((disable_tail_calls))
|
|
|
|
|
+#endif
|
|
|
{
|
|
{
|
|
|
void *fp = __builtin_frame_address(0);
|
|
void *fp = __builtin_frame_address(0);
|
|
|
ptrdiff_t diff = (unsigned char *)base - (unsigned char *)fp;
|
|
ptrdiff_t diff = (unsigned char *)base - (unsigned char *)fp;
|
|
|
assert(diff > 0);
|
|
assert(diff > 0);
|
|
|
- char buf[16];
|
|
|
|
|
- /*
|
|
|
|
|
- * note: we prefer to use memset_s here because, unlike memset,
|
|
|
|
|
- * memset_s is not allowed to be optimized away.
|
|
|
|
|
- *
|
|
|
|
|
- * memset_s is available for macOS 10.13+ according to:
|
|
|
|
|
- * https://developer.apple.com/documentation/kernel/2876438-memset_s
|
|
|
|
|
- */
|
|
|
|
|
-#if defined(__STDC_LIB_EXT1__) \
|
|
|
|
|
- || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) \
|
|
|
|
|
- && __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
|
|
|
|
|
- memset_s(buf, sizeof(buf), 0, sizeof(buf));
|
|
|
|
|
-#else
|
|
|
|
|
-#warning memset_s is not available
|
|
|
|
|
- memset(buf, 0, sizeof(buf));
|
|
|
|
|
-#endif
|
|
|
|
|
if (diff > stack) {
|
|
if (diff > stack) {
|
|
|
return diff;
|
|
return diff;
|
|
|
}
|
|
}
|
|
@@ -93,6 +78,12 @@ consume_stack1(wasm_exec_env_t exec_env, void *base, uint32_t stack)
|
|
|
uint32_t
|
|
uint32_t
|
|
|
host_consume_stack(wasm_exec_env_t exec_env, uint32_t stack)
|
|
host_consume_stack(wasm_exec_env_t exec_env, uint32_t stack)
|
|
|
{
|
|
{
|
|
|
|
|
+ /*
|
|
|
|
|
+ * this function consumes a bit more than "stack" bytes.
|
|
|
|
|
+ */
|
|
|
|
|
+ if (!wasm_runtime_detect_native_stack_overflow_size(exec_env, 64 + stack)) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
void *base = __builtin_frame_address(0);
|
|
void *base = __builtin_frame_address(0);
|
|
|
return consume_stack1(exec_env, base, stack);
|
|
return consume_stack1(exec_env, base, stack);
|
|
|
}
|
|
}
|