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