ReactOS 0.4.15-dev-8116-gf69e256
except.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wine/exception.h"
#include "msvcrt.h"
#include "excpt.h"
#include "wincon.h"
#include "wine/debug.h"
#include "cppexcept.h"
Include dependency graph for except.c:

Go to the source code of this file.

Classes

struct  __std_exception_data
 

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef void(CDECLfloat_handler) (int, int)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (seh)
 
static BOOL WINAPI msvcrt_console_handler (DWORD ctrlType)
 
void **CDECL MSVCRT___pxcptinfoptrs (void)
 
static LONG msvcrt_exception_filter (struct _EXCEPTION_POINTERS *except)
 
void msvcrt_init_signals (void)
 
void msvcrt_free_signals (void)
 
MSVCRT___sighandler_t CDECL MSVCRT_signal (int sig, MSVCRT___sighandler_t func)
 
int CDECL MSVCRT_raise (int sig)
 
int CDECL _XcptFilter (NTSTATUS ex, PEXCEPTION_POINTERS ptr)
 
int CDECL _abnormal_termination (void)
 
BOOL CDECL MSVCRT___uncaught_exception (void)
 
frame_info *CDECL _CreateFrameInfo (frame_info *fi, void *obj)
 
void CDECL _FindAndUnlinkFrame (frame_info *fi)
 
BOOL __cdecl _IsExceptionObjectToBeDestroyed (const void *obj)
 
void CDECL __DestructExceptionObject (EXCEPTION_RECORD *rec)
 
BOOL CDECL __CxxRegisterExceptionObject (EXCEPTION_POINTERS *ep, cxx_frame_info *frame_info)
 
void CDECL __CxxUnregisterExceptionObject (cxx_frame_info *frame_info, BOOL in_use)
 

Variables

static MSVCRT___sighandler_t sighandlers [MSVCRT_NSIG] = { MSVCRT_SIG_DFL }
 
struct {
   NTSTATUS   status
 
   int   signal
 
float_exception_map []
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 30 of file except.c.

Typedef Documentation

◆ float_handler

typedef void(CDECL * float_handler) (int, int)

Definition at line 76 of file except.c.

Function Documentation

◆ __CxxRegisterExceptionObject()

BOOL CDECL __CxxRegisterExceptionObject ( EXCEPTION_POINTERS ep,
cxx_frame_info frame_info 
)

Definition at line 440 of file except.c.

441{
443
444 TRACE("(%p, %p)\n", ep, frame_info);
445
446 if (!ep || !ep->ExceptionRecord)
447 {
448 frame_info->rec = (void*)-1;
449 frame_info->context = (void*)-1;
450 return TRUE;
451 }
452
453 frame_info->rec = data->exc_record;
454 frame_info->context = data->ctx_record;
455 data->exc_record = ep->ExceptionRecord;
456 data->ctx_record = ep->ContextRecord;
458 return TRUE;
459}
#define TRUE
Definition: types.h:120
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
frame_info *CDECL _CreateFrameInfo(frame_info *fi, void *obj)
Definition: except.c:344
#define TRACE(s)
Definition: solgame.cpp:4
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:200
PCONTEXT ContextRecord
Definition: rtltypes.h:201
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213

◆ __CxxUnregisterExceptionObject()

void CDECL __CxxUnregisterExceptionObject ( cxx_frame_info frame_info,
BOOL  in_use 
)

Definition at line 464 of file except.c.

465{
467
468 TRACE("(%p)\n", frame_info);
469
470 if(frame_info->rec == (void*)-1)
471 return;
472
473 _FindAndUnlinkFrame(&frame_info->frame_info);
474 if(data->exc_record->ExceptionCode == CXX_EXCEPTION && !in_use
475 && _IsExceptionObjectToBeDestroyed((void*)data->exc_record->ExceptionInformation[1]))
476 __DestructExceptionObject(data->exc_record);
477 data->exc_record = frame_info->rec;
478 data->ctx_record = frame_info->context;
479}
#define CXX_EXCEPTION
Definition: cppexcept.h:27
void CDECL __DestructExceptionObject(EXCEPTION_RECORD *rec)
Definition: except.c:405
void CDECL _FindAndUnlinkFrame(frame_info *fi)
Definition: except.c:359
BOOL __cdecl _IsExceptionObjectToBeDestroyed(const void *obj)
Definition: except.c:387

◆ __DestructExceptionObject()

void CDECL __DestructExceptionObject ( EXCEPTION_RECORD rec)

Definition at line 405 of file except.c.

406{
408 void *object = (void*)rec->ExceptionInformation[1];
409
410 TRACE("(%p)\n", rec);
411
412 if (rec->ExceptionCode != CXX_EXCEPTION) return;
413#ifndef __x86_64__
414 if (rec->NumberParameters != 3) return;
415#else
416 if (rec->NumberParameters != 4) return;
417#endif
420
421 if (!info || !info->destructor)
422 return;
423
424#if defined(__i386__)
425#ifdef _MSC_VER
426 ((void(__fastcall*)(void*))info->destructor)(object);
427#else
428 __asm__ __volatile__("call *%0" : : "r" (info->destructor), "c" (object) : "eax", "edx", "memory");
429#endif
430#elif defined(__x86_64__)
431 ((void (__cdecl*)(void*))(info->destructor+rec->ExceptionInformation[3]))(object);
432#else
433 ((void (__cdecl*)(void*))info->destructor)(object);
434#endif
435}
#define __cdecl
Definition: accygwin.h:79
#define CXX_FRAME_MAGIC_VC6
Definition: cppexcept.h:24
#define CXX_FRAME_MAGIC_VC8
Definition: cppexcept.h:26
#define __fastcall
Definition: sync.c:38
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
DWORD ExceptionCode
Definition: compat.h:208
DWORD NumberParameters
Definition: compat.h:212

Referenced by __CxxUnregisterExceptionObject().

◆ _abnormal_termination()

int CDECL _abnormal_termination ( void  )

Definition at line 285 of file except.c.

286{
287 FIXME("(void)stub\n");
288 return 0;
289}
#define FIXME(fmt,...)
Definition: debug.h:114

◆ _CreateFrameInfo()

frame_info *CDECL _CreateFrameInfo ( frame_info fi,
void obj 
)

Definition at line 344 of file except.c.

345{
347
348 TRACE("(%p, %p)\n", fi, obj);
349
350 fi->next = data->frame_info_head;
351 data->frame_info_head = fi;
352 fi->object = obj;
353 return fi;
354}

Referenced by __CxxRegisterExceptionObject().

◆ _FindAndUnlinkFrame()

void CDECL _FindAndUnlinkFrame ( frame_info fi)

Definition at line 359 of file except.c.

360{
362 frame_info *cur = data->frame_info_head;
363
364 TRACE("(%p)\n", fi);
365
366 if (cur == fi)
367 {
368 data->frame_info_head = cur->next;
369 return;
370 }
371
372 for (; cur->next; cur = cur->next)
373 {
374 if (cur->next == fi)
375 {
376 cur->next = fi->next;
377 return;
378 }
379 }
380
381 ERR("frame not found, native crashes in this case\n");
382}
#define ERR(fmt,...)
Definition: debug.h:113
FxCollectionEntry * cur

Referenced by __CxxUnregisterExceptionObject().

◆ _IsExceptionObjectToBeDestroyed()

BOOL __cdecl _IsExceptionObjectToBeDestroyed ( const void obj)

Definition at line 387 of file except.c.

388{
390
391 TRACE( "%p\n", obj );
392
393 for (cur = msvcrt_get_thread_data()->frame_info_head; cur; cur = cur->next)
394 {
395 if (cur->object == obj)
396 return FALSE;
397 }
398
399 return TRUE;
400}
#define FALSE
Definition: types.h:117

Referenced by __CxxUnregisterExceptionObject().

◆ _XcptFilter()

int CDECL _XcptFilter ( NTSTATUS  ex,
PEXCEPTION_POINTERS  ptr 
)

Definition at line 274 of file except.c.

275{
276 TRACE("(%08x,%p)\n", ex, ptr);
277 /* I assume ptr->ExceptionRecord->ExceptionCode is the same as ex */
279}
static PVOID ptr
Definition: dispmode.c:27
static LONG msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except)
Definition: except.c:93
Definition: comerr.c:44

◆ MSVCRT___pxcptinfoptrs()

void **CDECL MSVCRT___pxcptinfoptrs ( void  )

Definition at line 71 of file except.c.

72{
73 return (void**)&msvcrt_get_thread_data()->xcptinfo;
74}

Referenced by msvcrt_exception_filter(), and MSVCRT_raise().

◆ MSVCRT___uncaught_exception()

BOOL CDECL MSVCRT___uncaught_exception ( void  )

Definition at line 295 of file except.c.

296{
297 return msvcrt_get_thread_data()->processing_throw != 0;
298}

◆ msvcrt_console_handler()

static BOOL WINAPI msvcrt_console_handler ( DWORD  ctrlType)
static

Definition at line 50 of file except.c.

51{
52 BOOL ret = FALSE;
53
54 switch (ctrlType)
55 {
56 case CTRL_C_EVENT:
58 {
61 ret = TRUE;
62 }
63 break;
64 }
65 return ret;
66}
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MSVCRT_SIG_IGN
Definition: msvcrt.h:800
#define MSVCRT_SIGINT
Definition: msvcrt.h:788
static MSVCRT___sighandler_t sighandlers[MSVCRT_NSIG]
Definition: except.c:48
int ret
#define CTRL_C_EVENT
Definition: wincon.h:68

Referenced by msvcrt_free_signals(), and msvcrt_init_signals().

◆ msvcrt_exception_filter()

static LONG msvcrt_exception_filter ( struct _EXCEPTION_POINTERS except)
static

Definition at line 93 of file except.c.

94{
97
98 if (!except || !except->ExceptionRecord)
100
101 switch (except->ExceptionRecord->ExceptionCode)
102 {
105 {
106 if (handler != MSVCRT_SIG_IGN)
107 {
109
110 old_ep = *ep;
111 *ep = except;
114 *ep = old_ep;
115 }
117 }
118 break;
119 /* According to msdn,
120 * the FPE signal handler takes as a second argument the type of
121 * floating point exception.
122 */
131 {
132 if (handler != MSVCRT_SIG_IGN)
133 {
135 unsigned int i;
136 int float_signal = MSVCRT__FPE_INVALID;
137
139 for (i = 0; i < ARRAY_SIZE(float_exception_map); i++)
140 {
142 except->ExceptionRecord->ExceptionCode)
143 {
144 float_signal = float_exception_map[i].signal;
145 break;
146 }
147 }
148
149 old_ep = *ep;
150 *ep = except;
151 ((float_handler)handler)(MSVCRT_SIGFPE, float_signal);
152 *ep = old_ep;
153 }
155 }
156 break;
160 {
161 if (handler != MSVCRT_SIG_IGN)
162 {
164
165 old_ep = *ep;
166 *ep = except;
169 *ep = old_ep;
170 }
172 }
173 break;
174 }
175 return ret;
176}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define except(x)
Definition: btrfs_drv.h:136
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87
#define MSVCRT__FPE_INVALID
Definition: msvcrt.h:803
#define MSVCRT_SIGSEGV
Definition: msvcrt.h:791
void(__cdecl * MSVCRT___sighandler_t)(int)
Definition: msvcrt.h:797
#define MSVCRT_SIGILL
Definition: msvcrt.h:789
#define MSVCRT_SIGFPE
Definition: msvcrt.h:790
#define MSVCRT_SIG_DFL
Definition: msvcrt.h:799
long LONG
Definition: pedump.c:60
void **CDECL MSVCRT___pxcptinfoptrs(void)
Definition: except.c:71
void(CDECL * float_handler)(int, int)
Definition: except.c:76
static const struct @4322 float_exception_map[]
Definition: ps.c:97
#define EXCEPTION_FLT_STACK_CHECK
Definition: winbase.h:321
#define EXCEPTION_FLT_UNDERFLOW
Definition: winbase.h:322
#define EXCEPTION_FLT_OVERFLOW
Definition: winbase.h:320
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: winbase.h:316
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: winbase.h:318
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:327
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:311
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: winbase.h:319
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:325
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: winbase.h:317

Referenced by _XcptFilter().

◆ msvcrt_free_signals()

void msvcrt_free_signals ( void  )

Definition at line 183 of file except.c.

184{
186}
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2109
static BOOL WINAPI msvcrt_console_handler(DWORD ctrlType)
Definition: except.c:50

◆ msvcrt_init_signals()

void msvcrt_init_signals ( void  )

Definition at line 178 of file except.c.

◆ MSVCRT_raise()

int CDECL MSVCRT_raise ( int  sig)

Definition at line 225 of file except.c.

226{
228
229 TRACE("(%d)\n", sig);
230
231 switch (sig)
232 {
233 case MSVCRT_SIGFPE:
234 case MSVCRT_SIGILL:
235 case MSVCRT_SIGSEGV:
236 handler = sighandlers[sig];
238 if (handler != MSVCRT_SIG_IGN)
239 {
241
243
244 old_ep = *ep;
245 *ep = NULL;
246 if (sig == MSVCRT_SIGFPE)
248 else
249 handler(sig);
250 *ep = old_ep;
251 }
252 break;
253 case MSVCRT_SIGABRT:
254 case MSVCRT_SIGINT:
255 case MSVCRT_SIGTERM:
256 case MSVCRT_SIGBREAK:
257 handler = sighandlers[sig];
259 if (handler != MSVCRT_SIG_IGN)
260 {
262 handler(sig);
263 }
264 break;
265 default:
266 return -1;
267 }
268 return 0;
269}
#define NULL
Definition: types.h:112
#define MSVCRT__exit
Definition: winternl.h:310
#define MSVCRT_SIGTERM
Definition: msvcrt.h:792
#define MSVCRT__FPE_EXPLICITGEN
Definition: msvcrt.h:813
#define MSVCRT_SIGBREAK
Definition: msvcrt.h:793
#define MSVCRT_SIGABRT
Definition: msvcrt.h:794

◆ MSVCRT_signal()

MSVCRT___sighandler_t CDECL MSVCRT_signal ( int  sig,
MSVCRT___sighandler_t  func 
)

Definition at line 193 of file except.c.

194{
196
197 TRACE("(%d, %p)\n", sig, func);
198
199 if (func == MSVCRT_SIG_ERR) return MSVCRT_SIG_ERR;
200
201 switch (sig)
202 {
203 /* Cases handled internally. Note SIGTERM is never generated by Windows,
204 * so we effectively mask it.
205 */
206 case MSVCRT_SIGABRT:
207 case MSVCRT_SIGFPE:
208 case MSVCRT_SIGILL:
209 case MSVCRT_SIGSEGV:
210 case MSVCRT_SIGINT:
211 case MSVCRT_SIGTERM:
212 case MSVCRT_SIGBREAK:
213 ret = sighandlers[sig];
214 sighandlers[sig] = func;
215 break;
216 default:
218 }
219 return ret;
220}
GLenum func
Definition: glext.h:6028
#define MSVCRT_SIG_ERR
Definition: msvcrt.h:801

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( seh  )

Variable Documentation

◆ 

const struct { ... } float_exception_map[]

◆ sighandlers

◆ signal

◆ status

Definition at line 81 of file except.c.