Jelajahi Sumber

Update PAL to support Apple Silicon
- Some material brought in from PAL at github.com/dotnet/
- Various manual changes to fit with existing codebase
- Updated licensing in edited files, latest PAL is copyright .dotNet
- Updated copyright check scripts to check pal/ files for new text

rhuanjl 3 tahun lalu
induk
melakukan
3fb33a8271

+ 36 - 6
THIRD-PARTY-NOTICES.txt

@@ -1,19 +1,21 @@
 ChakraCore uses third party material from the projects listed below.
 ChakraCore uses third party material from the projects listed below.
 The original copyright notice and the license under which Microsoft
 The original copyright notice and the license under which Microsoft
-received such third party material are set forth below. Microsoft
-reserves all other rights not expressly granted, whether by
+or the ChakraCore Project Contributors received such third party material
+are set forth below. Microsoft, and where relevant the  ChakraCore Project
+Contributors reserve all other rights not expressly granted, whether by
 implication, estoppel or otherwise.
 implication, estoppel or otherwise.
 
 
 In the event that we accidentally failed to list a required notice, please
 In the event that we accidentally failed to list a required notice, please
-bring it to our attention. Post an issue or email us: [email protected]
+bring it to our attention. Post an issue or message us on discord.
 
 
 THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
 THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
 Do Not Translate or Localize
 Do Not Translate or Localize
 
 
 ChakraCore incorporates third party material from the projects listed below.
 ChakraCore incorporates third party material from the projects listed below.
-The original copyright notice and the license under which Microsoft received
-such third party material are set forth below. Microsoft reserves all other
-rights not expressly granted, whether by implication, estoppel or otherwise.
+The original copyright notice and the license under which Microsoft or the
+ChakraCore Project Contributors received such third party material are set
+forth below. Microsoft, and where relevant the  ChakraCore Project Contributors
+reserve all other rights not expressly granted, whether by implication, estoppel or otherwise.
 
 
 1.   backbone.suggestions (https://github.com/qloo/backbone.suggestions)
 1.   backbone.suggestions (https://github.com/qloo/backbone.suggestions)
 2.   BeatDetektor.js
 2.   BeatDetektor.js
@@ -48,6 +50,7 @@ rights not expressly granted, whether by implication, estoppel or otherwise.
 31.  yargs-parser.js (https://github.com/yargs/yargs-parser)
 31.  yargs-parser.js (https://github.com/yargs/yargs-parser)
 32.  camelcase.js (https://github.com/sindresorhus/camelcase)
 32.  camelcase.js (https://github.com/sindresorhus/camelcase)
 33.  ARES-6 (https://github.com/WebKit/webkit/tree/master/PerformanceTests/ARES-6)
 33.  ARES-6 (https://github.com/WebKit/webkit/tree/master/PerformanceTests/ARES-6)
+34.  PAL (from dotNet)
 
 
 %% backbone.suggestions NOTICES, INFORMATION, AND LICENSE BEGIN HERE
 %% backbone.suggestions NOTICES, INFORMATION, AND LICENSE BEGIN HERE
 =========================================
 =========================================
@@ -2041,3 +2044,30 @@ END OF ARES-6 NOTICES, INFORMATION, AND LICENSE
 
 
 ---------------------------------------------
 ---------------------------------------------
 
 
+%% PAL NOTICES, INFORMATION AND LICENSE BEGIN HERE
+=========================================
+The MIT License (MIT)
+
+Copyright (c) .NET Foundation and Contributors
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+=========================================
+END OF PAL NOTICES, INFORMATION, AND LICENSE

+ 11 - 2
pal/inc/cclock.hpp

@@ -1,12 +1,21 @@
 //-------------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------------
 
 
 #ifndef CC_PAL_INC_CCLOCK_H
 #ifndef CC_PAL_INC_CCLOCK_H
 #define CC_PAL_INC_CCLOCK_H
 #define CC_PAL_INC_CCLOCK_H
 
 
-class CCLock
+#if defined(_M_ARM64)
+#define CCLOCK_ALIGN __declspec(align(8))
+#else
+#define CCLOCK_ALIGN
+#endif
+
+class CCLOCK_ALIGN CCLock
 {
 {
     char           mutexPtr[64]; // keep mutex implementation opaque to consumer (PAL vs non-PAL)
     char           mutexPtr[64]; // keep mutex implementation opaque to consumer (PAL vs non-PAL)
 
 

+ 28 - 17
pal/inc/pal.h

@@ -1,8 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 /*++
 /*++
 
 
 Module Name:
 Module Name:
@@ -2907,6 +2909,7 @@ typedef struct _IMAGE_ARM_RUNTIME_FUNCTION_ENTRY {
 
 
 #define CONTEXT_CONTROL (CONTEXT_ARM64 | 0x1L)
 #define CONTEXT_CONTROL (CONTEXT_ARM64 | 0x1L)
 #define CONTEXT_INTEGER (CONTEXT_ARM64 | 0x2L)
 #define CONTEXT_INTEGER (CONTEXT_ARM64 | 0x2L)
+#define CONTEXT_SEGMENTS (CONTEXT_ARM64 | 0x4L)
 #define CONTEXT_FLOATING_POINT  (CONTEXT_ARM64 | 0x4L)
 #define CONTEXT_FLOATING_POINT  (CONTEXT_ARM64 | 0x4L)
 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM64 | 0x8L)
 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM64 | 0x8L)
 
 
@@ -3190,6 +3193,8 @@ PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context,
 #define PAL_CS_NATIVE_DATA_SIZE 76
 #define PAL_CS_NATIVE_DATA_SIZE 76
 #elif defined(__APPLE__) && defined(__x86_64__)
 #elif defined(__APPLE__) && defined(__x86_64__)
 #define PAL_CS_NATIVE_DATA_SIZE 120
 #define PAL_CS_NATIVE_DATA_SIZE 120
+#elif defined(__APPLE__) && defined(_ARM64_)
+#define PAL_CS_NATIVE_DATA_SIZE 120
 #elif defined(__LINUX__) && defined(__i386__)
 #elif defined(__LINUX__) && defined(__i386__)
 #define PAL_CS_NATIVE_DATA_SIZE 56
 #define PAL_CS_NATIVE_DATA_SIZE 56
 #elif defined(__LINUX__) && defined(__x86_64__)
 #elif defined(__LINUX__) && defined(__x86_64__)
@@ -4713,11 +4718,29 @@ enum {
 //
 //
 // A function table entry is generated for each frame function.
 // A function table entry is generated for each frame function.
 //
 //
+#ifdef _M_ARM64
+typedef struct _RUNTIME_FUNCTION {
+    DWORD BeginAddress;
+    union {
+        DWORD UnwindData;
+        struct {
+            DWORD Flag           : 2;
+            DWORD FunctionLength : 11;
+            DWORD RegF           : 3;
+            DWORD RegI           : 4;
+            DWORD H              : 1;
+            DWORD CR             : 2;
+            DWORD FrameSize      : 9;
+        };
+    };
+} RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
+#else
 typedef struct _RUNTIME_FUNCTION {
 typedef struct _RUNTIME_FUNCTION {
     DWORD BeginAddress;
     DWORD BeginAddress;
     DWORD EndAddress;
     DWORD EndAddress;
     DWORD UnwindData;
     DWORD UnwindData;
 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
+#endif
 
 
 PALIMPORT
 PALIMPORT
 BOOL
 BOOL
@@ -5810,11 +5833,6 @@ RtlCaptureContext(
   OUT PCONTEXT ContextRecord
   OUT PCONTEXT ContextRecord
 );
 );
 
 
-PALIMPORT
-VOID
-PALAPI
-FlushProcessWriteBuffers();
-
 typedef void (*PAL_ActivationFunction)(CONTEXT *context);
 typedef void (*PAL_ActivationFunction)(CONTEXT *context);
 typedef BOOL (*PAL_SafeActivationCheckFunction)(SIZE_T ip, BOOL checkingCurrentThread);
 typedef BOOL (*PAL_SafeActivationCheckFunction)(SIZE_T ip, BOOL checkingCurrentThread);
 
 
@@ -5825,13 +5843,6 @@ PAL_SetActivationFunction(
     IN PAL_ActivationFunction pActivationFunction,
     IN PAL_ActivationFunction pActivationFunction,
     IN PAL_SafeActivationCheckFunction pSafeActivationCheckFunction);
     IN PAL_SafeActivationCheckFunction pSafeActivationCheckFunction);
 
 
-PALIMPORT
-BOOL
-PALAPI
-PAL_InjectActivation(
-    IN HANDLE hThread
-);
-
 #define VER_PLATFORM_WIN32_WINDOWS        1
 #define VER_PLATFORM_WIN32_WINDOWS        1
 #define VER_PLATFORM_WIN32_NT        2
 #define VER_PLATFORM_WIN32_NT        2
 #define VER_PLATFORM_UNIX            10
 #define VER_PLATFORM_UNIX            10

+ 366 - 0
pal/inc/unixasmmacrosarm64.inc

@@ -0,0 +1,366 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+.macro NESTED_ENTRY Name, Section, Handler
+        LEAF_ENTRY \Name, \Section
+        .ifnc \Handler, NoHandler
+#if defined(__APPLE__)
+        .cfi_personality 0x9b, C_FUNC(\Handler) // 0x9b == DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4
+#else
+        .cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
+#endif
+        .endif
+.endm
+
+.macro NESTED_END Name, Section
+        LEAF_END \Name, \Section
+.endm
+
+.macro PATCH_LABEL Name
+        .global C_FUNC(\Name)
+C_FUNC(\Name):
+.endm
+
+.macro LEAF_ENTRY Name, Section
+        .global C_FUNC(\Name)
+#if defined(__APPLE__)
+        .text
+        .p2align        2
+#else
+        .type \Name, %function
+#endif
+C_FUNC(\Name):
+        .cfi_startproc
+.endm
+
+.macro LEAF_END Name, Section
+#if !defined(__APPLE__)
+        .size \Name, .-\Name
+#endif
+        .cfi_endproc
+.endm
+
+.macro LEAF_END_MARKED Name, Section
+C_FUNC(\Name\()_End):
+        .global C_FUNC(\Name\()_End)
+        LEAF_END \Name, \Section
+        // make sure this symbol gets its own address
+        nop
+.endm
+
+.macro PREPARE_EXTERNAL_VAR Name, HelperReg
+#if defined(__APPLE__)
+        adrp    \HelperReg, C_FUNC(\Name)@GOTPAGE
+        ldr     \HelperReg, [\HelperReg, C_FUNC(\Name)@GOTPAGEOFF]
+#else
+        adrp    \HelperReg, C_FUNC(\Name)
+        add     \HelperReg, \HelperReg, :lo12:C_FUNC(\Name)
+#endif
+.endm
+
+.macro PROLOG_STACK_ALLOC Size
+        sub sp, sp, \Size
+.endm
+
+.macro EPILOG_STACK_FREE Size
+        add sp, sp, \Size
+        .cfi_adjust_cfa_offset -\Size
+.endm
+
+.macro EPILOG_STACK_RESTORE
+        mov sp, fp
+        .cfi_restore sp
+.endm
+
+.macro PROLOG_SAVE_REG reg, ofs
+        str \reg, [sp, \ofs]
+        .cfi_rel_offset \reg, \ofs
+.endm
+
+.macro PROLOG_SAVE_REG_PAIR reg1, reg2, ofs
+        stp \reg1, \reg2, [sp, \ofs]
+        .cfi_rel_offset \reg1, \ofs
+        .cfi_rel_offset \reg2, \ofs + 8
+        .ifc \reg1, fp
+        mov fp, sp
+        .cfi_def_cfa_register fp
+        .endif
+.endm
+
+.macro PROLOG_SAVE_REG_PAIR_INDEXED reg1, reg2, ofs
+        stp \reg1, \reg2, [sp, \ofs]!
+        .cfi_adjust_cfa_offset -\ofs
+        .cfi_rel_offset \reg1, 0
+        .cfi_rel_offset \reg2, 8
+        .ifc \reg1, fp
+        mov fp, sp
+        .cfi_def_cfa_register fp
+        .endif
+.endm
+
+.macro EPILOG_RESTORE_REG reg, ofs
+        ldr \reg, [sp, \ofs]
+        .cfi_restore \reg
+.endm
+
+.macro EPILOG_RESTORE_REG_PAIR reg1, reg2, ofs
+        ldp \reg1, \reg2, [sp, \ofs]
+        .cfi_restore \reg1
+        .cfi_restore \reg2
+.endm
+
+.macro EPILOG_RESTORE_REG_PAIR_INDEXED reg1, reg2, ofs
+        ldp \reg1, \reg2, [sp], \ofs
+        .cfi_restore \reg1
+        .cfi_restore \reg2
+        .cfi_adjust_cfa_offset -\ofs
+.endm
+
+.macro EPILOG_RETURN
+        ret
+.endm
+
+.macro EMIT_BREAKPOINT
+        brk #0
+.endm
+
+//-----------------------------------------------------------------------------
+// Define the prolog for a TransitionFrame-based method. This macro should be called first in the method and
+// comprises the entire prolog (i.e. don't modify SP after calling this).The locals must be 8 byte aligned
+//
+// Stack layout:
+//
+// (stack parameters)
+// ...
+// fp
+// lr
+// CalleeSavedRegisters::x28
+// CalleeSavedRegisters::x27
+// CalleeSavedRegisters::x26
+// CalleeSavedRegisters::x25
+// CalleeSavedRegisters::x24
+// CalleeSavedRegisters::x23
+// CalleeSavedRegisters::x22
+// CalleeSavedRegisters::x21
+// CalleeSavedRegisters::x20
+// CalleeSavedRegisters::x19
+// CalleeSavedRegisters::x30 (Lr)
+// CalleeSavedRegisters::x29 (Fp)
+// ArgumentRegisters::x7
+// ArgumentRegisters::x6
+// ArgumentRegisters::x5
+// ArgumentRegisters::x4
+// ArgumentRegisters::x3
+// ArgumentRegisters::x2
+// ArgumentRegisters::x1
+// ArgumentRegisters::x0
+// FloatRegisters::q7
+// FloatRegisters::q6
+// FloatRegisters::q5
+// FloatRegisters::q4
+// FloatRegisters::q3
+// FloatRegisters::q2
+// FloatRegisters::q1
+// FloatRegisters::q0
+.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, SaveFPArgs = 1
+
+        __PWTB_FloatArgumentRegisters = \extraLocals
+        __PWTB_SaveFPArgs = \SaveFPArgs
+
+        .if ((__PWTB_FloatArgumentRegisters % 16) != 0)
+                __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8
+        .endif
+
+        __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters
+
+        .if (__PWTB_SaveFPArgs == 1)
+            __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters
+        .endif
+
+        __PWTB_StackAlloc = __PWTB_TransitionBlock
+        __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 104
+        __PWTB_ArgumentRegister_FirstArg = __PWTB_ArgumentRegisters + 8
+
+        PROLOG_SAVE_REG_PAIR_INDEXED   fp, lr, -176
+        // Spill callee saved registers
+        PROLOG_SAVE_REG_PAIR   x19, x20, 16
+        PROLOG_SAVE_REG_PAIR   x21, x22, 32
+        PROLOG_SAVE_REG_PAIR   x23, x24, 48
+        PROLOG_SAVE_REG_PAIR   x25, x26, 64
+        PROLOG_SAVE_REG_PAIR   x27, x28, 80
+
+        // Allocate space for the rest of the frame
+        PROLOG_STACK_ALLOC  __PWTB_StackAlloc
+
+        // Spill argument registers.
+        SAVE_ARGUMENT_REGISTERS        sp, __PWTB_ArgumentRegisters
+
+        .if (__PWTB_SaveFPArgs == 1)
+                SAVE_FLOAT_ARGUMENT_REGISTERS sp, \extraLocals
+        .endif
+
+.endm
+
+//-----------------------------------------------------------------------------
+// The Following sets of SAVE_*_REGISTERS expect the memory to be reserved and
+// base address to be passed in $reg
+//
+
+// Reserve 64 bytes of memory before calling  SAVE_ARGUMENT_REGISTERS
+.macro SAVE_ARGUMENT_REGISTERS reg, ofs
+
+        str                    x8, [\reg, #(\ofs)]
+        stp                    x0, x1, [\reg, #(\ofs + 8)]
+        stp                    x2, x3, [\reg, #(\ofs + 24)]
+        stp                    x4, x5, [\reg, #(\ofs + 40)]
+        stp                    x6, x7, [\reg, #(\ofs + 56)]
+
+.endm
+
+// Reserve 128 bytes of memory before calling  SAVE_FLOAT_ARGUMENT_REGISTERS
+.macro SAVE_FLOAT_ARGUMENT_REGISTERS reg, ofs
+
+        stp                    q0, q1, [\reg, #(\ofs)]
+        stp                    q2, q3, [\reg, #(\ofs + 32)]
+        stp                    q4, q5, [\reg, #(\ofs + 64)]
+        stp                    q6, q7, [\reg, #(\ofs + 96)]
+
+.endm
+
+.macro RESTORE_ARGUMENT_REGISTERS reg, ofs
+
+        ldr                    x8, [\reg, #(\ofs)]
+        ldp                    x0, x1, [\reg, #(\ofs + 8)]
+        ldp                    x2, x3, [\reg, #(\ofs + 24)]
+        ldp                    x4, x5, [\reg, #(\ofs + 40)]
+        ldp                    x6, x7, [\reg, #(\ofs + 56)]
+
+.endm
+
+.macro RESTORE_FLOAT_ARGUMENT_REGISTERS reg, ofs
+
+        ldp                    q0, q1, [\reg, #(\ofs)]
+        ldp                    q2, q3, [\reg, #(\ofs + 32)]
+        ldp                    q4, q5, [\reg, #(\ofs + 64)]
+        ldp                    q6, q7, [\reg, #(\ofs + 96)]
+
+.endm
+
+.macro EPILOG_BRANCH Target
+        b \Target
+.endm
+
+.macro EPILOG_BRANCH_REG reg
+
+        br \reg
+
+.endm
+
+
+.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN
+
+        EPILOG_STACK_FREE                 __PWTB_StackAlloc
+
+        EPILOG_RESTORE_REG_PAIR   x19, x20, 16
+        EPILOG_RESTORE_REG_PAIR   x21, x22, 32
+        EPILOG_RESTORE_REG_PAIR   x23, x24, 48
+        EPILOG_RESTORE_REG_PAIR   x25, x26, 64
+        EPILOG_RESTORE_REG_PAIR   x27, x28, 80
+        EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176
+        ret
+
+.endm
+
+
+//-----------------------------------------------------------------------------
+// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling.
+// Since this is a tail call argument registers are restored.
+//
+.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
+
+        .if (__PWTB_SaveFPArgs == 1)
+            RESTORE_FLOAT_ARGUMENT_REGISTERS  sp, __PWTB_FloatArgumentRegisters
+        .endif
+
+        RESTORE_ARGUMENT_REGISTERS        sp, __PWTB_ArgumentRegisters
+
+        EPILOG_STACK_FREE                 __PWTB_StackAlloc
+
+        EPILOG_RESTORE_REG_PAIR   x19, x20, 16
+        EPILOG_RESTORE_REG_PAIR   x21, x22, 32
+        EPILOG_RESTORE_REG_PAIR   x23, x24, 48
+        EPILOG_RESTORE_REG_PAIR   x25, x26, 64
+        EPILOG_RESTORE_REG_PAIR   x27, x28, 80
+        EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176
+
+.endm
+
+// ------------------------------------------------------------------
+// Macro to generate Redirection Stubs
+//
+// $reason : reason for redirection
+//                     Eg. GCThreadControl
+// NOTE: If you edit this macro, make sure you update GetCONTEXTFromRedirectedStubStackFrame.
+// This function is used by both the personality routine and the debugger to retrieve the original CONTEXT.
+.macro GenerateRedirectedHandledJITCaseStub reason
+
+#if NOTYET
+        GBLS __RedirectionStubFuncName
+        GBLS __RedirectionStubEndFuncName
+        GBLS __RedirectionFuncName
+__RedirectionStubFuncName SETS "RedirectedHandledJITCaseFor":CC:"$reason":CC:"_Stub"
+__RedirectionStubEndFuncName SETS "RedirectedHandledJITCaseFor":CC:"$reason":CC:"_StubEnd"
+__RedirectionFuncName SETS "|?RedirectedHandledJITCaseFor":CC:"$reason":CC:"@Thread@@CAXXZ|"
+
+        IMPORT $__RedirectionFuncName
+
+        NESTED_ENTRY $__RedirectionStubFuncName
+        PROLOG_SAVE_REG_PAIR    fp, lr, -16
+        sub sp, sp, #16                          // stack slot for CONTEXT * and padding
+
+        //REDIRECTSTUB_SP_OFFSET_CONTEXT is defined in asmconstants.h and is used in GetCONTEXTFromRedirectedStubStackFrame
+        //If CONTEXT is not saved at 0 offset from SP it must be changed as well.
+        ASSERT REDIRECTSTUB_SP_OFFSET_CONTEXT == 0
+
+        // Stack alignment. This check is necessary as this function can be
+        // entered before complete execution of the prolog of another function.
+        and x8, fp, #15
+        sub sp, sp, x8
+
+
+        //
+        // Save a copy of the redirect CONTEXT*.
+        // This is needed for the debugger to unwind the stack.
+        //
+        bl GetCurrentSavedRedirectContext
+        str x0, [sp]
+
+        //
+        // Fetch the interrupted pc and save it as our return address.
+        //
+        ldr x1, [x0, #CONTEXT_Pc]
+        str x1, [fp, #8]
+
+        //
+        // Call target, which will do whatever we needed to do in the context
+        // of the target thread, and will RtlRestoreContext when it is done.
+        //
+        bl $__RedirectionFuncName
+
+        EMIT_BREAKPOINT // Unreachable
+
+// Put a label here to tell the debugger where the end of this function is.
+$__RedirectionStubEndFuncName
+        EXPORT $__RedirectionStubEndFuncName
+
+        NESTED_END
+#else
+        EMIT_BREAKPOINT
+#endif
+
+.endm

+ 10 - 1
pal/src/CMakeLists.txt

@@ -19,6 +19,9 @@ elseif(CC_TARGETS_ARM)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
     set(PAL_CMAKE_PLATFORM_ARCH_ARM64 1)
     set(PAL_CMAKE_PLATFORM_ARCH_ARM64 1)
     add_definitions(-D_ARM64_)
     add_definitions(-D_ARM64_)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
+    set(PAL_CMAKE_PLATFORM_ARCH_ARM64 1)
+    add_definitions(-D_ARM64_)
 else()
 else()
     clr_unknown_arch()
     clr_unknown_arch()
 endif()
 endif()
@@ -58,7 +61,6 @@ endif()
 if(CC_TARGETS_AMD64 OR CC_TARGETS_X86)
 if(CC_TARGETS_AMD64 OR CC_TARGETS_X86)
   if(CC_TARGET_OS_OSX)
   if(CC_TARGET_OS_OSX)
     set(PLATFORM_SOURCES ${PLATFORM_SOURCES}
     set(PLATFORM_SOURCES ${PLATFORM_SOURCES}
-      arch/i386/activationhandlerwrapper.S
       arch/i386/dispatchexceptionwrapper.S
       arch/i386/dispatchexceptionwrapper.S
     )
     )
   endif()
   endif()
@@ -68,6 +70,13 @@ if(CC_TARGETS_AMD64 OR CC_TARGETS_X86)
     arch/i386/processor.cpp
     arch/i386/processor.cpp
     arch/i386/asmhelpers.S
     arch/i386/asmhelpers.S
     )
     )
+elseif(PAL_CMAKE_PLATFORM_ARCH_ARM64)
+  set(ARCH_SOURCES
+    arch/arm64/dispatchexceptionwrapper.S
+    arch/arm64/context2.S
+    arch/arm64/debugbreak.S
+  )
+
 elseif(CC_TARGETS_ARM)
 elseif(CC_TARGETS_ARM)
   set(ARCH_SOURCES
   set(ARCH_SOURCES
     arch/arm/context2.S
     arch/arm/context2.S

+ 100 - 0
pal/src/arch/arm64/asmconstants.h

@@ -0,0 +1,100 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#ifndef __PAL_ARM64_ASMCONSTANTS_H__
+#define __PAL_ARM64_ASMCONSTANTS_H__
+
+#define CONTEXT_ARM64   0x00400000L
+
+#define CONTEXT_CONTROL_BIT (0)
+#define CONTEXT_INTEGER_BIT (1)
+#define CONTEXT_FLOATING_POINT_BIT (2)
+#define CONTEXT_DEBUG_REGISTERS_BIT (3)
+
+#define CONTEXT_CONTROL (CONTEXT_ARM64 | (1L << CONTEXT_CONTROL_BIT))
+#define CONTEXT_INTEGER (CONTEXT_ARM64 | (1 << CONTEXT_INTEGER_BIT))
+#define CONTEXT_FLOATING_POINT  (CONTEXT_ARM64 | (1 << CONTEXT_FLOATING_POINT_BIT))
+#define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM64 | (1 << CONTEXT_DEBUG_REGISTERS_BIT))
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+
+
+#define CONTEXT_ContextFlags 0
+#define CONTEXT_Cpsr         CONTEXT_ContextFlags+4
+#define CONTEXT_X0           CONTEXT_Cpsr+4
+#define CONTEXT_X1           CONTEXT_X0+8
+#define CONTEXT_X2           CONTEXT_X1+8
+#define CONTEXT_X3           CONTEXT_X2+8
+#define CONTEXT_X4           CONTEXT_X3+8
+#define CONTEXT_X5           CONTEXT_X4+8
+#define CONTEXT_X6           CONTEXT_X5+8
+#define CONTEXT_X7           CONTEXT_X6+8
+#define CONTEXT_X8           CONTEXT_X7+8
+#define CONTEXT_X9           CONTEXT_X8+8
+#define CONTEXT_X10          CONTEXT_X9+8
+#define CONTEXT_X11          CONTEXT_X10+8
+#define CONTEXT_X12          CONTEXT_X11+8
+#define CONTEXT_X13          CONTEXT_X12+8
+#define CONTEXT_X14          CONTEXT_X13+8
+#define CONTEXT_X15          CONTEXT_X14+8
+#define CONTEXT_X16          CONTEXT_X15+8
+#define CONTEXT_X17          CONTEXT_X16+8
+#define CONTEXT_X18          CONTEXT_X17+8
+#define CONTEXT_X19          CONTEXT_X18+8
+#define CONTEXT_X20          CONTEXT_X19+8
+#define CONTEXT_X21          CONTEXT_X20+8
+#define CONTEXT_X22          CONTEXT_X21+8
+#define CONTEXT_X23          CONTEXT_X22+8
+#define CONTEXT_X24          CONTEXT_X23+8
+#define CONTEXT_X25          CONTEXT_X24+8
+#define CONTEXT_X26          CONTEXT_X25+8
+#define CONTEXT_X27          CONTEXT_X26+8
+#define CONTEXT_X28          CONTEXT_X27+8
+#define CONTEXT_Fp           CONTEXT_X28+8
+#define CONTEXT_Lr           CONTEXT_Fp+8
+#define CONTEXT_Sp           CONTEXT_Lr+8
+#define CONTEXT_Pc           CONTEXT_Sp+8
+#define CONTEXT_NEON_OFFSET  CONTEXT_Pc+8
+#define CONTEXT_V0           0
+#define CONTEXT_V1           CONTEXT_V0+16
+#define CONTEXT_V2           CONTEXT_V1+16
+#define CONTEXT_V3           CONTEXT_V2+16
+#define CONTEXT_V4           CONTEXT_V3+16
+#define CONTEXT_V5           CONTEXT_V4+16
+#define CONTEXT_V6           CONTEXT_V5+16
+#define CONTEXT_V7           CONTEXT_V6+16
+#define CONTEXT_V8           CONTEXT_V7+16
+#define CONTEXT_V9           CONTEXT_V8+16
+#define CONTEXT_V10          CONTEXT_V9+16
+#define CONTEXT_V11          CONTEXT_V10+16
+#define CONTEXT_V12          CONTEXT_V11+16
+#define CONTEXT_V13          CONTEXT_V12+16
+#define CONTEXT_V14          CONTEXT_V13+16
+#define CONTEXT_V15          CONTEXT_V14+16
+#define CONTEXT_V16          CONTEXT_V15+16
+#define CONTEXT_V17          CONTEXT_V16+16
+#define CONTEXT_V18          CONTEXT_V17+16
+#define CONTEXT_V19          CONTEXT_V18+16
+#define CONTEXT_V20          CONTEXT_V19+16
+#define CONTEXT_V21          CONTEXT_V20+16
+#define CONTEXT_V22          CONTEXT_V21+16
+#define CONTEXT_V23          CONTEXT_V22+16
+#define CONTEXT_V24          CONTEXT_V23+16
+#define CONTEXT_V25          CONTEXT_V24+16
+#define CONTEXT_V26          CONTEXT_V25+16
+#define CONTEXT_V27          CONTEXT_V26+16
+#define CONTEXT_V28          CONTEXT_V27+16
+#define CONTEXT_V29          CONTEXT_V28+16
+#define CONTEXT_V30          CONTEXT_V29+16
+#define CONTEXT_V31          CONTEXT_V30+16
+#define CONTEXT_FLOAT_CONTROL_OFFSET  CONTEXT_V31+16
+#define CONTEXT_Fpcr         0
+#define CONTEXT_Fpsr         CONTEXT_Fpcr+8
+#define CONTEXT_Size         ((CONTEXT_NEON_OFFSET + CONTEXT_Fpsr + 8 + 0xf) & ~0xf)
+
+#endif

+ 237 - 0
pal/src/arch/arm64/context2.S

@@ -0,0 +1,237 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+//
+// Implementation of _CONTEXT_CaptureContext for the ARM platform.
+// This function is processor dependent.  It is used by exception handling,
+// and is always apply to the current thread.
+//
+
+#include "unixasmmacros.inc"
+#include "asmconstants.h"
+
+// Incoming:
+//  x0: Context*
+//
+LEAF_ENTRY CONTEXT_CaptureContext, _TEXT
+    PROLOG_STACK_ALLOC 32
+    .cfi_adjust_cfa_offset 32
+
+    // save x1, x2 and x3 on stack so we can use them as scratch
+    stp x1, x2, [sp]
+    str x3, [sp, 16]
+    // save the current flags on the stack
+    mrs x1, nzcv
+    str x1, [sp, 24]
+
+    ldr w1, [x0, CONTEXT_ContextFlags]
+    // clangs assembler doesn't seem to support the mov Wx, imm32 yet
+    movz w2, #0x40, lsl #16
+    movk w2, #0x1
+    mov w3, w2
+    and w2, w1, w2
+    cmp w2, w3
+    b.ne LOCAL_LABEL(Done_CONTEXT_CONTROL)
+
+    // save the cpsr
+    ldr x2, [sp, 24]
+    str w2, [x0, CONTEXT_Cpsr]
+    stp fp, lr, [x0, CONTEXT_Fp]
+    add x2, sp, #32
+    stp x2, lr, [x0, CONTEXT_Sp]
+
+LOCAL_LABEL(Done_CONTEXT_CONTROL):
+    // we dont clobber x1 in the CONTEXT_CONTROL case
+    // ldr w1, [x0, CONTEXT_ContextFlags]
+    // clangs assembler doesn't seem to support the mov Wx, imm32 yet
+    movz w2, #0x40, lsl #16
+    movk w2, #0x2
+    mov w3, w2
+    and w2, w1, w2
+    cmp w2, w3
+    b.ne LOCAL_LABEL(Done_CONTEXT_INTEGER)
+
+    ldp x1, x2,   [sp]
+    ldr x3,       [sp, 16]
+
+    stp x0, x1,   [x0, CONTEXT_X0]
+    stp x2, x3,   [x0, CONTEXT_X2]
+    stp x4, x5,   [x0, CONTEXT_X4]
+    stp x6, x7,   [x0, CONTEXT_X6]
+    stp x8, x9,   [x0, CONTEXT_X8]
+    stp x10, x11, [x0, CONTEXT_X10]
+    stp x12, x13, [x0, CONTEXT_X12]
+    stp x14, x15, [x0, CONTEXT_X14]
+    stp x16, x17, [x0, CONTEXT_X16]
+    stp x18, x19, [x0, CONTEXT_X18]
+    stp x20, x21, [x0, CONTEXT_X20]
+    stp x22, x23, [x0, CONTEXT_X22]
+    stp x24, x25, [x0, CONTEXT_X24]
+    stp x26, x27, [x0, CONTEXT_X26]
+    str x28,      [x0, CONTEXT_X28]
+
+
+LOCAL_LABEL(Done_CONTEXT_INTEGER):
+    ldr w1, [x0, CONTEXT_ContextFlags]
+    // clangs assembler doesn't seem to support the mov Wx, imm32 yet
+    movz w2, #0x40, lsl #16
+    movk w2, #0x4
+    mov w3, w2
+    and w2, w1, w2
+    cmp w2, w3
+    b.ne LOCAL_LABEL(Done_CONTEXT_FLOATING_POINT)
+
+    add x0, x0,   CONTEXT_NEON_OFFSET
+    stp q0, q1,   [x0, CONTEXT_V0]
+    stp q2, q3,   [x0, CONTEXT_V2]
+    stp q4, q5,   [x0, CONTEXT_V4]
+    stp q6, q7,   [x0, CONTEXT_V6]
+    stp q8, q9,   [x0, CONTEXT_V8]
+    stp q10, q11, [x0, CONTEXT_V10]
+    stp q12, q13, [x0, CONTEXT_V12]
+    stp q14, q15, [x0, CONTEXT_V14]
+    stp q16, q17, [x0, CONTEXT_V16]
+    stp q18, q19, [x0, CONTEXT_V18]
+    stp q20, q21, [x0, CONTEXT_V20]
+    stp q22, q23, [x0, CONTEXT_V22]
+    stp q24, q25, [x0, CONTEXT_V24]
+    stp q26, q27, [x0, CONTEXT_V26]
+    stp q28, q29, [x0, CONTEXT_V28]
+    stp q30, q31, [x0, CONTEXT_V30]
+    add x0, x0,   CONTEXT_FLOAT_CONTROL_OFFSET
+    mrs x1, fpcr
+    mrs x2, fpsr
+    stp x1, x2,   [x0, CONTEXT_Fpcr]
+    sub x0, x0,   CONTEXT_FLOAT_CONTROL_OFFSET + CONTEXT_NEON_OFFSET
+
+LOCAL_LABEL(Done_CONTEXT_FLOATING_POINT):
+
+    EPILOG_STACK_FREE 32
+    ret
+LEAF_END CONTEXT_CaptureContext, _TEXT
+
+// Incoming:
+//  x0: Context*
+
+LEAF_ENTRY RtlCaptureContext, _TEXT
+    PROLOG_STACK_ALLOC 16
+    .cfi_adjust_cfa_offset 16
+    str x1, [sp]
+    // same as above, clang doesn't like mov with #imm32
+    // keep this in sync if CONTEXT_FULL changes
+    movz w1, #0x40, lsl #16
+    orr w1, w1, #0x1
+    orr w1, w1, #0x2
+    orr w1, w1, #0x4
+    orr w1, w1, #0x8
+    str w1, [x0, CONTEXT_ContextFlags]
+    ldr x1, [sp]
+    EPILOG_STACK_FREE 16
+    b C_FUNC(CONTEXT_CaptureContext)
+LEAF_END RtlCaptureContext, _TEXT
+
+// Incoming:
+//  x0: Context*
+//  x1: Exception*
+//
+LEAF_ENTRY RtlRestoreContext, _TEXT
+
+#ifdef HAS_ASAN
+    ldr w17, [x0, #(CONTEXT_ContextFlags)]
+    tbz w17, #CONTEXT_CONTROL_BIT, LOCAL_LABEL(Restore_CONTEXT_FLOATING_POINT)
+
+    stp x0, x1, [sp, -16]!
+    bl EXTERNAL_C_FUNC(__asan_handle_no_return)
+    ldp x0, x1, [sp], 16
+
+LOCAL_LABEL(Restore_CONTEXT_FLOATING_POINT):
+#endif
+    // aarch64 specifies:
+    //   IP0 and IP1, the Intra-Procedure Call temporary registers,
+    //   are available for use by e.g. veneers or branch islands during a procedure call.
+    //   They are otherwise corruptible.
+    // Since we cannot control $pc directly, we're going to corrupt x16 and x17
+    // so that we can restore control
+    // since we potentially clobber x0 below, we'll bank it in x16
+    mov x16, x0
+
+    ldr w17, [x16, CONTEXT_ContextFlags]
+    tbz w17, #CONTEXT_FLOATING_POINT_BIT, LOCAL_LABEL(No_Restore_CONTEXT_FLOATING_POINT)
+
+    add x16, x16,   CONTEXT_NEON_OFFSET
+    ldp q0, q1,   [x16, CONTEXT_V0]
+    ldp q2, q3,   [x16, CONTEXT_V2]
+    ldp q4, q5,   [x16, CONTEXT_V4]
+    ldp q6, q7,   [x16, CONTEXT_V6]
+    ldp q8, q9,   [x16, CONTEXT_V8]
+    ldp q10, q11, [x16, CONTEXT_V10]
+    ldp q12, q13, [x16, CONTEXT_V12]
+    ldp q14, q15, [x16, CONTEXT_V14]
+    ldp q16, q17, [x16, CONTEXT_V16]
+    ldp q18, q19, [x16, CONTEXT_V18]
+    ldp q20, q21, [x16, CONTEXT_V20]
+    ldp q22, q23, [x16, CONTEXT_V22]
+    ldp q24, q25, [x16, CONTEXT_V24]
+    ldp q26, q27, [x16, CONTEXT_V26]
+    ldp q28, q29, [x16, CONTEXT_V28]
+    ldp q30, q31, [x16, CONTEXT_V30]
+    add x16, x16, CONTEXT_FLOAT_CONTROL_OFFSET
+    ldp x1, x2,   [x16, CONTEXT_Fpcr]
+    msr fpcr, x1
+    msr fpsr, x2
+    sub x16, x16,   CONTEXT_FLOAT_CONTROL_OFFSET + CONTEXT_NEON_OFFSET
+
+LOCAL_LABEL(No_Restore_CONTEXT_FLOATING_POINT):
+    tbz w17, #CONTEXT_INTEGER_BIT, LOCAL_LABEL(No_Restore_CONTEXT_INTEGER)
+
+    ldp x0, x1,   [x16, CONTEXT_X0]
+    ldp x2, x3,   [x16, CONTEXT_X2]
+    ldp x4, x5,   [x16, CONTEXT_X4]
+    ldp x6, x7,   [x16, CONTEXT_X6]
+    ldp x8, x9,   [x16, CONTEXT_X8]
+    ldp x10, x11, [x16, CONTEXT_X10]
+    ldp x12, x13, [x16, CONTEXT_X12]
+    ldp x14, x15, [x16, CONTEXT_X14]
+    ldp x18, x19, [x16, CONTEXT_X18]
+    ldp x20, x21, [x16, CONTEXT_X20]
+    ldp x22, x23, [x16, CONTEXT_X22]
+    ldp x24, x25, [x16, CONTEXT_X24]
+    ldp x26, x27, [x16, CONTEXT_X26]
+    ldr x28,      [x16, CONTEXT_X28]
+
+LOCAL_LABEL(No_Restore_CONTEXT_INTEGER):
+    tbz w17, #CONTEXT_CONTROL_BIT, LOCAL_LABEL(No_Restore_CONTEXT_CONTROL)
+
+    ldr w17, [x16, CONTEXT_Cpsr]
+    msr nzcv, x17
+    ldp fp, lr, [x16, CONTEXT_Fp]
+    ldp x16, x17, [x16, CONTEXT_Sp] // Context_Pc is right after Context_Sp
+    mov sp, x16
+    br x17
+
+LOCAL_LABEL(No_Restore_CONTEXT_CONTROL):
+    ret
+
+LEAF_END RtlRestoreContext, _TEXT
+
+#ifdef __APPLE__
+
+// Incoming:
+//  x0: Context*
+//  x1: Exception*
+//
+LEAF_ENTRY RestoreCompleteContext, _TEXT
+    // We cannot restore all registers in the user mode code, so we rely on a help from kernel here. 
+    // The following instruction is an undefined instruction. In the hardware exception handler, we check
+    // if the faulting address is the RtlRestoreContext and in case it is, we update the context of
+    // the faulting thread using the CONTEXT pointed to by the x0 register.
+    // While this could be used for the full fidelity RtlRestoreContext implementation, it is too
+    // expensive for general usage of the RtlRestoreContext.
+    UDF #0
+LEAF_END RestoreCompleteContext, _TEXT
+
+#endif // __APPLE__

+ 15 - 0
pal/src/arch/arm64/debugbreak.S

@@ -0,0 +1,15 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+#include "unixasmmacros.inc"
+
+LEAF_ENTRY DBG_DebugBreak, _TEXT
+    EMIT_BREAKPOINT
+    ret
+LEAF_END_MARKED DBG_DebugBreak, _TEXT
+

+ 50 - 0
pal/src/arch/arm64/dispatchexceptionwrapper.S

@@ -0,0 +1,50 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+//
+// Implementation of the PAL_DispatchExceptionWrapper that is
+// interposed between a function that caused a hardware fault
+// and PAL_DispatchException that throws an SEH exception for
+// the fault, to make the stack unwindable.
+//
+
+#include "unixasmmacros.inc"
+
+// Offset of the return address from the PAL_DispatchException in the PAL_DispatchExceptionWrapper
+.globl C_FUNC(PAL_DispatchExceptionReturnOffset)
+C_FUNC(PAL_DispatchExceptionReturnOffset):
+    .int LOCAL_LABEL(PAL_DispatchExceptionReturn) - C_FUNC(PAL_DispatchExceptionWrapper)
+
+//
+// PAL_DispatchExceptionWrapper will never be called; it only serves
+// to be referenced from a stack frame on the faulting thread.  Its
+// unwinding behavior is equivalent to any standard function.
+// It is analogous to the following source file.
+//
+// extern "C" void PAL_DispatchException(CONTEXT *pContext, EXCEPTION_RECORD *pExceptionRecord, MachExceptionInfo *pMachExceptionInfo);
+//
+// extern "C" void PAL_DispatchExceptionWrapper()
+// {
+//     CONTEXT Context;
+//     EXCEPTION_RECORD ExceptionRecord;
+//     MachExceptionInfo MachExceptionInfo;
+//     PAL_DispatchException(&Context, &ExceptionRecord, &MachExceptionInfo);
+// }
+//
+
+NESTED_ENTRY PAL_DispatchExceptionWrapper, _TEXT, NoHandler
+    PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -16
+    // Should never actually run
+    EMIT_BREAKPOINT
+    bl      EXTERNAL_C_FUNC(PAL_DispatchException)
+LOCAL_LABEL(PAL_DispatchExceptionReturn):
+    // Should never return
+    EMIT_BREAKPOINT
+    EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 16
+    ret
+NESTED_END PAL_DispatchExceptionWrapper, _TEXT

+ 0 - 50
pal/src/arch/i386/activationhandlerwrapper.S

@@ -1,50 +0,0 @@
-// -------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-// -------------------------------------------------------------------------------------------------------
-
-.intel_syntax noprefix
-#include "unixasmmacros.inc"
-#include "asmconstants.h"
-
-#ifdef BIT64
-// Offset of the return address from the ActivationHandler in the ActivationHandlerWrapper
-.globl C_FUNC(ActivationHandlerReturnOffset)
-C_FUNC(ActivationHandlerReturnOffset):
-    .int LOCAL_LABEL(ActivationHandlerReturn)-C_FUNC(ActivationHandlerWrapper)
-
-NESTED_ENTRY ActivationHandlerWrapper, _TEXT, NoHandler
-    push_nonvol_reg rbp
-    mov     rbp, rsp
-    alloc_stack (CONTEXT_Size)
-    set_cfa_register rbp, (2*8)
-    mov     rdi, rsp
-    int3
-    call    C_FUNC(ActivationHandler)
-LOCAL_LABEL(ActivationHandlerReturn):
-    int3
-    free_stack (CONTEXT_Size)
-    pop_nonvol_reg rbp
-    ret
-NESTED_END ActivationHandlerWrapper, _TEXT
-
-#else
-
-// Offset of the return address from the ActivationHandler in the ActivationHandlerWrapper
-.globl C_FUNC(ActivationHandlerReturnOffset)
-C_FUNC(ActivationHandlerReturnOffset):
-    .int LOCAL_LABEL(ActivationHandlerReturn)-C_FUNC(ActivationHandlerWrapper)
-
-.globl C_FUNC(ActivationHandlerWrapper)
-C_FUNC(ActivationHandlerWrapper):
-    push    ebp
-    mov     ebp, esp
-    mov     edi, esp
-    int3
-    call    C_FUNC(ActivationHandler)
-LOCAL_LABEL(ActivationHandlerReturn):
-    int3
-    pop     ebp
-    ret
-
-#endif // BIT64

+ 9 - 0
pal/src/config.h.in

@@ -1,3 +1,11 @@
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
 #ifndef _PAL_CONFIG_H_INCLUDED
 #ifndef _PAL_CONFIG_H_INCLUDED
 #define _PAL_CONFIG_H_INCLUDED 1
 #define _PAL_CONFIG_H_INCLUDED 1
 
 
@@ -22,6 +30,7 @@
 #cmakedefine01 HAVE_PTHREAD_CONTINUE_NP
 #cmakedefine01 HAVE_PTHREAD_CONTINUE_NP
 #cmakedefine01 HAVE_PTHREAD_ATTR_GET_NP
 #cmakedefine01 HAVE_PTHREAD_ATTR_GET_NP
 #cmakedefine01 HAVE_PTHREAD_GETATTR_NP
 #cmakedefine01 HAVE_PTHREAD_GETATTR_NP
+#cmakedefine01 HAVE_PTHREAD_GETCPUCLOCKID
 #cmakedefine01 HAVE_PTHREAD_SIGQUEUE
 #cmakedefine01 HAVE_PTHREAD_SIGQUEUE
 #cmakedefine01 HAVE_SIGRETURN
 #cmakedefine01 HAVE_SIGRETURN
 #cmakedefine01 HAVE__THREAD_SYS_SIGRETURN
 #cmakedefine01 HAVE__THREAD_SYS_SIGRETURN

+ 1 - 0
pal/src/configure.cmake

@@ -44,6 +44,7 @@ check_library_exists(pthread pthread_continue_np "" HAVE_PTHREAD_CONTINUE_NP)
 check_library_exists(pthread pthread_resume_np "" HAVE_PTHREAD_RESUME_NP)
 check_library_exists(pthread pthread_resume_np "" HAVE_PTHREAD_RESUME_NP)
 check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
 check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
 check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
 check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
+check_library_exists(pthread pthread_getcpuclockid "" HAVE_PTHREAD_GETCPUCLOCKID)
 check_library_exists(pthread pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
 check_library_exists(pthread pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
 check_function_exists(sigreturn HAVE_SIGRETURN)
 check_function_exists(sigreturn HAVE_SIGRETURN)
 check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)
 check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)

File diff ditekan karena terlalu besar
+ 288 - 369
pal/src/exception/machexception.cpp


+ 7 - 7
pal/src/exception/machexception.h

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -26,8 +29,6 @@ extern "C"
 {
 {
 #endif // __cplusplus
 #endif // __cplusplus
 
 
-#define HIJACK_ON_SIGNAL 1
-
 // List of exception types we will be watching for
 // List of exception types we will be watching for
 // NOTE: if you change any of these, you need to adapt s_nMachExceptionPortsMax in thread.hpp
 // NOTE: if you change any of these, you need to adapt s_nMachExceptionPortsMax in thread.hpp
 #define PAL_EXC_ILLEGAL_MASK   (EXC_MASK_BAD_INSTRUCTION | EXC_MASK_EMULATION)
 #define PAL_EXC_ILLEGAL_MASK   (EXC_MASK_BAD_INSTRUCTION | EXC_MASK_EMULATION)
@@ -37,7 +38,6 @@ extern "C"
 
 
 // Process and thread initialization/cleanup/context routines
 // Process and thread initialization/cleanup/context routines
 BOOL SEHInitializeMachExceptions();
 BOOL SEHInitializeMachExceptions();
-void SEHCleanupExceptionPort (void);
 void MachExceptionInitializeDebug(void);
 void MachExceptionInitializeDebug(void);
 PAL_NORETURN void MachSetThreadContext(CONTEXT *lpContext);
 PAL_NORETURN void MachSetThreadContext(CONTEXT *lpContext);
 
 

+ 29 - 329
pal/src/exception/machmessage.cpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -55,12 +58,6 @@ void MachMessage::Receive(mach_port_t hPort)
     {
     {
     case SET_THREAD_MESSAGE_ID:
     case SET_THREAD_MESSAGE_ID:
     case FORWARD_EXCEPTION_MESSAGE_ID:
     case FORWARD_EXCEPTION_MESSAGE_ID:
-    case EXCEPTION_RAISE_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
@@ -99,9 +96,6 @@ bool MachMessage::IsExceptionNotification()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
@@ -116,9 +110,6 @@ bool MachMessage::IsExceptionReply()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
@@ -143,18 +134,6 @@ const char *MachMessage::GetMessageTypeName()
         return "SET_THREAD";
         return "SET_THREAD";
     case FORWARD_EXCEPTION_MESSAGE_ID:
     case FORWARD_EXCEPTION_MESSAGE_ID:
         return "FORWARD_EXCEPTION";
         return "FORWARD_EXCEPTION";
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        return "EXCEPTION_RAISE";
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-        return "EXCEPTION_RAISE_REPLY";
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return "EXCEPTION_RAISE_STATE";
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        return "EXCEPTION_RAISE_STATE_REPLY";
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return "EXCEPTION_RAISE_STATE_IDENTITY";
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        return "EXCEPTION_RAISE_STATE_IDENTITY_REPLY";
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         return "EXCEPTION_RAISE_64";
         return "EXCEPTION_RAISE_64";
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
@@ -202,25 +181,11 @@ void MachMessage::GetPorts(bool fCalculate, bool fValidThread)
         m_hThread = m_pMessage->data.forward_exception.thread;
         m_hThread = m_pMessage->data.forward_exception.thread;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_hThread = m_pMessage->data.raise.thread_port.name;
-        m_hTask = m_pMessage->data.raise.task_port.name;
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_hThread = m_pMessage->data.raise_64.thread_port.name;
         m_hThread = m_pMessage->data.raise_64.thread_port.name;
         m_hTask = m_pMessage->data.raise_64.task_port.name;
         m_hTask = m_pMessage->data.raise_64.task_port.name;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        if (fCalculate && m_hThread == MACH_PORT_NULL)
-        {
-            // This is a tricky case since the message itself doesn't contain the target thread.
-            m_hThread = GetThreadFromState(m_pMessage->data.raise_state.flavor,
-                                           m_pMessage->data.raise_state.old_state);
-        }
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         if (fCalculate && m_hThread == MACH_PORT_NULL)
         if (fCalculate && m_hThread == MACH_PORT_NULL)
         {
         {
@@ -230,11 +195,6 @@ void MachMessage::GetPorts(bool fCalculate, bool fValidThread)
         }
         }
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_hThread = m_pMessage->data.raise_state_identity.thread_port.name;
-        m_hTask = m_pMessage->data.raise_state_identity.task_port.name;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_hThread = m_pMessage->data.raise_state_identity_64.thread_port.name;
         m_hThread = m_pMessage->data.raise_state_identity_64.thread_port.name;
         m_hTask = m_pMessage->data.raise_state_identity_64.task_port.name;
         m_hTask = m_pMessage->data.raise_state_identity_64.task_port.name;
@@ -273,21 +233,12 @@ exception_type_t MachMessage::GetException()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        return m_pMessage->data.raise.exception;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         return m_pMessage->data.raise_64.exception;
         return m_pMessage->data.raise_64.exception;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return m_pMessage->data.raise_state.exception;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_64.exception;
         return m_pMessage->data.raise_state_64.exception;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_identity.exception;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_64.exception;
         return m_pMessage->data.raise_state_identity_64.exception;
 
 
@@ -301,21 +252,12 @@ int MachMessage::GetExceptionCodeCount()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        return m_pMessage->data.raise.code_count;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         return m_pMessage->data.raise_64.code_count;
         return m_pMessage->data.raise_64.code_count;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return m_pMessage->data.raise_state.code_count;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_64.code_count;
         return m_pMessage->data.raise_state_64.code_count;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_identity.code_count;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_64.code_count;
         return m_pMessage->data.raise_state_identity_64.code_count;
 
 
@@ -325,7 +267,7 @@ int MachMessage::GetExceptionCodeCount()
 }
 }
 
 
 // Get the exception sub-code at the specified zero-based index for an exception notification message.
 // Get the exception sub-code at the specified zero-based index for an exception notification message.
-MACH_EH_TYPE(exception_data_type_t) MachMessage::GetExceptionCode(int iIndex)
+mach_exception_data_type_t MachMessage::GetExceptionCode(int iIndex)
 {
 {
     if (iIndex < 0 || iIndex >= GetExceptionCodeCount())
     if (iIndex < 0 || iIndex >= GetExceptionCodeCount())
     {
     {
@@ -334,21 +276,12 @@ MACH_EH_TYPE(exception_data_type_t) MachMessage::GetExceptionCode(int iIndex)
 
 
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        return (MACH_EH_TYPE(exception_data_type_t))m_pMessage->data.raise.code[iIndex];
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         return m_pMessage->data.raise_64.code[iIndex];
         return m_pMessage->data.raise_64.code[iIndex];
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return (MACH_EH_TYPE(exception_data_type_t))m_pMessage->data.raise_state.code[iIndex];
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_64.code[iIndex];
         return m_pMessage->data.raise_state_64.code[iIndex];
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return (MACH_EH_TYPE(exception_data_type_t))m_pMessage->data.raise_state_identity.code[iIndex];
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_64.code[iIndex];
         return m_pMessage->data.raise_state_identity_64.code[iIndex];
 
 
@@ -363,33 +296,19 @@ thread_state_flavor_t MachMessage::GetThreadStateFlavor()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         return THREAD_STATE_NONE;
         return THREAD_STATE_NONE;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return m_pMessage->data.raise_state.flavor;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_64.flavor;
         return m_pMessage->data.raise_state_64.flavor;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_identity.flavor;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_64.flavor;
         return m_pMessage->data.raise_state_identity_64.flavor;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_reply.flavor;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_reply_64.flavor;
         return m_pMessage->data.raise_state_reply_64.flavor;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_identity_reply.flavor;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_reply_64.flavor;
         return m_pMessage->data.raise_state_identity_reply_64.flavor;
 
 
@@ -409,26 +328,11 @@ mach_msg_type_number_t MachMessage::GetThreadState(thread_state_flavor_t eFlavor
 
 
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         // No state in the message, fall through to get it directly from the thread.
         // No state in the message, fall through to get it directly from the thread.
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-    {
-        // There's a state in the message, but we need to check that the flavor matches what the caller's
-        // after (if not we'll fall through and get the correct flavor below).
-        if (m_pMessage->data.raise_state.flavor == eFlavor)
-        {
-            count = m_pMessage->data.raise_state.old_state_count;
-            memcpy(pState, m_pMessage->data.raise_state.old_state, count * sizeof(natural_t));
-            return count;
-        }
-        break;
-    }
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     {
     {
         // There's a state in the message, but we need to check that the flavor matches what the caller's
         // There's a state in the message, but we need to check that the flavor matches what the caller's
@@ -442,19 +346,6 @@ mach_msg_type_number_t MachMessage::GetThreadState(thread_state_flavor_t eFlavor
         break;
         break;
     }
     }
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-    {
-        // There's a state in the message, but we need to check that the flavor matches what the caller's
-        // after (if not we'll fall through and get the correct flavor below).
-        if (m_pMessage->data.raise_state_identity.flavor == eFlavor)
-        {
-            count = m_pMessage->data.raise_state_identity.old_state_count;
-            memcpy(pState, m_pMessage->data.raise_state_identity.old_state, count * sizeof(natural_t));
-            return count;
-        }
-        break;
-    }
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     {
     {
         // There's a state in the message, but we need to check that the flavor matches what the caller's
         // There's a state in the message, but we need to check that the flavor matches what the caller's
@@ -468,19 +359,6 @@ mach_msg_type_number_t MachMessage::GetThreadState(thread_state_flavor_t eFlavor
         break;
         break;
     }
     }
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-    {
-        // There's a state in the message, but we need to check that the flavor matches what the caller's
-        // after (if not we'll fall through and get the correct flavor below).
-        if (m_pMessage->data.raise_state_reply.flavor == eFlavor)
-        {
-            count = m_pMessage->data.raise_state_reply.new_state_count;
-            memcpy(pState, m_pMessage->data.raise_state_reply.new_state, count * sizeof(natural_t));
-            return count;
-        }
-        break;
-    }
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     {
     {
         // There's a state in the message, but we need to check that the flavor matches what the caller's
         // There's a state in the message, but we need to check that the flavor matches what the caller's
@@ -494,19 +372,6 @@ mach_msg_type_number_t MachMessage::GetThreadState(thread_state_flavor_t eFlavor
         break;
         break;
     }
     }
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-    {
-        // There's a state in the message, but we need to check that the flavor matches what the caller's
-        // after (if not we'll fall through and get the correct flavor below).
-        if (m_pMessage->data.raise_state_identity_reply.flavor == eFlavor)
-        {
-            count = m_pMessage->data.raise_state_identity_reply.new_state_count;
-            memcpy(pState, m_pMessage->data.raise_state_identity_reply.new_state, count * sizeof(natural_t));
-            return count;
-        }
-        break;
-    }
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     {
     {
         // There's a state in the message, but we need to check that the flavor matches what the caller's
         // There's a state in the message, but we need to check that the flavor matches what the caller's
@@ -538,21 +403,12 @@ kern_return_t MachMessage::GetReturnCode()
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-        return m_pMessage->data.raise_reply.ret;
-
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         return m_pMessage->data.raise_reply_64.ret;
         return m_pMessage->data.raise_reply_64.ret;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_reply.ret;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_reply_64.ret;
         return m_pMessage->data.raise_state_reply_64.ret;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        return m_pMessage->data.raise_state_identity_reply.ret;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         return m_pMessage->data.raise_state_identity_reply_64.ret;
         return m_pMessage->data.raise_state_identity_reply_64.ret;
 
 
@@ -807,17 +663,6 @@ void MachMessage::InitFixedFields()
     case FORWARD_EXCEPTION_MESSAGE_ID:
     case FORWARD_EXCEPTION_MESSAGE_ID:
         break;
         break;
 
 
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->data.raise.msgh_body.msgh_descriptor_count = 0;
-        m_pMessage->data.raise.ndr = NDR_record;
-        m_pMessage->data.raise.task_port.name = mach_task_self();
-        m_pMessage->data.raise.task_port.pad1 = 0;
-        m_pMessage->data.raise.task_port.pad2 = 0;
-        m_pMessage->data.raise.task_port.disposition = MACH_MSG_TYPE_COPY_SEND;
-        m_pMessage->data.raise.task_port.type = MACH_MSG_PORT_DESCRIPTOR;
-        m_hTask = mach_task_self();
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->data.raise_64.msgh_body.msgh_descriptor_count = 0;
         m_pMessage->data.raise_64.msgh_body.msgh_descriptor_count = 0;
         m_pMessage->data.raise_64.ndr = NDR_record;
         m_pMessage->data.raise_64.ndr = NDR_record;
@@ -829,25 +674,10 @@ void MachMessage::InitFixedFields()
         m_hTask = mach_task_self();
         m_hTask = mach_task_self();
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->data.raise_state.ndr = NDR_record;
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->data.raise_state_64.ndr = NDR_record;
         m_pMessage->data.raise_state_64.ndr = NDR_record;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.msgh_body.msgh_descriptor_count = 0;
-        m_pMessage->data.raise_state_identity.ndr = NDR_record;
-        m_pMessage->data.raise_state_identity.task_port.name = mach_task_self();
-        m_pMessage->data.raise_state_identity.task_port.pad1 = 0;
-        m_pMessage->data.raise_state_identity.task_port.pad2 = 0;
-        m_pMessage->data.raise_state_identity.task_port.disposition = MACH_MSG_TYPE_COPY_SEND;
-        m_pMessage->data.raise_state_identity.task_port.type = MACH_MSG_PORT_DESCRIPTOR;
-        m_hTask = mach_task_self();
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.msgh_body.msgh_descriptor_count = 0;
         m_pMessage->data.raise_state_identity_64.msgh_body.msgh_descriptor_count = 0;
         m_pMessage->data.raise_state_identity_64.ndr = NDR_record;
         m_pMessage->data.raise_state_identity_64.ndr = NDR_record;
@@ -859,26 +689,14 @@ void MachMessage::InitFixedFields()
         m_hTask = mach_task_self();
         m_hTask = mach_task_self();
         break;
         break;
 
 
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_reply.ndr = NDR_record;
-        break;
-
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_reply_64.ndr = NDR_record;
         m_pMessage->data.raise_reply_64.ndr = NDR_record;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_reply.ndr = NDR_record;
-        break;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_reply_64.ndr = NDR_record;
         m_pMessage->data.raise_state_reply_64.ndr = NDR_record;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity_reply.ndr = NDR_record;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_reply_64.ndr = NDR_record;
         m_pMessage->data.raise_state_identity_reply_64.ndr = NDR_record;
         break;
         break;
@@ -916,64 +734,32 @@ void MachMessage::InitMessageSize()
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(forward_exception_request_t);
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(forward_exception_request_t);
         break;
         break;
 
 
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_notification_t);
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_notification_64_t);
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_notification_64_t);
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
-            offsetof(exception_raise_state_notification_t, old_state) +
-            (m_pMessage->data.raise_state.old_state_count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
             offsetof(exception_raise_state_notification_64_t, old_state) +
             offsetof(exception_raise_state_notification_64_t, old_state) +
             (m_pMessage->data.raise_state_64.old_state_count * sizeof(natural_t));
             (m_pMessage->data.raise_state_64.old_state_count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
-            offsetof(exception_raise_state_identity_notification_t, old_state) +
-            (m_pMessage->data.raise_state_identity.old_state_count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
             offsetof(exception_raise_state_identity_notification_64_t, old_state) +
             offsetof(exception_raise_state_identity_notification_64_t, old_state) +
             (m_pMessage->data.raise_state_identity_64.old_state_count * sizeof(natural_t));
             (m_pMessage->data.raise_state_identity_64.old_state_count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_reply_t);
-        break;
-
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_reply_64_t);
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) + sizeof(exception_raise_reply_64_t);
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
-            offsetof(exception_raise_state_reply_t, new_state) +
-            (m_pMessage->data.raise_state_reply.new_state_count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
             offsetof(exception_raise_state_reply_64_t, new_state) +
             offsetof(exception_raise_state_reply_64_t, new_state) +
             (m_pMessage->data.raise_state_reply_64.new_state_count * sizeof(natural_t));
             (m_pMessage->data.raise_state_reply_64.new_state_count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
-            offsetof(exception_raise_state_identity_reply_t, new_state) +
-            (m_pMessage->data.raise_state_identity_reply.new_state_count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
         m_pMessage->header.msgh_size = sizeof(mach_msg_header_t) +
             offsetof(exception_raise_state_identity_reply_64_t, new_state) +
             offsetof(exception_raise_state_identity_reply_64_t, new_state) +
@@ -1014,6 +800,10 @@ thread_act_t MachMessage::GetThreadFromState(thread_state_flavor_t eFlavor, thre
     case x86_THREAD_STATE64:
     case x86_THREAD_STATE64:
         targetSP = ((x86_thread_state64_t*)pState)->__rsp;
         targetSP = ((x86_thread_state64_t*)pState)->__rsp;
         break;
         break;
+#elif defined(_ARM64_)
+    case ARM_THREAD_STATE64:
+        targetSP = arm_thread_state64_get_sp(*(arm_thread_state64_t*)pState);
+        break;
 #else
 #else
 #error Unexpected architecture.
 #error Unexpected architecture.
 #endif
 #endif
@@ -1032,9 +822,17 @@ thread_act_t MachMessage::GetThreadFromState(thread_state_flavor_t eFlavor, thre
     for (mach_msg_type_number_t i = 0; i < cThreads; i++)
     for (mach_msg_type_number_t i = 0; i < cThreads; i++)
     {
     {
         // Get the general register state of each thread.
         // Get the general register state of each thread.
+#if defined(_AMD64_)
         x86_thread_state_t threadState;
         x86_thread_state_t threadState;
         mach_msg_type_number_t count = x86_THREAD_STATE_COUNT;
         mach_msg_type_number_t count = x86_THREAD_STATE_COUNT;
         machret = thread_get_state(pThreads[i], x86_THREAD_STATE, (thread_state_t)&threadState, &count);
         machret = thread_get_state(pThreads[i], x86_THREAD_STATE, (thread_state_t)&threadState, &count);
+#elif defined(_ARM64_)
+        arm_thread_state64_t threadState;
+        mach_msg_type_number_t count = ARM_THREAD_STATE64_COUNT;
+        machret = thread_get_state(pThreads[i], ARM_THREAD_STATE64, (thread_state_t)&threadState, &count);
+#else
+#error Unexpected architecture
+#endif
         if (machret == KERN_SUCCESS)
         if (machret == KERN_SUCCESS)
         {
         {
             // If a thread has the same SP as our target it should be the same thread (otherwise we have two
             // If a thread has the same SP as our target it should be the same thread (otherwise we have two
@@ -1045,6 +843,8 @@ thread_act_t MachMessage::GetThreadFromState(thread_state_flavor_t eFlavor, thre
             if (threadState.uts.ts32.esp == targetSP)
             if (threadState.uts.ts32.esp == targetSP)
 #elif defined(_AMD64_)
 #elif defined(_AMD64_)
             if (threadState.uts.ts64.__rsp == targetSP)
             if (threadState.uts.ts64.__rsp == targetSP)
+#elif defined(_ARM64_)
+            if (arm_thread_state64_get_sp(threadState) == targetSP)
 #else
 #else
 #error Unexpected architecture.
 #error Unexpected architecture.
 #endif
 #endif
@@ -1056,6 +856,11 @@ thread_act_t MachMessage::GetThreadFromState(thread_state_flavor_t eFlavor, thre
                 CHECK_MACH("mach_port_mod_refs()", machret);
                 CHECK_MACH("mach_port_mod_refs()", machret);
 
 
                 // Deallocate the thread list now we're done with it.
                 // Deallocate the thread list now we're done with it.
+                for (mach_msg_type_number_t j = 0; j < cThreads; j++)
+                {
+                    machret = mach_port_deallocate(mach_task_self(), pThreads[j]);
+                    CHECK_MACH("mach_port_deallocate()", machret);
+                }
                 machret = vm_deallocate(mach_task_self(), (vm_address_t)pThreads, cThreads * sizeof(thread_act_t));
                 machret = vm_deallocate(mach_task_self(), (vm_address_t)pThreads, cThreads * sizeof(thread_act_t));
                 CHECK_MACH("vm_deallocate()", machret);
                 CHECK_MACH("vm_deallocate()", machret);
 
 
@@ -1069,17 +874,11 @@ thread_act_t MachMessage::GetThreadFromState(thread_state_flavor_t eFlavor, thre
     NONPAL_RETAIL_ASSERT("Failed to locate thread from state.");
     NONPAL_RETAIL_ASSERT("Failed to locate thread from state.");
 }
 }
 
 
-// Transform a exception handler behavior type into the corresponding Mach message ID for the notification.
+// Transform an exception handler behavior type into the corresponding Mach message ID for the notification.
 mach_msg_id_t MachMessage::MapBehaviorToNotificationType(exception_behavior_t eBehavior)
 mach_msg_id_t MachMessage::MapBehaviorToNotificationType(exception_behavior_t eBehavior)
 {
 {
     switch ((uint)eBehavior)
     switch ((uint)eBehavior)
     {
     {
-    case EXCEPTION_DEFAULT:
-        return EXCEPTION_RAISE_MESSAGE_ID;
-    case EXCEPTION_STATE:
-        return EXCEPTION_RAISE_STATE_MESSAGE_ID;
-    case EXCEPTION_STATE_IDENTITY:
-        return EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID;
     case MACH_EXCEPTION_CODES|EXCEPTION_DEFAULT:
     case MACH_EXCEPTION_CODES|EXCEPTION_DEFAULT:
         return EXCEPTION_RAISE_64_MESSAGE_ID;
         return EXCEPTION_RAISE_64_MESSAGE_ID;
     case MACH_EXCEPTION_CODES|EXCEPTION_STATE:
     case MACH_EXCEPTION_CODES|EXCEPTION_STATE:
@@ -1096,12 +895,6 @@ mach_msg_id_t MachMessage::MapNotificationToReplyType(mach_msg_id_t eNotificatio
 {
 {
     switch (eNotificationType)
     switch (eNotificationType)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        return EXCEPTION_RAISE_REPLY_MESSAGE_ID;
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        return EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID;
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        return EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID;
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         return EXCEPTION_RAISE_REPLY_64_MESSAGE_ID;
         return EXCEPTION_RAISE_REPLY_64_MESSAGE_ID;
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
@@ -1120,15 +913,6 @@ void MachMessage::SetThread(thread_act_t thread)
 
 
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->data.raise.thread_port.name = thread;
-        m_pMessage->data.raise.thread_port.pad1 = 0;
-        m_pMessage->data.raise.thread_port.pad2 = 0;
-        m_pMessage->data.raise.thread_port.disposition = MACH_MSG_TYPE_COPY_SEND;
-        m_pMessage->data.raise.thread_port.type = MACH_MSG_PORT_DESCRIPTOR;
-        fSet = true;
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->data.raise_64.thread_port.name = thread;
         m_pMessage->data.raise_64.thread_port.name = thread;
         m_pMessage->data.raise_64.thread_port.pad1 = 0;
         m_pMessage->data.raise_64.thread_port.pad1 = 0;
@@ -1138,20 +922,10 @@ void MachMessage::SetThread(thread_act_t thread)
         fSet = true;
         fSet = true;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         // No thread field in RAISE_STATE messages.
         // No thread field in RAISE_STATE messages.
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.thread_port.name = thread;
-        m_pMessage->data.raise_state_identity.thread_port.pad1 = 0;
-        m_pMessage->data.raise_state_identity.thread_port.pad2 = 0;
-        m_pMessage->data.raise_state_identity.thread_port.disposition = MACH_MSG_TYPE_COPY_SEND;
-        m_pMessage->data.raise_state_identity.thread_port.type = MACH_MSG_PORT_DESCRIPTOR;
-        fSet = true;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.thread_port.name = thread;
         m_pMessage->data.raise_state_identity_64.thread_port.name = thread;
         m_pMessage->data.raise_state_identity_64.thread_port.pad1 = 0;
         m_pMessage->data.raise_state_identity_64.thread_port.pad1 = 0;
@@ -1178,26 +952,14 @@ void MachMessage::SetException(exception_type_t eException)
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->data.raise.exception = eException;
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->data.raise_64.exception = eException;
         m_pMessage->data.raise_64.exception = eException;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->data.raise_state.exception = eException;
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->data.raise_state_64.exception = eException;
         m_pMessage->data.raise_state_64.exception = eException;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.exception = eException;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.exception = eException;
         m_pMessage->data.raise_state_identity_64.exception = eException;
         break;
         break;
@@ -1212,26 +974,14 @@ void MachMessage::SetExceptionCodeCount(int cCodes)
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->data.raise.code_count = cCodes;
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->data.raise_64.code_count = cCodes;
         m_pMessage->data.raise_64.code_count = cCodes;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->data.raise_state.code_count = cCodes;
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->data.raise_state_64.code_count = cCodes;
         m_pMessage->data.raise_state_64.code_count = cCodes;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.code_count = cCodes;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.code_count = cCodes;
         m_pMessage->data.raise_state_identity_64.code_count = cCodes;
         break;
         break;
@@ -1242,7 +992,7 @@ void MachMessage::SetExceptionCodeCount(int cCodes)
 }
 }
 
 
 // Set exception sub-code in an exception notification message.
 // Set exception sub-code in an exception notification message.
-void MachMessage::SetExceptionCode(int iIndex, MACH_EH_TYPE(exception_data_type_t) iCode)
+void MachMessage::SetExceptionCode(int iIndex, mach_exception_data_type_t iCode)
 {
 {
     if (iIndex < 0 || iIndex > 1)
     if (iIndex < 0 || iIndex > 1)
         NONPAL_RETAIL_ASSERT("Exception code index out of range");
         NONPAL_RETAIL_ASSERT("Exception code index out of range");
@@ -1252,26 +1002,14 @@ void MachMessage::SetExceptionCode(int iIndex, MACH_EH_TYPE(exception_data_type_
 
 
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-        m_pMessage->data.raise.code[iIndex] = (int)iCode;
-        break;
-
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
         m_pMessage->data.raise_64.code[iIndex] = iCode;
         m_pMessage->data.raise_64.code[iIndex] = iCode;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->data.raise_state.code[iIndex] = (int)iCode;
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->data.raise_state_64.code[iIndex] = iCode;
         m_pMessage->data.raise_state_64.code[iIndex] = iCode;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.code[iIndex] = (int)iCode;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.code[iIndex] = iCode;
         m_pMessage->data.raise_state_identity_64.code[iIndex] = iCode;
         break;
         break;
@@ -1286,26 +1024,14 @@ void MachMessage::SetReturnCode(kern_return_t eReturnCode)
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_reply.ret = eReturnCode;
-        break;
-
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_reply_64.ret = eReturnCode;
         m_pMessage->data.raise_reply_64.ret = eReturnCode;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_reply.ret = eReturnCode;
-        break;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_reply_64.ret = eReturnCode;
         m_pMessage->data.raise_state_reply_64.ret = eReturnCode;
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity_reply.ret = eReturnCode;
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_reply_64.ret = eReturnCode;
         m_pMessage->data.raise_state_identity_reply_64.ret = eReturnCode;
         break;
         break;
@@ -1320,55 +1046,29 @@ void MachMessage::SetThreadState(thread_state_flavor_t eFlavor, thread_state_t p
 {
 {
     switch (m_pMessage->header.msgh_id)
     switch (m_pMessage->header.msgh_id)
     {
     {
-    case EXCEPTION_RAISE_MESSAGE_ID:
-    case EXCEPTION_RAISE_REPLY_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_REPLY_64_MESSAGE_ID:
         // No thread state in RAISE or RAISE_REPLY messages.
         // No thread state in RAISE or RAISE_REPLY messages.
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_MESSAGE_ID:
-        m_pMessage->data.raise_state.flavor = eFlavor;
-        m_pMessage->data.raise_state.old_state_count = count;
-        memcpy(m_pMessage->data.raise_state.old_state, pState, count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_64_MESSAGE_ID:
         m_pMessage->data.raise_state_64.flavor = eFlavor;
         m_pMessage->data.raise_state_64.flavor = eFlavor;
         m_pMessage->data.raise_state_64.old_state_count = count;
         m_pMessage->data.raise_state_64.old_state_count = count;
         memcpy(m_pMessage->data.raise_state_64.old_state, pState, count * sizeof(natural_t));
         memcpy(m_pMessage->data.raise_state_64.old_state, pState, count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity.flavor = eFlavor;
-        m_pMessage->data.raise_state_identity.old_state_count = count;
-        memcpy(m_pMessage->data.raise_state_identity.old_state, pState, count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_64.flavor = eFlavor;
         m_pMessage->data.raise_state_identity_64.flavor = eFlavor;
         m_pMessage->data.raise_state_identity_64.old_state_count = count;
         m_pMessage->data.raise_state_identity_64.old_state_count = count;
         memcpy(m_pMessage->data.raise_state_identity_64.old_state, pState, count * sizeof(natural_t));
         memcpy(m_pMessage->data.raise_state_identity_64.old_state, pState, count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_reply.flavor = eFlavor;
-        m_pMessage->data.raise_state_reply.new_state_count = count;
-        memcpy(m_pMessage->data.raise_state_reply.new_state, pState, count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_reply_64.flavor = eFlavor;
         m_pMessage->data.raise_state_reply_64.flavor = eFlavor;
         m_pMessage->data.raise_state_reply_64.new_state_count = count;
         m_pMessage->data.raise_state_reply_64.new_state_count = count;
         memcpy(m_pMessage->data.raise_state_reply_64.new_state, pState, count * sizeof(natural_t));
         memcpy(m_pMessage->data.raise_state_reply_64.new_state, pState, count * sizeof(natural_t));
         break;
         break;
 
 
-    case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID:
-        m_pMessage->data.raise_state_identity_reply.flavor = eFlavor;
-        m_pMessage->data.raise_state_identity_reply.new_state_count = count;
-        memcpy(m_pMessage->data.raise_state_identity_reply.new_state, pState, count * sizeof(natural_t));
-        break;
-
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
     case EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID:
         m_pMessage->data.raise_state_identity_reply_64.flavor = eFlavor;
         m_pMessage->data.raise_state_identity_reply_64.flavor = eFlavor;
         m_pMessage->data.raise_state_identity_reply_64.new_state_count = count;
         m_pMessage->data.raise_state_identity_reply_64.new_state_count = count;

+ 25 - 96
pal/src/exception/machmessage.h

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -23,12 +26,6 @@ using namespace CorUnix;
 
 
 #if HAVE_MACH_EXCEPTIONS
 #if HAVE_MACH_EXCEPTIONS
 
 
-#if defined(_AMD64_)
-#define MACH_EH_TYPE(x) mach_##x
-#else
-#define MACH_EH_TYPE(x) x
-#endif // defined(_AMD64_)
-
 // The vast majority of Mach calls we make in this module are critical: we cannot recover from failures of
 // The vast majority of Mach calls we make in this module are critical: we cannot recover from failures of
 // these methods (principally because we're handling hardware exceptions in the context of a single dedicated
 // these methods (principally because we're handling hardware exceptions in the context of a single dedicated
 // handler thread). The following macro encapsulates checking the return code from Mach methods and emitting
 // handler thread). The following macro encapsulates checking the return code from Mach methods and emitting
@@ -37,7 +34,6 @@ using namespace CorUnix;
         if (machret != KERN_SUCCESS)                                        \
         if (machret != KERN_SUCCESS)                                        \
         {                                                                   \
         {                                                                   \
             char _szError[1024];                                            \
             char _szError[1024];                                            \
-            sprintf(_szError, "%s: %u: %s", __FUNCTION__, __LINE__, _msg);  \
             mach_error(_szError, machret);                                  \
             mach_error(_szError, machret);                                  \
             abort();                                                        \
             abort();                                                        \
         }                                                                   \
         }                                                                   \
@@ -46,7 +42,8 @@ using namespace CorUnix;
 // This macro terminates the process with some useful debug info as above, but for the general failure points
 // This macro terminates the process with some useful debug info as above, but for the general failure points
 // that have nothing to do with Mach.
 // that have nothing to do with Mach.
 #define NONPAL_RETAIL_ASSERT(_msg, ...) do {                                    \
 #define NONPAL_RETAIL_ASSERT(_msg, ...) do {                                    \
-        printf("%s: %u: " _msg "\n", __FUNCTION__, __LINE__, ## __VA_ARGS__);   \
+        fprintf(stdout, "%s: %u: " _msg "\n", __FUNCTION__, __LINE__, ## __VA_ARGS__);   \
+        fflush(stdout);                                                         \
         abort();                                                                \
         abort();                                                                \
     } while (false)
     } while (false)
 
 
@@ -66,9 +63,12 @@ using namespace CorUnix;
     } while (false)
     } while (false)
 
 
 // Debug-only output with printf-style formatting.
 // Debug-only output with printf-style formatting.
-#define NONPAL_TRACE(_format, ...)
+#define NONPAL_TRACE(_format, ...) 
+#define NONPAL_TRACE_ENABLED false
+
 #else // _DEBUG
 #else // _DEBUG
 
 
+#define NONPAL_TRACE_ENABLED false
 #define NONPAL_ASSERT(_msg, ...)
 #define NONPAL_ASSERT(_msg, ...)
 #define NONPAL_ASSERTE(_expr)
 #define NONPAL_ASSERTE(_expr)
 #define NONPAL_TRACE(_format, ...)
 #define NONPAL_TRACE(_format, ...)
@@ -82,11 +82,18 @@ struct MachExceptionInfo
 {
 {
     exception_type_t ExceptionType;
     exception_type_t ExceptionType;
     mach_msg_type_number_t SubcodeCount;
     mach_msg_type_number_t SubcodeCount;
-    MACH_EH_TYPE(exception_data_type_t) Subcodes[2];
+    mach_exception_data_type_t Subcodes[2];
+#if defined(_AMD64_)
     x86_thread_state_t ThreadState;
     x86_thread_state_t ThreadState;
     x86_float_state_t FloatState;
     x86_float_state_t FloatState;
     x86_debug_state_t DebugState;
     x86_debug_state_t DebugState;
-
+#elif defined(_ARM64_)
+    arm_thread_state64_t ThreadState;
+    arm_neon_state64_t FloatState;
+    arm_debug_state64_t DebugState;
+#else
+#error Unexpected architecture
+#endif
     MachExceptionInfo(mach_port_t thread, MachMessage& message);
     MachExceptionInfo(mach_port_t thread, MachMessage& message);
     void RestoreState(mach_port_t thread);
     void RestoreState(mach_port_t thread);
 };
 };
@@ -103,15 +110,9 @@ public:
         SET_THREAD_MESSAGE_ID = 1,
         SET_THREAD_MESSAGE_ID = 1,
         FORWARD_EXCEPTION_MESSAGE_ID = 2,
         FORWARD_EXCEPTION_MESSAGE_ID = 2,
         NOTIFY_SEND_ONCE_MESSAGE_ID = 71,
         NOTIFY_SEND_ONCE_MESSAGE_ID = 71,
-        EXCEPTION_RAISE_MESSAGE_ID = 2401,
-        EXCEPTION_RAISE_STATE_MESSAGE_ID = 2402,
-        EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID = 2403,
         EXCEPTION_RAISE_64_MESSAGE_ID = 2405,
         EXCEPTION_RAISE_64_MESSAGE_ID = 2405,
         EXCEPTION_RAISE_STATE_64_MESSAGE_ID = 2406,
         EXCEPTION_RAISE_STATE_64_MESSAGE_ID = 2406,
         EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID = 2407,
         EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID = 2407,
-        EXCEPTION_RAISE_REPLY_MESSAGE_ID = 2501,
-        EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID = 2502,
-        EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID = 2503,
         EXCEPTION_RAISE_REPLY_64_MESSAGE_ID = 2505,
         EXCEPTION_RAISE_REPLY_64_MESSAGE_ID = 2505,
         EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID = 2506,
         EXCEPTION_RAISE_STATE_REPLY_64_MESSAGE_ID = 2506,
         EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID = 2507
         EXCEPTION_RAISE_STATE_IDENTITY_REPLY_64_MESSAGE_ID = 2507
@@ -153,7 +154,7 @@ public:
     thread_act_t GetThread();           // Get the faulting thread
     thread_act_t GetThread();           // Get the faulting thread
     exception_type_t GetException();    // Get the exception type (e.g. EXC_BAD_ACCESS)
     exception_type_t GetException();    // Get the exception type (e.g. EXC_BAD_ACCESS)
     int GetExceptionCodeCount();        // Get the number of exception sub-codes
     int GetExceptionCodeCount();        // Get the number of exception sub-codes
-    MACH_EH_TYPE(exception_data_type_t) GetExceptionCode(int iIndex);   // Get the exception sub-code at the given index
+    mach_exception_data_type_t GetExceptionCode(int iIndex);   // Get the exception sub-code at the given index
 
 
     // Fetch the thread state flavor from a notification or reply message (return THREAD_STATE_NONE for the
     // Fetch the thread state flavor from a notification or reply message (return THREAD_STATE_NONE for the
     // messages that don't contain a thread state).
     // messages that don't contain a thread state).
@@ -212,25 +213,6 @@ private:
 
 
 #pragma pack(4)
 #pragma pack(4)
 
 
-    // EXCEPTION_RAISE_MESSAGE_ID
-    struct exception_raise_notification_t
-    {
-        mach_msg_body_t msgh_body;
-        mach_msg_port_descriptor_t thread_port;
-        mach_msg_port_descriptor_t task_port;
-        NDR_record_t ndr;
-        exception_type_t exception;
-        mach_msg_type_number_t code_count;
-        exception_data_type_t code[2];
-    };
-
-    // EXCEPTION_RAISE_REPLY_MESSAGE_ID
-    struct exception_raise_reply_t
-    {
-        NDR_record_t ndr;
-        kern_return_t ret;
-    };
-
     // EXCEPTION_RAISE_64_MESSAGE_ID
     // EXCEPTION_RAISE_64_MESSAGE_ID
     struct exception_raise_notification_64_t
     struct exception_raise_notification_64_t
     {
     {
@@ -250,28 +232,6 @@ private:
         kern_return_t ret;
         kern_return_t ret;
     };
     };
 
 
-    // EXCEPTION_RAISE_STATE_MESSAGE_ID
-    struct exception_raise_state_notification_t
-    {
-        NDR_record_t ndr;
-        exception_type_t exception;
-        mach_msg_type_number_t code_count;
-        exception_data_type_t code[2];
-        thread_state_flavor_t flavor;
-        mach_msg_type_number_t old_state_count;
-        natural_t old_state[THREAD_STATE_MAX];
-    };
-
-    // EXCEPTION_RAISE_STATE_REPLY_MESSAGE_ID
-    struct exception_raise_state_reply_t
-    {
-        NDR_record_t ndr;
-        kern_return_t ret;
-        thread_state_flavor_t flavor;
-        mach_msg_type_number_t new_state_count;
-        natural_t new_state[THREAD_STATE_MAX];
-    };
-
     // EXCEPTION_RAISE_STATE_64_MESSAGE_ID
     // EXCEPTION_RAISE_STATE_64_MESSAGE_ID
     struct exception_raise_state_notification_64_t
     struct exception_raise_state_notification_64_t
     {
     {
@@ -294,31 +254,6 @@ private:
         natural_t new_state[THREAD_STATE_MAX];
         natural_t new_state[THREAD_STATE_MAX];
     };
     };
 
 
-    // EXCEPTION_RAISE_STATE_IDENTITY_MESSAGE_ID
-    struct exception_raise_state_identity_notification_t
-    {
-        mach_msg_body_t msgh_body;
-        mach_msg_port_descriptor_t thread_port;
-        mach_msg_port_descriptor_t task_port;
-        NDR_record_t ndr;
-        exception_type_t exception;
-        mach_msg_type_number_t code_count;
-        exception_data_type_t code[2];
-        thread_state_flavor_t flavor;
-        mach_msg_type_number_t old_state_count;
-        natural_t old_state[THREAD_STATE_MAX];
-    };
-
-    // EXCEPTION_RAISE_STATE_IDENTITY_REPLY_MESSAGE_ID
-    struct exception_raise_state_identity_reply_t
-    {
-        NDR_record_t ndr;
-        kern_return_t ret;
-        thread_state_flavor_t flavor;
-        mach_msg_type_number_t new_state_count;
-        natural_t new_state[THREAD_STATE_MAX];
-    };
-
     // EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID
     // EXCEPTION_RAISE_STATE_IDENTITY_64_MESSAGE_ID
     struct exception_raise_state_identity_notification_64_t
     struct exception_raise_state_identity_notification_64_t
     {
     {
@@ -355,15 +290,9 @@ private:
         {
         {
             set_thread_request_t                                set_thread;
             set_thread_request_t                                set_thread;
             forward_exception_request_t                         forward_exception;
             forward_exception_request_t                         forward_exception;
-            exception_raise_notification_t                      raise;
-            exception_raise_state_notification_t                raise_state;
-            exception_raise_state_identity_notification_t       raise_state_identity;
             exception_raise_notification_64_t                   raise_64;
             exception_raise_notification_64_t                   raise_64;
             exception_raise_state_notification_64_t             raise_state_64;
             exception_raise_state_notification_64_t             raise_state_64;
             exception_raise_state_identity_notification_64_t    raise_state_identity_64;
             exception_raise_state_identity_notification_64_t    raise_state_identity_64;
-            exception_raise_reply_t                             raise_reply;
-            exception_raise_state_reply_t                       raise_state_reply;
-            exception_raise_state_identity_reply_t              raise_state_identity_reply;
             exception_raise_reply_64_t                          raise_reply_64;
             exception_raise_reply_64_t                          raise_reply_64;
             exception_raise_state_reply_64_t                    raise_state_reply_64;
             exception_raise_state_reply_64_t                    raise_state_reply_64;
             exception_raise_state_identity_reply_64_t           raise_state_identity_reply_64;
             exception_raise_state_identity_reply_64_t           raise_state_identity_reply_64;
@@ -390,7 +319,7 @@ private:
     // x86_THREAD_STATE and x86_THREAD_STATE32 state flavors are supported.
     // x86_THREAD_STATE and x86_THREAD_STATE32 state flavors are supported.
     thread_act_t GetThreadFromState(thread_state_flavor_t eFlavor, thread_state_t pState);
     thread_act_t GetThreadFromState(thread_state_flavor_t eFlavor, thread_state_t pState);
 
 
-    // Transform a exception handler behavior type into the corresponding Mach message ID for the
+    // Transform an exception handler behavior type into the corresponding Mach message ID for the
     // notification.
     // notification.
     mach_msg_id_t MapBehaviorToNotificationType(exception_behavior_t eBehavior);
     mach_msg_id_t MapBehaviorToNotificationType(exception_behavior_t eBehavior);
 
 
@@ -407,7 +336,7 @@ private:
     void SetThread(thread_act_t thread);
     void SetThread(thread_act_t thread);
     void SetException(exception_type_t eException);
     void SetException(exception_type_t eException);
     void SetExceptionCodeCount(int cCodes);
     void SetExceptionCodeCount(int cCodes);
-    void SetExceptionCode(int iIndex, MACH_EH_TYPE(exception_data_type_t) iCode);
+    void SetExceptionCode(int iIndex, mach_exception_data_type_t iCode);
 
 
     // Defined for replies:
     // Defined for replies:
     void SetReturnCode(kern_return_t eReturnCode);
     void SetReturnCode(kern_return_t eReturnCode);

+ 14 - 31
pal/src/exception/signal.cpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -26,7 +29,7 @@ Abstract:
 #include "pal/threadsusp.hpp"
 #include "pal/threadsusp.hpp"
 
 
 #include "pal/palinternal.h"
 #include "pal/palinternal.h"
-#if !HAVE_MACH_EXCEPTIONS
+
 #include "pal/dbgmsg.h"
 #include "pal/dbgmsg.h"
 #include "pal/init.h"
 #include "pal/init.h"
 #include "pal/process.h"
 #include "pal/process.h"
@@ -45,7 +48,11 @@ using namespace CorUnix;
 
 
 SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);
 SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);
 
 
+#ifdef SIGRTMIN
 #define INJECT_ACTIVATION_SIGNAL SIGRTMIN
 #define INJECT_ACTIVATION_SIGNAL SIGRTMIN
+#else
+#define INJECT_ACTIVATION_SIGNAL SIGUSR1
+#endif
 
 
 /* local type definitions *****************************************************/
 /* local type definitions *****************************************************/
 
 
@@ -57,6 +64,8 @@ typedef void *siginfo_t;
 #endif  /* !HAVE_SIGINFO_T */
 #endif  /* !HAVE_SIGINFO_T */
 typedef void (*SIGFUNC)(int, siginfo_t *, void *);
 typedef void (*SIGFUNC)(int, siginfo_t *, void *);
 
 
+#if !HAVE_MACH_EXCEPTIONS
+
 /* internal function declarations *********************************************/
 /* internal function declarations *********************************************/
 
 
 static void sigill_handler(int code, siginfo_t *siginfo, void *context);
 static void sigill_handler(int code, siginfo_t *siginfo, void *context);
@@ -445,32 +454,6 @@ static void inject_activation_handler(int code, siginfo_t *siginfo, void *contex
     }
     }
 }
 }
 
 
-/*++
-Function :
-    InjectActivationInternal
-
-    Interrupt the specified thread and have it call the activationFunction passed in
-
-Parameters :
-    pThread            - target PAL thread
-    activationFunction - function to call
-
-(no return value)
---*/
-PAL_ERROR InjectActivationInternal(CorUnix::CPalThread* pThread)
-{
-    int status = pthread_kill(pThread->GetPThreadSelf(), INJECT_ACTIVATION_SIGNAL);
-    if (status != 0)
-    {
-        // Failure to send the signal is fatal. There are only two cases when sending
-        // the signal can fail. First, if the signal ID is invalid and second,
-        // if the thread doesn't exist anymore.
-        abort();
-    }
-
-    return NO_ERROR;
-}
-
 /*++
 /*++
 Function :
 Function :
     SEHSetSafeState
     SEHSetSafeState

+ 7 - 15
pal/src/include/pal/process.h

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -130,17 +133,6 @@ Function:
 --*/
 --*/
 void PROCCleanupProcess(BOOL bTerminateUnconditionally);
 void PROCCleanupProcess(BOOL bTerminateUnconditionally);
 
 
-/*++
-Function:
-  InitializeFlushProcessWriteBuffers
-
-Abstract
-  This function initializes data structures needed for the FlushProcessWriteBuffers
-Return
-  TRUE if it succeeded, FALSE otherwise
---*/
-BOOL InitializeFlushProcessWriteBuffers();
-
 #if HAVE_MACH_EXCEPTIONS
 #if HAVE_MACH_EXCEPTIONS
 /*++
 /*++
 Function:
 Function:

+ 41 - 47
pal/src/include/pal/thread.hpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -55,7 +58,7 @@ namespace CorUnix
         LPVOID lpParameter,
         LPVOID lpParameter,
         DWORD dwCreationFlags,
         DWORD dwCreationFlags,
         PalThreadType eThreadType,
         PalThreadType eThreadType,
-        LPDWORD lpThreadId,
+        SIZE_T* pThreadId,
         HANDLE *phThread
         HANDLE *phThread
         );
         );
 
 
@@ -95,11 +98,6 @@ namespace CorUnix
         HANDLE *phThread
         HANDLE *phThread
         );
         );
 
 
-    PAL_ERROR
-    InitializeGlobalThreadData(
-        void
-        );
-
     PAL_ERROR
     PAL_ERROR
     CreateThreadData(
     CreateThreadData(
         CPalThread **ppThread
         CPalThread **ppThread
@@ -112,11 +110,6 @@ namespace CorUnix
         HANDLE *phThread
         HANDLE *phThread
         );
         );
 
 
-    PAL_ERROR
-    InitializeEndingThreadsData(
-        void
-        );
-
     BOOL
     BOOL
     GetThreadTimesInternal(
     GetThreadTimesInternal(
         IN HANDLE hThread,
         IN HANDLE hThread,
@@ -153,37 +146,35 @@ namespace CorUnix
         thread_state_flavor_t m_flavor;
         thread_state_flavor_t m_flavor;
     };
     };
 
 
-    // Class abstracting previousy registered Mach exception handlers for a thread.
-    class CThreadMachExceptionHandlers
+    // Struct abstracting previously registered Mach exception handlers for a thread.
+    struct CThreadMachExceptionHandlers
     {
     {
     public:
     public:
-        // Returns a pointer to the handler node that should be initialized next. The first time this is
-        // called for a thread the bottom node will be returned. Thereafter the top node will be returned.
-        // Also returns the Mach exception port that should be registered.
-        CThreadMachExceptionHandlerNode *GetNodeForInitialization(mach_port_t *pExceptionPort);
-
-        // Returns a pointer to the handler node for cleanup. This will always be the bottom node. This isn't
-        // really the right algorithm (because there isn't one). There are lots of reasonable scenarios where
-        // we will break chaining by removing our handler from a thread (by registering two handler ports we
-        // can support a lot more chaining scenarios but we can't pull the same sort of trick when
-        // unregistering, in particular we have two sets of chain back handlers and no way to reach into other
-        // components and alter what their chain-back information is).
-        CThreadMachExceptionHandlerNode *GetNodeForCleanup() { return &m_bottom; }
+        // Maximum number of exception ports we hook.  Must be the count
+        // of all bits set in the exception masks defined in machexception.h.
+        static const int s_nPortsMax = 6;
+
+        // Saved exception ports, exactly as returned by
+        // thread_swap_exception_ports.
+        mach_msg_type_number_t m_nPorts;
+        exception_mask_t m_masks[s_nPortsMax];
+        exception_handler_t m_handlers[s_nPortsMax];
+        exception_behavior_t m_behaviors[s_nPortsMax];
+        thread_state_flavor_t m_flavors[s_nPortsMax];
+
+        CThreadMachExceptionHandlers() :
+            m_nPorts(-1)
+        {
+        }
 
 
         // Get handler details for a given type of exception. If successful the structure pointed at by
         // Get handler details for a given type of exception. If successful the structure pointed at by
-        // pHandler is filled in and true is returned. Otherwise false is returned. The fTopException argument
-        // indicates whether the handlers found at the time of a call to ICLRRuntimeHost2::RegisterMacEHPort()
-        // should be searched (if not, or a handler is not found there, we'll fallback to looking at the
-        // handlers discovered at the point when the CLR first saw this thread).
-        bool GetHandler(exception_type_t eException, bool fTopException, MachExceptionHandler *pHandler);
+        // pHandler is filled in and true is returned. Otherwise false is returned.
+        bool GetHandler(exception_type_t eException, MachExceptionHandler *pHandler);
 
 
     private:
     private:
         // Look for a handler for the given exception within the given handler node. Return its index if
         // Look for a handler for the given exception within the given handler node. Return its index if
         // successful or -1 otherwise.
         // successful or -1 otherwise.
-        int GetIndexOfHandler(exception_mask_t bmExceptionMask, CThreadMachExceptionHandlerNode *pNode);
-
-        CThreadMachExceptionHandlerNode m_top;
-        CThreadMachExceptionHandlerNode m_bottom;
+        int GetIndexOfHandler(exception_mask_t bmExceptionMask);
     };
     };
 #endif // HAVE_MACH_EXCEPTIONS
 #endif // HAVE_MACH_EXCEPTIONS
 #endif // FEATURE_PAL_SXS
 #endif // FEATURE_PAL_SXS
@@ -242,7 +233,7 @@ namespace CorUnix
                 LPVOID,
                 LPVOID,
                 DWORD,
                 DWORD,
                 PalThreadType,
                 PalThreadType,
-                LPDWORD,
+                SIZE_T*,
                 HANDLE*
                 HANDLE*
                 );
                 );
 
 
@@ -263,12 +254,6 @@ namespace CorUnix
                 int
                 int
                 );
                 );
 
 
-        friend
-            PAL_ERROR
-            InitializeGlobalThreadData(
-                void
-                );
-
         friend
         friend
             PAL_ERROR
             PAL_ERROR
             CreateThreadData(
             CreateThreadData(
@@ -737,9 +722,18 @@ namespace CorUnix
     extern "C" CPalThread *CreateCurrentThreadData();
     extern "C" CPalThread *CreateCurrentThreadData();
 #endif // FEATURE_PAL_SXS
 #endif // FEATURE_PAL_SXS
 
 
-    CPalThread *GetCurrentPalThread(bool force = false);
+    inline CPalThread *GetCurrentPalThread()
+    {
+        return reinterpret_cast<CPalThread*>(pthread_getspecific(thObjKey));
+    }
 
 
-    CPalThread *InternalGetCurrentThread();
+    inline CPalThread *InternalGetCurrentThread()
+    {
+        CPalThread *pThread = GetCurrentPalThread();
+        if (pThread == nullptr)
+            pThread = CreateCurrentThreadData();
+        return pThread;
+    }
 
 
 /***
 /***
 
 

+ 25 - 4
pal/src/include/pal/utils.h

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -25,6 +28,24 @@ Abstract:
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 
 
+#include <pal_assert.h>
+
+// Alignment helpers (copied for PAL use from stdmacros.h)
+
+inline size_t ALIGN_UP(size_t val, size_t alignment)
+{
+    // alignment must be a power of 2 for this implementation to work (need modulo otherwise)
+    _ASSERTE(0 == (alignment & (alignment - 1)));
+    size_t result = (val + (alignment - 1)) & ~(alignment - 1);
+    _ASSERTE(result >= val);      // check for overflow
+    return result;
+}
+
+inline void* ALIGN_UP(void* val, size_t alignment)
+{
+    return (void*)ALIGN_UP((size_t)val, alignment);
+}
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C"
 extern "C"
 {
 {

+ 10 - 5
pal/src/include/pal/virtual.h

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -63,7 +66,9 @@ enum VIRTUAL_CONSTANTS
     VIRTUAL_EXECUTE_READ,
     VIRTUAL_EXECUTE_READ,
 
 
     /* Page manipulation constants. */
     /* Page manipulation constants. */
-#ifdef __sparc__
+#if defined(__APPLE__) && defined(_ARM64_)
+    VIRTUAL_PAGE_SIZE       = 0x4000,
+#elif __sparc__
     VIRTUAL_PAGE_SIZE       = 0x2000,
     VIRTUAL_PAGE_SIZE       = 0x2000,
 #else   // __sparc__
 #else   // __sparc__
     VIRTUAL_PAGE_SIZE       = 0x1000,
     VIRTUAL_PAGE_SIZE       = 0x1000,

+ 8 - 32
pal/src/init/pal.cpp

@@ -1,8 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 /*++
 /*++
 
 
 
 
@@ -132,7 +134,7 @@ Initialize()
 
 
     // prevent un-reasonable stack limits. (otherwise affects mmap calls later)
     // prevent un-reasonable stack limits. (otherwise affects mmap calls later)
 #if !defined(__IOS__) && !defined(__ANDROID__)
 #if !defined(__IOS__) && !defined(__ANDROID__)
-#ifdef _AMD64_
+#if defined (_AMD64_) || defined (_M_ARM64)
     const rlim_t maxStackSize = 8 * 1024 * 1024;   // CC Max stack size
     const rlim_t maxStackSize = 8 * 1024 * 1024;   // CC Max stack size
 #else
 #else
     const rlim_t maxStackSize = 2 * 1024 * 1024;   // CC Max stack size
     const rlim_t maxStackSize = 2 * 1024 * 1024;   // CC Max stack size
@@ -241,16 +243,6 @@ Initialize()
         }
         }
 #endif // HAVE_MACH_EXCEPTIONS
 #endif // HAVE_MACH_EXCEPTIONS
 
 
-        //
-        // Initialize global thread data
-        //
-        palError = InitializeGlobalThreadData();
-        if (NO_ERROR != palError)
-        {
-            ERROR("Unable to initialize thread data\n");
-            goto CLEANUP1;
-        }
-
         //
         //
         // Allocate the initial thread data
         // Allocate the initial thread data
         //
         //
@@ -263,17 +255,6 @@ Initialize()
         }
         }
         PROCAddThread(pThread, pThread);
         PROCAddThread(pThread, pThread);
 
 
-        //
-        // Initialize mutex and condition variable used to synchronize the ending threads count
-        //
-
-        palError = InitializeEndingThreadsData();
-        if (NO_ERROR != palError)
-        {
-            ERROR("Unable to create ending threads data\n");
-            goto CLEANUP1b;
-        }
-
         //
         //
         // It's now safe to access our thread data
         // It's now safe to access our thread data
         //
         //
@@ -501,11 +482,6 @@ PAL_InitializeChakraCore()
         return ERROR_SUCCESS;
         return ERROR_SUCCESS;
     }
     }
 
 
-    if (!InitializeFlushProcessWriteBuffers())
-    {
-        return ERROR_GEN_FAILURE;
-    }
-
     return ERROR_SUCCESS;
     return ERROR_SUCCESS;
 }
 }
 
 

+ 11 - 8
pal/src/init/sxs.cpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -48,7 +51,7 @@ PAL_Enter(PAL_Boundary boundary)
     ENTRY_EXTERNAL("PAL_Enter(boundary=%u)\n", boundary);
     ENTRY_EXTERNAL("PAL_Enter(boundary=%u)\n", boundary);
 
 
     PAL_ERROR palError = ERROR_SUCCESS;
     PAL_ERROR palError = ERROR_SUCCESS;
-    CPalThread *pThread = GetCurrentPalThread();
+    CPalThread *pThread = InternalGetCurrentThread();
     if (pThread != NULL)
     if (pThread != NULL)
     {
     {
         palError = pThread->Enter(boundary);
         palError = pThread->Enter(boundary);
@@ -160,7 +163,7 @@ PAL_Reenter(PAL_Boundary boundary)
 {
 {
     ENTRY_EXTERNAL("PAL_Reenter(boundary=%u)\n", boundary);
     ENTRY_EXTERNAL("PAL_Reenter(boundary=%u)\n", boundary);
 
 
-    CPalThread *pThread = GetCurrentPalThread();
+    CPalThread *pThread = InternalGetCurrentThread();
     if (pThread == NULL)
     if (pThread == NULL)
     {
     {
         ASSERT("PAL_Reenter called on a thread unknown to this PAL\n");
         ASSERT("PAL_Reenter called on a thread unknown to this PAL\n");
@@ -187,7 +190,7 @@ PAL_HasEntered()
 {
 {
     ENTRY_EXTERNAL("PAL_HasEntered()\n");
     ENTRY_EXTERNAL("PAL_HasEntered()\n");
 
 
-    CPalThread *pThread = GetCurrentPalThread();
+    CPalThread *pThread = InternalGetCurrentThread();
     if (pThread == NULL)
     if (pThread == NULL)
     {
     {
         ASSERT("PAL_Reenter called on a thread unknown to this PAL\n");
         ASSERT("PAL_Reenter called on a thread unknown to this PAL\n");
@@ -229,7 +232,7 @@ PAL_Leave(PAL_Boundary boundary)
 {
 {
     ENTRY("PAL_Leave(boundary=%u)\n", boundary);
     ENTRY("PAL_Leave(boundary=%u)\n", boundary);
 
 
-    CPalThread *pThread = GetCurrentPalThread();
+    CPalThread *pThread = InternalGetCurrentThread();
     // We ignore the return code.  This call should only fail on internal
     // We ignore the return code.  This call should only fail on internal
     // error, and we assert at the actual failure.
     // error, and we assert at the actual failure.
     pThread->Leave(boundary);
     pThread->Leave(boundary);

+ 10 - 5
pal/src/misc/sysinfo.cpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -188,7 +191,9 @@ GetCurrentThreadStackLimits(&lowl, &highl);
 #elif defined(USERLIMIT)
 #elif defined(USERLIMIT)
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT;
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT;
 #elif defined(_WIN64)
 #elif defined(_WIN64)
-#if defined(USRSTACK64)
+#if defined(_M_ARM64)
+    lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47);
+#elif defined(USRSTACK64)
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) PAL_MAX(highl, USRSTACK64);
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) PAL_MAX(highl, USRSTACK64);
 #else // !USRSTACK64
 #else // !USRSTACK64
 #error How come USRSTACK64 is not defined for 64bit?
 #error How come USRSTACK64 is not defined for 64bit?

+ 10 - 20
pal/src/misc/time.cpp

@@ -1,7 +1,10 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
+//-------------------------------------------------------------------------------------------------------
+// ChakraCore/Pal
+// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
+// and edits (c) copyright the ChakraCore Contributors.
+// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
 
 
 /*++
 /*++
 
 
@@ -265,22 +268,9 @@ QueryPerformanceFrequency(
     BOOL retval = TRUE;
     BOOL retval = TRUE;
     PERF_ENTRY(QueryPerformanceFrequency);
     PERF_ENTRY(QueryPerformanceFrequency);
     ENTRY("QueryPerformanceFrequency()\n");
     ENTRY("QueryPerformanceFrequency()\n");
-#if HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC
-    lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds;
-#elif HAVE_MACH_ABSOLUTE_TIME
-    // use denom == 0 to indicate that s_TimebaseInfo is uninitialised.
-    if (s_TimebaseInfo.denom == 0)
-    {
-        ASSERT("s_TimebaseInfo is uninitialized.\n");
-        retval = FALSE;
-    }
-    else
-    {
-        lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds * ((LONGLONG)s_TimebaseInfo.denom / (LONGLONG)s_TimebaseInfo.numer);
-    }
-#else
-    lpFrequency->QuadPart = (LONGLONG)tccSecondsToMicroSeconds;
-#endif // HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC
+
+    lpFrequency->QuadPart = (LONGLONG)(tccSecondsToNanoSeconds);
+
     LOGEXIT("QueryPerformanceFrequency\n");
     LOGEXIT("QueryPerformanceFrequency\n");
     PERF_EXIT(QueryPerformanceFrequency);
     PERF_EXIT(QueryPerformanceFrequency);
     return retval;
     return retval;

File diff ditekan karena terlalu besar
+ 551 - 210
pal/src/thread/context.cpp


File diff ditekan karena terlalu besar
+ 284 - 391
pal/src/thread/pal_thread.cpp


File diff ditekan karena terlalu besar
+ 213 - 836
pal/src/thread/process.cpp


+ 19 - 4
tools/StyleChecks/check_copyright.py

@@ -19,10 +19,15 @@ copyright_lines = [
     r'.*' # the above should always be followed by at least one other line, so make sure that line is present
     r'.*' # the above should always be followed by at least one other line, so make sure that line is present
 ]
 ]
 
 
-regexes = []
-for line in copyright_lines:
-    pattern = '^.{1,5}%s$' % line
-    regexes.append(re.compile(pattern))
+pal_copyright_lines = [
+    r'-------------------------------------------------------------------------------------------------------',
+    r' ChakraCore/Pal',
+    r' Contains portions \(c\) copyright Microsoft, portions copyright \(c\) the \.NET Foundation and Contributors',
+    r' and edits \(c\) copyright the ChakraCore Contributors\.',
+    r' See THIRD-PARTY-NOTICES\.txt in the project root for \.NET Foundation license',
+    r' Licensed under the MIT license\. See LICENSE\.txt file in the project root for full license information\.',
+    r'.*' # the above should always be followed by at least one other line, so make sure that line is present
+]
 
 
 if len(sys.argv) < 2:
 if len(sys.argv) < 2:
     print("Requires passing a filename as an argument.")
     print("Requires passing a filename as an argument.")
@@ -33,6 +38,16 @@ if not os.path.isfile(file_name):
     print("File does not exist:", file_name, "(not necessarily an error)")
     print("File does not exist:", file_name, "(not necessarily an error)")
     exit(0)
     exit(0)
 
 
+regexes = []
+if file_name[:4] == "pal/":
+    for line in pal_copyright_lines:
+        pattern = '^.{1,5}%s$' % line
+        regexes.append(re.compile(pattern))
+else:
+    for line in copyright_lines:
+        pattern = '^.{1,5}%s$' % line
+        regexes.append(re.compile(pattern))
+
 def report_incorrect(file_name, pairs):
 def report_incorrect(file_name, pairs):
     # found a problem so report the problem to the caller and exit
     # found a problem so report the problem to the caller and exit
     print(file_name, "... does not contain a correct copyright notice.\n")
     print(file_name, "... does not contain a correct copyright notice.\n")

+ 0 - 1
tools/StyleChecks/check_copyright.sh

@@ -53,7 +53,6 @@ git diff --name-only `git merge-base origin/master HEAD` HEAD |
     grep -v -E 'test/benchmarks/.*\.js_c$' |
     grep -v -E 'test/benchmarks/.*\.js_c$' |
     grep -v -E 'bin/External/.*$' |
     grep -v -E 'bin/External/.*$' |
     grep -v -E 'bin/NativeTests/Scripts/splay.js$' |
     grep -v -E 'bin/NativeTests/Scripts/splay.js$' |
-    grep -v -E 'pal/.*' |
     grep -v -E 'libChakraCoreLib.version|ch.version' |
     grep -v -E 'libChakraCoreLib.version|ch.version' |
     grep -v -E 'lib/Backend/CRC.h' |
     grep -v -E 'lib/Backend/CRC.h' |
     xargs -I % sh -c "echo 'Check Copyright > Checking %'; python tools/StyleChecks/check_copyright.py % > $ERRFILETEMP || cat $ERRFILETEMP >> $ERRFILE"
     xargs -I % sh -c "echo 'Check Copyright > Checking %'; python tools/StyleChecks/check_copyright.py % > $ERRFILETEMP || cat $ERRFILETEMP >> $ERRFILE"

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini