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__
100ucontext_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
181
182 standard_access_violation (::i32 signal, void * psiginfo, void * pc);
183
184};
185
186
187
188#if defined(__ANDROID__) || defined(RASPBERRYPIOS)
189
191 {
192 public:
193
194
195 standard_sigfpe(::i32 iSignal,void * psiginfo,void * pc):
196 standard_exception(iSignal, psiginfo, pc)
197 {
198
199 }
200
201
202
203 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
204 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
205 };
206
207#elif defined(NETBSD)
208
210 {
211 public:
212 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc); //:
213 //standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip),
214// standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext.mc_rip)
215 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
216 // {
217
218 // }
219
220
221 public:
222 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
223 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
224 };
225
226
227#elif defined(LINUX) || defined(__APPLE__)
228
230 {
231 public:
232 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc) :
233#ifdef LINUX
234#ifdef _LP64
235 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
236 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip),
237#else
238#ifdef __arm__
239 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.arm_ip)
240 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
241#else
242 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
243 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
244
245#endif
246#endif
247#else
248#ifdef _LP64
249
250#ifdef __ARM_ARCH_ISA_A64
251 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__pc)
252#else
253 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((ucontext_t *) pc)->uc_mcontext->__ss.__rip)
254
255#endif
256
257#else
258#if defined(APPLE_IOS)
259 ::callstack(3, nullptr),
260#else
261 //::callstack(3, (void *) ((ucontext_t *) pc)->uc_mcontext.eip),
262#endif
263#endif
264#endif
265// ::exception(),
266// standard_exception(iSignal, psiginfo, pc)
267 {
268
269 }
270
271
272 public:
273 // bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
274 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
275 };
276
277#endif
278
279
280//} // namespace exception
281
282/*#else
283
284
285#include "translator.h"
286#if !defined(__APPLE__)
287#include <ucontext.h>
288#include <sys/ucontext.h>
289#endif*/
290
291/*class CLASS_DECL_ACME standard_exception :
292 public bastandard_exception
293{
294public:
295 friend class translator;
296
297
298 ~standard_exception() {}
299
300protected:
301
302private:
303};*/
304
305/*class standard_sigsegv : public standard_exception
306{
307 friend class translator;
308protected:
309 standard_sigsegv (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
310public:
311 //bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
312 //uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
313};*/
314
315/*class standard_sigfpe : public standard_exception
316{
317 friend class translator;
318protected:
319 standard_sigfpe (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#endif*/
326
327
328
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