Changeset 252239 in webkit for trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp
- Timestamp:
- Nov 8, 2019, 8:58:49 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp
r251736 r252239 32 32 #include "DOMJITGetterSetter.h" 33 33 #include "Debugger.h" 34 #include "Error.h" 34 35 #include "FrameTracers.h" 35 36 #include "FunctionCodeBlock.h" … … 44 45 #include "Options.h" 45 46 #include "Parser.h" 47 #include "ProbeContext.h" 46 48 #include "ShadowChicken.h" 47 49 #include "Snippet.h" … … 64 66 65 67 IGNORE_WARNINGS_BEGIN("frame-address") 68 69 extern "C" void ctiMasmProbeTrampoline(); 70 71 namespace JSC { 72 73 // This class is only here as a simple way to grant JSDollarVM friend privileges 74 // to all the classes that it needs special access to. 75 class JSDollarVMHelper { 76 public: 77 JSDollarVMHelper(VM& vm) 78 : m_vm(vm) 79 { } 80 81 void updateVMStackLimits() { return m_vm.updateStackLimits(); }; 82 83 private: 84 VM& m_vm; 85 }; 86 87 } // namespace JSC 66 88 67 89 namespace { … … 1969 1991 } 1970 1992 1993 // Calls the specified test function after adjusting the stack to have the specified 1994 // remaining size from the end of the physical stack. 1995 // Usage: $vm.callWithStackSize(funcToCall, desiredStackSize) 1996 // 1997 // This function will only work in test configurations, specifically, only if JSC 1998 // options are not frozen. For the jsc shell, the --disableOptionsFreezingForTesting 1999 // argument needs to be passed in on the command line. 2000 2001 #if ENABLE(MASM_PROBE) 2002 static void callWithStackSizeProbeFunction(Probe::State* state) 2003 { 2004 JSGlobalObject* globalObject = bitwise_cast<JSGlobalObject*>(state->arg); 2005 JSFunction* function = bitwise_cast<JSFunction*>(state->probeFunction); 2006 state->initializeStackFunction = nullptr; 2007 state->initializeStackArg = nullptr; 2008 2009 DollarVMAssertScope assertScope; 2010 VM& vm = globalObject->vm(); 2011 2012 CallData callData; 2013 CallType callType = getCallData(vm, function, callData); 2014 MarkedArgumentBuffer args; 2015 call(globalObject, function, callType, callData, jsUndefined(), args); 2016 } 2017 #endif // ENABLE(MASM_PROBE) 2018 2019 static EncodedJSValue JSC_HOST_CALL functionCallWithStackSize(JSGlobalObject* globalObject, CallFrame* callFrame) 2020 { 2021 DollarVMAssertScope assertScope; 2022 VM& vm = globalObject->vm(); 2023 JSLockHolder lock(vm); 2024 auto throwScope = DECLARE_THROW_SCOPE(vm); 2025 2026 #if OS(DARWIN) && CPU(X86_64) 2027 constexpr bool isSupportedByPlatform = true; 2028 #else 2029 constexpr bool isSupportedByPlatform = false; 2030 #endif 2031 2032 if (!isSupportedByPlatform) 2033 return throwVMError(globalObject, throwScope, "Not supported for this platform"); 2034 2035 #if ENABLE(MASM_PROBE) 2036 if (g_jscConfig.isPermanentlyFrozen || !g_jscConfig.disabledFreezingForTesting) 2037 return throwVMError(globalObject, throwScope, "Options are frozen"); 2038 2039 if (callFrame->argumentCount() < 2) 2040 return throwVMError(globalObject, throwScope, "Invalid number of arguments"); 2041 JSValue arg0 = callFrame->argument(0); 2042 JSValue arg1 = callFrame->argument(1); 2043 if (!arg0.isFunction(vm)) 2044 return throwVMError(globalObject, throwScope, "arg0 should be a function"); 2045 if (!arg1.isNumber()) 2046 return throwVMError(globalObject, throwScope, "arg1 should be a number"); 2047 2048 JSFunction* function = jsCast<JSFunction*>(arg0.toObject(globalObject)); 2049 size_t desiredStackSize = arg1.asNumber(); 2050 2051 const StackBounds& bounds = Thread::current().stack(); 2052 uint8_t* currentStackPosition = bitwise_cast<uint8_t*>(currentStackPointer()); 2053 uint8_t* end = bitwise_cast<uint8_t*>(bounds.end()); 2054 uint8_t* desiredStart = end + desiredStackSize; 2055 if (desiredStart >= currentStackPosition) 2056 return throwVMError(globalObject, throwScope, "Unable to setup desired stack size"); 2057 2058 JSDollarVMHelper helper(vm); 2059 2060 unsigned originalMaxPerThreadStackUsage = Options::maxPerThreadStackUsage(); 2061 void* originalVMSoftStackLimit = vm.softStackLimit(); 2062 void* originalVMStackLimit = vm.stackLimit(); 2063 2064 // This is a hack to make the VM think it's stack limits are near the end 2065 // of the physical stack. 2066 uint8_t* vmStackStart = bitwise_cast<uint8_t*>(vm.stackPointerAtVMEntry()); 2067 uint8_t* vmStackEnd = vmStackStart - originalMaxPerThreadStackUsage; 2068 ptrdiff_t sizeDiff = vmStackEnd - end; 2069 RELEASE_ASSERT(sizeDiff >= 0); 2070 RELEASE_ASSERT(sizeDiff < UINT_MAX); 2071 2072 Options::maxPerThreadStackUsage() = originalMaxPerThreadStackUsage + sizeDiff; 2073 helper.updateVMStackLimits(); 2074 2075 #if OS(DARWIN) && CPU(X86_64) 2076 __asm__ volatile ( 2077 "subq %[sizeDiff], %%rsp" "\n" 2078 "pushq %%rax" "\n" 2079 "pushq %%rcx" "\n" 2080 "pushq %%rdx" "\n" 2081 "pushq %%rbx" "\n" 2082 "callq *%%rax" "\n" 2083 "addq %[sizeDiff], %%rsp" "\n" 2084 : 2085 : "a" (ctiMasmProbeTrampoline) 2086 , "c" (callWithStackSizeProbeFunction) 2087 , "d" (function) 2088 , "b" (globalObject) 2089 , [sizeDiff] "rm" (sizeDiff) 2090 : "memory" 2091 ); 2092 #else 2093 UNUSED_PARAM(function); 2094 UNUSED_PARAM(callWithStackSizeProbeFunction); 2095 #endif // OS(DARWIN) && CPU(X86_64) 2096 2097 Options::maxPerThreadStackUsage() = originalMaxPerThreadStackUsage; 2098 helper.updateVMStackLimits(); 2099 RELEASE_ASSERT(vm.softStackLimit() == originalVMSoftStackLimit); 2100 RELEASE_ASSERT(vm.stackLimit() == originalVMStackLimit); 2101 2102 return encodedJSUndefined(); 2103 2104 #else // not ENABLE(MASM_PROBE) 2105 UNUSED_PARAM(callFrame); 2106 return throwVMError(globalObject, throwScope, "Not supported for this platform"); 2107 #endif // ENABLE(MASM_PROBE) 2108 } 2109 1971 2110 // Creates a new global object. 1972 2111 // Usage: $vm.createGlobalObject() … … 2630 2769 addFunction(vm, "haveABadTime", functionHaveABadTime, 1); 2631 2770 addFunction(vm, "isHavingABadTime", functionIsHavingABadTime, 1); 2771 2772 addFunction(vm, "callWithStackSize", functionCallWithStackSize, 2); 2632 2773 2633 2774 addFunction(vm, "createGlobalObject", functionCreateGlobalObject, 0);
Note:
See TracChangeset
for help on using the changeset viewer.