From d99b84e4894f2dbe8a8a5044fd0785166a26704d Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 30 Mar 2022 11:20:39 +0000 Subject: [PATCH] [Wasm] Disable use of `returnaddress` in exclusivity diagnostics Function calls and returns in Wasm are protected by Wasm runtime and there is no way to get or control return address. --- lib/IRGen/IRGenSIL.cpp | 4 +++- stdlib/public/runtime/Exclusivity.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 511da1a84da46..3d51e23758f16 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -5765,7 +5765,9 @@ void IRGenSILFunction::visitBeginUnpairedAccessInst( // in which case we should use the caller, which is generally ok because // materializeForSet can't usually be thunked. llvm::Value *pc; - if (hasBeenInlined(access)) { + // Wasm doesn't have returnaddress because it can't access call frame + // for security purposes + if (IGM.Triple.isWasm() || hasBeenInlined(access)) { pc = llvm::ConstantPointerNull::get(IGM.Int8PtrTy); } else { auto retAddrFn = diff --git a/stdlib/public/runtime/Exclusivity.cpp b/stdlib/public/runtime/Exclusivity.cpp index 0a6630108b726..5e0cf63fd114f 100644 --- a/stdlib/public/runtime/Exclusivity.cpp +++ b/stdlib/public/runtime/Exclusivity.cpp @@ -42,6 +42,9 @@ #elif _MSC_VER #include #define get_return_address() _ReturnAddress() +#elif defined(__wasm__) +// Wasm can't access call frame for security purposes +#define get_return_address() ((void*) 0) #else #error missing implementation for get_return_address #define get_return_address() ((void*) 0)