Changeset 238376 in webkit
- Timestamp:
- Nov 19, 2018 8:49:43 AM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r238367 r238376 1 2018-11-19 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 3 [WebAssembly] I64 arguments / return value check should be moved from callWebAssemblyFunction to JSToWasm wrapper 4 https://bugs.webkit.org/show_bug.cgi?id=190512 5 6 Reviewed by Keith Miller. 7 8 This patch moves I64 arguments / return value check from callWebAssemblyFunction to JSToWasm wrapper. Since this 9 check can be done when compiling the function, we should encode the result into the generated wrapper instead of 10 checking every time we call callWebAssemblyFunction. This change is also one of the steps removing callWebAssemblyFunction 11 entirely. 12 13 * wasm/WasmExceptionType.h: 14 * wasm/js/JSToWasm.cpp: 15 (JSC::Wasm::createJSToWasmWrapper): 16 * wasm/js/WebAssemblyFunction.cpp: 17 (JSC::callWebAssemblyFunction): 18 * wasm/js/WebAssemblyWrapperFunction.cpp: 19 (JSC::callWebAssemblyWrapperFunction): 20 1 21 2018-11-12 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 22 -
trunk/Source/JavaScriptCore/wasm/WasmExceptionType.h
r217060 r238376 41 41 macro(DivisionByZero, "Division by zero") \ 42 42 macro(IntegerOverflow, "Integer overflow") \ 43 macro(StackOverflow, "Stack overflow") 43 macro(StackOverflow, "Stack overflow") \ 44 macro(I64ArgumentType, "WebAssembly function with an i64 argument can't be called from JavaScript") \ 45 macro(I64ReturnType, "WebAssembly function that returns i64 can't be called from JavaScript") 44 46 45 47 enum class ExceptionType : uint32_t { -
trunk/Source/JavaScriptCore/wasm/js/JSToWasm.cpp
r236734 r238376 31 31 #include "CCallHelpers.h" 32 32 #include "JSWebAssemblyInstance.h" 33 #include "JSWebAssemblyRuntimeError.h" 34 #include "MaxFrameExtentForSlowPathCall.h" 33 35 #include "WasmCallingConvention.h" 34 36 #include "WasmContextInlines.h" 35 37 #include "WasmSignatureInlines.h" 38 #include "WasmToJS.h" 36 39 37 40 namespace JSC { namespace Wasm { … … 71 74 unsigned numGPRs = 0; 72 75 unsigned numFPRs = 0; 76 bool argumentsIncludeI64 = false; 73 77 for (unsigned i = 0; i < signature.argumentCount(); i++) { 74 78 switch (signature.argument(i)) { 75 79 case Wasm::I64: 80 argumentsIncludeI64 = true; 81 FALLTHROUGH; 76 82 case Wasm::I32: 77 83 if (numGPRs >= wasmCallingConvention().m_gprArgs.size()) … … 101 107 ptrdiff_t offset = regAtOffset.offset(); 102 108 jit.storePtr(reg, CCallHelpers::Address(GPRInfo::callFrameRegister, offset)); 109 } 110 111 if (argumentsIncludeI64 || signature.returnType() == Wasm::I64) { 112 if (Context::useFastTLS()) 113 jit.loadWasmContextInstance(GPRInfo::argumentGPR2); 114 else { 115 // vmEntryToWasm passes the JSWebAssemblyInstance corresponding to Wasm::Context*'s 116 // instance as the first JS argument when we're not using fast TLS to hold the 117 // Wasm::Context*'s instance. 118 jit.loadPtr(CCallHelpers::Address(GPRInfo::callFrameRegister, CallFrameSlot::thisArgument * sizeof(EncodedJSValue)), GPRInfo::argumentGPR2); 119 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR2, JSWebAssemblyInstance::offsetOfPoisonedInstance()), GPRInfo::argumentGPR2); 120 jit.move(CCallHelpers::TrustedImm64(JSWebAssemblyInstancePoison::key()), GPRInfo::argumentGPR0); 121 jit.xor64(GPRInfo::argumentGPR0, GPRInfo::argumentGPR2); 122 } 123 124 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR2, Instance::offsetOfPointerToTopEntryFrame()), GPRInfo::argumentGPR0); 125 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0), GPRInfo::argumentGPR0); 126 jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(GPRInfo::argumentGPR0); 127 jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0); 128 jit.move(CCallHelpers::TrustedImm32(static_cast<int32_t>(argumentsIncludeI64 ? ExceptionType::I64ArgumentType : ExceptionType::I64ReturnType)), GPRInfo::argumentGPR1); 129 130 CCallHelpers::Call call = jit.call(OperationPtrTag); 131 132 jit.jump(GPRInfo::returnValueGPR, ExceptionHandlerPtrTag); 133 jit.breakpoint(); // We should not reach this. 134 135 jit.addLinkTask([=] (LinkBuffer& linkBuffer) { 136 linkBuffer.link(call, FunctionPtr<OperationPtrTag>(wasmToJSException)); 137 }); 138 return result; 103 139 } 104 140 … … 201 237 }); 202 238 203 204 239 for (const RegisterAtOffset& regAtOffset : registersToSpill) { 205 240 GPRReg reg = regAtOffset.reg().gpr(); -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r237042 r238376 56 56 VM& vm = exec->vm(); 57 57 auto scope = DECLARE_THROW_SCOPE(vm); 58 WebAssemblyFunction* wasmFunction = jsDynamicCast<WebAssemblyFunction*>(vm, exec->jsCallee()); 59 if (!wasmFunction) 60 return JSValue::encode(throwException(exec, scope, createTypeError(exec, "expected a WebAssembly function", defaultSourceAppender, runtimeTypeForValue(vm, exec->jsCallee())))); 58 WebAssemblyFunction* wasmFunction = jsCast<WebAssemblyFunction*>(exec->jsCallee()); 61 59 Wasm::SignatureIndex signatureIndex = wasmFunction->signatureIndex(); 62 60 const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex); … … 64 62 // Make sure that the memory we think we are going to run with matches the one we expect. 65 63 ASSERT(wasmFunction->instance()->instance().codeBlock()->isSafeToRun(wasmFunction->instance()->memory()->memory().mode())); 66 {67 // Check if we have a disallowed I64 use.68 69 for (unsigned argIndex = 0; argIndex < signature.argumentCount(); ++argIndex) {70 if (signature.argument(argIndex) == Wasm::I64) {71 JSWebAssemblyRuntimeError* error = JSWebAssemblyRuntimeError::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyRuntimeErrorStructure(),72 "WebAssembly function with an i64 argument can't be called from JavaScript");73 return JSValue::encode(throwException(exec, scope, error));74 }75 }76 77 if (signature.returnType() == Wasm::I64) {78 JSWebAssemblyRuntimeError* error = JSWebAssemblyRuntimeError::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyRuntimeErrorStructure(),79 "WebAssembly function that returns i64 can't be called from JavaScript");80 return JSValue::encode(throwException(exec, scope, error));81 }82 }83 64 84 65 std::optional<TraceScope> traceScope; … … 100 81 arg = JSValue::decode(arg.toInt32(exec)); 101 82 break; 83 case Wasm::I64: 84 arg = JSValue(); 85 break; 102 86 case Wasm::F32: 103 87 arg = JSValue::decode(bitwise_cast<uint32_t>(arg.toFloat(exec))); … … 107 91 break; 108 92 case Wasm::Void: 109 case Wasm::I64:110 93 case Wasm::Func: 111 94 case Wasm::Anyfunc: -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp
r236697 r238376 43 43 VM& vm = exec->vm(); 44 44 auto scope = DECLARE_THROW_SCOPE(vm); 45 WebAssemblyWrapperFunction* wasmFunction = jsDynamicCast<WebAssemblyWrapperFunction*>(vm, exec->jsCallee()); 46 if (!wasmFunction) 47 return JSValue::encode(throwException(exec, scope, createTypeError(exec, "expected a WebAssembly function"))); 48 45 WebAssemblyWrapperFunction* wasmFunction = jsCast<WebAssemblyWrapperFunction*>(exec->jsCallee()); 49 46 CallData callData; 50 47 JSObject* function = wasmFunction->function();
Note: See TracChangeset
for help on using the changeset viewer.