summaryrefslogtreecommitdiff
path: root/Runtime/Utilities/ErrorExit.h
blob: b531acea215f2a85e8ae3319338de3d03a0043db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef ERROREXIT_H
#define ERROREXIT_H

#include "Configuration/UnityConfigure.h"

#if SUPPORT_ERROR_EXIT

enum ExitErrorCode
{
	kErrorNone = 0,
	kErrorSecurityBreach = 1,
	kErrorFatalException = 2,
	kErrorNoSSE2Architecture = 3,
	kErrorIncompatibleRuntimeVersion = 4,
	kErrorUnsupportedGPU = 5,
};

extern ExitErrorCode gExitErrorCode;

#if !UNITY_WIN
#include <setjmp.h>
void InsertThreadExitPoint(jmp_buf *buf);
class AutoRemoveEntryPoint {
	bool m_ShouldRemove;
public:
	AutoRemoveEntryPoint (jmp_buf *buf);
	~AutoRemoveEntryPoint ();
};
#endif
void ExitWithErrorCode(ExitErrorCode error);
ExitErrorCode GetExitErrorCode();
const char *GetExitErrorString(ExitErrorCode err);

#if UNITY_WIN

DWORD OnExcept(DWORD code, LPEXCEPTION_POINTERS exception);

#define UNITY_ENTRY_POINT(x) if(GetExitErrorCode()) return x; __try {
#define UNITY_ENTRY_POINT_NO_RETURN_VALUE() if(GetExitErrorCode()) return; __try {
#define UNITY_ENTRY_POINT_SKIP() if(!GetExitErrorCode()) { __try {
#define UNITY_EXIT_POINT(x) } __except (OnExcept(GetExceptionCode(), GetExceptionInformation())) { return x; }
#define UNITY_EXIT_POINT_NO_RETURN_VALUE() } __except (OnExcept(GetExceptionCode(), GetExceptionInformation())) { return; }
#define UNITY_EXIT_POINT_SKIP() } __except (OnExcept(GetExceptionCode(), GetExceptionInformation())) { } }

#define ERROR_EXIT_THREAD_ENTRY()			\
	__try									\
	{
#define ERROR_EXIT_THREAD_EXIT()			\
	}										\
	__except (OnExcept(GetExceptionCode(),	\
	          GetExceptionInformation()))	\
	{										\
		/* do nothing */					\
	}

#else
#define UNITY_ENTRY_POINT(x) if(GetExitErrorCode()) return x; jmp_buf buf; if (setjmp (buf)) return x; AutoRemoveEntryPoint entry(&buf); 
#define UNITY_ENTRY_POINT_NO_RETURN_VALUE() if(GetExitErrorCode()) return; jmp_buf buf; if (setjmp (buf)) return; AutoRemoveEntryPoint entry(&buf);
#define UNITY_EXIT_POINT(x)
#define UNITY_EXIT_POINT_NO_RETURN_VALUE()

#define ERROR_EXIT_THREAD_ENTRY()			\
	jmp_buf buf;							\
	if (!setjmp (buf))						\
	{										\
		InsertThreadExitPoint (&buf);
#define ERROR_EXIT_THREAD_EXIT()			\
	}

#endif

#else
#define ExitWithErrorCode(x) 
#define GetExitErrorCode() kErrorNone
#endif

#endif