1999-05-12 15:10:39 +02:00
|
|
|
/*
|
|
|
|
* Wine exception handling
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-05-12 15:10:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __WINE_WINE_EXCEPTION_H
|
|
|
|
#define __WINE_WINE_EXCEPTION_H
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
2002-12-10 23:56:43 +01:00
|
|
|
#include "windef.h"
|
1999-05-12 15:10:39 +02:00
|
|
|
|
|
|
|
/* The following definitions allow using exceptions in Wine and Winelib code
|
|
|
|
*
|
|
|
|
* They should be used like this:
|
|
|
|
*
|
1999-05-14 20:21:55 +02:00
|
|
|
* __TRY
|
1999-05-12 15:10:39 +02:00
|
|
|
* {
|
|
|
|
* do some stuff that can raise an exception
|
|
|
|
* }
|
|
|
|
* __EXCEPT(filter_func,param)
|
|
|
|
* {
|
|
|
|
* handle the exception here
|
|
|
|
* }
|
1999-05-14 20:21:55 +02:00
|
|
|
* __ENDTRY
|
1999-05-12 15:10:39 +02:00
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
1999-05-14 20:21:55 +02:00
|
|
|
* __TRY
|
1999-05-12 15:10:39 +02:00
|
|
|
* {
|
|
|
|
* do some stuff that can raise an exception
|
|
|
|
* }
|
|
|
|
* __FINALLY(finally_func,param)
|
|
|
|
*
|
|
|
|
* The filter_func must be defined with the WINE_EXCEPTION_FILTER
|
|
|
|
* macro, and return one of the EXCEPTION_* code; it can use
|
|
|
|
* GetExceptionInformation and GetExceptionCode to retrieve the
|
|
|
|
* exception info.
|
|
|
|
*
|
|
|
|
* The finally_func must be defined with the WINE_FINALLY_FUNC macro.
|
|
|
|
*
|
1999-05-14 20:21:55 +02:00
|
|
|
* Warning: inside a __TRY or __EXCEPT block, 'break' or 'continue' statements
|
1999-06-18 20:26:35 +02:00
|
|
|
* break out of the current block. You cannot use 'return', 'goto'
|
|
|
|
* or 'longjmp' to leave a __TRY block, as this will surely crash.
|
|
|
|
* You can use them to leave a __EXCEPT block though.
|
1999-05-12 15:10:39 +02:00
|
|
|
*
|
|
|
|
* -- AJ
|
|
|
|
*/
|
|
|
|
|
1999-05-14 20:21:55 +02:00
|
|
|
/* Define this if you want to use your compiler built-in __try/__except support.
|
|
|
|
* This is only useful when compiling to a native Windows binary, as the built-in
|
|
|
|
* compiler exceptions will most certainly not work under Winelib.
|
|
|
|
*/
|
|
|
|
#ifdef USE_COMPILER_EXCEPTIONS
|
|
|
|
|
|
|
|
#define __TRY __try
|
1999-06-18 20:26:35 +02:00
|
|
|
#define __EXCEPT(func) __except((func)(GetExceptionInformation()))
|
|
|
|
#define __FINALLY(func) __finally { (func)(!AbnormalTermination()); }
|
1999-05-14 20:21:55 +02:00
|
|
|
#define __ENDTRY /*nothing*/
|
|
|
|
|
|
|
|
#else /* USE_COMPILER_EXCEPTIONS */
|
|
|
|
|
|
|
|
#define __TRY \
|
|
|
|
do { __WINE_FRAME __f; \
|
|
|
|
int __first = 1; \
|
|
|
|
for (;;) if (!__first) \
|
|
|
|
{ \
|
|
|
|
do {
|
1999-05-12 15:10:39 +02:00
|
|
|
|
1999-06-18 20:26:35 +02:00
|
|
|
#define __EXCEPT(func) \
|
1999-05-14 20:21:55 +02:00
|
|
|
} while(0); \
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_pop_frame( &__f.frame ); \
|
1999-05-14 20:21:55 +02:00
|
|
|
break; \
|
|
|
|
} else { \
|
2000-08-06 04:42:46 +02:00
|
|
|
__f.frame.Handler = (PEXCEPTION_HANDLER)__wine_exception_handler; \
|
1999-06-18 20:26:35 +02:00
|
|
|
__f.u.filter = (func); \
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_push_frame( &__f.frame ); \
|
1999-06-18 20:26:35 +02:00
|
|
|
if (setjmp( __f.jmp)) { \
|
|
|
|
const __WINE_FRAME * const __eptr WINE_UNUSED = &__f; \
|
1999-05-14 20:21:55 +02:00
|
|
|
do {
|
|
|
|
|
|
|
|
#define __ENDTRY \
|
|
|
|
} while (0); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
__first = 0; \
|
|
|
|
} \
|
1999-05-12 15:10:39 +02:00
|
|
|
} while (0);
|
|
|
|
|
1999-06-18 20:26:35 +02:00
|
|
|
#define __FINALLY(func) \
|
1999-05-14 20:21:55 +02:00
|
|
|
} while(0); \
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_pop_frame( &__f.frame ); \
|
1999-06-18 20:26:35 +02:00
|
|
|
(func)(1); \
|
1999-05-14 20:21:55 +02:00
|
|
|
break; \
|
|
|
|
} else { \
|
2000-08-23 21:19:35 +02:00
|
|
|
__f.frame.Handler = (PEXCEPTION_HANDLER)__wine_finally_handler; \
|
1999-06-18 20:26:35 +02:00
|
|
|
__f.u.finally_func = (func); \
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_push_frame( &__f.frame ); \
|
1999-05-14 20:21:55 +02:00
|
|
|
__first = 0; \
|
|
|
|
} \
|
|
|
|
} while (0);
|
1999-05-12 15:10:39 +02:00
|
|
|
|
|
|
|
|
2002-02-01 00:22:07 +01:00
|
|
|
typedef DWORD (CALLBACK *__WINE_FILTER)(PEXCEPTION_POINTERS);
|
|
|
|
typedef void (CALLBACK *__WINE_FINALLY)(BOOL);
|
1999-05-12 15:10:39 +02:00
|
|
|
|
1999-06-18 20:26:35 +02:00
|
|
|
#define WINE_EXCEPTION_FILTER(func) DWORD WINAPI func( EXCEPTION_POINTERS *__eptr )
|
|
|
|
#define WINE_FINALLY_FUNC(func) void WINAPI func( BOOL __normal )
|
1999-05-12 15:10:39 +02:00
|
|
|
|
1999-05-14 20:21:55 +02:00
|
|
|
#define GetExceptionInformation() (__eptr)
|
1999-06-18 20:26:35 +02:00
|
|
|
#define GetExceptionCode() (__eptr->ExceptionRecord->ExceptionCode)
|
1999-05-14 20:21:55 +02:00
|
|
|
#define AbnormalTermination() (!__normal)
|
1999-05-12 15:10:39 +02:00
|
|
|
|
1999-06-18 20:26:35 +02:00
|
|
|
typedef struct __tagWINE_FRAME
|
1999-05-12 15:10:39 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_FRAME frame;
|
|
|
|
union
|
|
|
|
{
|
1999-06-18 20:26:35 +02:00
|
|
|
/* exception data */
|
|
|
|
__WINE_FILTER filter;
|
|
|
|
/* finally data */
|
|
|
|
__WINE_FINALLY finally_func;
|
1999-05-12 15:10:39 +02:00
|
|
|
} u;
|
1999-06-18 20:26:35 +02:00
|
|
|
jmp_buf jmp;
|
|
|
|
/* hack to make GetExceptionCode() work in handler */
|
|
|
|
DWORD ExceptionCode;
|
|
|
|
const struct __tagWINE_FRAME *ExceptionRecord;
|
1999-05-12 15:10:39 +02:00
|
|
|
} __WINE_FRAME;
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
extern DWORD __wine_exception_handler( PEXCEPTION_RECORD record, EXCEPTION_FRAME *frame,
|
|
|
|
CONTEXT *context, LPVOID pdispatcher );
|
|
|
|
extern DWORD __wine_finally_handler( PEXCEPTION_RECORD record, EXCEPTION_FRAME *frame,
|
1999-11-10 20:42:13 +01:00
|
|
|
CONTEXT *context, LPVOID pdispatcher );
|
1999-05-12 15:10:39 +02:00
|
|
|
|
1999-05-14 20:21:55 +02:00
|
|
|
#endif /* USE_COMPILER_EXCEPTIONS */
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
static inline EXCEPTION_FRAME * WINE_UNUSED __wine_push_frame( EXCEPTION_FRAME *frame )
|
1999-05-12 15:10:39 +02:00
|
|
|
{
|
1999-05-14 20:21:55 +02:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
|
|
|
EXCEPTION_FRAME *prev;
|
|
|
|
__asm__ __volatile__(".byte 0x64\n\tmovl (0),%0"
|
|
|
|
"\n\tmovl %0,(%1)"
|
|
|
|
"\n\t.byte 0x64\n\tmovl %1,(0)"
|
|
|
|
: "=&r" (prev) : "r" (frame) : "memory" );
|
|
|
|
return prev;
|
|
|
|
#else
|
2000-09-27 00:20:14 +02:00
|
|
|
NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
|
|
|
|
frame->Prev = (void *)teb->ExceptionList;
|
|
|
|
teb->ExceptionList = (void *)frame;
|
1999-05-14 20:21:55 +02:00
|
|
|
return frame->Prev;
|
|
|
|
#endif
|
1999-05-12 15:10:39 +02:00
|
|
|
}
|
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
static inline EXCEPTION_FRAME * WINE_UNUSED __wine_pop_frame( EXCEPTION_FRAME *frame )
|
1999-05-12 15:10:39 +02:00
|
|
|
{
|
1999-05-14 20:21:55 +02:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
|
|
|
__asm__ __volatile__(".byte 0x64\n\tmovl %0,(0)"
|
|
|
|
: : "r" (frame->Prev) : "memory" );
|
|
|
|
return frame->Prev;
|
|
|
|
|
|
|
|
#else
|
2000-09-27 00:20:14 +02:00
|
|
|
NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
|
|
|
|
teb->ExceptionList = (void *)frame->Prev;
|
1999-05-12 15:10:39 +02:00
|
|
|
return frame->Prev;
|
1999-05-14 20:21:55 +02:00
|
|
|
#endif
|
1999-05-12 15:10:39 +02:00
|
|
|
}
|
|
|
|
|
2000-09-18 04:15:07 +02:00
|
|
|
|
|
|
|
/* Wine-specific exceptions codes */
|
|
|
|
|
2000-10-27 00:03:34 +02:00
|
|
|
#define EXCEPTION_WINE_STUB 0x80000100 /* stub entry point called */
|
2002-10-29 00:56:58 +01:00
|
|
|
#define EXCEPTION_WINE_ASSERTION 0x80000101 /* assertion failed */
|
2000-10-27 00:03:34 +02:00
|
|
|
|
2000-09-18 04:15:07 +02:00
|
|
|
/* unhandled return status from vm86 mode */
|
2002-10-29 00:56:58 +01:00
|
|
|
#define EXCEPTION_VM86_INTx 0x80000110
|
|
|
|
#define EXCEPTION_VM86_STI 0x80000111
|
|
|
|
#define EXCEPTION_VM86_PICRETURN 0x80000112
|
2000-09-18 04:15:07 +02:00
|
|
|
|
2000-09-24 05:11:54 +02:00
|
|
|
extern void __wine_enter_vm86( CONTEXT *context );
|
2000-09-18 04:15:07 +02:00
|
|
|
|
1999-05-12 15:10:39 +02:00
|
|
|
#endif /* __WINE_WINE_EXCEPTION_H */
|