Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (213885 => 213886)
--- trunk/Source/_javascript_Core/ChangeLog 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-03-14 07:33:08 UTC (rev 213886)
@@ -1,3 +1,42 @@
+2017-03-13 Yusuke Suzuki <[email protected]>
+
+ [JSC][Linux] Implement VMTrap in Linux ports
+ https://bugs.webkit.org/show_bug.cgi?id=169436
+
+ Reviewed by Mark Lam.
+
+ This patch port VMTrap to Linux ports.
+ We extract MachineContext accessors from various places (wasm/, heap/ and tools/)
+ and use them in all the JSC code.
+
+ * _javascript_Core.xcodeproj/project.pbxproj:
+ * heap/MachineStackMarker.cpp:
+ (JSC::MachineThreads::Thread::Registers::stackPointer):
+ (JSC::MachineThreads::Thread::Registers::framePointer):
+ (JSC::MachineThreads::Thread::Registers::instructionPointer):
+ (JSC::MachineThreads::Thread::Registers::llintPC):
+ * heap/MachineStackMarker.h:
+ * runtime/MachineContext.h: Added.
+ (JSC::MachineContext::stackPointer):
+ (JSC::MachineContext::framePointer):
+ (JSC::MachineContext::instructionPointer):
+ (JSC::MachineContext::argumentPointer<1>):
+ (JSC::MachineContext::argumentPointer):
+ (JSC::MachineContext::llintInstructionPointer):
+ * runtime/PlatformThread.h:
+ (JSC::platformThreadSignal):
+ * runtime/VMTraps.cpp:
+ (JSC::SignalContext::SignalContext):
+ (JSC::SignalContext::adjustPCToPointToTrappingInstruction):
+ * tools/CodeProfiling.cpp:
+ (JSC::profilingTimer):
+ * tools/SigillCrashAnalyzer.cpp:
+ (JSC::SignalContext::SignalContext):
+ (JSC::SignalContext::dump):
+ * tools/VMInspector.cpp:
+ * wasm/WasmFaultSignalHandler.cpp:
+ (JSC::Wasm::trapHandler):
+
2017-03-13 Mark Lam <[email protected]>
Make the HeapVerifier useful again.
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (213885 => 213886)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2017-03-14 07:33:08 UTC (rev 213886)
@@ -2439,6 +2439,7 @@
FEE43FCE1E6641710077D6D1 /* PlatformThread.h in Headers */ = {isa = PBXBuildFile; fileRef = FEE43FCD1E6641400077D6D1 /* PlatformThread.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEF040511AAE662D00BD28B0 /* CompareAndSwapTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */; };
FEFD6FC61D5E7992008F2F0B /* JSStringInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 981ED82328234D91BAECCADE /* MachineContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 28806E21155E478A93FA7B02 /* MachineContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -5034,6 +5035,7 @@
FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompareAndSwapTest.cpp; path = API/tests/CompareAndSwapTest.cpp; sourceTree = "<group>"; };
FEF040521AAEC4ED00BD28B0 /* CompareAndSwapTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompareAndSwapTest.h; path = API/tests/CompareAndSwapTest.h; sourceTree = "<group>"; };
FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringInlines.h; sourceTree = "<group>"; };
+ 28806E21155E478A93FA7B02 /* MachineContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MachineContext.h; path = MachineContext.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -6933,6 +6935,7 @@
709FB8661AE335C60039D069 /* WeakSetPrototype.h */,
A7DCB77912E3D90500911940 /* WriteBarrier.h */,
C2B6D75218A33793004A9301 /* WriteBarrierInlines.h */,
+ 28806E21155E478A93FA7B02 /* MachineContext.h */,
);
path = runtime;
sourceTree = "<group>";
@@ -9370,6 +9373,7 @@
86704B8A12DBA33700A9FE7B /* YarrPattern.h in Headers */,
86704B4312DB8A8100A9FE7B /* YarrSyntaxChecker.h in Headers */,
9F63434577274FAFB9336C38 /* ModuleNamespaceAccessCase.h in Headers */,
+ 981ED82328234D91BAECCADE /* MachineContext.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: trunk/Source/_javascript_Core/heap/MachineStackMarker.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/heap/MachineStackMarker.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/heap/MachineStackMarker.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -481,88 +481,13 @@
void* MachineThreads::Thread::Registers::stackPointer() const
{
-#if OS(DARWIN)
-
-#if __DARWIN_UNIX03
-
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.__esp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.__rsp);
-#elif CPU(PPC) || CPU(PPC64)
- return reinterpret_cast<void*>(regs.__r1);
-#elif CPU(ARM)
- return reinterpret_cast<void*>(regs.__sp);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>(regs.__sp);
-#else
-#error Unknown Architecture
-#endif
-
-#else // !__DARWIN_UNIX03
-
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.esp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.rsp);
-#elif CPU(PPC) || CPU(PPC64)
- return reinterpret_cast<void*>(regs.r1);
-#else
-#error Unknown Architecture
-#endif
-
-#endif // __DARWIN_UNIX03
-
-// end OS(DARWIN)
-#elif OS(WINDOWS)
-
-#if CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.Sp);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.IntSp);
-#elif CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.Esp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.Rsp);
-#else
-#error Unknown Architecture
-#endif
-
+#if OS(DARWIN) || OS(WINDOWS)
+ return MachineContext::stackPointer(regs);
#elif USE(PTHREADS)
-#if OS(FREEBSD) && ENABLE(JIT)
-
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_esp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rsp);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_SP]);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_sp);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[29]);
+#if (OS(FREEBSD) || defined(__GLIBC__)) && ENABLE(JIT)
+ return MachineContext::stackPointer(regs.machineContext);
#else
-#error Unknown Architecture
-#endif
-
-#elif defined(__GLIBC__) && ENABLE(JIT)
-
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_ESP]);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_RSP]);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.arm_sp);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sp);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[29]);
-#else
-#error Unknown Architecture
-#endif
-
-#else
void* stackBase = 0;
size_t stackSize = 0;
#if OS(OPENBSD)
@@ -586,83 +511,11 @@
#if ENABLE(SAMPLING_PROFILER)
void* MachineThreads::Thread::Registers::framePointer() const
{
-#if OS(DARWIN)
-
-#if __DARWIN_UNIX03
-
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.__ebp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.__rbp);
-#elif CPU(ARM)
- return reinterpret_cast<void*>(regs.__r[11]);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>(regs.__x[29]);
+#if OS(DARWIN) || OS(WINDOWS)
+ return MachineContext::framePointer(regs);
+#elif OS(FREEBSD) || defined(__GLIBC__)
+ return MachineContext::framePointer(regs.machineContext);
#else
-#error Unknown Architecture
-#endif
-
-#else // !__DARWIN_UNIX03
-
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.esp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.rsp);
-#else
-#error Unknown Architecture
-#endif
-
-#endif // __DARWIN_UNIX03
-
-// end OS(DARWIN)
-#elif OS(WINDOWS)
-
-#if CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.R11);
-#elif CPU(MIPS)
-#error Dont know what to do with mips. Do we even need this?
-#elif CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.Ebp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.Rbp);
-#else
-#error Unknown Architecture
-#endif
-
-#elif OS(FREEBSD)
-
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_ebp);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rbp);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_FP]);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_x[29]);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[30]);
-#else
-#error Unknown Architecture
-#endif
-
-#elif defined(__GLIBC__)
-
-// The following sequence depends on glibc's sys/ucontext.h.
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_EBP]);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_RBP]);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.arm_fp);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.regs[29]);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[30]);
-#else
-#error Unknown Architecture
-#endif
-
-#else
#error Need a way to get the frame pointer for another thread on this platform
#endif
}
@@ -669,173 +522,23 @@
void* MachineThreads::Thread::Registers::instructionPointer() const
{
-#if OS(DARWIN)
-
-#if __DARWIN_UNIX03
-
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.__eip);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.__rip);
-#elif CPU(ARM)
- return reinterpret_cast<void*>(regs.__pc);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>(regs.__pc);
+#if OS(DARWIN) || OS(WINDOWS)
+ return MachineContext::instructionPointer(regs);
+#elif OS(FREEBSD) || defined(__GLIBC__)
+ return MachineContext::instructionPointer(regs.machineContext);
#else
-#error Unknown Architecture
-#endif
-
-#else // !__DARWIN_UNIX03
-#if CPU(X86)
- return reinterpret_cast<void*>(regs.eip);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>(regs.rip);
-#else
-#error Unknown Architecture
-#endif
-
-#endif // __DARWIN_UNIX03
-
-// end OS(DARWIN)
-#elif OS(WINDOWS)
-
-#if CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.Pc);
-#elif CPU(MIPS)
-#error Dont know what to do with mips. Do we even need this?
-#elif CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.Eip);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.Rip);
-#else
-#error Unknown Architecture
-#endif
-
-#elif OS(FREEBSD)
-
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_eip);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rip);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_PC]);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_elr);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_pc);
-#else
-#error Unknown Architecture
-#endif
-
-#elif defined(__GLIBC__)
-
-// The following sequence depends on glibc's sys/ucontext.h.
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_EIP]);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_RIP]);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.arm_pc);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.pc);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.pc);
-#else
-#error Unknown Architecture
-#endif
-
-#else
#error Need a way to get the instruction pointer for another thread on this platform
#endif
}
+
void* MachineThreads::Thread::Registers::llintPC() const
{
// LLInt uses regT4 as PC.
-#if OS(DARWIN)
-
-#if __DARWIN_UNIX03
-
-#if CPU(X86)
- static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.__esi);
-#elif CPU(X86_64)
- static_assert(LLInt::LLIntPC == X86Registers::r8, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.__r8);
-#elif CPU(ARM)
- static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.__r[8]);
-#elif CPU(ARM64)
- static_assert(LLInt::LLIntPC == ARM64Registers::x4, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.__x[4]);
+#if OS(DARWIN) || OS(WINDOWS)
+ return MachineContext::llintInstructionPointer(regs);
+#elif OS(FREEBSD) || defined(__GLIBC__)
+ return MachineContext::llintInstructionPointer(regs.machineContext);
#else
-#error Unknown Architecture
-#endif
-
-#else // !__DARWIN_UNIX03
-#if CPU(X86)
- static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.esi);
-#elif CPU(X86_64)
- static_assert(LLInt::LLIntPC == X86Registers::r8, "Wrong LLInt PC.");
- return reinterpret_cast<void*>(regs.r8);
-#else
-#error Unknown Architecture
-#endif
-
-#endif // __DARWIN_UNIX03
-
-// end OS(DARWIN)
-#elif OS(WINDOWS)
-
-#if CPU(ARM)
- static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC.");
- return reinterpret_cast<void*>((uintptr_t) regs.R8);
-#elif CPU(MIPS)
-#error Dont know what to do with mips. Do we even need this?
-#elif CPU(X86)
- static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
- return reinterpret_cast<void*>((uintptr_t) regs.Esi);
-#elif CPU(X86_64)
- static_assert(LLInt::LLIntPC == X86Registers::r10, "Wrong LLInt PC.");
- return reinterpret_cast<void*>((uintptr_t) regs.R10);
-#else
-#error Unknown Architecture
-#endif
-
-#elif OS(FREEBSD)
-
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_esi);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_r8);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_R8]);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_x[4]);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[12]);
-#else
-#error Unknown Architecture
-#endif
-
-#elif defined(__GLIBC__)
-
-// The following sequence depends on glibc's sys/ucontext.h.
-#if CPU(X86)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_ESI]);
-#elif CPU(X86_64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[REG_R8]);
-#elif CPU(ARM)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.arm_r8);
-#elif CPU(ARM64)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.regs[4]);
-#elif CPU(MIPS)
- return reinterpret_cast<void*>((uintptr_t) regs.machineContext.gregs[12]);
-#else
-#error Unknown Architecture
-#endif
-
-#else
#error Need a way to get the LLIntPC for another thread on this platform
#endif
}
Modified: trunk/Source/_javascript_Core/heap/MachineStackMarker.h (213885 => 213886)
--- trunk/Source/_javascript_Core/heap/MachineStackMarker.h 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/heap/MachineStackMarker.h 2017-03-14 07:33:08 UTC (rev 213886)
@@ -21,6 +21,7 @@
#pragma once
+#include "MachineContext.h"
#include "PlatformThread.h"
#include "RegisterState.h"
#include <wtf/Lock.h>
@@ -80,25 +81,8 @@
void* llintPC() const;
#endif // ENABLE(SAMPLING_PROFILER)
-#if OS(DARWIN)
-#if CPU(X86)
- typedef i386_thread_state_t PlatformRegisters;
-#elif CPU(X86_64)
- typedef x86_thread_state64_t PlatformRegisters;
-#elif CPU(PPC)
- typedef ppc_thread_state_t PlatformRegisters;
-#elif CPU(PPC64)
- typedef ppc_thread_state64_t PlatformRegisters;
-#elif CPU(ARM)
- typedef arm_thread_state_t PlatformRegisters;
-#elif CPU(ARM64)
- typedef arm_thread_state64_t PlatformRegisters;
-#else
-#error Unknown Architecture
-#endif
-
-#elif OS(WINDOWS)
- typedef CONTEXT PlatformRegisters;
+#if OS(DARWIN) || OS(WINDOWS)
+ using PlatformRegisters = MachineContext::PlatformRegisters;
#elif USE(PTHREADS)
struct PlatformRegisters {
pthread_attr_t attribute;
Added: trunk/Source/_javascript_Core/runtime/MachineContext.h (0 => 213886)
--- trunk/Source/_javascript_Core/runtime/MachineContext.h (rev 0)
+++ trunk/Source/_javascript_Core/runtime/MachineContext.h 2017-03-14 07:33:08 UTC (rev 213886)
@@ -0,0 +1,611 @@
+/*
+ * Copyright (C) 2017 Yusuke Suzuki <[email protected]>.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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
+
+#include "GPRInfo.h"
+#include "LLIntPCRanges.h"
+#include <wtf/StdLibExtras.h>
+
+#if OS(DARWIN) || OS(FREEBSD) || defined(__GLIBC__)
+#include <signal.h>
+// Using signal.h didn't make mcontext_t and ucontext_t available on FreeBSD.
+// This bug has been fixed in FreeBSD 11.0-CURRENT, so this workaround can be
+// removed after FreeBSD 10.x goes EOL.
+// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207079
+#if OS(FREEBSD)
+#include <ucontext.h>
+#endif
+#endif
+
+namespace JSC {
+namespace MachineContext {
+
+#if OS(DARWIN)
+
+#if CPU(X86)
+typedef i386_thread_state_t PlatformRegisters;
+#elif CPU(X86_64)
+typedef x86_thread_state64_t PlatformRegisters;
+#elif CPU(PPC)
+typedef ppc_thread_state_t PlatformRegisters;
+#elif CPU(PPC64)
+typedef ppc_thread_state64_t PlatformRegisters;
+#elif CPU(ARM)
+typedef arm_thread_state_t PlatformRegisters;
+#elif CPU(ARM64)
+typedef arm_thread_state64_t PlatformRegisters;
+#else
+#error Unknown Architecture
+#endif
+
+#elif OS(WINDOWS)
+
+typedef CONTEXT PlatformRegisters;
+
+#endif
+
+
+#if OS(DARWIN) || OS(WINDOWS)
+inline void*& stackPointer(PlatformRegisters& regs)
+{
+#if OS(DARWIN)
+#if __DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.__esp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.__rsp);
+#elif CPU(PPC) || CPU(PPC64)
+ return reinterpret_cast<void*&>(regs.__r1);
+#elif CPU(ARM_THUMB2) || CPU(ARM) || CPU(ARM64)
+ return reinterpret_cast<void*&>(regs.__sp);
+#else
+#error Unknown Architecture
+#endif
+
+#else // !__DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.esp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.rsp);
+#elif CPU(PPC) || CPU(PPC64)
+ return reinterpret_cast<void*&>(regs.r1);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // __DARWIN_UNIX03
+
+#elif OS(WINDOWS)
+
+#if CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Sp);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.IntSp);
+#elif CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Esp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Rsp);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // OS(DARWIN)
+}
+
+inline void* stackPointer(const PlatformRegisters& regs)
+{
+ return stackPointer(const_cast<PlatformRegisters&>(regs));
+}
+#endif // OS(DARWIN) || OS(WINDOWS)
+
+
+#if OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+inline void*& stackPointer(mcontext_t& machineContext)
+{
+#if OS(DARWIN)
+ return stackPointer(machineContext->__ss);
+#elif OS(FREEBSD)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_esp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_rsp);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.__gregs[_REG_SP]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_gpregs.gp_sp);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_regs[29]);
+#else
+#error Unknown Architecture
+#endif
+
+#elif defined(__GLIBC__)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_ESP]);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_RSP]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.arm_sp);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.sp);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[29]);
+#else
+#error Unknown Architecture
+#endif
+#endif
+}
+
+inline void* stackPointer(const mcontext_t& machineContext)
+{
+ return stackPointer(const_cast<mcontext_t&>(machineContext));
+}
+#endif // OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+
+
+#if OS(DARWIN) || OS(WINDOWS)
+inline void*& framePointer(PlatformRegisters& regs)
+{
+#if OS(DARWIN)
+
+#if __DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.__ebp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.__rbp);
+#elif CPU(ARM_THUMB2)
+ return reinterpret_cast<void*&>(regs.__r[7]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>(regs.__r[11]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>(regs.__x[29]);
+#else
+#error Unknown Architecture
+#endif
+
+#else // !__DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.esp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.rsp);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // __DARWIN_UNIX03
+
+#elif OS(WINDOWS)
+
+#if CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.R11);
+#elif CPU(MIPS)
+#error Dont know what to do with mips. Do we even need this?
+#elif CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Ebp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Rbp);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // OS(DARWIN)
+}
+
+inline void* framePointer(const PlatformRegisters& regs)
+{
+ return framePointer(const_cast<PlatformRegisters&>(regs));
+}
+#endif // OS(DARWIN) || OS(WINDOWS)
+
+
+#if OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+inline void*& framePointer(mcontext_t& machineContext)
+{
+#if OS(DARWIN)
+ return framePointer(machineContext->__ss);
+#elif OS(FREEBSD)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_ebp);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_rbp);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.__gregs[_REG_FP]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_gpregs.gp_x[29]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_regs[30]);
+#else
+#error Unknown Architecture
+#endif
+
+#elif defined(__GLIBC__)
+
+// The following sequence depends on glibc's sys/ucontext.h.
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_EBP]);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_RBP]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.arm_fp);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.regs[29]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[30]);
+#else
+#error Unknown Architecture
+#endif
+
+#else
+#error Need a way to get the frame pointer for another thread on this platform
+#endif
+}
+
+inline void* framePointer(const mcontext_t& machineContext)
+{
+ return framePointer(const_cast<mcontext_t&>(machineContext));
+}
+#endif // OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+
+
+#if OS(DARWIN) || OS(WINDOWS)
+inline void*& instructionPointer(PlatformRegisters& regs)
+{
+#if OS(DARWIN)
+#if __DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.__eip);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.__rip);
+#elif CPU(ARM_THUMB2) || CPU(ARM) || CPU(ARM64)
+ return reinterpret_cast<void*&>(regs.__pc);
+#else
+#error Unknown Architecture
+#endif
+
+#else // !__DARWIN_UNIX03
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.eip);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.rip);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // __DARWIN_UNIX03
+
+#elif OS(WINDOWS)
+
+#if CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Pc);
+#elif CPU(MIPS)
+#error Dont know what to do with mips. Do we even need this?
+#elif CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Eip);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Rip);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // OS(DARWIN)
+}
+
+inline void* instructionPointer(const PlatformRegisters& regs)
+{
+ return instructionPointer(const_cast<PlatformRegisters&>(regs));
+}
+#endif // OS(DARWIN) || OS(WINDOWS)
+
+
+#if OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+
+inline void*& instructionPointer(mcontext_t& machineContext)
+{
+#if OS(DARWIN)
+ return instructionPointer(machineContext->__ss);
+#elif OS(FREEBSD)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_eip);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_rip);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.__gregs[_REG_PC]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_gpregs.gp_elr);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_pc);
+#else
+#error Unknown Architecture
+#endif
+
+#elif defined(__GLIBC__)
+
+// The following sequence depends on glibc's sys/ucontext.h.
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_EIP]);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_RIP]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.arm_pc);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.pc);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.pc);
+#else
+#error Unknown Architecture
+#endif
+
+#else
+#error Need a way to get the instruction pointer for another thread on this platform
+#endif
+}
+
+inline void* instructionPointer(const mcontext_t& machineContext)
+{
+ return instructionPointer(const_cast<mcontext_t&>(machineContext));
+}
+#endif // OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+
+
+#if OS(DARWIN) || OS(WINDOWS)
+template<size_t N>
+void*& argumentPointer(PlatformRegisters&);
+
+template<>
+inline void*& argumentPointer<1>(PlatformRegisters& regs)
+{
+#if OS(DARWIN)
+#if __DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.__edx);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.__rsi);
+#elif CPU(ARM_THUMB2) || CPU(ARM)
+ return reinterpret_cast<void*&>(regs.__r[1]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>(regs.__x[1]);
+#else
+#error Unknown Architecture
+#endif
+
+#else // !__DARWIN_UNIX03
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>(regs.edx);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>(regs.rsi);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // __DARWIN_UNIX03
+
+#elif OS(WINDOWS)
+
+#if CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.R1);
+#elif CPU(MIPS)
+#error Dont know what to do with mips. Do we even need this?
+#elif CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Edx);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Rdx);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // OS(DARWIN)
+}
+
+template<size_t N>
+inline void* argumentPointer(const PlatformRegisters& regs)
+{
+ return argumentPointer<N>(const_cast<PlatformRegisters&>(regs));
+}
+#endif // OS(DARWIN) || OS(WINDOWS)
+
+
+#if OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+template<unsigned N>
+void*& argumentPointer(mcontext_t&);
+
+template<>
+inline void*& argumentPointer<1>(mcontext_t& machineContext)
+{
+#if OS(DARWIN)
+ return argumentPointer<1>(machineContext->__ss);
+#elif OS(FREEBSD)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_edx);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_rsi);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.__gregs[_REG_R1]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_gpregs.gp_x[1]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_regs[5]);
+#else
+#error Unknown Architecture
+#endif
+
+#elif defined(__GLIBC__)
+
+// The following sequence depends on glibc's sys/ucontext.h.
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_EDX]);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_RSI]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.arm_r1);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.regs[1]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[5]);
+#else
+#error Unknown Architecture
+#endif
+
+#else
+#error Need a way to get the frame pointer for another thread on this platform
+#endif
+}
+
+template<unsigned N>
+inline void* argumentPointer(const mcontext_t& machineContext)
+{
+ return argumentPointer<N>(const_cast<mcontext_t&>(machineContext));
+}
+#endif // OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+
+#if ENABLE(JIT)
+#if OS(DARWIN) || OS(WINDOWS)
+inline void*& llintInstructionPointer(PlatformRegisters& regs)
+{
+ // LLInt uses regT4 as PC.
+#if OS(DARWIN)
+#if __DARWIN_UNIX03
+
+#if CPU(X86)
+ static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.__esi);
+#elif CPU(X86_64)
+ static_assert(LLInt::LLIntPC == X86Registers::r8, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.__r8);
+#elif CPU(ARM)
+ static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.__r[8]);
+#elif CPU(ARM64)
+ static_assert(LLInt::LLIntPC == ARM64Registers::x4, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.__x[4]);
+#else
+#error Unknown Architecture
+#endif
+
+#else // !__DARWIN_UNIX03
+#if CPU(X86)
+ static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.esi);
+#elif CPU(X86_64)
+ static_assert(LLInt::LLIntPC == X86Registers::r8, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>(regs.r8);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // __DARWIN_UNIX03
+
+#elif OS(WINDOWS)
+
+#if CPU(ARM)
+ static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>((uintptr_t&) regs.R8);
+#elif CPU(MIPS)
+#error Dont know what to do with mips. Do we even need this?
+#elif CPU(X86)
+ static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>((uintptr_t&) regs.Esi);
+#elif CPU(X86_64)
+ static_assert(LLInt::LLIntPC == X86Registers::r10, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>((uintptr_t&) regs.R10);
+#else
+#error Unknown Architecture
+#endif
+
+#endif // OS(DARWIN)
+}
+
+inline void* llintInstructionPointer(const PlatformRegisters& regs)
+{
+ return llintInstructionPointer(const_cast<PlatformRegisters&>(regs));
+}
+#endif // OS(DARWIN) || OS(WINDOWS)
+
+
+#if OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+inline void*& llintInstructionPointer(mcontext_t& machineContext)
+{
+ // LLInt uses regT4 as PC.
+#if OS(DARWIN)
+ return llintInstructionPointer(machineContext->__ss);
+#elif OS(FREEBSD)
+
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_esi);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_r8);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.__gregs[_REG_R8]);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_gpregs.gp_x[4]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.mc_regs[12]);
+#else
+#error Unknown Architecture
+#endif
+
+#elif defined(__GLIBC__)
+
+// The following sequence depends on glibc's sys/ucontext.h.
+#if CPU(X86)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_ESI]);
+#elif CPU(X86_64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_R8]);
+#elif CPU(ARM)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.arm_r8);
+#elif CPU(ARM64)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.regs[4]);
+#elif CPU(MIPS)
+ return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[12]);
+#else
+#error Unknown Architecture
+#endif
+
+#else
+#error Need a way to get the LLIntPC for another thread on this platform
+#endif
+}
+
+inline void* llintInstructionPointer(const mcontext_t& machineContext)
+{
+ return llintInstructionPointer(const_cast<mcontext_t&>(machineContext));
+}
+#endif // OS(DARWIN) || ((OS(FREEBSD) || defined(__GLIBC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+#endif // ENABLE(JIT)
+
+}
+}
Modified: trunk/Source/_javascript_Core/runtime/PlatformThread.h (213885 => 213886)
--- trunk/Source/_javascript_Core/runtime/PlatformThread.h 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/runtime/PlatformThread.h 2017-03-14 07:33:08 UTC (rev 213886)
@@ -29,6 +29,10 @@
#include <pthread.h>
#endif
+#if USE(PTHREADS) && !OS(WINDOWS) && !OS(DARWIN)
+#include <signal.h>
+#endif
+
#if OS(DARWIN)
#include <mach/thread_act.h>
#elif OS(WINDOWS)
@@ -63,6 +67,12 @@
int errNo = pthread_kill(pthreadID, signalNumber);
return !errNo; // A 0 errNo means success.
}
+#elif USE(PTHREADS)
+inline bool platformThreadSignal(PlatformThread pthreadID, int signalNumber)
+{
+ int errNo = pthread_kill(pthreadID, signalNumber);
+ return !errNo; // A 0 errNo means success.
+}
#endif
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/VMTraps.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/runtime/VMTraps.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -33,6 +33,7 @@
#include "ExceptionHelpers.h"
#include "HeapInlines.h"
#include "LLIntPCRanges.h"
+#include "MachineContext.h"
#include "MachineStackMarker.h"
#include "MacroAssembler.h"
#include "VM.h"
@@ -56,22 +57,24 @@
struct sigaction originalSigusr1Action;
struct sigaction originalSigtrapAction;
-#if CPU(X86_64)
-
struct SignalContext {
SignalContext(mcontext_t& mcontext)
: mcontext(mcontext)
- , trapPC(reinterpret_cast<void*>(mcontext->__ss.__rip))
- , stackPointer(reinterpret_cast<void*>(mcontext->__ss.__rsp))
- , framePointer(reinterpret_cast<void*>(mcontext->__ss.__rbp))
+ , trapPC(MachineContext::instructionPointer(mcontext))
+ , stackPointer(MachineContext::stackPointer(mcontext))
+ , framePointer(MachineContext::framePointer(mcontext))
{
+#if CPU(X86_64) || CPU(X86)
// On X86_64, SIGTRAP reports the address after the trapping PC. So, dec by 1.
trapPC = reinterpret_cast<uint8_t*>(trapPC) - 1;
+#endif
}
void adjustPCToPointToTrappingInstruction()
{
- mcontext->__ss.__rip = reinterpret_cast<uintptr_t>(trapPC);
+#if CPU(X86_64) || CPU(X86)
+ MachineContext::instructionPointer(mcontext) = trapPC;
+#endif
}
mcontext_t& mcontext;
@@ -79,57 +82,7 @@
void* stackPointer;
void* framePointer;
};
-
-#elif CPU(X86)
-struct SignalContext {
- SignalContext(mcontext_t& mcontext)
- : mcontext(mcontext)
- , trapPC(reinterpret_cast<void*>(mcontext->__ss.__eip))
- , stackPointer(reinterpret_cast<void*>(mcontext->__ss.__esp))
- , framePointer(reinterpret_cast<void*>(mcontext->__ss.__ebp))
- {
- // On X86, SIGTRAP reports the address after the trapping PC. So, dec by 1.
- trapPC = reinterpret_cast<uint8_t*>(trapPC) - 1;
- }
-
- void adjustPCToPointToTrappingInstruction()
- {
- mcontext->__ss.__eip = reinterpret_cast<uintptr_t>(trapPC);
- }
-
- mcontext_t& mcontext;
- void* trapPC;
- void* stackPointer;
- void* framePointer;
-};
-
-#elif CPU(ARM64) || CPU(ARM_THUMB2) || CPU(ARM)
-
-struct SignalContext {
- SignalContext(mcontext_t& mcontext)
- : mcontext(mcontext)
- , trapPC(reinterpret_cast<void*>(mcontext->__ss.__pc))
- , stackPointer(reinterpret_cast<void*>(mcontext->__ss.__sp))
-#if CPU(ARM64)
- , framePointer(reinterpret_cast<void*>(mcontext->__ss.__fp))
-#elif CPU(ARM_THUMB2)
- , framePointer(reinterpret_cast<void*>(mcontext->__ss.__r[7]))
-#elif CPU(ARM)
- , framePointer(reinterpret_cast<void*>(mcontext->__ss.__r[11]))
-#endif
- { }
-
- void adjustPCToPointToTrappingInstruction() { }
-
- mcontext_t& mcontext;
- void* trapPC;
- void* stackPointer;
- void* framePointer;
-};
-
-#endif
-
inline static bool vmIsInactive(VM& vm)
{
return !vm.entryScope && !vm.ownerThread();
Modified: trunk/Source/_javascript_Core/tools/CodeProfiling.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/tools/CodeProfiling.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/tools/CodeProfiling.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -27,6 +27,7 @@
#include "CodeProfiling.h"
#include "CodeProfile.h"
+#include "MachineContext.h"
#include <wtf/MetaAllocator.h>
#if HAVE(SIGNAL_H)
@@ -66,20 +67,14 @@
#pragma clang diagnostic pop
#endif
-#if OS(DARWIN) && !PLATFORM(GTK) && CPU(X86_64)
+#if (OS(DARWIN) && !PLATFORM(GTK) && CPU(X86_64)) || (OS(LINUX) && CPU(X86))
static void profilingTimer(int, siginfo_t*, void* uap)
{
mcontext_t context = static_cast<ucontext_t*>(uap)->uc_mcontext;
- CodeProfiling::sample(reinterpret_cast<void*>(context->__ss.__rip),
- reinterpret_cast<void**>(context->__ss.__rbp));
+ CodeProfiling::sample(
+ MachineContext::instructionPointer(context),
+ reinterpret_cast<void**>(MachineContext::framePointer(context)));
}
-#elif OS(LINUX) && CPU(X86)
-static void profilingTimer(int, siginfo_t*, void* uap)
-{
- mcontext_t context = static_cast<ucontext_t*>(uap)->uc_mcontext;
- CodeProfiling::sample(reinterpret_cast<void*>(context.gregs[REG_EIP]),
- reinterpret_cast<void**>(context.gregs[REG_EBP]));
-}
#endif
// Callback triggered when the timer is fired.
Modified: trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -28,6 +28,7 @@
#include "CallFrame.h"
#include "CodeBlock.h"
+#include "MachineContext.h"
#include "VMInspector.h"
#include <mutex>
#include <wtf/StdLibExtras.h>
@@ -78,17 +79,17 @@
#endif // USE(OS_LOG)
-#if CPU(X86_64)
struct SignalContext {
SignalContext(mcontext_t& mcontext)
: mcontext(mcontext)
- , machinePC(reinterpret_cast<void*>(mcontext->__ss.__rip))
- , stackPointer(reinterpret_cast<void*>(mcontext->__ss.__rsp))
- , framePointer(reinterpret_cast<CallFrame*>(mcontext->__ss.__rbp))
+ , machinePC(MachineContext::instructionPointer(mcontext))
+ , stackPointer(MachineContext::stackPointer(mcontext))
+ , framePointer(MachineContext::framePointer(mcontext))
{ }
void dump()
{
+#if CPU(X86_64)
#define FOR_EACH_REGISTER(v) \
v(rax) \
v(rbx) \
@@ -116,26 +117,8 @@
log("Register " #__reg ": %p", reinterpret_cast<void*>(mcontext->__ss.__##__reg));
FOR_EACH_REGISTER(DUMP_REGISTER)
#undef FOR_EACH_REGISTER
- }
- mcontext_t& mcontext;
- void* machinePC;
- void* stackPointer;
- void* framePointer;
-};
-
#elif CPU(ARM64)
-
-struct SignalContext {
- SignalContext(mcontext_t& mcontext)
- : mcontext(mcontext)
- , machinePC(reinterpret_cast<void*>(mcontext->__ss.__pc))
- , stackPointer(reinterpret_cast<void*>(mcontext->__ss.__sp))
- , framePointer(reinterpret_cast<CallFrame*>(mcontext->__ss.__fp))
- { }
-
- void dump()
- {
int i;
for (i = 0; i < 28; i += 4) {
log("x%d: %016llx x%d: %016llx x%d: %016llx x%d: %016llx",
@@ -149,6 +132,7 @@
i, mcontext->__ss.__x[i], mcontext->__ss.__fp, mcontext->__ss.__lr);
log("sp: %016llx pc: %016llx cpsr: %08x",
mcontext->__ss.__sp, mcontext->__ss.__pc, mcontext->__ss.__cpsr);
+#endif
}
mcontext_t& mcontext;
@@ -157,20 +141,6 @@
void* framePointer;
};
-#else
-
-struct SignalContext {
- SignalContext(mcontext_t&) { }
-
- void dump() { }
-
- void* machinePC;
- void* stackPointer;
- void* framePointer;
-};
-
-#endif
-
struct sigaction originalSigIllAction;
static void handleCrash(int signalNumber, siginfo_t* info, void* uap)
Modified: trunk/Source/_javascript_Core/tools/VMInspector.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/tools/VMInspector.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/tools/VMInspector.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -29,6 +29,7 @@
#include "CodeBlock.h"
#include "CodeBlockSet.h"
#include "HeapInlines.h"
+#include "MachineContext.h"
#include <mutex>
#include <wtf/Expected.h>
Modified: trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp (213885 => 213886)
--- trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp 2017-03-14 07:33:08 UTC (rev 213886)
@@ -29,6 +29,7 @@
#if ENABLE(WEBASSEMBLY)
#include "ExecutableAllocator.h"
+#include "MachineContext.h"
#include "VM.h"
#include "WasmExceptionType.h"
#include "WasmMemory.h"
@@ -50,40 +51,10 @@
static StaticLock codeLocationsLock;
static LazyNeverDestroyed<HashSet<std::tuple<VM*, void*, void*>>> codeLocations; // (vm, start, end)
-// FIXME: Clean up mcontext_t handling code since it is scattered in heap/, tools/ and wasm/.
-// https://bugs.webkit.org/show_bug.cgi?id=169180
-#if CPU(X86_64)
-
-#if OS(DARWIN)
-#define InstructionPointerGPR context->__ss.__rip
-#define FirstArgumentGPR context->__ss.__rsi
-#elif OS(FREEBSD)
-#define InstructionPointerGPR context.mc_rip
-#define FirstArgumentGPR context.mc_rsi
-#elif defined(__GLIBC__)
-#define InstructionPointerGPR context.gregs[REG_RIP]
-#define FirstArgumentGPR context.gregs[REG_RSI]
-#endif
-
-#else
-
-#if OS(DARWIN)
-#define InstructionPointerGPR context->__ss.__pc
-#define FirstArgumentGPR context->__ss.__x[1]
-#elif OS(FREEBSD)
-#define InstructionPointerGPR context.mc_gpregs.gp_elr
-#define FirstArgumentGPR context.mc_gpregs.gp_x[1]
-#elif defined(__GLIBC__)
-#define InstructionPointerGPR context.pc
-#define FirstArgumentGPR context.regs[1]
-#endif
-
-#endif
-
static void trapHandler(int signal, siginfo_t* sigInfo, void* ucontext)
{
mcontext_t& context = static_cast<ucontext_t*>(ucontext)->uc_mcontext;
- void* faultingInstruction = reinterpret_cast<void*>(InstructionPointerGPR);
+ void* faultingInstruction = MachineContext::instructionPointer(context);
dataLogLnIf(verbose, "starting handler for fault at: ", RawPointer(faultingInstruction));
dataLogLnIf(verbose, "JIT memory start: ", RawPointer(reinterpret_cast<void*>(startOfFixedExecutableMemoryPool)), " end: ", RawPointer(reinterpret_cast<void*>(endOfFixedExecutableMemoryPool)));
@@ -122,8 +93,8 @@
if (!exceptionStub)
break;
dataLogLnIf(verbose, "found stub: ", RawPointer(exceptionStub.code().executableAddress()));
- FirstArgumentGPR = static_cast<uint64_t>(ExceptionType::OutOfBoundsMemoryAccess);
- InstructionPointerGPR = reinterpret_cast<uint64_t>(exceptionStub.code().executableAddress());
+ MachineContext::argumentPointer<1>(context) = reinterpret_cast<void*>(ExceptionType::OutOfBoundsMemoryAccess);
+ MachineContext::instructionPointer(context) = exceptionStub.code().executableAddress();
return;
}
}
Modified: trunk/Source/WTF/ChangeLog (213885 => 213886)
--- trunk/Source/WTF/ChangeLog 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/WTF/ChangeLog 2017-03-14 07:33:08 UTC (rev 213886)
@@ -1,5 +1,16 @@
2017-03-13 Yusuke Suzuki <[email protected]>
+ [JSC][Linux] Implement VMTrap in Linux ports
+ https://bugs.webkit.org/show_bug.cgi?id=169436
+
+ Reviewed by Mark Lam.
+
+ Enable VMTrap mechanism for Linux and FreeBSD.
+
+ * wtf/Platform.h:
+
+2017-03-13 Yusuke Suzuki <[email protected]>
+
[WTF] Clean up RunLoop and WorkQueue with Seconds and Function
https://bugs.webkit.org/show_bug.cgi?id=169537
Modified: trunk/Source/WTF/wtf/Platform.h (213885 => 213886)
--- trunk/Source/WTF/wtf/Platform.h 2017-03-14 06:51:23 UTC (rev 213885)
+++ trunk/Source/WTF/wtf/Platform.h 2017-03-14 07:33:08 UTC (rev 213886)
@@ -922,7 +922,7 @@
#endif
#endif
-#if OS(DARWIN) && ENABLE(JIT)
+#if (OS(DARWIN) || OS(LINUX) || OS(FREEBSD)) && ENABLE(JIT)
#define ENABLE_SIGNAL_BASED_VM_TRAPS 1
#endif