aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/wasm-external-refs.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/wasm/wasm-external-refs.cc')
-rw-r--r--deps/v8/src/wasm/wasm-external-refs.cc51
1 files changed, 47 insertions, 4 deletions
diff --git a/deps/v8/src/wasm/wasm-external-refs.cc b/deps/v8/src/wasm/wasm-external-refs.cc
index 83f060cb9a..997cf83bb7 100644
--- a/deps/v8/src/wasm/wasm-external-refs.cc
+++ b/deps/v8/src/wasm/wasm-external-refs.cc
@@ -11,9 +11,26 @@
#include "src/base/bits.h"
#include "src/base/ieee754.h"
-#include "src/memcopy.h"
-#include "src/utils.h"
-#include "src/v8memory.h"
+#include "src/utils/memcopy.h"
+
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
+ defined(UNDEFINED_SANITIZER)
+#define V8_WITH_SANITIZER
+#endif
+
+#if defined(V8_OS_WIN) && defined(V8_WITH_SANITIZER)
+// With ASAN on Windows we have to reset the thread-in-wasm flag. Exceptions
+// caused by ASAN let the thread-in-wasm flag get out of sync. Even marking
+// functions with DISABLE_ASAN is not sufficient when the compiler produces
+// calls to memset. Therefore we add test-specific code for ASAN on
+// Windows.
+#define RESET_THREAD_IN_WASM_FLAG_FOR_ASAN_ON_WINDOWS
+#include "src/trap-handler/trap-handler.h"
+#endif
+
+#include "src/common/v8memory.h"
+#include "src/utils/utils.h"
#include "src/wasm/wasm-external-refs.h"
namespace v8 {
@@ -249,7 +266,15 @@ void float64_pow_wrapper(Address data) {
WriteUnalignedValue<double>(data, base::ieee754::pow(x, y));
}
-void memory_copy_wrapper(Address dst, Address src, uint32_t size) {
+// Asan on Windows triggers exceptions in this function to allocate
+// shadow memory lazily. When this function is called from WebAssembly,
+// these exceptions would be handled by the trap handler before they get
+// handled by Asan, and thereby confuse the thread-in-wasm flag.
+// Therefore we disable ASAN for this function. Alternatively we could
+// reset the thread-in-wasm flag before calling this function. However,
+// as this is only a problem with Asan on Windows, we did not consider
+// it worth the overhead.
+DISABLE_ASAN void memory_copy_wrapper(Address dst, Address src, uint32_t size) {
// Use explicit forward and backward copy to match the required semantics for
// the memory.copy instruction. It is assumed that the caller of this
// function has already performed bounds checks, so {src + size} and
@@ -270,7 +295,17 @@ void memory_copy_wrapper(Address dst, Address src, uint32_t size) {
}
}
+// Asan on Windows triggers exceptions in this function that confuse the
+// WebAssembly trap handler, so Asan is disabled. See the comment on
+// memory_copy_wrapper above for more info.
void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size) {
+#if defined(RESET_THREAD_IN_WASM_FLAG_FOR_ASAN_ON_WINDOWS)
+ bool thread_was_in_wasm = trap_handler::IsThreadInWasm();
+ if (thread_was_in_wasm) {
+ trap_handler::ClearThreadInWasm();
+ }
+#endif
+
// Use an explicit forward copy to match the required semantics for the
// memory.fill instruction. It is assumed that the caller of this function
// has already performed bounds checks, so {dst + size} should not overflow.
@@ -280,6 +315,11 @@ void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size) {
for (; size > 0; size--) {
*dst8++ = value8;
}
+#if defined(RESET_THREAD_IN_WASM_FLAG_FOR_ASAN_ON_WINDOWS)
+ if (thread_was_in_wasm) {
+ trap_handler::SetThreadInWasm();
+ }
+#endif
}
static WasmTrapCallbackForTesting wasm_trap_callback_for_testing = nullptr;
@@ -297,3 +337,6 @@ void call_trap_callback_for_testing() {
} // namespace wasm
} // namespace internal
} // namespace v8
+
+#undef V8_WITH_SANITIZER
+#undef RESET_THREAD_IN_WASM_FLAG_FOR_ASAN_ON_WINDOWS