home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / EXCPT.H < prev    next >
C/C++ Source or Header  |  1997-01-16  |  12KB  |  402 lines

  1. /***
  2. *excpt.h - defines exception values, types and routines
  3. *
  4. *Purpose:
  5. *   This file contains the definitions and prototypes for the compiler-
  6. *   dependent intrinsics, support functions and keywords which implement
  7. *   the structured exception handling extensions.
  8. *
  9. ****/
  10.  
  11. /* $Copyright: 1990$ */
  12.  
  13.  
  14.  
  15. #ifndef __EXCPT_H
  16. #define __EXCPT_H
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #if defined(__BORLANDC__) && !defined(__FLAT__)
  23.  
  24. #if !defined(__WINDOWS_H)
  25. typedef unsigned char       BYTE;
  26. typedef unsigned long       DWORD;
  27. typedef void __far *        LPVOID;
  28. typedef unsigned int        UINT;
  29. typedef DWORD  __far *      LPDWORD;
  30. #define WINAPI              _far _pascal
  31. #endif
  32.  
  33. /* From WINNT.H */
  34.  
  35. //
  36. //  Define the size of the 80387 save area, which is in the context frame.
  37. //
  38.  
  39. #define SIZE_OF_80387_REGISTERS      80
  40.  
  41. typedef struct _FLOATING_SAVE_AREA {
  42.     DWORD   ControlWord;
  43.     DWORD   StatusWord;
  44.     DWORD   TagWord;
  45.     DWORD   ErrorOffset;
  46.     DWORD   ErrorSelector;
  47.     DWORD   DataOffset;
  48.     DWORD   DataSelector;
  49.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  50.     DWORD   Cr0NpxState;
  51. } FLOATING_SAVE_AREA;
  52.  
  53. //
  54. // Context Frame
  55. //
  56. //  This frame has a several purposes: 1) it is used as an argument to
  57. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  58. //  and 3) it is used in the user level thread creation routines.
  59. //
  60. //  The layout of the record conforms to a standard call frame.
  61. //
  62.  
  63. typedef struct _CONTEXT {
  64.  
  65.     //
  66.     // The flags values within this flag control the contents of
  67.     // a CONTEXT record.
  68.     //
  69.     // If the context record is used as an input parameter, then
  70.     // for each portion of the context record controlled by a flag
  71.     // whose value is set, it is assumed that that portion of the
  72.     // context record contains valid context. If the context record
  73.     // is being used to modify a threads context, then only that
  74.     // portion of the threads context will be modified.
  75.     //
  76.     // If the context record is used as an IN OUT parameter to capture
  77.     // the context of a thread, then only those portions of the thread's
  78.     // context corresponding to set flags will be returned.
  79.     //
  80.     // The context record is never used as an OUT only parameter.
  81.     //
  82.  
  83.     DWORD ContextFlags;
  84.  
  85.     //
  86.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  87.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  88.     // included in CONTEXT_FULL.
  89.     //
  90.  
  91.     DWORD   Dr0;
  92.     DWORD   Dr1;
  93.     DWORD   Dr2;
  94.     DWORD   Dr3;
  95.     DWORD   Dr6;
  96.     DWORD   Dr7;
  97.  
  98.     //
  99.     // This section is specified/returned if the
  100.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  101.     //
  102.  
  103.     FLOATING_SAVE_AREA FloatSave;
  104.  
  105.     //
  106.     // This section is specified/returned if the
  107.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  108.     //
  109.  
  110.     DWORD   SegGs;
  111.     DWORD   SegFs;
  112.     DWORD   SegEs;
  113.     DWORD   SegDs;
  114.  
  115.     //
  116.     // This section is specified/returned if the
  117.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  118.     //
  119.  
  120.     DWORD   Edi;
  121.     DWORD   Esi;
  122.     DWORD   Ebx;
  123.     DWORD   Edx;
  124.     DWORD   Ecx;
  125.     DWORD   Eax;
  126.  
  127.     //
  128.     // This section is specified/returned if the
  129.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  130.     //
  131.  
  132.     DWORD   Ebp;
  133.     DWORD   Eip;
  134.     DWORD   SegCs;              // MUST BE SANITIZED
  135.     DWORD   EFlags;             // MUST BE SANITIZED
  136.     DWORD   Esp;
  137.     DWORD   SegSs;
  138.  
  139. } CONTEXT;
  140.  
  141.  
  142. typedef CONTEXT *PCONTEXT;
  143.  
  144. /* From WINNT.H */
  145. #define STATUS_WAIT_0                    ((DWORD   )0x00000000L)
  146. #define STATUS_ABANDONED_WAIT_0          ((DWORD   )0x00000080L)
  147. #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)
  148. #define STATUS_TIMEOUT                   ((DWORD   )0x00000102L)
  149. #define STATUS_PENDING                   ((DWORD   )0x00000103L)
  150. #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)
  151. #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)
  152. #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)
  153. #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)
  154. #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)
  155. #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)
  156. #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)
  157. #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)
  158. #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)
  159. #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)
  160. #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)
  161. #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)
  162. #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)
  163. #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)
  164. #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)
  165. #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)
  166. #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)
  167. #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)
  168. #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)
  169. #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)
  170. #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)
  171. #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)
  172.  
  173. /* From WINNT.H */
  174. #define EXCEPTION_CONTINUABLE        0      // Continuable exception
  175. #define EXCEPTION_NONCONTINUABLE     0x1    // Noncontinuable exception
  176. #define EXCEPTION_MAXIMUM_PARAMETERS 15     // maximum number of exception parameters
  177.  
  178. //
  179. // Exception record definition.
  180. //
  181.  
  182. typedef struct _EXCEPTION_RECORD {
  183.     DWORD ExceptionCode;
  184.     DWORD ExceptionFlags;
  185.     struct _EXCEPTION_RECORD __ss *ExceptionRecord;
  186.     LPVOID ExceptionAddress;
  187.     UINT NumberParameters;
  188.     DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  189. } EXCEPTION_RECORD;
  190.  
  191. typedef EXCEPTION_RECORD __ss *PEXCEPTION_RECORD;
  192.  
  193. //
  194. // Typedef for pointer returned by exception_info()
  195. //
  196.  
  197. typedef struct _EXCEPTION_POINTERS {
  198.     PEXCEPTION_RECORD ExceptionRecord;
  199.     PCONTEXT ContextRecord;
  200. } EXCEPTION_POINTERS, __ss *PEXCEPTION_POINTERS;
  201.  
  202.  
  203. /* From WINBASE.H */
  204. #define EXCEPTION_ACCESS_VIOLATION      STATUS_ACCESS_VIOLATION
  205. #define EXCEPTION_DATATYPE_MISALIGNMENT STATUS_DATATYPE_MISALIGNMENT
  206. #define EXCEPTION_BREAKPOINT            STATUS_BREAKPOINT
  207. #define EXCEPTION_SINGLE_STEP           STATUS_SINGLE_STEP
  208. #define EXCEPTION_ARRAY_BOUNDS_EXCEEDED STATUS_ARRAY_BOUNDS_EXCEEDED
  209. #define EXCEPTION_FLT_DENORMAL_OPERAND  STATUS_FLOAT_DENORMAL_OPERAND
  210. #define EXCEPTION_FLT_DIVIDE_BY_ZERO    STATUS_FLOAT_DIVIDE_BY_ZERO
  211. #define EXCEPTION_FLT_INEXACT_RESULT    STATUS_FLOAT_INEXACT_RESULT
  212. #define EXCEPTION_FLT_INVALID_OPERATION STATUS_FLOAT_INVALID_OPERATION
  213. #define EXCEPTION_FLT_OVERFLOW          STATUS_FLOAT_OVERFLOW
  214. #define EXCEPTION_FLT_STACK_CHECK       STATUS_FLOAT_STACK_CHECK
  215. #define EXCEPTION_FLT_UNDERFLOW         STATUS_FLOAT_UNDERFLOW
  216. #define EXCEPTION_INT_DIVIDE_BY_ZERO    STATUS_INTEGER_DIVIDE_BY_ZERO
  217. #define EXCEPTION_INT_OVERFLOW          STATUS_INTEGER_OVERFLOW
  218. #define EXCEPTION_PRIV_INSTRUCTION      STATUS_PRIVILEGED_INSTRUCTION
  219. #define EXCEPTION_IN_PAGE_ERROR         STATUS_IN_PAGE_ERROR
  220.  
  221. void
  222. __cdecl __far
  223. RaiseException(
  224.     DWORD dwExceptionCode,
  225.     DWORD dwExceptionFlags,
  226.     DWORD nNumberOfArguments,
  227.     const LPDWORD lpArguments
  228.     );
  229.  
  230. long
  231. WINAPI
  232. UnhandledExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo);
  233.  
  234. typedef long (WINAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
  235.    PEXCEPTION_POINTERS ExceptionInfo
  236.    );
  237. typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
  238.  
  239. LPTOP_LEVEL_EXCEPTION_FILTER
  240. WINAPI
  241. SetUnhandledExceptionFilter(
  242.    LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
  243.    );
  244.  
  245. #endif  /* __BORLANDC__ && !__FLAT__ */
  246.  
  247.  
  248. /*
  249.  * Conditional macro definition for function calling type and variable type
  250.  * qualifiers.
  251.  */
  252. #if   ( (_MSC_VER >= 800) && (_M_IX86 >= 300) ) || defined(__BORLANDC__)
  253.  
  254. /* From WINNT.H */
  255. #define EXCEPTION_CONTINUABLE        0      // Continuable exception
  256. #define EXCEPTION_NONCONTINUABLE     0x1    // Noncontinuable exception
  257. #define EXCEPTION_MAXIMUM_PARAMETERS 15     // maximum number of exception parameters
  258.  
  259. /*
  260.  * Definitions for MS C8-32 (386/486) compiler
  261.  */
  262. #define _CRTAPI1 __cdecl
  263. #define _CRTAPI2 __cdecl
  264.  
  265. #else
  266.  
  267. /*
  268.  * Other compilers (e.g., MIPS)
  269.  */
  270. #define _CRTAPI1
  271. #define _CRTAPI2
  272.  
  273. #endif
  274.  
  275.  
  276. /*
  277.  * Exception disposition return values.
  278.  */
  279. typedef enum _EXCEPTION_DISPOSITION {
  280.     ExceptionContinueExecution,
  281.     ExceptionContinueSearch,
  282.     ExceptionNestedException,
  283.     ExceptionCollidedUnwind
  284. } EXCEPTION_DISPOSITION;
  285.  
  286.  
  287. /*
  288.  * Prototype for SEH support function.
  289.  */
  290.  
  291. #if defined(_M_IX86)
  292.  
  293. /*
  294.  * Declarations to keep MS C 8 (386/486) compiler happy
  295.  */
  296. struct _EXCEPTION_RECORD;
  297. struct _CONTEXT;
  298.  
  299. EXCEPTION_DISPOSITION _CRTAPI2 _except_handler (
  300.         struct _EXCEPTION_RECORD *ExceptionRecord,
  301.         void *EstablisherFrame,
  302.         struct _CONTEXT *ContextRecord,
  303.         void *DispatcherContext
  304.         );
  305.  
  306. #elif defined(_M_MRX000) || defined(_MIPS_) || defined(_ALPHA_)
  307.  
  308. /*
  309.  * Declarations to keep MIPS and ALPHA compiler happy
  310.  */
  311. typedef struct _EXCEPTION_POINTERS *Exception_info_ptr;
  312. struct _EXCEPTION_RECORD;
  313. struct _CONTEXT;
  314. struct _DISPATCHER_CONTEXT;
  315.  
  316.  
  317. EXCEPTION_DISPOSITION __C_specific_handler (
  318.         struct _EXCEPTION_RECORD *ExceptionRecord,
  319.         void *EstablisherFrame,
  320.         struct _CONTEXT *ContextRecord,
  321.         struct _DISPATCHER_CONTEXT *DispatcherContext
  322.         );
  323.  
  324. #endif
  325.  
  326.  
  327. /*
  328.  * Keywords and intrinsics for SEH
  329.  */
  330.  
  331. #if defined(__BORLANDC__)
  332. /*
  333.  * Borland C++
  334.  */
  335. #ifndef __cplusplus
  336. #  define try                       __try
  337. #  define finally                   __finally
  338. #  define AbnormalTermination()     __abnormal_termination
  339. #  define abnormal_termination()    __abnormal_termination
  340. #endif
  341.  
  342. #  define except                    __except
  343. #  define GetExceptionCode()        __exception_code
  344. #  define exception_code()          __exception_code
  345. #  define GetExceptionInformation() ((PEXCEPTION_POINTERS)__exception_info)
  346. #  define exception_info()          ((PEXCEPTION_POINTERS)__exception_info)
  347.  
  348. #elif     ( _MSC_VER >= 800 )
  349. /*
  350.  * MS C8-32 (386/486)
  351.  */
  352. #define try                             __try
  353. #define except                          __except
  354. #define finally                         __finally
  355. #define leave                           __leave
  356. #define GetExceptionCode                _exception_code
  357. #define exception_code                  _exception_code
  358. #define GetExceptionInformation         (struct _EXCEPTION_POINTERS *)_exception_info
  359. #define exception_info                  (struct _EXCEPTION_POINTERS *)_exception_info
  360. #define AbnormalTermination             _abnormal_termination
  361. #define abnormal_termination            _abnormal_termination
  362.  
  363. unsigned long _CRTAPI1 _exception_code(void);
  364. void *        _CRTAPI1 _exception_info(void);
  365. int           _CRTAPI1 _abnormal_termination(void);
  366.  
  367. #elif defined(_M_MRX000) || defined(_MIPS_) || defined(_ALPHA_)
  368. /*
  369.  * MIPS or ALPHA compiler
  370.  */
  371. #define try                             __builtin_try
  372. #define except                          __builtin_except
  373. #define finally                         __builtin_finally
  374. #define leave                           __builtin_leave
  375. #define GetExceptionCode()              __exception_code
  376. #define exception_code()                __exception_code
  377. #define GetExceptionInformation()       (struct _EXCEPTION_POINTERS *)__exception_info
  378. #define exception_info()                (struct _EXCEPTION_POINTERS *)__exception_info
  379. #define AbnormalTermination()           __abnormal_termination
  380. #define abnormal_termination()          __abnormal_termination
  381.  
  382. extern unsigned long __exception_code;
  383. extern int           __exception_info;
  384. extern int           __abnormal_termination;
  385.  
  386. #endif
  387.  
  388.  
  389. /*
  390.  * Legal values for expression in except().
  391.  */
  392.  
  393. #define EXCEPTION_EXECUTE_HANDLER        1
  394. #define EXCEPTION_CONTINUE_SEARCH        0
  395. #define EXCEPTION_CONTINUE_EXECUTION    -1
  396.  
  397. #ifdef __cplusplus
  398. }
  399. #endif
  400.  
  401. #endif  /* __EXCPT_H */
  402.