This library contains code that extends and simplifies different operations
for C language based programs.
Revisión | 5c48a0b7b550ce25a335b4fd8028977dda96048d (tree) |
---|---|
Tiempo | 2017-02-12 18:30:55 |
Autor | s.gusarov |
Commiter | s.gusarov |
Added seh module
@@ -0,0 +1,36 @@ | ||
1 | +/* | |
2 | + * @author Sergey Gusarov <laborer2008 (at) gmail.com> | |
3 | + * @section LICENSE | |
4 | + * This Source Code Form is subject to the terms of the Mozilla Public | |
5 | + * License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | + * | |
8 | + * @section DESCRIPTION | |
9 | + * | |
10 | + */ | |
11 | + | |
12 | +#pragma once | |
13 | + | |
14 | +#include "ctools/predef/compiler.h" | |
15 | + | |
16 | + | |
17 | +#if defined (CT_COMPL_MSVC) | |
18 | +# define CT_SEH_AVAILABLE | |
19 | +#endif | |
20 | + | |
21 | +#if defined (CT_SEH_AVAILABLE) | |
22 | + | |
23 | +# include "ctools/predef/cxx11_attributes.h" | |
24 | +# include "ctools/std/stdint.h" | |
25 | +# include "ctools/namespace.h" | |
26 | + | |
27 | + | |
28 | +CT_BEGIN_NAMESPACE | |
29 | + | |
30 | +extern void setDefaultSehHandler() CT_NOEXCEPT; | |
31 | + | |
32 | +extern char* sehCodeToString(const uint32_t code) CT_NOEXCEPT; | |
33 | + | |
34 | +CT_END_NAMESPACE | |
35 | + | |
36 | +#endif // defined (CT_SEH_AVAILABLE) |
@@ -0,0 +1,140 @@ | ||
1 | +/* | |
2 | + * @author Sergey Gusarov <laborer2008 (at) gmail.com> | |
3 | + * @section LICENSE | |
4 | + * This Source Code Form is subject to the terms of the Mozilla Public | |
5 | + * License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | + * | |
8 | + * @section DESCRIPTION | |
9 | + * | |
10 | + */ | |
11 | + | |
12 | +#include "ctools/os/windows/seh.h" | |
13 | + | |
14 | +#if defined (CT_SEH_AVAILABLE) | |
15 | + | |
16 | +# include "ctools/predef/external_headers.h" | |
17 | + | |
18 | +CT_BEGIN_EXTERNAL_HEADERS | |
19 | +# include <windows.h> | |
20 | +CT_END_EXTERNAL_HEADERS | |
21 | + | |
22 | +# include "ctools/trace.h" | |
23 | + | |
24 | + | |
25 | +CT_BEGIN_NAMESPACE | |
26 | + | |
27 | +void defaultSeHandler(unsigned int code, struct _EXCEPTION_POINTERS* exceptionPointer) | |
28 | +{ | |
29 | + CT_TRACE_FATAL("Caught structured exception:", sehCodeToString(code)); | |
30 | +} | |
31 | + | |
32 | +void setDefaultSehHandler() CT_NOEXCEPT | |
33 | +{ | |
34 | + _set_se_translator(defaultSeHandler); | |
35 | +} | |
36 | + | |
37 | +char* sehCodeToString(const uint32_t code) CT_NOEXCEPT | |
38 | +{ | |
39 | + char* sehDescription; | |
40 | + | |
41 | + switch (code) | |
42 | + { | |
43 | + case EXCEPTION_ACCESS_VIOLATION: | |
44 | + sehDescription = "Access violation"; | |
45 | + break; | |
46 | + | |
47 | + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: | |
48 | + sehDescription = "Out of array bounds"; | |
49 | + break; | |
50 | + | |
51 | + case EXCEPTION_BREAKPOINT: | |
52 | + sehDescription = "Breakpoint"; | |
53 | + break; | |
54 | + | |
55 | + case EXCEPTION_DATATYPE_MISALIGNMENT: | |
56 | + sehDescription = "Misaligned data"; | |
57 | + break; | |
58 | + | |
59 | + case EXCEPTION_FLT_DENORMAL_OPERAND: | |
60 | + sehDescription = "Denormalized floating-point value"; | |
61 | + break; | |
62 | + | |
63 | + case EXCEPTION_FLT_DIVIDE_BY_ZERO: | |
64 | + sehDescription = "Floating-point divide-by-zero"; | |
65 | + break; | |
66 | + | |
67 | + case EXCEPTION_FLT_INEXACT_RESULT: | |
68 | + sehDescription = "Inexact floating-point value"; | |
69 | + break; | |
70 | + | |
71 | + case EXCEPTION_FLT_INVALID_OPERATION: | |
72 | + sehDescription = "Invalid floating-point operation"; | |
73 | + break; | |
74 | + | |
75 | + case EXCEPTION_FLT_OVERFLOW: | |
76 | + sehDescription = "Floating-point overflow"; | |
77 | + break; | |
78 | + | |
79 | + case EXCEPTION_FLT_STACK_CHECK: | |
80 | + sehDescription = "Floating-point stack overflow or underflow"; | |
81 | + break; | |
82 | + | |
83 | + case EXCEPTION_FLT_UNDERFLOW: | |
84 | + sehDescription = "Floating-point underflow"; | |
85 | + break; | |
86 | + | |
87 | + case EXCEPTION_GUARD_PAGE: | |
88 | + sehDescription = "Page-guard access"; | |
89 | + break; | |
90 | + | |
91 | + case EXCEPTION_ILLEGAL_INSTRUCTION: | |
92 | + sehDescription = "Illegal instruction"; | |
93 | + break; | |
94 | + | |
95 | + case EXCEPTION_IN_PAGE_ERROR: | |
96 | + sehDescription = "Invalid page access"; | |
97 | + break; | |
98 | + | |
99 | + case EXCEPTION_INT_DIVIDE_BY_ZERO: | |
100 | + sehDescription = "Integer divide-by-zero"; | |
101 | + break; | |
102 | + | |
103 | + case EXCEPTION_INT_OVERFLOW: | |
104 | + sehDescription = "Integer overflow"; | |
105 | + break; | |
106 | + | |
107 | + case EXCEPTION_INVALID_DISPOSITION: | |
108 | + sehDescription = "Invalid exception dispatcher"; | |
109 | + break; | |
110 | + | |
111 | + case EXCEPTION_INVALID_HANDLE: | |
112 | + sehDescription = "Invalid handle"; | |
113 | + break; | |
114 | + | |
115 | + case EXCEPTION_NONCONTINUABLE_EXCEPTION: | |
116 | + sehDescription = "Non-continuable exception"; | |
117 | + break; | |
118 | + | |
119 | + case EXCEPTION_PRIV_INSTRUCTION: | |
120 | + sehDescription = "Invalid instruction"; | |
121 | + break; | |
122 | + | |
123 | + case EXCEPTION_SINGLE_STEP: | |
124 | + sehDescription = "Single instruction step"; | |
125 | + break; | |
126 | + | |
127 | + case EXCEPTION_STACK_OVERFLOW: | |
128 | + sehDescription = "Stack overflow"; | |
129 | + break; | |
130 | + | |
131 | + default: | |
132 | + sehDescription = "Unknown exception"; | |
133 | + } | |
134 | + | |
135 | + return sehDescription; | |
136 | +} | |
137 | + | |
138 | +CT_END_NAMESPACE | |
139 | + | |
140 | +#endif // defined (CT_SEH_AVAILABLE) |
@@ -0,0 +1,30 @@ | ||
1 | +/* | |
2 | + * @author Sergey Gusarov <laborer2008 (at) gmail.com> | |
3 | + * @section LICENSE | |
4 | + * This Source Code Form is subject to the terms of the Mozilla Public | |
5 | + * License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | + * | |
8 | + * @section DESCRIPTION | |
9 | + * | |
10 | + */ | |
11 | + | |
12 | +#include "tests/unity_headers.h" | |
13 | + | |
14 | +#include <ctools/os/windows/seh.h> | |
15 | + | |
16 | + | |
17 | +void setUp(void) | |
18 | +{ | |
19 | +} | |
20 | + | |
21 | +void tearDown(void) | |
22 | +{ | |
23 | +} | |
24 | + | |
25 | +void testCompile(void) | |
26 | +{ | |
27 | +#if defined (CT_SEH_AVAILABLE) | |
28 | + setDefaultSehHandler(); | |
29 | +#endif | |
30 | +} |