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