Skip to content

Commit

Permalink
Reserve more space on the stack to save state for context switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-goodspeed committed Jan 1, 2025
1 parent 1bde50e commit 07d0ff8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
27 changes: 17 additions & 10 deletions src/asm/jump_x86_64_ms_pe_masm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,60 @@
; | 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| <alignment> | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 |
; ----------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ----------------------------------------------------------------------------------
; | FCTX | DATA | |
; | FCTX | DATA | GS:[0] | GS:[8] |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
; ----------------------------------------------------------------------------------
; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c |
; ----------------------------------------------------------------------------------
; | GS:[16] | |
; ----------------------------------------------------------------------------------

.code
Expand All @@ -88,7 +95,7 @@ jump_fcontext PROC BOOST_CONTEXT_EXPORT FRAME
.endprolog

; prepare stack
lea rsp, [rsp-0118h]
lea rsp, [rsp-0130h]

IFNDEF BOOST_USE_TSX
; save XMM storage
Expand Down Expand Up @@ -185,7 +192,7 @@ ENDIF
mov rax, [rsp+0110h] ; restore hidden address of transport_t

; prepare stack
lea rsp, [rsp+0118h]
lea rsp, [rsp+0130h]

; load return-address
pop r10
Expand Down
25 changes: 16 additions & 9 deletions src/asm/make_x86_64_ms_pe_masm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,60 @@
; | 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| <alignment> | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 |
; ----------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ----------------------------------------------------------------------------------
; | FCTX | DATA | |
; | FCTX | DATA | GS:[0] | GS:[8] |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
; ----------------------------------------------------------------------------------
; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c |
; ----------------------------------------------------------------------------------
; | GS:[16] | |
; ----------------------------------------------------------------------------------

; standard C library function
Expand All @@ -100,7 +107,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, 0168h

; third arg of make_fcontext() == address of context-function
; stored in RBX
Expand Down
27 changes: 17 additions & 10 deletions src/asm/ontop_x86_64_ms_pe_masm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,60 @@
; | 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| <alignment> | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 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 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 |
; ----------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ----------------------------------------------------------------------------------
; | FCTX | DATA | |
; | FCTX | DATA | GS:[0] | GS:[8] |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
; ----------------------------------------------------------------------------------
; | 0x160 | 0x164 | 0x168 | 0x16c | 0x170 | 0x174 | 0x178 | 0x17c |
; ----------------------------------------------------------------------------------
; | GS:[16] | |
; ----------------------------------------------------------------------------------

.code
Expand All @@ -88,7 +95,7 @@ ontop_fcontext PROC BOOST_CONTEXT_EXPORT FRAME
.endprolog

; prepare stack
lea rsp, [rsp-0118h]
lea rsp, [rsp-0130h]

IFNDEF BOOST_USE_TSX
; save XMM storage
Expand Down Expand Up @@ -185,7 +192,7 @@ ENDIF
mov rax, [rsp+0110h] ; restore hidden address of transport_t

; prepare stack
lea rsp, [rsp+0118h]
lea rsp, [rsp+0130h]

; keep return-address on stack

Expand Down

0 comments on commit 07d0ff8

Please sign in to comment.