MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FailPlatformSpecific.h
1 #ifndef FAILPLATFORMSPECIFIC_H /* -*- C++ -*- */
2 #define FAILPLATFORMSPECIFIC_H
3 
4 #include <setjmp.h> /* For jmp_buf, setjmp, longjmp */
5 #include <stdio.h> /* For FILE */
6 #include <pthread.h> /* For __thread */
7 
8 typedef struct MFMErrorEnvironment * volatile MFMErrorEnvironmentPointer_t;
9 
11  jmp_buf buffer; /* the system state as of the unwind_protect entry */
12  volatile const char * file; /* the file name of the original failure */
13  volatile int lineno; /* the line number of the original failure */
14  volatile int thrown; /* Return value(s) from setjmp call */
15  MFMErrorEnvironmentPointer_t prev; /* Back link to previous error environment */
16 } ;
17 
18 
19 /* Pointer to thread-local error environment stack top */
20 extern "C"
21  __thread MFMErrorEnvironmentPointer_t * MFMPtrToErrEnvStackPtr;
22 
23 extern "C" void MFMPrintErrorEnvironment(FILE * stream, MFMErrorEnvironmentPointer_t errenv) ;
24 
25 extern "C" void MFMPrintError(FILE * stream, const char * file, const int line, const int code) ;
26 
27 extern "C" void MFMFailHere(const char * file, const int line, const int code) __attribute__ ((noreturn));
28 extern "C" void MFMLongJmpHere(jmp_buf buffer, const int toThrow) __attribute__ ((noreturn));
29 extern "C" const char * MFMFailCodeReason(int failCode) ;
30 
31 #define MFM_FAIL_CODE_NUMBER(code) (MFM_FAIL_CODE_REASON_##code)
32 
33 #define FAIL(code) \
34  ((MFMPtrToErrEnvStackPtr && *MFMPtrToErrEnvStackPtr)? \
35  ((*MFMPtrToErrEnvStackPtr)->file = __FILE__, \
36  (*MFMPtrToErrEnvStackPtr)->lineno = __LINE__, \
37  MFMLongJmpHere((*MFMPtrToErrEnvStackPtr)->buffer, \
38  MFM_FAIL_CODE_NUMBER(code)),0) : \
39  (MFMFailHere(__FILE__,__LINE__, \
40  MFM_FAIL_CODE_NUMBER(code)),0))
41 
92 #define unwind_protect(cleanup,block) \
93 do { \
94  MFMErrorEnvironment unwindProtect_errorEnvironment; \
95  unwindProtect_errorEnvironment.prev = (*MFMPtrToErrEnvStackPtr); \
96  (*MFMPtrToErrEnvStackPtr) = &unwindProtect_errorEnvironment; \
97  if ((unwindProtect_errorEnvironment.thrown = \
98  setjmp(unwindProtect_errorEnvironment.buffer)) != 0) { \
99  /* Currently nothing special to do */ \
100  } else { \
101  {block} \
102  } \
103  (*MFMPtrToErrEnvStackPtr) = (*MFMPtrToErrEnvStackPtr)->prev; \
104  if (unwindProtect_errorEnvironment.thrown) { \
105  int MFMThrownFailCode __attribute__ ((unused)) = \
106  unwindProtect_errorEnvironment.thrown; \
107  {cleanup} \
108  } \
109 } while (0)
110 
111 
112 #endif /*FAILPLATFORMSPECIFIC_H*/
113 
Definition: FailPlatformSpecific.h:10
const char * MFMFailCodeReason(int failCode)
Definition: Fail.cpp:14