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(LINUX)
208
210 {
211 public:
212 standard_sigfpe (::i32 iSignal, siginfo_t * psiginfo, void * pc) :
213#ifdef _LP64
214
215#if defined(__aarch64__)
216 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.pc)
217#else
218 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
219#endif
220 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip),
221#else
222#ifdef __arm__
223 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.arm_ip)
224 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
225#else
226 standard_exception(iSignal, psiginfo, pc, 3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.rip)
227 //::callstack(3, (void *) ((sig_ucontext_t *) pc)->uc_mcontext.eip),
228
229#endif
230#endif
231 {
232
233 }
234 };
235
236//} // namespace exception
237
238/*#else
239
240
241#include "translator.h"
242#if !defined(__APPLE__)
243#include <ucontext.h>
244#include <sys/ucontext.h>
245#endif*/
246
247/*class CLASS_DECL_ACME standard_exception :
248 public bastandard_exception
249{
250public:
251 friend class translator;
252
253
254 ~standard_exception() {}
255
256protected:
257
258private:
259};*/
260
261/*class standard_sigsegv : public standard_exception
262{
263 friend class translator;
264protected:
265 standard_sigsegv (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
266public:
267 //bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
268 //uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
269};*/
270
271/*class standard_sigfpe : public standard_exception
272{
273 friend class translator;
274protected:
275 standard_sigfpe (siginfo_t * psiginfo, void * pc) : ::matter(pparticle), standard_exception(psiginfo, pc) {}
276public:
277// bool is_read_op() const { return !info()->ExceptionRecord->ExceptionInformation [0]; }
278 // uptr inaccessible_address() const { return info()->ExceptionRecord->ExceptionInformation [1]; }
279};
280*/
281
282#endif
283
284
285
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