@@ -44,7 +44,9 @@ ALTERNATE_ENTRY RhpThrowHwExGEHCONT ; this needs to be an EHCONT target since we
4444 .pushframe
4545
4646 alloc_stack SIZEOF_XmmSaves + 8h ;; reserve stack for the xmm saves (+8h to realign stack)
47- push_vol_reg r8 ;; padding
47+ rdsspq r8 ;; nop if SSP is not implemented, 0 if not enabled
48+ push_vol_reg r8 ;; SSP
49+ xor r8 , r8
4850 push_nonvol_reg r15
4951 push_nonvol_reg r14
5052 push_nonvol_reg r13
@@ -127,7 +129,9 @@ NESTED_ENTRY RhpThrowEx, _TEXT
127129 xor r8 , r8
128130
129131 alloc_stack SIZEOF_XmmSaves + 8h ;; reserve stack for the xmm saves (+8h to realign stack)
130- push_vol_reg r8 ;; padding
132+ rdsspq r8 ;; nop if SSP is not implemented, 0 if not enabled
133+ push_vol_reg r8 ;; SSP
134+ xor r8 , r8
131135 push_nonvol_reg r15
132136 push_nonvol_reg r14
133137 push_nonvol_reg r13
@@ -221,7 +225,9 @@ NESTED_ENTRY RhpRethrow, _TEXT
221225 xor r8 , r8
222226
223227 alloc_stack SIZEOF_XmmSaves + 8h ;; reserve stack for the xmm saves (+8h to realign stack)
224- push_vol_reg r8 ;; padding
228+ rdsspq r8 ;; nop if SSP is not implemented, 0 if not enabled
229+ push_vol_reg r8 ;; SSP
230+ xor r8 , r8
225231 push_nonvol_reg r15
226232 push_nonvol_reg r14
227233 push_nonvol_reg r13
@@ -490,7 +496,7 @@ endif
490496 INLINE_THREAD_UNHIJACK rdx , rcx , r9 ;; Thread in rdx, trashes rcx and r9
491497
492498 mov rcx , [ rsp + rsp_offsetof_arguments + 18h ] ;; rcx <- current ExInfo *
493- mov r10 , [ r8 + OFFSETOF__REGDISPLAY__IP ] ;; r10 <- original IP value
499+ mov r11 , [ r8 + OFFSETOF__REGDISPLAY__SSP ] ;; r11 <- resume SSP value
494500 mov r8 , [ r8 + OFFSETOF__REGDISPLAY__SP ] ;; r8 <- resume SP value
495501 xor r9 , r9 ;; r9 <- 0
496502
@@ -505,7 +511,7 @@ endif
505511 ;; Sanity check: if we have shadow stack, it should agree with what we have in rsp
506512 LOCAL_STACK_USE equ 118h
507513 ifdef _DEBUG
508- rdsspq r9
514+ rdsspq r9 ;; NB, r9 == 0 prior to this
509515 test r9 , r9
510516 jz @f
511517 mov r9 , [ r9 ]
@@ -531,23 +537,23 @@ endif
531537 ;; reset RSP and jump to RAX
532538 @@: mov rsp , r8 ;; reset the SP to resume SP value
533539
534- ;; if have shadow stack, then we need to reconcile it with the rsp change we have just made
535- rdsspq r9
540+ ;; if have shadow stack, then we need to reconcile it with the rsp change we have just made. (r11 must contain target SSP)
541+ rdsspq r9 ;; NB, r9 == 0 prior to this
536542 test r9 , r9
537- jz NoSSP
538-
539- ;; Find the shadow stack pointer for the frame we are going to restore to.
540- ;; The SSP we search is pointing to the return address of the frame represented
541- ;; by the passed in context. So we search for the instruction pointer from
542- ;; the context and return one slot up from there.
543- ;; (Same logic as in GetSSPForFrameOnCurrentStack)
544- xor r11 , r11
545- @@: inc r11
546- cmp [ r9 + r11 * 8 - 8 ], r10
547- jne @b
548-
549- incsspq r11
550- NoSSP : jmp rax
543+ je No_Ssp_Update
544+ sub r11 , r9
545+ shr r11 , 3
546+ ;; the incsspq instruction uses only the lowest 8 bits of the argument, so we need to loop in case the increment is larger than 255
547+ mov r9 , 255
548+ Update_Loop:
549+ cmp r11 , r9
550+ cmovb r9 , r11
551+ incsspq r9
552+ sub r11 , r9
553+ ja Update_Loop
554+
555+
556+ No_Ssp_Update : jmp rax
551557
552558
553559NESTED_END RhpCallCatchFunclet , _TEXT
0 commit comments