~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/include/wine/exception.h

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Wine exception handling
  3  *
  4  * Copyright (c) 1999 Alexandre Julliard
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #ifndef __WINE_WINE_EXCEPTION_H
 22 #define __WINE_WINE_EXCEPTION_H
 23 
 24 #include <setjmp.h>
 25 #include <windef.h>
 26 #include <winternl.h>
 27 #include <excpt.h>
 28 
 29 /* The following definitions allow using exceptions in Wine and Winelib code
 30  *
 31  * They should be used like this:
 32  *
 33  * __TRY
 34  * {
 35  *     do some stuff that can raise an exception
 36  * }
 37  * __EXCEPT(filter_func,param)
 38  * {
 39  *     handle the exception here
 40  * }
 41  * __ENDTRY
 42  *
 43  * or
 44  *
 45  * __TRY
 46  * {
 47  *     do some stuff that can raise an exception
 48  * }
 49  * __FINALLY(finally_func,param)
 50  *
 51  * The filter_func must be defined with the WINE_EXCEPTION_FILTER
 52  * macro, and return one of the EXCEPTION_* code; it can use
 53  * GetExceptionInformation and GetExceptionCode to retrieve the
 54  * exception info.
 55  *
 56  * The finally_func must be defined with the WINE_FINALLY_FUNC macro.
 57  *
 58  * Warning: inside a __TRY or __EXCEPT block, 'break' or 'continue' statements
 59  *          break out of the current block. You cannot use 'return', 'goto'
 60  *          or 'longjmp' to leave a __TRY block, as this will surely crash.
 61  *          You can use them to leave a __EXCEPT block though.
 62  *
 63  * -- AJ
 64  */
 65 
 66 /* Define this if you want to use your compiler built-in __try/__except support.
 67  * This is only useful when compiling to a native Windows binary, as the built-in
 68  * compiler exceptions will most certainly not work under Winelib.
 69  */
 70 #ifdef USE_COMPILER_EXCEPTIONS
 71 
 72 #define __TRY __try
 73 #define __EXCEPT(func) __except((func)(GetExceptionInformation()))
 74 #define __FINALLY(func) __finally { (func)(!AbnormalTermination()); }
 75 #define __ENDTRY /*nothing*/
 76 #define __EXCEPT_PAGE_FAULT __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
 77 #define __EXCEPT_ALL __except(EXCEPTION_EXECUTE_HANDLER)
 78 
 79 #else  /* USE_COMPILER_EXCEPTIONS */
 80 
 81 #ifndef __GNUC__
 82 #define __attribute__(x) /* nothing */
 83 #endif
 84 
 85 #if defined(__MINGW32__) || defined(__CYGWIN__)
 86 #define sigjmp_buf jmp_buf
 87 #define sigsetjmp(buf,sigs) setjmp(buf)
 88 #define siglongjmp(buf,val) longjmp(buf,val)
 89 #endif
 90 
 91 #define __TRY \
 92     do { __WINE_FRAME __f; \
 93          int __first = 1; \
 94          for (;;) if (!__first) \
 95          { \
 96              do {
 97 
 98 #define __EXCEPT(func) \
 99              } while(0); \
100              __wine_pop_frame( &__f.frame ); \
101              break; \
102          } else { \
103              __f.frame.Handler = __wine_exception_handler; \
104              __f.u.filter = (func); \
105              if (sigsetjmp( __f.jmp, 0 )) { \
106                  const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
107                  do {
108 
109 /* convenience handler for page fault exceptions */
110 #define __EXCEPT_PAGE_FAULT \
111              } while(0); \
112              __wine_pop_frame( &__f.frame ); \
113              break; \
114          } else { \
115              __f.frame.Handler = __wine_exception_handler_page_fault; \
116              if (sigsetjmp( __f.jmp, 0 )) { \
117                  const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
118                  do {
119 
120 /* convenience handler for all exception */
121 #define __EXCEPT_ALL \
122              } while(0); \
123              __wine_pop_frame( &__f.frame ); \
124              break; \
125          } else { \
126              __f.frame.Handler = __wine_exception_handler_all; \
127              if (sigsetjmp( __f.jmp, 0 )) { \
128                  const __WINE_FRAME * const __eptr __attribute__((unused)) = &__f; \
129                  do {
130 
131 #define __ENDTRY \
132                  } while (0); \
133                  break; \
134              } \
135              __wine_push_frame( &__f.frame ); \
136              __first = 0; \
137          } \
138     } while (0);
139 
140 #define __FINALLY(func) \
141              } while(0); \
142              __wine_pop_frame( &__f.frame ); \
143              (func)(1); \
144              break; \
145          } else { \
146              __f.frame.Handler = __wine_finally_handler; \
147              __f.u.finally_func = (func); \
148              __wine_push_frame( &__f.frame ); \
149              __first = 0; \
150          } \
151     } while (0);
152 
153 
154 typedef LONG (CALLBACK *__WINE_FILTER)(PEXCEPTION_POINTERS);
155 typedef void (CALLBACK *__WINE_FINALLY)(BOOL);
156 
157 #define GetExceptionInformation() (__eptr)
158 #define GetExceptionCode()        (__eptr->ExceptionRecord->ExceptionCode)
159 #define AbnormalTermination()     (!__normal)
160 
161 typedef struct __tagWINE_FRAME
162 {
163     EXCEPTION_REGISTRATION_RECORD frame;
164     union
165     {
166         /* exception data */
167         __WINE_FILTER filter;
168         /* finally data */
169         __WINE_FINALLY finally_func;
170     } u;
171     sigjmp_buf jmp;
172     /* hack to make GetExceptionCode() work in handler */
173     DWORD ExceptionCode;
174     const struct __tagWINE_FRAME *ExceptionRecord;
175 } __WINE_FRAME;
176 
177 #endif /* USE_COMPILER_EXCEPTIONS */
178 
179 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame )
180 {
181 #if defined(__GNUC__) && defined(__i386__)
182     EXCEPTION_REGISTRATION_RECORD *prev;
183     __asm__ __volatile__(".byte 0x64\n\tmovl (0),%0"
184                          "\n\tmovl %0,(%1)"
185                          "\n\t.byte 0x64\n\tmovl %1,(0)"
186                          : "=&r" (prev) : "r" (frame) : "memory" );
187     return prev;
188 #else
189     NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
190     frame->Prev = (void *)teb->ExceptionList;
191     teb->ExceptionList = (void *)frame;
192     return frame->Prev;
193 #endif
194 }
195 
196 static inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGISTRATION_RECORD *frame )
197 {
198 #if defined(__GNUC__) && defined(__i386__)
199     __asm__ __volatile__(".byte 0x64\n\tmovl %0,(0)"
200                          : : "r" (frame->Prev) : "memory" );
201     return frame->Prev;
202 
203 #else
204     NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
205     teb->ExceptionList = (void *)frame->Prev;
206     return frame->Prev;
207 #endif
208 }
209 
210 /* Exception handling flags - from OS/2 2.0 exception handling */
211 
212 /* Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD */
213 #define EH_NONCONTINUABLE   0x01
214 #define EH_UNWINDING        0x02
215 #define EH_EXIT_UNWIND      0x04
216 #define EH_STACK_INVALID    0x08
217 #define EH_NESTED_CALL      0x10
218 
219 /* Wine-specific exceptions codes */
220 
221 #define EXCEPTION_WINE_STUB       0x80000100  /* stub entry point called */
222 #define EXCEPTION_WINE_ASSERTION  0x80000101  /* assertion failed */
223 
224 /* unhandled return status from vm86 mode */
225 #define EXCEPTION_VM86_INTx       0x80000110
226 #define EXCEPTION_VM86_STI        0x80000111
227 #define EXCEPTION_VM86_PICRETURN  0x80000112
228 
229 extern void __wine_enter_vm86( CONTEXT *context );
230 
231 #ifndef USE_COMPILER_EXCEPTIONS
232 
233 static inline void DECLSPEC_NORETURN __wine_unwind_frame( EXCEPTION_RECORD *record,
234                                                           EXCEPTION_REGISTRATION_RECORD *frame )
235 {
236     __WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
237 
238     /* hack to make GetExceptionCode() work in handler */
239     wine_frame->ExceptionCode   = record->ExceptionCode;
240     wine_frame->ExceptionRecord = wine_frame;
241 
242 #if defined(__GNUC__) && defined(__i386__)
243     {
244         /* RtlUnwind clobbers registers on Windows */
245         int dummy1, dummy2, dummy3;
246         __asm__ __volatile__("pushl %%ebp\n\t"
247                              "pushl %%ebx\n\t"
248                              "pushl $0\n\t"
249                              "pushl %2\n\t"
250                              "pushl $0\n\t"
251                              "pushl %1\n\t"
252                              "call *%0\n\t"
253                              "popl %%ebx\n\t"
254                              "popl %%ebp"
255                              : "=a" (dummy1), "=S" (dummy2), "=D" (dummy3)
256                              : "" (RtlUnwind), "1" (frame), "2" (record)
257                              : "ecx", "edx", "memory" );
258     }
259 #else
260     RtlUnwind( frame, 0, record, 0 );
261 #endif
262     __wine_pop_frame( frame );
263     siglongjmp( wine_frame->jmp, 1 );
264 }
265 
266 static inline DWORD __wine_exception_handler( EXCEPTION_RECORD *record,
267                                               EXCEPTION_REGISTRATION_RECORD *frame,
268                                               CONTEXT *context,
269                                               EXCEPTION_REGISTRATION_RECORD **pdispatcher )
270 {
271     __WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
272     EXCEPTION_POINTERS ptrs;
273 
274     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
275         return ExceptionContinueSearch;
276 
277     ptrs.ExceptionRecord = record;
278     ptrs.ContextRecord = context;
279     switch(wine_frame->u.filter( &ptrs ))
280     {
281     case EXCEPTION_CONTINUE_SEARCH:
282         return ExceptionContinueSearch;
283     case EXCEPTION_CONTINUE_EXECUTION:
284         return ExceptionContinueExecution;
285     case EXCEPTION_EXECUTE_HANDLER:
286         break;
287     }
288     __wine_unwind_frame( record, frame );
289 }
290 
291 static inline DWORD __wine_exception_handler_page_fault( EXCEPTION_RECORD *record,
292                                                          EXCEPTION_REGISTRATION_RECORD *frame,
293                                                          CONTEXT *context,
294                                                          EXCEPTION_REGISTRATION_RECORD **pdispatcher )
295 {
296     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
297         return ExceptionContinueSearch;
298     if (record->ExceptionCode != STATUS_ACCESS_VIOLATION)
299         return ExceptionContinueSearch;
300     __wine_unwind_frame( record, frame );
301 }
302 
303 static inline DWORD __wine_exception_handler_all( EXCEPTION_RECORD *record,
304                                                   EXCEPTION_REGISTRATION_RECORD *frame,
305                                                   CONTEXT *context,
306                                                   EXCEPTION_REGISTRATION_RECORD **pdispatcher )
307 {
308     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))
309         return ExceptionContinueSearch;
310     __wine_unwind_frame( record, frame );
311 }
312 
313 static inline DWORD __wine_finally_handler( EXCEPTION_RECORD *record,
314                                             EXCEPTION_REGISTRATION_RECORD *frame,
315                                             CONTEXT *context,
316                                             EXCEPTION_REGISTRATION_RECORD **pdispatcher )
317 {
318     if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
319     {
320         __WINE_FRAME *wine_frame = (__WINE_FRAME *)frame;
321         wine_frame->u.finally_func( FALSE );
322     }
323     return ExceptionContinueSearch;
324 }
325 
326 #endif /* USE_COMPILER_EXCEPTIONS */
327 
328 #endif  /* __WINE_WINE_EXCEPTION_H */
329 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.