exception.h: merge changes from wine.

Revision 1.37 fixes the exception in ole32 when opening a file with FoxitReader. Also fixes some warnings and hopefully some usermode crashes.

1.28: Jonathan Ernst <jonathan@ernstfamily.ch>
Update the address of the Free Software Foundation.

1.29: Alexandre Julliard <julliard@winehq.org>
include: Exception filters should return LONG, not DWORD.
Also move UnhandledExceptionFilter definitions to winbase.h since they
are there in the latest SDK.

1.30: Rob Shearman <rob@codeweavers.com>
include: Move Wine-specific EH_* defines from winnt.h to include/wine/exception.h.

1.33: Rob Shearman <rob@codeweavers.com>
Add a new convenience macro for an exception handler that handles all exceptions.
When using native compiler exceptions, the previous method of doing
this, __EXCEPT(NULL), would expand to __except(
(NULL)(GetExceptionInformation())) which doesn't compile as NULL isn't a
function.
So add a new macro, __EXCEPT_ALL, which works correctly both when using
native compiler exceptions and without and which makes the meaning of
code in which it is used clearer.

1.35: Alexandre Julliard <julliard@winehq.org>
ntdll: Make the exception handling functions inline.

1.36: Alexandre Julliard <julliard@winehq.org>
exception.h: Only push the exception frame after sigsetjmp.
Otherwise on Windows longjmp may want to mess with the exception frame.

1.37: Alexandre Julliard <julliard@winehq.org>
exception.h: Preserve registers when calling RtlUnwind.

See issue #812 for more details.

svn path=/trunk/; revision=33732
This commit is contained in:
Timo Kreuzer 2008-05-28 00:41:13 +00:00
parent fb517419d2
commit 31335eaca5

View file

@ -15,7 +15,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __WINE_WINE_EXCEPTION_H
@ -79,6 +79,7 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
#define __FINALLY(func) __finally { (func)(!AbnormalTermination()); }
#define __ENDTRY /*nothing*/
#define __EXCEPT_PAGE_FAULT __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
#define __EXCEPT_ALL __except(EXCEPTION_EXECUTE_HANDLER)
#else /* USE_COMPILER_EXCEPTIONS */
@ -100,7 +101,28 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
} else { \
__f.frame.Handler = __wine_exception_handler; \
__f.u.filter = (func); \
__wine_push_frame( &__f.frame ); \
if (setjmp( __f.jmp )) { \
const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
do {
/* convenience handler for page fault exceptions */
#define __EXCEPT_PAGE_FAULT \
} while(0); \
__wine_pop_frame( &__f.frame ); \
break; \
} else { \
__f.frame.Handler = __wine_exception_handler_page_fault; \
if (setjmp( __f.jmp )) { \
const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
do {
/* convenience handler for all exception */
#define __EXCEPT_ALL \
} while(0); \
__wine_pop_frame( &__f.frame ); \
break; \
} else { \
__f.frame.Handler = __wine_exception_handler_all; \
if (setjmp( __f.jmp )) { \
const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
do {
@ -109,6 +131,7 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
} while (0); \
break; \
} \
__wine_push_frame( &__f.frame ); \
__first = 0; \
} \
} while (0);
@ -127,13 +150,10 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
} while (0);
typedef DWORD (CALLBACK *__WINE_FILTER)(PEXCEPTION_POINTERS);
typedef LONG (CALLBACK *__WINE_FILTER)(PEXCEPTION_POINTERS);
typedef void (CALLBACK *__WINE_FINALLY)(BOOL);
/* convenience handler for page fault exceptions */
#define __EXCEPT_PAGE_FAULT __EXCEPT( (__WINE_FILTER)1 )
#define WINE_EXCEPTION_FILTER(func) DWORD CALLBACK func( PEXCEPTION_POINTERS __eptr )
#define WINE_EXCEPTION_FILTER(func) LONG WINAPI func( EXCEPTION_POINTERS *__eptr )
#define WINE_FINALLY_FUNC(func) void CALLBACK func( BOOL __normal )
#define GetExceptionInformation() (__eptr)
@ -193,6 +213,39 @@ static __inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGIS
#ifndef USE_COMPILER_EXCEPTIONS
static inline void DECLSPEC_NORETURN __wine_unwind_frame( EXCEPTION_RECORD *record,
EXCEPTION_REGISTRATION_RECORD *frame )
{
__WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
/* hack to make GetExceptionCode() work in handler */
wine_frame->ExceptionCode = record->ExceptionCode;
wine_frame->ExceptionRecord = wine_frame;
#if defined(__GNUC__) && defined(__i386__)
{
/* RtlUnwind clobbers registers on Windows */
int dummy1, dummy2, dummy3;
__asm__ __volatile__("pushl %%ebp\n\t"
"pushl %%ebx\n\t"
"pushl $0\n\t"
"pushl %2\n\t"
"pushl $0\n\t"
"pushl %1\n\t"
"call *%0\n\t"
"popl %%ebx\n\t"
"popl %%ebp"
: "=a" (dummy1), "=S" (dummy2), "=D" (dummy3)
: "0" (RtlUnwind), "1" (frame), "2" (record)
: "ecx", "edx", "memory" );
}
#else
RtlUnwind( frame, 0, record, 0 );
#endif
__wine_pop_frame( frame );
longjmp( wine_frame->jmp, 1 );
}
static __inline EXCEPTION_DISPOSITION
__wine_exception_handler( struct _EXCEPTION_RECORD *record, void *frame,
struct _CONTEXT *context, void *pdispatcher )
@ -224,15 +277,28 @@ __wine_exception_handler( struct _EXCEPTION_RECORD *record, void *frame,
break;
}
}
/* hack to make GetExceptionCode() work in handler */
wine_frame->ExceptionCode = record->ExceptionCode;
wine_frame->ExceptionRecord = wine_frame;
RtlUnwind( frame, 0, record, 0 );
__wine_pop_frame( frame );
longjmp( wine_frame->jmp, 1 );
__wine_unwind_frame( record, frame );
}
static __inline EXCEPTION_DISPOSITION
__wine_exception_handler_page_fault( struct _EXCEPTION_RECORD *record, void *frame,
struct _CONTEXT *context, void *pdispatcher )
{
if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
return ExceptionContinueSearch;
if (record->ExceptionCode != STATUS_ACCESS_VIOLATION)
return ExceptionContinueSearch;
__wine_unwind_frame( record, frame );
}
static __inline EXCEPTION_DISPOSITION
__wine_exception_handler_all( struct _EXCEPTION_RECORD *record, void *frame,
struct _CONTEXT *context, void *pdispatcher )
{
if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
return ExceptionContinueSearch;
__wine_unwind_frame( record, frame );
}
static __inline EXCEPTION_DISPOSITION
__wine_finally_handler( struct _EXCEPTION_RECORD *record, void *frame,
@ -248,6 +314,14 @@ __wine_finally_handler( struct _EXCEPTION_RECORD *record, void *frame,
#endif /* USE_COMPILER_EXCEPTIONS */
/* Exception handling flags - from OS/2 2.0 exception handling */
/* Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD */
#define EH_NONCONTINUABLE 0x01
#define EH_UNWINDING 0x02
#define EH_EXIT_UNWIND 0x04
#define EH_STACK_INVALID 0x08
#define EH_NESTED_CALL 0x10
/* Wine-specific exceptions codes */