/src/WasmEdge/include/system/fault.h
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | //===-- wasmedge/system/fault.h - Memory and arithmetic exception ---------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the software exception handler for various operating |
12 | | /// system. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | #pragma once |
16 | | |
17 | | #include "common/errcode.h" |
18 | | #include <array> |
19 | | #include <csetjmp> |
20 | | |
21 | | namespace WasmEdge { |
22 | | |
23 | | class Fault { |
24 | | public: |
25 | | Fault(); |
26 | | |
27 | | ~Fault() noexcept; |
28 | | |
29 | | [[noreturn]] static void emitFault(ErrCode Error); |
30 | | |
31 | 0 | std::jmp_buf &buffer() noexcept { return Buffer; } |
32 | | |
33 | 0 | Span<void *const> stacktrace() const noexcept { |
34 | 0 | return Span<void *const>{StackTraceBuffer}.first(StackTraceSize); |
35 | 0 | } |
36 | | |
37 | | private: |
38 | | Fault *Prev = nullptr; |
39 | | std::jmp_buf Buffer; |
40 | | std::array<void *, 256> StackTraceBuffer; |
41 | | size_t StackTraceSize; |
42 | | }; |
43 | | |
44 | | } // namespace WasmEdge |
45 | | |
46 | 0 | #define PREPARE_FAULT(f) (static_cast<uint32_t>(setjmp((f).buffer()))) |