Reflect CR feedback
authorJan Vorlicek <janvorli@microsoft.com>
Wed, 18 Feb 2015 10:36:37 +0000 (11:36 +0100)
committerJan Vorlicek <janvorli@microsoft.com>
Wed, 18 Feb 2015 10:36:37 +0000 (11:36 +0100)
Rename VirtualUnwind in PAL to PAL_VirtualUnwind
Move .cfi annotation inside macros and update PROLOG_WITH_TRANSITION_BLOCK
to use these macros. I've verified that the annotation is correct by
stepping through the asm code and verifying that the stack trace is
correct at every instruction.

src/pal/inc/rt/palrt.h
src/pal/src/exception/seh-unwind.cpp
src/vm/amd64/calldescrworkeramd64.S
src/vm/amd64/gmsamd64.cpp
src/vm/amd64/unixasmmacros.inc
src/vm/stackwalk.cpp

index c497947..8fbbb8e 100644 (file)
@@ -1705,7 +1705,7 @@ typedef LONG (WINAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
     );
 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
 
-BOOL VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers);
+BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers);
 
 /******************* ntdef ************************************/
 
index 94d9c3b..b3b5d18 100644 (file)
@@ -152,7 +152,7 @@ static void GetContextPointers(unw_cursor_t *cursor, KNONVOLATILE_CONTEXT_POINTE
 #endif
 }
 
-BOOL VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
+BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
 {
     int st;
     unw_context_t unwContext;
@@ -498,7 +498,7 @@ static void RtlpRaiseException(EXCEPTION_RECORD *ExceptionRecord)
     // Find the caller of RtlpRaiseException.  This provides the exact context
     // that handlers expect to see, which is the one they would want to fix up
     // to resume after a continuable exception.
-    VirtualUnwind(&ContextRecord, NULL);
+    PAL_VirtualUnwind(&ContextRecord, NULL);
 
     // The frame we're looking at now is either RaiseException or PAL_TryExcept.
     // If it's RaiseException, we have to unwind one level further to get the
@@ -512,7 +512,7 @@ static void RtlpRaiseException(EXCEPTION_RECORD *ExceptionRecord)
 #endif
     if ((SIZE_T) pc - (SIZE_T) RaiseException < (SIZE_T) pc - (SIZE_T) PAL_TryExcept)
     {
-        VirtualUnwind(&ContextRecord, NULL);
+        PAL_VirtualUnwind(&ContextRecord, NULL);
 #if defined(_PPC_)
         pc = (void *) ContextRecord.Iar;
 #elif defined(_X86_)
index 4d69311..16bcca2 100644 (file)
@@ -42,12 +42,8 @@ NESTED_END FastCallFinalizeWorker, _TEXT
 
 NESTED_ENTRY CallDescrWorkerInternal, _TEXT, CallDescrWorkerUnwindFrameChainHandler
         push_nonvol_reg rbx             // save nonvolatile registers
-        .cfi_def_cfa_offset 16          //
         push_nonvol_reg rbp             // 
-        .cfi_adjust_cfa_offset 8        //
-        .cfi_offset rbp, -24            //
         set_frame rbp, 0                // set frame pointer
-        .cfi_def_cfa_register rbp       //
         lea     rsp, [rsp - 8]          // ensure proper alignment of the rsp
 
         END_PROLOGUE
index 6b0fd3a..39f58f1 100644 (file)
@@ -66,7 +66,7 @@ void LazyMachState::unwindLazyState(LazyMachState* baseState,
 #ifndef FEATURE_PAL
         pvControlPc = Thread::VirtualUnwindCallFrame(&ctx, &nonVolRegPtrs);
 #else // !FEATURE_PAL
-        VirtualUnwind(&ctx, &nonVolRegPtrs);
+        PAL_VirtualUnwind(&ctx, &nonVolRegPtrs);
         pvControlPc = GetIP(&ctx);
 #endif // !FEATURE_PAL
 
index 8c666f9..8fb0ff2 100644 (file)
@@ -51,6 +51,7 @@ C_FUNC(\Name):
         .type \Name, %function
 #endif
         .cfi_startproc
+        .cfi_def_cfa_offset 8
 C_FUNC(\Name):
 .endm
 
@@ -73,7 +74,14 @@ C_FUNC(\Name\()_End):
 
 .macro push_nonvol_reg Register
         push \Register
-        //.pushreg \Register
+        .cfi_adjust_cfa_offset 8
+        .cfi_rel_offset \Register, 0
+.endm
+
+.macro pop_nonvol_reg Register
+        pop \Register
+        .cfi_adjust_cfa_offset -8
+        .cfi_restore \Register
 .endm
 
 .macro NESTED_ENTRY Name, Section, Handler
@@ -94,11 +102,24 @@ C_FUNC(\Name\()_End):
 .att_syntax
         lea -\Size(%rsp), %rsp
 .intel_syntax noprefix
-        //.allocstack \Size
+        .cfi_adjust_cfa_offset \Size
+.endm
+
+.macro free_stack Size
+.att_syntax
+        lea \Size(%rsp), %rsp
+.intel_syntax noprefix
+        .cfi_adjust_cfa_offset -\Size
 .endm
 
 .macro set_frame Reg, Offset
         lea     \Reg, \Offset[rsp]
+        .cfi_def_cfa_register \Reg
+.endm
+
+.macro restore_frame Reg, Offset
+        lea     rsp, \Offset[\Reg]
+        .cfi_def_cfa_register rsp
 .endm
 
 .macro save_reg_postrsp Reg, Offset
@@ -109,12 +130,7 @@ C_FUNC(\Name\()_End):
 
         __Offset = \Offset
         mov     qword ptr [rsp + __Offset], \Reg
-
-//
-// TODO: find the right directive
-//       this one gives an "unknown directive" error
-//
-//        .savereg \Reg, \Offset
+        .cfi_rel_offset \Reg, __Offset
 
         ___STACK_ADJUSTMENT_FORBIDDEN = 1
 
@@ -123,6 +139,7 @@ C_FUNC(\Name\()_End):
 .macro restore_reg Reg, Offset
         __Offset = \Offset
         mov             \Reg, [rsp + __Offset]
+        .cfi_restore \Reg
 .endm
 
 .macro save_xmm128_postrsp Reg, Offset
@@ -133,12 +150,7 @@ C_FUNC(\Name\()_End):
 
         __Offset = \Offset
         movdqa  [rsp + __Offset], \Reg
-
-//
-// TODO: find the right directive
-//       this one gives an "unknown directive" error
-//
-//        .savexmm128 \Reg, \Offset
+        .cfi_rel_offset \Reg, __Offset
 
         ___STACK_ADJUSTMENT_FORBIDDEN = 1
 
@@ -147,38 +159,49 @@ C_FUNC(\Name\()_End):
 .macro restore_xmm128 Reg, ofs
         __Offset = \ofs
         movdqa          \Reg, [rsp + __Offset]
+        .cfi_restore \Reg
 .endm
 
 .macro POP_CALLEE_SAVED_REGISTERS
 
-        pop             rbx
-        pop             rbp
-        pop             r12
-        pop             r13
-        pop             r14
-        pop             r15
+        pop_nonvol_reg rbx
+        pop_nonvol_reg rbp
+        pop_nonvol_reg r12
+        pop_nonvol_reg r13
+        pop_nonvol_reg r14
+        pop_nonvol_reg r15
 
 .endm
 
+.macro push_argument_register Reg
+        push            \Reg
+        .cfi_adjust_cfa_offset 8
+.endm
+
 .macro PUSH_ARGUMENT_REGISTERS
 
-        push            r9
-        push            r8
-        push            rdx
-        push            rcx
-        push            rsi
-        push            rdi
+        push_argument_register r9
+        push_argument_register r8
+        push_argument_register rdx
+        push_argument_register rcx
+        push_argument_register rsi
+        push_argument_register rdi
+
+.endm
 
+.macro pop_argument_register Reg
+        pop            \Reg
+        .cfi_adjust_cfa_offset -8
 .endm
 
 .macro POP_ARGUMENT_REGISTERS
 
-        pop             rdi
-        pop             rsi
-        pop             rcx
-        pop             rdx
-        pop             r8
-        pop             r9
+        pop_argument_register rdi
+        pop_argument_register rsi
+        pop_argument_register rcx
+        pop_argument_register rdx
+        pop_argument_register r8
+        pop_argument_register r9
 
 .endm
 
@@ -251,7 +274,7 @@ C_FUNC(\Name\()_End):
         .endif
 
         .if \stackAllocOnEntry > 0
-        //.allocstack \stackAllocOnEntry
+        .cfi_adjust_cfa_offset \stackAllocOnEntry
         .endif
 
         // PUSH_CALLEE_SAVED_REGISTERS expanded here
@@ -300,7 +323,7 @@ C_FUNC(\Name\()_End):
 .macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
 
         RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters
-        lea rsp,        [rsp + __PWTB_StackAlloc]
+        free_stack      __PWTB_StackAlloc
         POP_ARGUMENT_REGISTERS
         POP_CALLEE_SAVED_REGISTERS
 
index 8ad5cdd..e677cef 100644 (file)
@@ -778,7 +778,7 @@ UINT_PTR Thread::VirtualUnwindToFirstManagedCallFrame(T_CONTEXT* pContext)
 #ifndef FEATURE_PAL
         uControlPc = VirtualUnwindCallFrame(pContext);
 #else // !FEATURE_PAL
-        VirtualUnwind(pContext, NULL);
+        PAL_VirtualUnwind(pContext, NULL);
         uControlPc = GetIP(pContext);
 #endif // !FEATURE_PAL
     }