$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r84181 - in trunk: boost/context/detail libs/context/src/asm
From: oliver.kowalke_at_[hidden]
Date: 2013-05-07 13:34:14
Author: olli
Date: 2013-05-07 13:34:13 EDT (Tue, 07 May 2013)
New Revision: 84181
URL: http://svn.boost.org/trac/boost/changeset/84181
Log:
context: fix deallocation stack issue on 64bit Windows
Text files modified: 
   trunk/boost/context/detail/fcontext_x86_64_win.hpp    |     4 ++                                      
   trunk/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm |    57 +++++++++++++++++++++++---------------- 
   trunk/libs/context/src/asm/make_x86_64_ms_pe_masm.asm |    14 +++++++--                               
   3 files changed, 48 insertions(+), 27 deletions(-)
Modified: trunk/boost/context/detail/fcontext_x86_64_win.hpp
==============================================================================
--- trunk/boost/context/detail/fcontext_x86_64_win.hpp	(original)
+++ trunk/boost/context/detail/fcontext_x86_64_win.hpp	2013-05-07 13:34:13 EDT (Tue, 07 May 2013)
@@ -51,12 +51,14 @@
     stack_t             fc_stack;
     void            *   fc_local_storage;
     boost::uint64_t     fc_fp[24];
+    boost::uint64_t     fc_dealloc;
 
     fcontext_t() :
         fc_greg(),
         fc_stack(),
         fc_local_storage( 0),
-        fc_fp()
+        fc_fp(),
+        fc_dealloc()
     {}
 };
 
Modified: trunk/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm
==============================================================================
--- trunk/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm	(original)
+++ trunk/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm	2013-05-07 13:34:13 EDT (Tue, 07 May 2013)
@@ -81,6 +81,13 @@
 ;  ----------------------------------------------------------------------------------
 ;  |                          SEE registers (XMM6-XMM15)                            |
 ;  ----------------------------------------------------------------------------------
+;  ----------------------------------------------------------------------------------
+;  |    76   |   77    |                                                            |
+;  ----------------------------------------------------------------------------------
+;  |  0x130  |  0x134  |                                                            |
+;  ----------------------------------------------------------------------------------
+;  |    fc_dealloc     |                                                            |
+;  ----------------------------------------------------------------------------------
 
 EXTERN  _exit:PROC            ; standard C library function
 .code
@@ -88,22 +95,24 @@
 jump_fcontext PROC EXPORT FRAME
     .endprolog
 
-    mov     [rcx],       r12        ; save R12
-    mov     [rcx+08h],   r13        ; save R13
-    mov     [rcx+010h],  r14        ; save R14
-    mov     [rcx+018h],  r15        ; save R15
-    mov     [rcx+020h],  rdi        ; save RDI
-    mov     [rcx+028h],  rsi        ; save RSI
-    mov     [rcx+030h],  rbx        ; save RBX
-    mov     [rcx+038h],  rbp        ; save RBP
-
-    mov     r10,         gs:[030h]  ; load NT_TIB
-    mov     rax,         [r10+08h]  ; load current stack base
-    mov     [rcx+050h],  rax        ; save current stack base
-    mov     rax,         [r10+010h] ; load current stack limit
-    mov     [rcx+060h],  rax        ; save current stack limit
-    mov     rax,         [r10+018h] ; load fiber local storage
-    mov     [rcx+068h],  rax        ; save fiber local storage
+    mov     [rcx],       r12          ; save R12
+    mov     [rcx+08h],   r13          ; save R13
+    mov     [rcx+010h],  r14          ; save R14
+    mov     [rcx+018h],  r15          ; save R15
+    mov     [rcx+020h],  rdi          ; save RDI
+    mov     [rcx+028h],  rsi          ; save RSI
+    mov     [rcx+030h],  rbx          ; save RBX
+    mov     [rcx+038h],  rbp          ; save RBP
+
+    mov     r10,         gs:[030h]    ; load NT_TIB
+    mov     rax,         [r10+08h]    ; load current stack base
+    mov     [rcx+050h],  rax          ; save current stack base
+    mov     rax,         [r10+010h]   ; load current stack limit
+    mov     [rcx+060h],  rax          ; save current stack limit
+    mov     rax,         [r10+01478h] ; load current deallocation stack
+    mov     [rcx+0130h], rax          ; save current deallocation stack
+    mov     rax,         [r10+018h]   ; load fiber local storage
+    mov     [rcx+068h],  rax          ; save fiber local storage
 
     test    r9,          r9
     je      nxt
@@ -163,13 +172,15 @@
     mov     rbx,        [rdx+030h]  ; restore RBX
     mov     rbp,        [rdx+038h]  ; restore RBP
 
-    mov     r10,        gs:[030h]   ; load NT_TIB
-    mov     rax,        [rdx+050h]  ; load stack base
-    mov     [r10+08h],  rax         ; restore stack base
-    mov     rax,        [rdx+060h]  ; load stack limit
-    mov     [r10+010h], rax         ; restore stack limit
-    mov     rax,        [rdx+068h]  ; load fiber local storage
-    mov     [r10+018h], rax         ; restore fiber local storage
+    mov     r10,          gs:[030h]   ; load NT_TIB
+    mov     rax,          [rdx+050h]  ; load stack base
+    mov     [r10+08h],    rax         ; restore stack base
+    mov     rax,          [rdx+060h]  ; load stack limit
+    mov     [r10+010h],   rax         ; restore stack limit
+    mov     rax,          [rdx+0130h] ; load deallocation stack
+    mov     [r10+01478h], rax         ; restore deallocation stack
+    mov     rax,          [rdx+068h]  ; load fiber local storage
+    mov     [r10+018h],   rax         ; restore fiber local storage
 
     mov     rsp,        [rdx+040h]  ; restore RSP
     mov     r10,        [rdx+048h]  ; fetch the address to returned to
Modified: trunk/libs/context/src/asm/make_x86_64_ms_pe_masm.asm
==============================================================================
--- trunk/libs/context/src/asm/make_x86_64_ms_pe_masm.asm	(original)
+++ trunk/libs/context/src/asm/make_x86_64_ms_pe_masm.asm	2013-05-07 13:34:13 EDT (Tue, 07 May 2013)
@@ -81,6 +81,13 @@
 ;  ----------------------------------------------------------------------------------
 ;  |                          SEE registers (XMM6-XMM15)                            |
 ;  ----------------------------------------------------------------------------------
+;  ----------------------------------------------------------------------------------
+;  |    76   |   77    |                                                            |
+;  ----------------------------------------------------------------------------------
+;  |  0x130  |  0x134  |                                                            |
+;  ----------------------------------------------------------------------------------
+;  |     fc_dealloc    |                                                            |
+;  ----------------------------------------------------------------------------------
 
 EXTERN  _exit:PROC            ; standard C library function
 .code
@@ -88,7 +95,7 @@
 make_fcontext PROC EXPORT FRAME  ; generate function table entry in .pdata and unwind information in
     .endprolog                   ; .xdata for a function's structured exception handling unwind behavior
 
-    lea  rax,        [rcx-0130h] ; reserve space for fcontext_t at top of context stack
+    lea  rax,        [rcx-0138h] ; reserve space for fcontext_t at top of context stack
 
     ; shift address in RAX to lower 16 byte boundary
     ; == pointer to fcontext_t and address of context stack
@@ -99,8 +106,9 @@
     mov  [rax+050h], rcx         ; save address of context stack pointer (base) in fcontext_t
 
     neg  rdx                     ; negate stack size for LEA instruction (== substraction)
-    lea  rcx,        [rcx+rdx]   ; compute bottom address of context stack (limit)
-    mov  [rax+060h], rcx         ; save bottom address of context stack (limit) in fcontext_t
+    lea  rcx,         [rcx+rdx]  ; compute bottom address of context stack (limit)
+    mov  [rax+060h],  rcx        ; save bottom address of context stack (limit) in fcontext_t
+    mov  [rax+0130h], rcx        ; save address of context stack limit as 'dealloction stack'
 
     stmxcsr [rax+070h]           ; save MMX control and status word
     fnstcw  [rax+074h]           ; save x87 control word