Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Windows: fix exception handling for the VC runtime 14.23 that comes with VS 2019 16.3 #164

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/ldc/eh_msvc.d
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,37 @@ void msvc_eh_terminate() nothrow @naked
je L_retVC14_16

cmp 0x1B(%rax), %rbx // dec [rax+30h]; xor eax,eax; add rsp,nn (vcruntime140.dll 14.14.x.y)
jne L_term
je L_retVC14_14

mov $$0x30245C8B483048FF, %rbx // dec [rax+30h]; mov rbx,qword ptr [rsp+30h]
cmp -0x2b(%rax), %rbx // (libcmt.lib, 14.23.x.x)
je L_retVC14_23_libcmt
cmp 0x11(%rax), %rbx // (vcruntime140.lib, 14.23.x.x)
je L_retVC14_23_msvcrt

mov $$0xccc348c48348c033, %rbx // xor eax,eax; add rsp,48h; ret; int 3
cmp 0x2d(%rax), %rbx // (libcmtd.lib, 14.23.x.x)
je L_retVC14_23_libcmtd

jmp L_term

L_retVC14_23_msvcrt: // vcruntime140.dll 14.23.28105
lea 0x1b(%rax), %rax
mov 0x38(%rdx), %rbx // restore RBX from stack
jmp L_rbxRestored

L_retVC14_23_libcmt: // libcmt.lib 14.23.28105
lea -0x21(%rax), %rax
mov 0x38(%rdx), %rbx // restore RBX from stack
jmp L_rbxRestored

L_retVC14_23_libcmtd: // libcmtd.lib/vcruntime140d.dll 14.23.28105
lea 0x2f(%rax), %rax
jmp L_rbxRestored // rbx not saved

L_retVC14_14: // (vcruntime140.dll 14.14.x.y)
lea 0x20(%rax), %rax
jmp L_retContinue

L_retVC14_16: // vcruntime140 14.16.27012.6
lea 0x16(%rax), %rax
jmp L_retContinue
Expand Down Expand Up @@ -480,6 +507,7 @@ void msvc_eh_terminate() nothrow @naked
cmovnz -8(%rdx), %rbx // restore RBX (pushed inside terminate())
cmovz (%rsp), %rbx // RBX not changed in terminate inside UCRT 10.0.14393.0

L_rbxRestored:
lea 8(%rdx), %rsp
push %rax // new return after setting return value in __frameUnwindHandler

Expand Down