Repository: dotnet/runtime
File: src/coreclr/nativeaot/Runtime/arm64/GcProbe.asm (Assembly)

Code before:
        PROLOG_NOP ldr          x2,       [sp, #0x88]

        ; Restore the FP/HFA/HVA return registers
        EPILOG_NOP ldp          q0, q1,   [sp, #0x90]
        EPILOG_NOP ldp          q2, q3,   [sp, #0xB0]

        ;; Restore callee saved registers
        EPILOG_RESTORE_REG_PAIR x19, x20, #0x20
        EPILOG_RESTORE_REG_PAIR x21, x22, #0x30
        EPILOG_RESTORE_REG_PAIR x23, x24, #0x40
        EPILOG_RESTORE_REG_PAIR x25, x26, #0x50
        EPILOG_RESTORE_REG_PAIR x27, x28, #0x60

        EPILOG_RESTORE_REG_PAIR fp, lr, #(PROBE_FRAME_SIZE)!
    MEND

;;
;; The prolog for all GC suspension hijacks (normal and stress). Fixes up the hijacked return address, and
;; clears the hijack state.
;;
;; Register state on entry:
;;  All registers correct for return to the original return address.
;;
;; Register state on exit:
;;  x4: thread pointer
;;  x2: preserved
;;  x3: trashed
;;
    MACRO
        FixupHijackedCallstack

        ;; x4 <- GetThread(), TRASHES x3
        INLINE_GETTHREAD x4, x3

        ;;
        ;; Fix the stack by restoring the original return address
        ;;
        ldr         lr, [x4, #OFFSETOF__Thread__m_pvHijackedReturnAddress]

        ;;
        ;; Clear hijack state
        ;;
        ASSERT OFFSETOF__Thread__m_pvHijackedReturnAddress == (OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation + 8)
        ;; Clear m_ppvHijackedReturnAddressLocation and m_pvHijackedReturnAddress
        stp         xzr, xzr, [x4, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation]
    MEND

    MACRO
        HijackTargetFakeProlog

        ;; This is a fake entrypoint for the method that 'tricks' the OS into calling our personality routine.

Review comment (suggestion):
```suggestion
```
We do not say that r0 and r1 are preserved either. The comment "All registers correct for return to the original return address." covers them all.

Code after:
        PROLOG_NOP ldr          x2,       [sp, #0x88]

        ; Restore the FP/HFA/HVA return registers
        EPILOG_NOP ldp          q0, q1,   [sp, #0x90]
        EPILOG_NOP ldp          q2, q3,   [sp, #0xB0]

        ;; Restore callee saved registers
        EPILOG_RESTORE_REG_PAIR x19, x20, #0x20
        EPILOG_RESTORE_REG_PAIR x21, x22, #0x30
        EPILOG_RESTORE_REG_PAIR x23, x24, #0x40
        EPILOG_RESTORE_REG_PAIR x25, x26, #0x50
        EPILOG_RESTORE_REG_PAIR x27, x28, #0x60

        EPILOG_RESTORE_REG_PAIR fp, lr, #(PROBE_FRAME_SIZE)!
    MEND

;;
;; The prolog for all GC suspension hijacks (normal and stress). Fixes up the hijacked return address, and
;; clears the hijack state.
;;
;; Register state on entry:
;;  All registers correct for return to the original return address.
;;
;; Register state on exit:
;;  x4: thread pointer
;;  x3: trashed
;;
    MACRO
        FixupHijackedCallstack

        ;; x4 <- GetThread(), TRASHES x3
        INLINE_GETTHREAD x4, x3

        ;;
        ;; Fix the stack by restoring the original return address
        ;;
        ldr         lr, [x4, #OFFSETOF__Thread__m_pvHijackedReturnAddress]

        ;;
        ;; Clear hijack state
        ;;
        ASSERT OFFSETOF__Thread__m_pvHijackedReturnAddress == (OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation + 8)
        ;; Clear m_ppvHijackedReturnAddressLocation and m_pvHijackedReturnAddress
        stp         xzr, xzr, [x4, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation]
    MEND

    MACRO
        HijackTargetFakeProlog

        ;; This is a fake entrypoint for the method that 'tricks' the OS into calling our personality routine.
        ;; The code here should never be executed, and the unwind info is bogus, but we don't mind since the