Coverage Report

Created: 2026-11-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/include/system/fault.h
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
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
/// systems.
13
///
14
//===----------------------------------------------------------------------===//
15
#pragma once
16
17
#include "common/errcode.h"
18
#include "common/span.h"
19
#include <array>
20
#include <csetjmp>
21
22
namespace WasmEdge {
23
24
class Fault {
25
public:
26
  Fault();
27
28
  ~Fault() noexcept;
29
30
  [[noreturn]] static void emitFault(ErrCode Error);
31
32
0
  std::jmp_buf &buffer() noexcept { return Buffer; }
33
34
0
  Span<void *const> stacktrace() const noexcept {
35
0
    return Span<void *const>{StackTraceBuffer}.first(StackTraceSize);
36
0
  }
37
38
private:
39
  Fault *Prev = nullptr;
40
  std::jmp_buf Buffer;
41
  std::array<void *, 256> StackTraceBuffer;
42
  size_t StackTraceSize;
43
};
44
45
} // namespace WasmEdge
46
47
0
#define PREPARE_FAULT(f) (static_cast<uint32_t>(setjmp((f).buffer())))