Ignore:
Timestamp:
Apr 18, 2012, 10:46:37 PM (13 years ago)
Author:
dmik
Message:

kernel32: Make SEH work in OS/2 context.

See #82 for details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibexcept.cpp

    r21980 r21999  
    1616#include <win32type.h>
    1717#include <misc.h>
    18 #include "oslibexcept.h"
    1918#include <exceptions.h>
    2019#include <wprocess.h>
    2120
     21#include "oslibexcept.h"
     22
    2223#define DBG_LOCALLOG    DBG_oslibexcept
    2324#include "dbglocal.h"
    2425
    25 //******************************************************************************
    26 //Dispatches OS/2 exception to win32 handler
    27 //Returns: TRUE, win32 exception handler returned continue execution
    28 //         FALSE, otherwise
    29 //******************************************************************************
    30 BOOL APIENTRY OSLibDispatchException(PEXCEPTIONREPORTRECORD pReportRec,
    31                                      PEXCEPTIONREGISTRATIONRECORD pRegistrationRec,
    32                                      PCONTEXTRECORD pContextRec, PVOID p)
     26/**
     27 * Converts the OS/2 exception information to the Win32 exception information.
     28 *
     29 * Returns TRUE on succes and FALSE otherwise.
     30 */
     31BOOL APIENTRY OSLibConvertExceptionInfo(PEXCEPTIONREPORTRECORD pReportRec,
     32                                        PCONTEXTRECORD pContextRec,
     33                                        PWINEXCEPTION_RECORD pWinReportRec,
     34                                        PWINCONTEXT pWinContextRec,
     35                                        TEB *pWinTEB)
    3336{
    34  WINEXCEPTION_RECORD winreportrec;
    35  WINCONTEXT          wincontextrec;
    36  ULONG               rc;
    37 
    38   memset(&winreportrec, 0, sizeof(winreportrec));
    39   memcpy(&winreportrec, pReportRec, sizeof(*pReportRec));
    40 
    41   switch(pReportRec->ExceptionNum) {
    42   case XCPT_FLOAT_DENORMAL_OPERAND:
    43         winreportrec.ExceptionCode = EXCEPTION_FLT_DENORMAL_OPERAND;
    44         break;
    45   case XCPT_FLOAT_DIVIDE_BY_ZERO:
    46         winreportrec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
    47         break;
    48   case XCPT_FLOAT_INEXACT_RESULT:
    49         winreportrec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
    50         break;
    51   case XCPT_FLOAT_INVALID_OPERATION:
    52         winreportrec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
    53         break;
    54   case XCPT_FLOAT_OVERFLOW:
    55         winreportrec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
    56         break;
    57   case XCPT_FLOAT_STACK_CHECK:
    58         winreportrec.ExceptionCode = EXCEPTION_FLT_STACK_CHECK;
    59         break;
    60   case XCPT_FLOAT_UNDERFLOW:
    61         winreportrec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
    62         break;
    63   case XCPT_INTEGER_DIVIDE_BY_ZERO:
    64         winreportrec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
    65         break;
    66   case XCPT_INTEGER_OVERFLOW:
    67         winreportrec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
    68         break;
    69   case XCPT_PRIVILEGED_INSTRUCTION:
    70         winreportrec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
    71         break;
    72   case XCPT_BREAKPOINT:
    73         winreportrec.ExceptionCode = EXCEPTION_BREAKPOINT;
    74         break;
    75   case XCPT_SINGLE_STEP:
    76         winreportrec.ExceptionCode = EXCEPTION_SINGLE_STEP;
    77         break;
    78   case XCPT_ARRAY_BOUNDS_EXCEEDED:
    79         winreportrec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
    80         break;
    81   case XCPT_DATATYPE_MISALIGNMENT:
    82         winreportrec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
    83         break;
    84   case XCPT_ILLEGAL_INSTRUCTION:
    85         winreportrec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
    86         break;
    87   case XCPT_INVALID_LOCK_SEQUENCE:
    88         winreportrec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
    89         break;
    90   case XCPT_GUARD_PAGE_VIOLATION:
    91         winreportrec.ExceptionCode = EXCEPTION_GUARD_PAGE;
    92         break;
    93   case XCPT_UNABLE_TO_GROW_STACK:
    94         winreportrec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
    95         break;
    96   case XCPT_IN_PAGE_ERROR:
    97         winreportrec.ExceptionCode = EXCEPTION_IN_PAGE_ERROR;
    98         break;
    99   case XCPT_ACCESS_VIOLATION:
    100         winreportrec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
    101         break;
    102   default: //no other exceptions should be dispatched to win32 apps
     37    memset(pWinReportRec, 0, sizeof(*pWinReportRec));
     38    memcpy(pWinReportRec, pReportRec, sizeof(*pReportRec));
     39
     40    switch (pReportRec->ExceptionNum)
     41    {
     42    case XCPT_FLOAT_DENORMAL_OPERAND:
     43        pWinReportRec->ExceptionCode = EXCEPTION_FLT_DENORMAL_OPERAND;
     44        break;
     45    case XCPT_FLOAT_DIVIDE_BY_ZERO:
     46        pWinReportRec->ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
     47        break;
     48    case XCPT_FLOAT_INEXACT_RESULT:
     49        pWinReportRec->ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
     50        break;
     51    case XCPT_FLOAT_INVALID_OPERATION:
     52        pWinReportRec->ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
     53        break;
     54    case XCPT_FLOAT_OVERFLOW:
     55        pWinReportRec->ExceptionCode = EXCEPTION_FLT_OVERFLOW;
     56        break;
     57    case XCPT_FLOAT_STACK_CHECK:
     58        pWinReportRec->ExceptionCode = EXCEPTION_FLT_STACK_CHECK;
     59        break;
     60    case XCPT_FLOAT_UNDERFLOW:
     61        pWinReportRec->ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
     62        break;
     63    case XCPT_INTEGER_DIVIDE_BY_ZERO:
     64        pWinReportRec->ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
     65        break;
     66    case XCPT_INTEGER_OVERFLOW:
     67        pWinReportRec->ExceptionCode = EXCEPTION_INT_OVERFLOW;
     68        break;
     69    case XCPT_PRIVILEGED_INSTRUCTION:
     70        pWinReportRec->ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
     71        break;
     72    case XCPT_BREAKPOINT:
     73        pWinReportRec->ExceptionCode = EXCEPTION_BREAKPOINT;
     74        break;
     75    case XCPT_SINGLE_STEP:
     76        pWinReportRec->ExceptionCode = EXCEPTION_SINGLE_STEP;
     77        break;
     78    case XCPT_ARRAY_BOUNDS_EXCEEDED:
     79        pWinReportRec->ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
     80        break;
     81    case XCPT_DATATYPE_MISALIGNMENT:
     82        pWinReportRec->ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
     83        break;
     84    case XCPT_ILLEGAL_INSTRUCTION:
     85        pWinReportRec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
     86        break;
     87    case XCPT_INVALID_LOCK_SEQUENCE:
     88        pWinReportRec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
     89        break;
     90    case XCPT_GUARD_PAGE_VIOLATION:
     91        pWinReportRec->ExceptionCode = EXCEPTION_GUARD_PAGE;
     92        break;
     93    case XCPT_UNABLE_TO_GROW_STACK:
     94        pWinReportRec->ExceptionCode = EXCEPTION_STACK_OVERFLOW;
     95        break;
     96    case XCPT_IN_PAGE_ERROR:
     97        pWinReportRec->ExceptionCode = EXCEPTION_IN_PAGE_ERROR;
     98        break;
     99    case XCPT_ACCESS_VIOLATION:
     100        pWinReportRec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
     101        break;
     102    default: // no other exceptions should be dispatched to win32 apps
    103103        return FALSE;
    104   }
    105   //TODO:
    106   //According to the Wine folks the flags are the same in OS/2 and win32
    107   //Let's assume for now the rest is identical as well
    108 
    109   //copy context record info
    110   memset(&wincontextrec, 0, sizeof(wincontextrec));
    111   if(pContextRec->ContextFlags & CONTEXT_CONTROL) {
    112         wincontextrec.ContextFlags |= WINCONTEXT_CONTROL;
    113         wincontextrec.Ebp     = pContextRec->ctx_RegEbp;
    114         wincontextrec.Eip     = pContextRec->ctx_RegEip;
    115         wincontextrec.SegCs   = pContextRec->ctx_SegCs;
    116         wincontextrec.EFlags  = pContextRec->ctx_EFlags;
    117         wincontextrec.Esp     = pContextRec->ctx_RegEsp;
    118         wincontextrec.SegSs   = pContextRec->ctx_SegSs;
    119   }
    120   if(pContextRec->ContextFlags & CONTEXT_INTEGER) {
    121         wincontextrec.ContextFlags |= WINCONTEXT_INTEGER;
    122         wincontextrec.Edi     = pContextRec->ctx_RegEdi;
    123         wincontextrec.Esi     = pContextRec->ctx_RegEsi;
    124         wincontextrec.Ebx     = pContextRec->ctx_RegEbx;
    125         wincontextrec.Edx     = pContextRec->ctx_RegEdx;
    126         wincontextrec.Ecx     = pContextRec->ctx_RegEcx;
    127         wincontextrec.Eax     = pContextRec->ctx_RegEax;
    128   }
    129 
    130   TEB *winteb = GetThreadTEB();
    131 
    132   if(pContextRec->ContextFlags & CONTEXT_SEGMENTS) {
    133         wincontextrec.ContextFlags |= WINCONTEXT_SEGMENTS;
    134         wincontextrec.SegGs   = pContextRec->ctx_SegGs;
    135 //   This resets FS to 0x150B - we DON'T want that!!
    136 //      wincontextrec.SegFs   = pContextRec->ctx_SegFs;
    137         wincontextrec.SegFs   = winteb->teb_sel;
    138         wincontextrec.SegEs   = pContextRec->ctx_SegEs;
    139         wincontextrec.SegDs   = pContextRec->ctx_SegDs;
    140   }
    141   if(pContextRec->ContextFlags & CONTEXT_FLOATING_POINT) {
    142         wincontextrec.ContextFlags |= WINCONTEXT_FLOATING_POINT;
     104    }
     105
     106    // TODO:
     107    // According to the Wine folks the flags are the same in OS/2 and win32
     108    // Let's assume for now the rest is identical as well
     109
     110    // copy context record info
     111    memset(pWinContextRec, 0, sizeof(*pWinContextRec));
     112    if (pContextRec->ContextFlags & CONTEXT_CONTROL)
     113    {
     114        pWinContextRec->ContextFlags |= WINCONTEXT_CONTROL;
     115        pWinContextRec->Ebp     = pContextRec->ctx_RegEbp;
     116        pWinContextRec->Eip     = pContextRec->ctx_RegEip;
     117        pWinContextRec->SegCs   = pContextRec->ctx_SegCs;
     118        pWinContextRec->EFlags  = pContextRec->ctx_EFlags;
     119        pWinContextRec->Esp     = pContextRec->ctx_RegEsp;
     120        pWinContextRec->SegSs   = pContextRec->ctx_SegSs;
     121    }
     122    if (pContextRec->ContextFlags & CONTEXT_INTEGER)
     123    {
     124        pWinContextRec->ContextFlags |= WINCONTEXT_INTEGER;
     125        pWinContextRec->Edi     = pContextRec->ctx_RegEdi;
     126        pWinContextRec->Esi     = pContextRec->ctx_RegEsi;
     127        pWinContextRec->Ebx     = pContextRec->ctx_RegEbx;
     128        pWinContextRec->Edx     = pContextRec->ctx_RegEdx;
     129        pWinContextRec->Ecx     = pContextRec->ctx_RegEcx;
     130        pWinContextRec->Eax     = pContextRec->ctx_RegEax;
     131    }
     132
     133    if (pContextRec->ContextFlags & CONTEXT_SEGMENTS)
     134    {
     135        pWinContextRec->ContextFlags |= WINCONTEXT_SEGMENTS;
     136        pWinContextRec->SegGs   = pContextRec->ctx_SegGs;
     137        // set Wn32 TEB if we run in switch FS mode
     138        if (pWinTEB)
     139            pWinContextRec->SegFs   = pWinTEB->teb_sel;
     140        else
     141            pWinContextRec->SegFs   = pContextRec->ctx_SegFs;
     142        pWinContextRec->SegEs   = pContextRec->ctx_SegEs;
     143        pWinContextRec->SegDs   = pContextRec->ctx_SegDs;
     144    }
     145
     146    if (pContextRec->ContextFlags & CONTEXT_FLOATING_POINT)
     147    {
     148        pWinContextRec->ContextFlags |= WINCONTEXT_FLOATING_POINT;
    143149        //TODO: First 7 dwords the same?
    144         memcpy(&wincontextrec.FloatSave, pContextRec->ctx_env, sizeof(pContextRec->ctx_env));
    145         memcpy(&wincontextrec.FloatSave.RegisterArea, pContextRec->ctx_stack, sizeof(pContextRec->ctx_stack));
    146   }
    147   //It doesn't seem correct if we dispatch real exceptions to win32 apps
    148   //Some just call RtlUnwind and continue as if they were processing an
    149   //exception thrown by C++ code. (instead of real OS exception)
    150 #if 1
    151   // We need to reset FS to its original (Win32) value, otherwise we'll likely
    152   // fuck up the Win32 exception handlers. They could end up using the wrong
    153   // exception chain if they access FS:[0] directly.
    154   DWORD oldsel = SetReturnFS(winteb->teb_sel);
    155 
    156   switch(pReportRec->ExceptionNum) {
    157   case XCPT_FLOAT_DENORMAL_OPERAND:
    158   case XCPT_FLOAT_DIVIDE_BY_ZERO:
    159   case XCPT_FLOAT_INEXACT_RESULT:
    160   case XCPT_FLOAT_INVALID_OPERATION:
    161   case XCPT_FLOAT_OVERFLOW:
    162   case XCPT_FLOAT_STACK_CHECK:
    163   case XCPT_FLOAT_UNDERFLOW:
    164         rc = RtlDispatchException(&winreportrec, &wincontextrec);
    165         break;
    166 
    167   case XCPT_ACCESS_VIOLATION:
    168         rc = RtlDispatchException(&winreportrec, &wincontextrec);
    169         break;
    170 
    171   case XCPT_ILLEGAL_INSTRUCTION:
    172   case XCPT_PRIVILEGED_INSTRUCTION:
    173   case XCPT_INTEGER_DIVIDE_BY_ZERO:
    174   case XCPT_UNABLE_TO_GROW_STACK:
    175   case XCPT_GUARD_PAGE_VIOLATION:
     150        memcpy(&pWinContextRec->FloatSave,
     151               pContextRec->ctx_env, sizeof(pContextRec->ctx_env));
     152        memcpy(&pWinContextRec->FloatSave.RegisterArea,
     153               pContextRec->ctx_stack, sizeof(pContextRec->ctx_stack));
     154    }
     155
     156    return TRUE;
     157}
     158
     159/**
     160 * Converts the Win32 exception handler result to the OS/2 exception handler
     161 * result.
     162 *
     163 * Returns TRUE if the OS/2 exception handler result should be
     164 * XCPT_CONTINUE_EXECUTION and FALSE otherwise.
     165 */
     166BOOL APIENTRY OSLibConvertExceptionResult(ULONG rc,
     167                                          PWINCONTEXT pWinContextRec,
     168                                          PCONTEXTRECORD pContextRec)
     169{
     170    if (rc != ExceptionContinueExecution)
     171    {
     172        dprintf(("Win32 exception handler returned %x", rc));
     173        return FALSE;
     174    }
     175
     176    dprintf(("Win32 exception handler returned ExceptionContinueExecution"));
     177
     178    if (pWinContextRec->ContextFlags & WINCONTEXT_CONTROL)
     179    {
     180        pContextRec->ctx_RegEbp = pWinContextRec->Ebp;
     181        pContextRec->ctx_RegEip = pWinContextRec->Eip;
     182        pContextRec->ctx_SegCs  = pWinContextRec->SegCs;
     183        pContextRec->ctx_EFlags = pWinContextRec->EFlags;
     184        pContextRec->ctx_RegEsp = pWinContextRec->Esp;
     185        pContextRec->ctx_SegSs  = pWinContextRec->SegSs;
     186    }
     187
     188    if (pWinContextRec->ContextFlags & WINCONTEXT_INTEGER)
     189    {
     190        pContextRec->ctx_RegEdi = pWinContextRec->Edi;
     191        pContextRec->ctx_RegEsi = pWinContextRec->Esi;
     192        pContextRec->ctx_RegEbx = pWinContextRec->Ebx;
     193        pContextRec->ctx_RegEdx = pWinContextRec->Edx;
     194        pContextRec->ctx_RegEcx = pWinContextRec->Ecx;
     195        pContextRec->ctx_RegEax = pWinContextRec->Eax;
     196    }
     197
     198#if 0
     199    // This is not a good idea
     200    if (pWinContextRec->ContextFlags & WINCONTEXT_SEGMENTS)
     201    {
     202        pContextRec->ctx_SegGs = pWinContextRec->SegGs;
     203        pContextRec->ctx_SegFs = pWinContextRec->SegFs;
     204        pContextRec->ctx_SegEs = pWinContextRec->SegEs;
     205        pContextRec->ctx_SegDs = pWinContextRec->SegDs;
     206    }
     207#endif
     208
     209    if (pWinContextRec->ContextFlags & WINCONTEXT_FLOATING_POINT)
     210    {
     211        //TODO: First 7 dwords the same?
     212        memcpy(pContextRec->ctx_env, &pWinContextRec->FloatSave,
     213               sizeof(pContextRec->ctx_env));
     214        memcpy(pContextRec->ctx_stack, &pWinContextRec->FloatSave.RegisterArea,
     215               sizeof(pContextRec->ctx_stack));
     216    }
     217
     218    if (pContextRec->ContextFlags & CONTEXT_CONTROL)         /* check flags */
     219        dprintf(("   SS:ESP=%04x:%08x EFLAGS=%08x\n",
     220                 pContextRec->ctx_SegSs,
     221                 pContextRec->ctx_RegEsp,
     222                 pContextRec->ctx_EFlags));
     223    dprintf(("   CS:EIP=%04x:%08x EBP   =%08x\n",
     224             pContextRec->ctx_SegCs,
     225             pContextRec->ctx_RegEip,
     226             pContextRec->ctx_RegEbp));
     227
     228    if (pContextRec->ContextFlags & CONTEXT_INTEGER)         /* check flags */
     229        dprintf(("   EAX=%08x EBX=%08x ESI=%08x\n",
     230                 pContextRec->ctx_RegEax,
     231                 pContextRec->ctx_RegEbx,
     232                 pContextRec->ctx_RegEsi));
     233    dprintf(("   ECX=%08x EDX=%08x EDI=%08x\n",
     234             pContextRec->ctx_RegEcx,
     235             pContextRec->ctx_RegEdx,
     236             pContextRec->ctx_RegEdi));
     237
     238    if (pContextRec->ContextFlags & CONTEXT_SEGMENTS)        /* check flags */
     239        dprintf(("   DS=%04x     ES=%08x"
     240                 "   FS=%04x     GS=%04x\n",
     241                 pContextRec->ctx_SegDs,
     242                 pContextRec->ctx_SegEs,
     243                 pContextRec->ctx_SegFs,
     244                 pContextRec->ctx_SegGs));
     245
     246    if (pContextRec->ContextFlags & CONTEXT_FLOATING_POINT)  /* check flags */
     247    {
     248        ULONG ulCounter;                 /* temporary local counter for fp stack */
     249
     250        dprintf(("   Env[0]=%08x Env[1]=%08x Env[2]=%08x Env[3]=%08x\n",
     251                 pContextRec->ctx_env[0],
     252                 pContextRec->ctx_env[1],
     253                 pContextRec->ctx_env[2],
     254                 pContextRec->ctx_env[3]));
     255
     256        dprintf(("   Env[4]=%08x Env[5]=%08x Env[6]=%08x\n",
     257                 pContextRec->ctx_env[4],
     258                 pContextRec->ctx_env[5],
     259                 pContextRec->ctx_env[6]));
     260
     261        for (ulCounter = 0;
     262             ulCounter < 8; /* see TOOLKIT\INCLUDE\BSEEXPT.H, _CONTEXT structure */
     263             ulCounter ++)
     264            dprintf(("   FP-Stack[%u] losig=%08x hisig=%08x signexp=%04x\n",
     265                     ulCounter,
     266                     pContextRec->ctx_stack[0].losig,
     267                     pContextRec->ctx_stack[0].hisig,
     268                     pContextRec->ctx_stack[0].signexp));
     269    }
     270
     271    return TRUE;
     272}
     273
     274/**
     275 * Dispatches OS/2 exception to win32 handler.
     276 *
     277 * Returns TRUE if the Win32 exception handler returned
     278 * ExceptionContinueExecution and FALSE otherwise.
     279 */
     280BOOL APIENTRY OSLibDispatchExceptionWin32(PEXCEPTIONREPORTRECORD pReportRec,
     281                                          PEXCEPTIONREGISTRATIONRECORD pRegistrationRec,
     282                                          PCONTEXTRECORD pContextRec, PVOID p)
     283{
     284    WINEXCEPTION_RECORD winReportRec;
     285    WINCONTEXT          winContextRec;
     286
     287    ULONG rc;
     288
     289    TEB *pWinTEB = GetThreadTEB();
     290
     291    OSLibConvertExceptionInfo(pReportRec, pContextRec,
     292                              &winReportRec, &winContextRec, pWinTEB);
     293
     294    // It doesn't seem correct if we dispatch real exceptions to win32 apps
     295    // Some just call RtlUnwind and continue as if they were processing an
     296    // exception thrown by C++ code. (instead of real OS exception)
     297
     298    // We need to reset FS to its original (Win32) value, otherwise we'll likely
     299    // fuck up the Win32 exception handlers. They could end up using the wrong
     300    // exception chain if they access FS:[0] directly.
     301    DWORD oldsel = SetReturnFS(pWinTEB->teb_sel);
     302
     303    switch(pReportRec->ExceptionNum)
     304    {
     305    case XCPT_FLOAT_DENORMAL_OPERAND:
     306    case XCPT_FLOAT_DIVIDE_BY_ZERO:
     307    case XCPT_FLOAT_INEXACT_RESULT:
     308    case XCPT_FLOAT_INVALID_OPERATION:
     309    case XCPT_FLOAT_OVERFLOW:
     310    case XCPT_FLOAT_STACK_CHECK:
     311    case XCPT_FLOAT_UNDERFLOW:
     312        rc = RtlDispatchException(&winReportRec, &winContextRec);
     313        break;
     314
     315    case XCPT_ACCESS_VIOLATION:
     316        rc = RtlDispatchException(&winReportRec, &winContextRec);
     317        break;
     318
     319    case XCPT_ILLEGAL_INSTRUCTION:
     320    case XCPT_PRIVILEGED_INSTRUCTION:
     321    case XCPT_INTEGER_DIVIDE_BY_ZERO:
     322    case XCPT_UNABLE_TO_GROW_STACK:
     323    case XCPT_GUARD_PAGE_VIOLATION:
    176324#ifndef DEBUG
    177   case XCPT_BREAKPOINT:
     325    case XCPT_BREAKPOINT:
    178326#endif
    179         rc = RtlDispatchException(&winreportrec, &wincontextrec);
     327        rc = RtlDispatchException(&winReportRec, &winContextRec);
    180328        break;
    181329
    182330#ifdef DEBUG
    183   case XCPT_BREAKPOINT:
     331    case XCPT_BREAKPOINT:
    184332#endif
    185   case XCPT_INTEGER_OVERFLOW:
    186   case XCPT_SINGLE_STEP:
    187   case XCPT_ARRAY_BOUNDS_EXCEEDED:
    188   case XCPT_DATATYPE_MISALIGNMENT:
    189   case XCPT_INVALID_LOCK_SEQUENCE:
    190   case XCPT_IN_PAGE_ERROR:
    191   default:
    192         SetFS(oldsel);  //restore FS
     333    case XCPT_INTEGER_OVERFLOW:
     334    case XCPT_SINGLE_STEP:
     335    case XCPT_ARRAY_BOUNDS_EXCEEDED:
     336    case XCPT_DATATYPE_MISALIGNMENT:
     337    case XCPT_INVALID_LOCK_SEQUENCE:
     338    case XCPT_IN_PAGE_ERROR:
     339    default:
     340        SetFS(oldsel);  //restore FS
    193341        return FALSE; //let's not dispatch those for now
    194   }
    195   SetFS(oldsel);        //restore FS
    196 
    197   if(rc == ExceptionContinueExecution) {
    198         dprintf(("Win32 exception handler returned ExceptionContinueExecution"));
    199         if(wincontextrec.ContextFlags & WINCONTEXT_CONTROL) {
    200                 pContextRec->ctx_RegEbp = wincontextrec.Ebp;
    201                 pContextRec->ctx_RegEip = wincontextrec.Eip;
    202                 pContextRec->ctx_SegCs  = wincontextrec.SegCs;
    203                 pContextRec->ctx_EFlags = wincontextrec.EFlags;
    204                 pContextRec->ctx_RegEsp = wincontextrec.Esp;
    205                 pContextRec->ctx_SegSs  = wincontextrec.SegSs;
    206         }
    207         if(wincontextrec.ContextFlags & WINCONTEXT_INTEGER) {
    208                 pContextRec->ctx_RegEdi = wincontextrec.Edi;
    209                 pContextRec->ctx_RegEsi = wincontextrec.Esi;
    210                 pContextRec->ctx_RegEbx = wincontextrec.Ebx;
    211                 pContextRec->ctx_RegEdx = wincontextrec.Edx;
    212                 pContextRec->ctx_RegEcx = wincontextrec.Ecx;
    213                 pContextRec->ctx_RegEax = wincontextrec.Eax;
    214         }
    215 #if 0
    216         //This is not a good idea
    217         if(wincontextrec.ContextFlags & WINCONTEXT_SEGMENTS) {
    218                 pContextRec->ctx_SegGs = wincontextrec.SegGs;
    219                 pContextRec->ctx_SegFs = wincontextrec.SegFs;
    220                 pContextRec->ctx_SegEs = wincontextrec.SegEs;
    221                 pContextRec->ctx_SegDs = wincontextrec.SegDs;
    222         }
    223 #endif
    224         if(wincontextrec.ContextFlags & WINCONTEXT_FLOATING_POINT) {
    225                 //TODO: First 7 dwords the same?
    226                 memcpy(pContextRec->ctx_env, &wincontextrec.FloatSave, sizeof(pContextRec->ctx_env));
    227                 memcpy(pContextRec->ctx_stack, &wincontextrec.FloatSave.RegisterArea, sizeof(pContextRec->ctx_stack));
    228         }
    229         if (pContextRec->ContextFlags & CONTEXT_CONTROL)         /* check flags */
    230                 dprintf(("   SS:ESP=%04x:%08x EFLAGS=%08x\n",
    231                              pContextRec->ctx_SegSs,
    232                              pContextRec->ctx_RegEsp,
    233                              pContextRec->ctx_EFlags));
    234                 dprintf(("   CS:EIP=%04x:%08x EBP   =%08x\n",
    235                              pContextRec->ctx_SegCs,
    236                              pContextRec->ctx_RegEip,
    237                              pContextRec->ctx_RegEbp));
    238 
    239         if (pContextRec->ContextFlags & CONTEXT_INTEGER)         /* check flags */
    240                     dprintf(("   EAX=%08x EBX=%08x ESI=%08x\n",
    241                              pContextRec->ctx_RegEax,
    242                              pContextRec->ctx_RegEbx,
    243                              pContextRec->ctx_RegEsi));
    244                     dprintf(("   ECX=%08x EDX=%08x EDI=%08x\n",
    245                              pContextRec->ctx_RegEcx,
    246                              pContextRec->ctx_RegEdx,
    247                              pContextRec->ctx_RegEdi));
    248 
    249         if (pContextRec->ContextFlags & CONTEXT_SEGMENTS)        /* check flags */
    250                     dprintf(("   DS=%04x     ES=%08x"
    251                              "   FS=%04x     GS=%04x\n",
    252                               pContextRec->ctx_SegDs,
    253                               pContextRec->ctx_SegEs,
    254                               pContextRec->ctx_SegFs,
    255                               pContextRec->ctx_SegGs));
    256 
    257         if (pContextRec->ContextFlags & CONTEXT_FLOATING_POINT)  /* check flags */
    258         {
    259             ULONG ulCounter;                 /* temporary local counter for fp stack */
    260 
    261                 dprintf(("   Env[0]=%08x Env[1]=%08x Env[2]=%08x Env[3]=%08x\n",
    262                              pContextRec->ctx_env[0],
    263                              pContextRec->ctx_env[1],
    264                              pContextRec->ctx_env[2],
    265                              pContextRec->ctx_env[3]));
    266 
    267                 dprintf(("   Env[4]=%08x Env[5]=%08x Env[6]=%08x\n",
    268                              pContextRec->ctx_env[4],
    269                              pContextRec->ctx_env[5],
    270                              pContextRec->ctx_env[6]));
    271 
    272                 for (ulCounter = 0;
    273                      ulCounter < 8; /* see TOOLKIT\INCLUDE\BSEEXPT.H, _CONTEXT structure */
    274                      ulCounter ++)
    275                       dprintf(("   FP-Stack[%u] losig=%08x hisig=%08x signexp=%04x\n",
    276                                ulCounter,
    277                                pContextRec->ctx_stack[0].losig,
    278                                pContextRec->ctx_stack[0].hisig,
    279                                pContextRec->ctx_stack[0].signexp));
    280         }
    281 
    282         return TRUE;
    283   }
    284   dprintf(("Win32 exception handler returned %x", rc));
    285 #endif
    286   return FALSE;
     342    }
     343
     344    SetFS(oldsel);      //restore FS
     345
     346    return OSLibConvertExceptionResult(rc, &winContextRec, pContextRec);
    287347}
    288 //******************************************************************************
    289 //******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.