Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (237041 => 237042)
--- trunk/Source/_javascript_Core/ChangeLog 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/ChangeLog 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,3 +1,50 @@
+2018-10-10 Mark Lam <[email protected]>
+
+ Changes towards allowing use of the ASAN detect_stack_use_after_return option.
+ https://bugs.webkit.org/show_bug.cgi?id=190405
+ <rdar://problem/45131464>
+
+ Reviewed by Michael Saboff.
+
+ The ASAN detect_stack_use_after_return option checks for use of stack variables
+ after they have been freed. It does this by allocating relevant stack variables
+ in heap memory (instead of on the stack) if the code ever takes the address of
+ those stack variables. Unfortunately, this is a common idiom that we use to
+ compute the approximate stack pointer value. As a result, on such ASAN runs, the
+ computed approximate stack pointer value will point into the heap instead of the
+ stack. This breaks the VM's expectations and wreaks havoc.
+
+ To fix this, we use the newly introduced WTF::currentStackPointer() instead of
+ taking the address of stack variables.
+
+ We also need to enhance ExceptionScopes to be able to work with ASAN
+ detect_stack_use_after_return which will allocated the scope in the heap. We
+ work around this by passing the current stack pointer of the instantiating calling
+ frame into the scope constructor, and using that for the position check in
+ ~ThrowScope() instead.
+
+ The above is only a start towards enabling ASAN detect_stack_use_after_return on
+ the VM. There are still other issues to be resolved before we can run with this
+ ASAN option.
+
+ * runtime/CatchScope.h:
+ * runtime/ExceptionEventLocation.h:
+ (JSC::ExceptionEventLocation::ExceptionEventLocation):
+ * runtime/ExceptionScope.h:
+ (JSC::ExceptionScope::stackPosition const):
+ * runtime/JSLock.cpp:
+ (JSC::JSLock::didAcquireLock):
+ * runtime/ThrowScope.cpp:
+ (JSC::ThrowScope::~ThrowScope):
+ * runtime/ThrowScope.h:
+ * runtime/VM.h:
+ (JSC::VM::needExceptionCheck const):
+ (JSC::VM::isSafeToRecurse const):
+ * wasm/js/WebAssemblyFunction.cpp:
+ (JSC::callWebAssemblyFunction):
+ * yarr/YarrPattern.cpp:
+ (JSC::Yarr::YarrPatternConstructor::isSafeToRecurse const):
+
2018-10-10 Devin Rousso <[email protected]>
Web Inspector: create special Network waterfall for media events
Modified: trunk/Source/_javascript_Core/runtime/CatchScope.h (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/CatchScope.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/CatchScope.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,7 +35,7 @@
// top of the function (as early as possible) using the DECLARE_CATCH_SCOPE macro.
// Declaring a CatchScope in a function means that the function intends to clear
// pending exceptions before returning to its caller.
-
+
class CatchScope : public ExceptionScope {
public:
JS_EXPORT_PRIVATE CatchScope(VM&, ExceptionEventLocation);
@@ -48,7 +48,7 @@
};
#define DECLARE_CATCH_SCOPE(vm__) \
- JSC::CatchScope((vm__), JSC::ExceptionEventLocation(__FUNCTION__, __FILE__, __LINE__))
+ JSC::CatchScope((vm__), JSC::ExceptionEventLocation(EXCEPTION_SCOPE_POSITION_FOR_ASAN, __FUNCTION__, __FILE__, __LINE__))
#else // not ENABLE(EXCEPTION_SCOPE_VERIFICATION)
Modified: trunk/Source/_javascript_Core/runtime/ExceptionEventLocation.h (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/ExceptionEventLocation.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/ExceptionEventLocation.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,12 +29,14 @@
struct ExceptionEventLocation {
ExceptionEventLocation() { }
- ExceptionEventLocation(const char* functionName, const char* file, unsigned line)
- : functionName(functionName)
+ ExceptionEventLocation(void* stackPosition, const char* functionName, const char* file, unsigned line)
+ : stackPosition(stackPosition)
+ , functionName(functionName)
, file(file)
, line(line)
{ }
+ void* stackPosition { nullptr }; // Needed for ASAN detect_stack_use_after_return.
const char* functionName { nullptr };
const char* file { nullptr };
unsigned line { 0 };
Modified: trunk/Source/_javascript_Core/runtime/ExceptionScope.h (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/ExceptionScope.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/ExceptionScope.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
#pragma once
#include "VM.h"
+#include <wtf/StackPointer.h>
namespace JSC {
@@ -37,6 +38,12 @@
#define EXCEPTION_ASSERT_UNUSED(variable, assertion) RELEASE_ASSERT(assertion)
#define EXCEPTION_ASSERT_WITH_MESSAGE(assertion, message) RELEASE_ASSERT_WITH_MESSAGE(assertion, message)
+#if ASAN_ENABLED && COMPILER(GCC_COMPATIBLE)
+#define EXCEPTION_SCOPE_POSITION_FOR_ASAN currentStackPointer()
+#else
+#define EXCEPTION_SCOPE_POSITION_FOR_ASAN nullptr
+#endif
+
class ExceptionScope {
public:
VM& vm() const { return m_vm; }
@@ -46,6 +53,12 @@
ALWAYS_INLINE void assertNoException() { RELEASE_ASSERT_WITH_MESSAGE(!exception(), "%s", unexpectedExceptionMessage().data()); }
ALWAYS_INLINE void releaseAssertNoException() { RELEASE_ASSERT_WITH_MESSAGE(!exception(), "%s", unexpectedExceptionMessage().data()); }
+#if ASAN_ENABLED
+ const void* stackPosition() const { return m_location.stackPosition; }
+#else
+ const void* stackPosition() const { return this; }
+#endif
+
protected:
ExceptionScope(VM&, ExceptionEventLocation);
ExceptionScope(const ExceptionScope&) = delete;
Modified: trunk/Source/_javascript_Core/runtime/JSLock.cpp (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/JSLock.cpp 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/JSLock.cpp 2018-10-11 19:19:18 UTC (rev 237042)
@@ -30,6 +30,7 @@
#include "SamplingProfiler.h"
#include "WasmMachineThreads.h"
#include <thread>
+#include <wtf/StackPointer.h>
#include <wtf/Threading.h>
#include <wtf/threads/Signals.h>
@@ -143,7 +144,7 @@
}
RELEASE_ASSERT(!m_vm->stackPointerAtVMEntry());
- void* p = &p; // A proxy for the current stack pointer.
+ void* p = currentStackPointer();
m_vm->setStackPointerAtVMEntry(p);
m_vm->heap.machineThreads().addCurrentThread();
Modified: trunk/Source/_javascript_Core/runtime/ThrowScope.cpp (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/ThrowScope.cpp 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/ThrowScope.cpp 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -56,7 +56,7 @@
}
bool willBeHandleByLLIntOrJIT = false;
- void* previousScope = m_previousScope;
+ const void* previousScopeStackPosition = m_previousScope ? m_previousScope->stackPosition() : nullptr;
void* topEntryFrame = m_vm.topEntryFrame;
// If the topEntryFrame was pushed on the stack after the previousScope was instantiated,
@@ -63,9 +63,9 @@
// then this throwScope will be returning to LLINT or JIT code that always do an exception
// check. In that case, skip the simulated throw because the LLInt and JIT will be
// checking for the exception their own way instead of calling ThrowScope::exception().
- if (topEntryFrame && previousScope > topEntryFrame)
+ if (topEntryFrame && previousScopeStackPosition > topEntryFrame)
willBeHandleByLLIntOrJIT = true;
-
+
if (!willBeHandleByLLIntOrJIT)
simulateThrow();
}
Modified: trunk/Source/_javascript_Core/runtime/ThrowScope.h (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/ThrowScope.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/ThrowScope.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -62,7 +62,7 @@
};
#define DECLARE_THROW_SCOPE(vm__) \
- JSC::ThrowScope((vm__), JSC::ExceptionEventLocation(__FUNCTION__, __FILE__, __LINE__))
+ JSC::ThrowScope((vm__), JSC::ExceptionEventLocation(EXCEPTION_SCOPE_POSITION_FOR_ASAN, __FUNCTION__, __FILE__, __LINE__))
#define throwScopePrintIfNeedCheck(scope__) \
scope__.printIfNeedCheck(__FUNCTION__, __FILE__, __LINE__)
Modified: trunk/Source/_javascript_Core/runtime/VM.h (237041 => 237042)
--- trunk/Source/_javascript_Core/runtime/VM.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/runtime/VM.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -64,6 +64,7 @@
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/StackBounds.h>
+#include <wtf/StackPointer.h>
#include <wtf/Stopwatch.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/ThreadSpecific.h>
@@ -884,6 +885,7 @@
#if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
StackTrace* nativeStackTraceOfLastThrow() const { return m_nativeStackTraceOfLastThrow.get(); }
Thread* throwingThread() const { return m_throwingThread.get(); }
+ bool needExceptionCheck() const { return m_needExceptionCheck; }
#endif
#if USE(CF)
@@ -903,7 +905,7 @@
bool isSafeToRecurse(void* stackLimit) const
{
ASSERT(Thread::current().stack().isGrowingDownward());
- void* curr = reinterpret_cast<void*>(&curr);
+ void* curr = currentStackPointer();
return curr >= stackLimit;
}
Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp (237041 => 237042)
--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp 2018-10-11 19:19:18 UTC (rev 237042)
@@ -44,6 +44,7 @@
#include "WasmMemory.h"
#include "WasmSignatureInlines.h"
#include <wtf/FastTLS.h>
+#include <wtf/StackPointer.h>
#include <wtf/SystemTracing.h>
namespace JSC {
@@ -135,7 +136,7 @@
{
// We do the stack check here for the wrapper function because we don't
// want to emit a stack check inside every wrapper function.
- const intptr_t sp = bitwise_cast<intptr_t>(&sp); // A proxy for the current stack pointer.
+ const intptr_t sp = bitwise_cast<intptr_t>(currentStackPointer());
const intptr_t frameSize = (boxedArgs.size() + CallFrame::headerSizeInRegisters) * sizeof(Register);
const intptr_t stackSpaceUsed = 2 * frameSize; // We're making two calls. One to the wrapper, and one to the actual wasm code.
if (UNLIKELY((sp < stackSpaceUsed) || ((sp - stackSpaceUsed) < bitwise_cast<intptr_t>(vm.softStackLimit()))))
Modified: trunk/Source/_javascript_Core/yarr/YarrPattern.cpp (237041 => 237042)
--- trunk/Source/_javascript_Core/yarr/YarrPattern.cpp 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/_javascript_Core/yarr/YarrPattern.cpp 2018-10-11 19:19:18 UTC (rev 237042)
@@ -33,6 +33,7 @@
#include "YarrParser.h"
#include <wtf/DataLog.h>
#include <wtf/Optional.h>
+#include <wtf/StackPointer.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -1093,7 +1094,7 @@
if (!m_stackLimit)
return true;
ASSERT(Thread::current().stack().isGrowingDownward());
- int8_t* curr = reinterpret_cast<int8_t*>(&curr);
+ int8_t* curr = reinterpret_cast<int8_t*>(currentStackPointer());
int8_t* limit = reinterpret_cast<int8_t*>(m_stackLimit);
return curr >= limit;
}
Modified: trunk/Source/WTF/ChangeLog (237041 => 237042)
--- trunk/Source/WTF/ChangeLog 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/WTF/ChangeLog 2018-10-11 19:19:18 UTC (rev 237042)
@@ -1,3 +1,21 @@
+2018-10-10 Mark Lam <[email protected]>
+
+ Changes towards allowing use of the ASAN detect_stack_use_after_return option.
+ https://bugs.webkit.org/show_bug.cgi?id=190405
+ <rdar://problem/45131464>
+
+ Reviewed by Michael Saboff.
+
+ Introduce WTF::currentStackPointer() which computes its caller's stack pointer value.
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ * wtf/StackBounds.h:
+ (WTF::StackBounds::checkConsistency const):
+ * wtf/StackPointer.cpp: Added.
+ (WTF::currentStackPointer):
+ * wtf/StackPointer.h: Added.
+
2018-10-09 Mark Lam <[email protected]>
StringTypeAdapter constructor is not properly enforcing String::MaxLength.
Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (237041 => 237042)
--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2018-10-11 19:19:18 UTC (rev 237042)
@@ -158,6 +158,7 @@
FE05FAFF1FE5007500093230 /* WTFAssertions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE05FAFE1FE5007500093230 /* WTFAssertions.cpp */; };
FE85416E1FBE285D008DA5DA /* Poisoned.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE85416C1FBE285B008DA5DA /* Poisoned.cpp */; };
FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
+ FEEA4DF9216D7BE400AC0602 /* StackPointer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEEA4DF8216D7BE400AC0602 /* StackPointer.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -660,6 +661,8 @@
FEB6B035201BE0B600B958C1 /* PointerPreparations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PointerPreparations.h; sourceTree = "<group>"; };
FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; };
+ FEEA4DF7216D608C00AC0602 /* StackPointer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackPointer.h; sourceTree = "<group>"; };
+ FEEA4DF8216D7BE400AC0602 /* StackPointer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackPointer.cpp; sourceTree = "<group>"; };
FEF295BF20B49DCB00CF283A /* UTF8ConversionError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8ConversionError.h; sourceTree = "<group>"; };
FF0A436588954F3CB07DBECA /* StdList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdList.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -1086,6 +1089,8 @@
A8A4730D151A825B004123FF /* Spectrum.h */,
A8A4730E151A825B004123FF /* StackBounds.cpp */,
A8A4730F151A825B004123FF /* StackBounds.h */,
+ FEEA4DF8216D7BE400AC0602 /* StackPointer.cpp */,
+ FEEA4DF7216D608C00AC0602 /* StackPointer.h */,
0F9DAA041FD1C37B0079C5B2 /* StackShot.h */,
0F9DAA051FD1C37B0079C5B2 /* StackShotProfiler.h */,
FEDACD3B1630F83F00C69634 /* StackStats.cpp */,
@@ -1542,6 +1547,7 @@
51F1752C1F3D486000C74950 /* PersistentDecoder.cpp in Sources */,
51F1752D1F3D486000C74950 /* PersistentEncoder.cpp in Sources */,
FE85416E1FBE285D008DA5DA /* Poisoned.cpp in Sources */,
+ FEEA4DF9216D7BE400AC0602 /* StackPointer.cpp in Sources */,
0F9D3362165DBA73005AD387 /* PrintStream.cpp in Sources */,
7AF023B52061E17000A8EFD6 /* ProcessPrivilege.cpp in Sources */,
143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */,
Modified: trunk/Source/WTF/wtf/CMakeLists.txt (237041 => 237042)
--- trunk/Source/WTF/wtf/CMakeLists.txt 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/WTF/wtf/CMakeLists.txt 2018-10-11 19:19:18 UTC (rev 237042)
@@ -210,6 +210,7 @@
SoftLinking.h
Spectrum.h
StackBounds.h
+ StackPointer.h
StackShot.h
StackShotProfiler.h
StackStats.h
@@ -384,6 +385,7 @@
Seconds.cpp
SixCharacterHash.cpp
StackBounds.cpp
+ StackPointer.cpp
StackStats.cpp
StackTrace.cpp
StringPrintStream.cpp
Modified: trunk/Source/WTF/wtf/StackBounds.h (237041 => 237042)
--- trunk/Source/WTF/wtf/StackBounds.h 2018-10-11 18:56:08 UTC (rev 237041)
+++ trunk/Source/WTF/wtf/StackBounds.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -28,6 +28,7 @@
#define StackBounds_h
#include <algorithm>
+#include <wtf/StackPointer.h>
#include <wtf/ThreadingPrimitives.h>
namespace WTF {
@@ -146,7 +147,7 @@
void checkConsistency() const
{
#if !ASSERT_DISABLED
- void* currentPosition = ¤tPosition;
+ void* currentPosition = currentStackPointer();
ASSERT(m_origin != m_bound);
ASSERT(isGrowingDownward()
? (currentPosition < m_origin && currentPosition > m_bound)
Added: trunk/Source/WTF/wtf/StackPointer.cpp (0 => 237042)
--- trunk/Source/WTF/wtf/StackPointer.cpp (rev 0)
+++ trunk/Source/WTF/wtf/StackPointer.cpp 2018-10-11 19:19:18 UTC (rev 237042)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StackPointer.h"
+
+namespace WTF {
+
+#if USE(GENERIC_CURRENT_STACK_POINTER)
+constexpr size_t sizeOfFrameHeader = 2 * sizeof(void*);
+
+SUPPRESS_ASAN NEVER_INLINE
+void* currentStackPointer()
+{
+#if COMPILER(GCC_COMPATIBLE)
+ return reinterpret_cast<uint8_t*>(__builtin_frame_address(0)) + sizeOfFrameHeader;
+#else
+ // Make sure that sp is the only local variable declared in this function.
+ void* sp = reinterpret_cast<uint8_t*>(&sp) + sizeOfFrameHeader + sizeof(sp);
+ return sp;
+#endif
+}
+#endif // USE(GENERIC_CURRENT_STACK_POINTER)
+
+} // namespace WTF
Added: trunk/Source/WTF/wtf/StackPointer.h (0 => 237042)
--- trunk/Source/WTF/wtf/StackPointer.h (rev 0)
+++ trunk/Source/WTF/wtf/StackPointer.h 2018-10-11 19:19:18 UTC (rev 237042)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WTF {
+
+#if defined(NDEBUG) && COMPILER(GCC_COMPATIBLE) \
+ && (CPU(X86_64) || CPU(X86) || CPU(ARM64) || CPU(ARM_THUMB2) || CPU(ARM_TRADITIONAL))
+
+// We can only use the inline asm implementation on release builds because it
+// needs to be inlinable in order to be correct.
+ALWAYS_INLINE void* currentStackPointer()
+{
+ void* stackPointer = nullptr;
+#if CPU(X86_64)
+ __asm__ volatile ("movq %%rsp, %0" : "=r"(stackPointer) ::);
+#elif CPU(X86)
+ __asm__ volatile ("movl %%esp, %0" : "=r"(stackPointer) ::);
+#elif CPU(ARM64) && defined(__ILP32__)
+ uint64_t stackPointerRegister = 0;
+ __asm__ volatile ("mov %0, sp" : "=r"(stackPointerRegister) ::);
+ stackPointer = reinterpret_cast<void*>(stackPointerRegister);
+#elif CPU(ARM64) || CPU(ARM_THUMB2) || CPU(ARM_TRADITIONAL)
+ __asm__ volatile ("mov %0, sp" : "=r"(stackPointer) ::);
+#endif
+ return stackPointer;
+}
+
+#else
+
+#define USE_GENERIC_CURRENT_STACK_POINTER 1
+WTF_EXPORT_PRIVATE void* currentStackPointer();
+
+#endif
+
+} // namespace WTF
+
+using WTF::currentStackPointer;