diff --git a/src/asm/jump_x86_64_ms_pe_masm.asm b/src/asm/jump_x86_64_ms_pe_masm.asm index c8a28a55..607c9f9e 100644 --- a/src/asm/jump_x86_64_ms_pe_masm.asm +++ b/src/asm/jump_x86_64_ms_pe_masm.asm @@ -33,52 +33,59 @@ ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ; ---------------------------------------------------------------------------------- ; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ; ---------------------------------------------------------------------------------- ; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | ; ---------------------------------------------------------------------------------- ; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | ; ---------------------------------------------------------------------------------- ; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | ; ---------------------------------------------------------------------------------- ; | limit | base | R12 | R13 | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ; ---------------------------------------------------------------------------------- ; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | ; ---------------------------------------------------------------------------------- ; | R14 | R15 | RDI | RSI | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ; ---------------------------------------------------------------------------------- ; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | ; ---------------------------------------------------------------------------------- -; | RBX | RBP | hidden | RIP | +; | RBX | RBP | hidden | padding | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | ; ---------------------------------------------------------------------------------- ; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | ; ---------------------------------------------------------------------------------- -; | parameter area | +; | GS:[0] | GS:[8] | GS:[16] | RIP | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | ; ---------------------------------------------------------------------------------- ; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | ; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | +; ---------------------------------------------------------------------------------- +; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c | +; ---------------------------------------------------------------------------------- ; | FCTX | DATA | | ; ---------------------------------------------------------------------------------- @@ -88,7 +95,7 @@ jump_fcontext PROC BOOST_CONTEXT_EXPORT FRAME .endprolog ; prepare stack - lea rsp, [rsp-0118h] + lea rsp, [rsp-0138h] IFNDEF BOOST_USE_TSX ; save XMM storage @@ -134,6 +141,13 @@ ENDIF mov [rsp+0110h], rcx ; save hidden address of transport_t + mov rax, gs:[0h] ; save exception block at gs:[0] + mov [rsp+0120h], rax + mov rax, gs:[8h] + mov [rsp+0128h], rax + mov rax, gs:[10h] + mov [rsp+0130h], rax + ; preserve RSP (pointing to context-data) in R9 mov r9, rsp @@ -182,10 +196,17 @@ ENDIF mov rbx, [rsp+0100h] ; restore RBX mov rbp, [rsp+0108h] ; restore RBP + mov rax, [rsp+0120h] ; restore exception block at gs:[0] + mov gs:[0h], rax + mov rax, [rsp+0128h] + mov gs:[8h], rax + mov rax, [rsp+0130h] + mov gs:[10h], rax + mov rax, [rsp+0110h] ; restore hidden address of transport_t ; prepare stack - lea rsp, [rsp+0118h] + lea rsp, [rsp+0138h] ; load return-address pop r10 diff --git a/src/asm/make_x86_64_ms_pe_masm.asm b/src/asm/make_x86_64_ms_pe_masm.asm index 8f6c959a..bdde3527 100644 --- a/src/asm/make_x86_64_ms_pe_masm.asm +++ b/src/asm/make_x86_64_ms_pe_masm.asm @@ -1,4 +1,3 @@ - ; Copyright Oliver Kowalke 2009. ; Distributed under the Boost Software License, Version 1.0. ; (See accompanying file LICENSE_1_0.txt or copy at @@ -33,52 +32,59 @@ ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ; ---------------------------------------------------------------------------------- ; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ; ---------------------------------------------------------------------------------- ; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | ; ---------------------------------------------------------------------------------- ; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | ; ---------------------------------------------------------------------------------- ; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | ; ---------------------------------------------------------------------------------- ; | limit | base | R12 | R13 | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ; ---------------------------------------------------------------------------------- ; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | ; ---------------------------------------------------------------------------------- ; | R14 | R15 | RDI | RSI | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ; ---------------------------------------------------------------------------------- ; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | ; ---------------------------------------------------------------------------------- -; | RBX | RBP | hidden | RIP | +; | RBX | RBP | hidden | padding | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | ; ---------------------------------------------------------------------------------- ; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | ; ---------------------------------------------------------------------------------- -; | parameter area | +; | GS:[0] | GS:[8] | GS:[16] | RIP | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | ; ---------------------------------------------------------------------------------- ; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | ; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | +; ---------------------------------------------------------------------------------- +; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c | +; ---------------------------------------------------------------------------------- ; | FCTX | DATA | | ; ---------------------------------------------------------------------------------- @@ -100,7 +106,7 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME ; reserve space for context-data on context-stack ; on context-function entry: (RSP -0x8) % 16 == 0 - sub rax, 0150h + sub rax, 0170h ; third arg of make_fcontext() == address of context-function ; stored in RBX @@ -109,6 +115,8 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME ; first arg of make_fcontext() == top of context-stack ; save top address of context stack as 'base' mov [rax+0c8h], rcx + ; also save high address in GS:[8] + mov [rax+0128h], rcx ; second arg of make_fcontext() == size of context-stack ; negate stack size for LEA instruction (== substraction) neg rdx @@ -116,19 +124,26 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME lea rcx, [rcx+rdx] ; save bottom address of context stack as 'limit' mov [rax+0c0h], rcx - ; save address of context stack limit as 'dealloction stack' + ; also save low address in GS:[16] + mov [rax+0130h], rcx + ; save address of context stack limit as 'deallocation stack' mov [rax+0b8h], rcx - ; set fiber-storage to zero - xor rcx, rcx + ; set fiber-storage to zero + xor rcx, rcx mov [rax+0b0h], rcx - ; save MMX control- and status-word + ; set GS:[0] to end-pointer marker (ffff'ffff'ffff'ffffh) for exception + ; handler chain + not rcx + mov [rax+0120h], rcx + + ; save MMX control- and status-word stmxcsr [rax+0a0h] ; save x87 control-word fnstcw [rax+0a4h] ; compute address of transport_t - lea rcx, [rax+0140h] + lea rcx, [rax+0160h] ; store address of transport_t in hidden field mov [rax+0110h], rcx @@ -136,7 +151,7 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME lea rcx, trampoline ; save address of trampoline as return-address for context-function ; will be entered after calling jump_fcontext() first time - mov [rax+0118h], rcx + mov [rax+0138h], rcx ; compute abs address of label finish lea rcx, finish diff --git a/src/asm/ontop_x86_64_ms_pe_masm.asm b/src/asm/ontop_x86_64_ms_pe_masm.asm index b57dd158..1a0c9ab4 100644 --- a/src/asm/ontop_x86_64_ms_pe_masm.asm +++ b/src/asm/ontop_x86_64_ms_pe_masm.asm @@ -33,52 +33,59 @@ ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | +; | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ; ---------------------------------------------------------------------------------- ; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | +; | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ; ---------------------------------------------------------------------------------- ; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | ; ---------------------------------------------------------------------------------- ; | fc_mxcsr|fc_x87_cw| | fbr_strg | fc_dealloc | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | +; | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | ; ---------------------------------------------------------------------------------- ; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | ; ---------------------------------------------------------------------------------- ; | limit | base | R12 | R13 | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | +; | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ; ---------------------------------------------------------------------------------- ; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | ; ---------------------------------------------------------------------------------- ; | R14 | R15 | RDI | RSI | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | +; | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ; ---------------------------------------------------------------------------------- ; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | ; ---------------------------------------------------------------------------------- -; | RBX | RBP | hidden | RIP | +; | RBX | RBP | hidden | padding | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | +; | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | ; ---------------------------------------------------------------------------------- ; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | ; ---------------------------------------------------------------------------------- -; | parameter area | +; | GS:[0] | GS:[8] | GS:[16] | RIP | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- -; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | +; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | ; ---------------------------------------------------------------------------------- ; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | ; ---------------------------------------------------------------------------------- +; | parameter area | +; ---------------------------------------------------------------------------------- +; ---------------------------------------------------------------------------------- +; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | +; ---------------------------------------------------------------------------------- +; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c | +; ---------------------------------------------------------------------------------- ; | FCTX | DATA | | ; ---------------------------------------------------------------------------------- @@ -88,7 +95,7 @@ ontop_fcontext PROC BOOST_CONTEXT_EXPORT FRAME .endprolog ; prepare stack - lea rsp, [rsp-0118h] + lea rsp, [rsp-0138h] IFNDEF BOOST_USE_TSX ; save XMM storage @@ -134,6 +141,13 @@ ENDIF mov [rsp+0110h], rcx ; save hidden address of transport_t + mov rax, gs:[0h] ; save exception block at gs:[0] + mov [rsp+0120h], rax + mov rax, gs:[8h] + mov [rsp+0128h], rax + mov rax, gs:[10h] + mov [rsp+0130h], rax + ; preserve RSP (pointing to context-data) in RCX mov rcx, rsp @@ -182,10 +196,17 @@ ENDIF mov rbx, [rsp+0100h] ; restore RBX mov rbp, [rsp+0108h] ; restore RBP + mov rax, [rsp+0120h] ; restore exception block at gs:[0] + mov gs:[0h], rax + mov rax, [rsp+0128h] + mov gs:[8h], rax + mov rax, [rsp+0130h] + mov gs:[10h], rax + mov rax, [rsp+0110h] ; restore hidden address of transport_t ; prepare stack - lea rsp, [rsp+0118h] + lea rsp, [rsp+0138h] ; keep return-address on stack