acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_standard.h
1/*
2 Copyright (ca) 2001
3 Author: Konstantin Boukreev
5 Created: 25.12.2001 14:47:20
6 Version: 1.0.0
7
8 Permission to use, copy, modify, distribute and sell this software
9 and its documentation for any purpose is hereby granted without fee,
10 provided that the above copyright notice appear in all copies and
11 that both that copyright notice and this permission notice appear
12 in supporting documentation. Konstantin Boukreev makes no representations
13 about the suitability of this software for any purpose.
14 It is provided "as is" without express or implied warranty.
15
16 wrapper class for _set_standard_translator API
17 maps Win32 exceptions (C structured exceptions) into C++ typed exceptions.
18*/
19#pragma once
20
21
22//#include "exception.h"
23
24
25#if defined(__ANDROID__)
26
27#include <signal.h>
28#include <ucontext.h>
29
30
31#if OSBIT == 64
32
33#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 3000
34
35#else
36
37#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 0
38
39#endif
40
41#elif defined(WINDOWS)
42
43#elif defined(__APPLE__)
44
45
46#include <sys/ucontext.h>
47#include <signal.h>
48
49#if OSBIT == 64
50
51#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 3000
52
53#else
54
55#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 0
56
57#endif
58
59#else
60
61
62//#if OSBIT == 64
63//
64//#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 3000
65//
66//#else
67//
68//#define DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP 0
69//
70//#endif
71
72#endif
73
74
75class CLASS_DECL_ACME standard_exception :
76 public ::exception
77{
78public:
79
80
81 friend class ::exception_translator;
82
83
84#ifdef WINDOWS
85 //EXCEPTION_POINTERS * m_ppointers;
86#else
87 ::i32 m_iSignal;
88 void * m_psiginfo;
89#ifndef __ANDROID__
90 ucontext_t m_ucontext;
91#endif
92#endif
93
94
95#ifdef WINDOWS
96 //EXCEPTION_POINTERS * info() const { return m_ppointers; }
97#else
98 ::u32 code() const;
99 void * address() const;
100 const void * info() const; // siginfo_t *
101 const_char_pointer pszName() const;
102 const_char_pointer description() const;
103#ifndef __ANDROID__
104 const ::ucontext_t * ucontext() const;
105#endif
106#endif
107
108
109
110#if !defined(WINDOWS)
111
112 static void * siginfodup(void * psiginfo);
113 static void siginfofree(void * psiginfo);
114
115#ifdef __ANDROID__
116
117 standard_exception(::i32 iSignal, void * psiginfo, void * pc, ::i32 iSkip = DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP) :
118 ::exception(error_exception, nullptr, nullptr, iSkip),
119 m_iSignal(iSignal),
120 m_psiginfo(siginfodup(psiginfo))
121 {
122
123 /*_ASSERTE(psiginfo != 0);*/
124
125 }
126
127#else
128
129 standard_exception(::i32 iSignal, void * psiginfo, void * pc, ::i32 iSkip = -1, void * caller_address = nullptr);
130
131#endif
132
133#endif
134
135
137 {
138
139#ifndef WINDOWS
140
141 siginfofree(m_psiginfo);
142
143#endif
144
145 }
146
147
148};
149
150#if defined(LINUX)
151
152typedef struct _sig_ucontext
153{
154 ulong uc_flags;
155 struct ucontext *uc_link;
156 stack_t uc_stack;
157 sigcontext uc_mcontext;
158 sigset_t uc_sigmask;
159
160} sig_ucontext_t;
161
162#endif
163
164//namespace exception
165//{
166//
167 class standard_access_violation : public standard_exception
168 {
169 public:
170#if defined(__ANDROID__) || defined(RASPBERRYPIOS)
171
172
173 standard_access_violation (::i32 signal, void * psiginfo, void * pc) :
174 ::standard_exception(signal, psiginfo, pc)
175 {
176
177 }
178
179#elif defined(FREEBSD_UNIX)
180 standard_access_violation (::i32 signal, void * psiginfo, void * pc) :
181 standard_exception(signal, psiginfo, pc, 3, (void *) pc)
182 {
183
184 }
185
186
187#elif defined(LINUX) || defined(__APPLE__) || defined(SOLARIS)
188
189 standard_access_violation (::i32 signal, void * psiginfo, void * pc);
190
191#else
192
193
194
195 public:
196#endif
197 };
198#if defined(__ANDROID__) || defined(RASPBERRYPIOS)
199
201 {
202 public:
203
204
205 standard_sigfpe(::i32 iSignal,void * psiginfo,void * pc):
206 standard_exception(iSignal, psiginfo, pc)
207 {
208
209 }
210
211
212
213 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
214 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
215 };
216
217#elif defined(FREEBSD)
218
220 {
221 public:
222 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc) :
223 //standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip),
224 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext.mc_rip)
225 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
226 {
227
228 }
229
230
231 public:
232 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
233 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
234 };
235
236
237#elif defined(LINUX) || defined(__APPLE__)
238
240 {
241 public:
242 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc) :
243#ifdef LINUX
244#ifdef _LP64
245 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
246 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip),
247#else
248#ifdef __arm__
249 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.arm_ip)
250 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
251#else
252 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
253 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
254
255#endif
256#endif
257#else
258#ifdef _LP64
259
260#ifdef __ARM_ARCH_ISA_A64
261 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__pc)
262#else
263 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__rip)
264
265#endif
266
267#else
268#if defined(APPLE_IOS)
269 ::callstack(3, nullptr),
270#else
271 //::callstack(3, (void *) ((ucontext_t *) pc)->uc_mcontext.eip),
272#endif
273#endif
274#endif
275// ::exception(),
276// standard_exception(iSignal, psiginfo, pc)
277 {
278
279 }
280
281
282 public:
283 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
284 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
285 };
286
287#endif
288
289
290//} // namespace exception
291
292/*#else
293
294
295#include "translator.h"
296#if !defined(__APPLE__)
297#include <ucontext.h>
298#include <sys/ucontext.h>
299#endif*/
300
301/*class CLASS_DECL_ACME standard_exception :
302 public bastandard_exception
303{
304public:
305 friend class translator;
306
307
308 ~standard_exception() {}
309
310protected:
311
312private:
313};*/
314
315/*class standard_sigsegv : public standard_exception
316{
317 friend class translator;
318protected:
319 standard_sigsegv (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
320public:
321 //bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
322 //uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
323};*/
324
325/*class standard_sigfpe : public standard_exception
326{
327 friend class translator;
328protected:
329 standard_sigfpe (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
330public:
331// bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
332 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
333};
334
335#endif*/
336
Definition aaa_standard.h:77
virtual ~standard_exception()
def(WINDOWS)
Definition aaa_standard.h:136
Definition standard_exception.h:192