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
85class CLASS_DECL_ACME standard_exception :
86public ::exception
87{
88public:
89
90
91friend class ::exception_translator;
92
93
94#ifdef WINDOWS
95//EXCEPTION_POINTERS * m_ppointers;
96#else
97::i32 m_iSignal;
98void * m_psiginfo;
99#ifndef __ANDROID__
100//ucontext_t m_ucontext;
101#endif
102#endif
103
104
105#ifdef WINDOWS
106//EXCEPTION_POINTERS * info() const { return m_ppointers; }
107#else
108::u32 code() const;
109void * address() const;
110const void * info() const; // siginfo_t *
111const_char_pointer pszName() const;
112const_char_pointer description() const;
113#ifndef __ANDROID__
114const ::ucontext_t * ucontext() const;
115#endif
116#endif
117
118
119
120#if !defined(WINDOWS)
121
122static void * siginfodup(void * psiginfo);
123static void siginfofree(void * psiginfo);
124
125#ifdef __ANDROID__
126
127standard_exception(::i32 iSignal, void * psiginfo, void * pc, ::i32 iSkip = DEFAULT_SE_EXCEPTION_CALLSTACK_SKIP) :
128 ::exception(error_exception, nullptr, nullptr, iSkip),
129 m_iSignal(iSignal),
130 m_psiginfo(siginfodup(psiginfo))
131 {
132
133 /*_ASSERTE(psiginfo != 0);*/
134
135 }
136
137#else
138
139standard_exception(::i32 iSignal, void * psiginfo, void * pc, ::i32 iSkip = -1, void * caller_address = nullptr);
140
141#endif
142
143#endif
144
145
147{
148
149#ifndef WINDOWS
150
151 siginfofree(m_psiginfo);
152
153#endif
154
155}
156
157
158};
159
160#if defined(LINUX)
161
162typedef struct _sig_ucontext
163{
164 ulong uc_flags;
165 struct ucontext *uc_link;
166 stack_t uc_stack;
167 sigcontext uc_mcontext;
168 sigset_t uc_sigmask;
169
170} sig_ucontext_t;
171
172#endif
173
174//namespace exception
175//{
176//
178{
179public:
180#if defined(__ANDROID__) || defined(RASPBERRYPIOS)
181
182
183 standard_access_violation (::i32 signal, void * psiginfo, void * pc) :
184 ::standard_exception(signal, psiginfo, pc)
185 {
186
187 }
188
189#elif defined(FREEBSD_UNIX)
190 standard_access_violation (::i32 signal, void * psiginfo, void * pc) :
191 standard_exception(signal, psiginfo, pc, 3, (void *) pc)
192 {
193
194 }
195
196
197#elif defined(LINUX) || defined(__APPLE__) || defined(SOLARIS)
198
199 standard_access_violation (::i32 signal, void * psiginfo, void * pc);
200
201#else
202
203
204
205public:
206#endif
207};
208#if defined(__ANDROID__) || defined(RASPBERRYPIOS)
209
211 {
212 public:
213
214
215 standard_sigfpe(::i32 iSignal,void * psiginfo,void * pc):
216 standard_exception(iSignal, psiginfo, pc)
217 {
218
219 }
220
221
222
223 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
224 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
225 };
226
227#elif defined(__APPLE__)
228
230 {
231 public:
232 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc) :
233#ifdef _LP64
234
235#ifdef __ARM_ARCH_ISA_A64
236 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__pc)
237#else
238 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__rip)
239
240#endif
241
242#else
243#if defined(APPLE_IOS)
244 ::callstack(3, nullptr),
245#else
246 //::callstack(3, (void *) ((ucontext_t *) pc)->uc_mcontext.eip),
247#endif
248#endif
249// ::exception(),
250// standard_exception(iSignal, psiginfo, pc)
251 {
252
253 }
254
255
256 public:
257 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
258 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
259 };
260
261#endif
262
263
264//} // namespace exception
265
266/*#else
267
268
269#include "translator.h"
270#if !defined(__APPLE__)
271#include <ucontext.h>
272#include <sys/ucontext.h>
273#endif*/
274
275/*class CLASS_DECL_ACME standard_exception :
276 public bastandard_exception
277{
278public:
279 friend class translator;
280
281
282 ~standard_exception() {}
283
284protected:
285
286private:
287};*/
288
289/*class standard_sigsegv : public standard_exception
290{
291 friend class translator;
292protected:
293 standard_sigsegv (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
294public:
295 //bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
296 //uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
297};*/
298
299/*class standard_sigfpe : public standard_exception
300{
301 friend class translator;
302protected:
303 standard_sigfpe (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
304public:
305// bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
306 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
307};
308
309#endif*/
310
311
312
Definition aaa_standard.h:168
Definition aaa_standard.h:77
virtual ~standard_exception()
def(WINDOWS)
Definition standard_exception.h:146
Definition standard_exception.h:192