Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81706 - in trunk/libs/context: build src src/asm
From: oliver.kowalke_at_[hidden]
Date: 2012-12-04 13:10:38


Author: olli
Date: 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
New Revision: 81706
URL: http://svn.boost.org/trac/boost/changeset/81706

Log:
context: seh cleanup for Windows

Removed:
   trunk/libs/context/src/seh.cpp
Text files modified:
   trunk/libs/context/build/Jamfile.v2 | 18 ++++++------------
   trunk/libs/context/src/asm/jump_i386_ms_pe_masm.asm | 2 --
   trunk/libs/context/src/asm/jump_x86_64_ms_pe_masm.asm | 3 +--
   trunk/libs/context/src/asm/make_i386_ms_pe_masm.asm | 34 ++++++++++++++++++++++++++--------
   4 files changed, 33 insertions(+), 24 deletions(-)

Modified: trunk/libs/context/build/Jamfile.v2
==============================================================================
--- trunk/libs/context/build/Jamfile.v2 (original)
+++ trunk/libs/context/build/Jamfile.v2 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
@@ -281,8 +281,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- asm/make_i386_ms_pe_masm.asm
+ : asm/make_i386_ms_pe_masm.asm
      asm/jump_i386_ms_pe_masm.asm
    : <abi>ms
      <address-model>32
@@ -293,8 +292,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- asm/make_i386_ms_pe_masm.asm
+ : asm/make_i386_ms_pe_masm.asm
      asm/jump_i386_ms_pe_masm.asm
    : <abi>ms
      <address-model>32
@@ -305,8 +303,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- [ make asm/make_i386_ms_pe_masm.o : asm/make_i386_ms_pe_masm.asm : @masm ]
+ : [ make asm/make_i386_ms_pe_masm.o : asm/make_i386_ms_pe_masm.asm : @masm ]
      [ make asm/jump_i386_ms_pe_masm.o : asm/jump_i386_ms_pe_masm.asm : @masm ]
    : <abi>ms
      <address-model>32
@@ -388,8 +385,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- asm/make_x86_64_ms_pe_masm.asm
+ : asm/make_x86_64_ms_pe_masm.asm
      asm/jump_x86_64_ms_pe_masm.asm
    : <abi>ms
      <address-model>64
@@ -400,8 +396,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- asm/make_x86_64_ms_pe_masm.asm
+ : asm/make_x86_64_ms_pe_masm.asm
      asm/jump_x86_64_ms_pe_masm.asm
    : <abi>ms
      <address-model>64
@@ -412,8 +407,7 @@
    ;
 
 alias asm_context_sources
- : seh.cpp
- [ make asm/make_x86_64_ms_pe_masm.o : asm/make_x86_64_ms_pe_masm.asm : @masm64 ]
+ : [ make asm/make_x86_64_ms_pe_masm.o : asm/make_x86_64_ms_pe_masm.asm : @masm64 ]
      [ make asm/jump_x86_64_ms_pe_masm.o : asm/jump_x86_64_ms_pe_masm.asm : @masm64 ]
    : <abi>ms
      <address-model>64

Modified: trunk/libs/context/src/asm/jump_i386_ms_pe_masm.asm
==============================================================================
--- trunk/libs/context/src/asm/jump_i386_ms_pe_masm.asm (original)
+++ trunk/libs/context/src/asm/jump_i386_ms_pe_masm.asm 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
@@ -43,8 +43,6 @@
 .386
 .XMM
 .model flat, c
-_exit PROTO, value:SDWORD
-seh_fcontext PROTO, except:DWORD, frame:DWORD, context:DWORD, dispatch:DWORD
 .code
 
 jump_fcontext PROC EXPORT

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 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
@@ -83,10 +83,9 @@
 ; ----------------------------------------------------------------------------------
 
 EXTERN _exit:PROC ; standard C library function
-EXTERN seh_fcontext:PROC ; exception handler
 .code
 
-jump_fcontext PROC EXPORT FRAME:seh_fcontext
+jump_fcontext PROC EXPORT FRAME
     .endprolog
 
     mov [rcx], r12 ; save R12

Modified: trunk/libs/context/src/asm/make_i386_ms_pe_masm.asm
==============================================================================
--- trunk/libs/context/src/asm/make_i386_ms_pe_masm.asm (original)
+++ trunk/libs/context/src/asm/make_i386_ms_pe_masm.asm 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
@@ -44,7 +44,6 @@
 .XMM
 .model flat, c
 _exit PROTO, value:SDWORD
-seh_fcontext PROTO, except:DWORD, frame:DWORD, context:DWORD, dispatch:DWORD
 .code
 
 make_fcontext PROC EXPORT
@@ -53,7 +52,7 @@
 
     ; shift address in EAX to lower 16 byte boundary
     ; == pointer to fcontext_t and address of context stack
- and eax, -16
+ and eax, -16
 
     mov ecx, [esp+04h] ; load 1. arg of make_fcontext, pointer to context stack (base)
     mov [eax+018h], ecx ; save address of context stack (base) in fcontext_t
@@ -71,17 +70,36 @@
     lea edx, [eax-01ch] ; reserve space for last frame and seh on context stack, (ESP - 0x4) % 16 == 0
     mov [eax+010h], edx ; save address in EDX as stack pointer for context function
 
- mov ecx, seh_fcontext ; set ECX to exception-handler
- mov [edx+018h], ecx ; save ECX as SEH handler
+ mov ecx, finish ; abs address of finish
+ mov [edx], ecx ; save address of finish as return address for context function
+ ; entered after context function returns
+
+ ; traverse current seh chain to get the last exception handler installed by Windows
+ ; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default
+ ; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler
+ ; at its end by RaiseException all seh andlers are disregarded if not present and the
+ ; program is aborted
+ assume fs:nothing
+ mov ecx, fs:[018h] ; load NT_TIB into ECX
+ assume fs:error
+
+walk:
+ mov edx, [ecx] ; load 'next' member of current SEH into EDX
+ inc edx ; test if 'next' of current SEH is last (== 0xffffffff)
+ jz found
+ dec edx
+ xchg edx, ecx ; exchange content; ECX contains address of next SEH
+ jmp walk ; inspect next SEH
+
+found:
+ mov ecx, [ecx+04h] ; load 'handler' member of SEH == address of last SEH handler installed by Windows
+ mov edx, [eax+010h] ; load address of stack pointer for context function
+ mov [edx+018h], ecx ; save address in ECX as SEH handler for context
     mov ecx, 0ffffffffh ; set ECX to -1
     mov [edx+014h], ecx ; save ECX as next SEH item
     lea ecx, [edx+014h] ; load address of next SEH item
     mov [eax+024h], ecx ; save next SEH
 
- mov ecx, finish ; abs address of finish
- mov [edx], ecx ; save address of finish as return address for context function
- ; entered after context function returns
-
     ret
 
 finish:

Deleted: trunk/libs/context/src/seh.cpp
==============================================================================
--- trunk/libs/context/src/seh.cpp 2012-12-04 13:10:37 EST (Tue, 04 Dec 2012)
+++ (empty file)
@@ -1,92 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#define BOOST_CONTEXT_SOURCE
-
-extern "C" {
-
-#include <stddef.h>
-#include <stdio.h>
-
-#include <excpt.h>
-#include <windows.h>
-#include <winnt.h>
-
-#if defined(_MSC_VER)
-# define SNPRINTF _snprintf
-#else
-# define SNPRINTF snprintf
-#endif
-
-#if defined(_MSC_VER)
-# pragma warning(push)
-# pragma warning(disable:4996)
-# endif
-
-static const char * exception_description(
- _EXCEPTION_RECORD const* record, char * description, size_t len)
-{
- const DWORD code = record->ExceptionCode;
- const ULONG_PTR * info = record->ExceptionInformation;
-
- switch ( code)
- {
- case EXCEPTION_ACCESS_VIOLATION:
- {
- const char * accessType = ( info[0]) ? "writing" : "reading";
- const ULONG_PTR address = info[1];
- SNPRINTF( description, len, "Access violation %s %p", accessType, reinterpret_cast< void * >( address) );
- return description;
- }
- case EXCEPTION_DATATYPE_MISALIGNMENT: return "Datatype misalignment";
- case EXCEPTION_BREAKPOINT: return "Breakpoint";
- case EXCEPTION_SINGLE_STEP: return "Single step";
- case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "Array bounds exceeded";
- case EXCEPTION_FLT_DENORMAL_OPERAND: return "FPU denormal operand";
- case EXCEPTION_FLT_DIVIDE_BY_ZERO: return "FPU divide by zero";
- case EXCEPTION_FLT_INEXACT_RESULT: return "FPU inexact result";
- case EXCEPTION_FLT_INVALID_OPERATION: return "FPU invalid operation";
- case EXCEPTION_FLT_OVERFLOW: return "FPU overflow";
- case EXCEPTION_FLT_STACK_CHECK: return "FPU stack check";
- case EXCEPTION_FLT_UNDERFLOW: return "FPU underflow";
- case EXCEPTION_INT_DIVIDE_BY_ZERO: return "Integer divide by zero";
- case EXCEPTION_INT_OVERFLOW: return "Integer overflow";
- case EXCEPTION_PRIV_INSTRUCTION: return "Privileged instruction";
- case EXCEPTION_IN_PAGE_ERROR: return "In page error";
- case EXCEPTION_ILLEGAL_INSTRUCTION: return "Illegal instruction";
- case EXCEPTION_NONCONTINUABLE_EXCEPTION: return "Noncontinuable exception";
- case EXCEPTION_STACK_OVERFLOW: return "Stack overflow";
- case EXCEPTION_INVALID_DISPOSITION: return "Invalid disposition";
- case EXCEPTION_GUARD_PAGE: return "Guard page";
- case EXCEPTION_INVALID_HANDLE: return "Invalid handle";
- }
-
- SNPRINTF( description, len, "Unknown (0x%08lX)", code);
- return description;
-}
-
-EXCEPTION_DISPOSITION seh_fcontext(
- struct _EXCEPTION_RECORD * record,
- void *,
- struct _CONTEXT *,
- void *)
-{
- char description[255];
-
- fprintf( stderr, "exception: %s (%08lX)\n",
- exception_description( record, description, sizeof( description) ),
- record->ExceptionCode);
-
- ExitProcess( -1);
-
- return ExceptionContinueSearch; // never reached
-}
-
-# if defined(BOOST_MSVC)
-# pragma warning(pop)
-# endif
-
-}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk