diff --git a/reactos/include/reactos/wine/exception.h b/reactos/include/reactos/wine/exception.h index 5d3a5c672e5..ac433cdaee2 100644 --- a/reactos/include/reactos/wine/exception.h +++ b/reactos/include/reactos/wine/exception.h @@ -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 */