GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_callstacks.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 43 51 84.3%
Functions: 12 14 85.7%
Branches: 4 8 50.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/callstacks.hpp"
30
31 namespace gate
32 {
33 3 static gate_result_t callstack_run_runnable(gate_dataptr_t arg)
34 {
35 3 IRunnable* ptr = static_cast<IRunnable*>(arg);
36
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
3 ExceptionInfo info = catchException(*ptr);
37 1 return info.result_code;
38 }
39
40 1 Result<size_t> Callstack::trace(Address* ptr_addresses, size_t addresses_max) noexcept
41 {
42 1 size_t addresses_used = 0;
43 1 result_t result = gate_callstack_trace(ptr_addresses, addresses_max, &addresses_used);
44 1 return makeResult(result, addresses_used);
45 }
46
47 1 Result<size_t> Callstack::print(Address addr, char* buffer, size_t buffer_capacity) noexcept
48 {
49 1 size_t buffer_used = 0;
50 1 result_t result = gate_callstack_print(addr, buffer, buffer_capacity, &buffer_used);
51 1 return makeResult(result, buffer_used);
52 }
53
54 1 VoidResult Callstack::print(Address addr, StringBuilder& builder) noexcept
55 {
56 char buffer[1024];
57 2 Result<size_t> result = Callstack::print(addr, buffer, sizeof(buffer) - 1);
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (result.hasError())
59 {
60 return makeErr(result.error());
61 }
62 1 size_t const buffer_used = result.value();
63 1 buffer[buffer_used] = 0;
64 1 builder.append(buffer, buffer_used);
65 1 return makeResult(results::Ok);
66 }
67
68
69
70 1 VoidResult Callstack::fork(Anchor& state,
71 gate_entrypoint_t entry, void* entry_param,
72 gate_entrypoint_t branch, void* branch_param) noexcept
73 {
74 1 result_t result = gate_callstack_fork(&state, entry, entry_param, branch, branch_param);
75 1 return makeResult(result);
76 }
77
78 1 VoidResult Callstack::fork(Anchor& state, IRunnable& code, IRunnable& branch) noexcept
79 {
80 1 return Callstack::fork(state, &callstack_run_runnable, &code, &callstack_run_runnable, &branch);
81 }
82
83 1 void Callstack::jumpToBranch(Anchor& state) noexcept
84 {
85 1 gate_callstack_jump(&state);
86 }
87
88
89
90 1 Callstack::Callstack(size_t initstacksize)
91 1 : stacksize(initstacksize), stackptr(NULL)
92 {
93 1 result_t result = gate_callstack_create(&this->stacksize, &this->stackptr);
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
95 1 }
96
97 2 Callstack::~Callstack() noexcept
98 {
99 1 gate_callstack_destroy(this->stackptr, this->stacksize);
100 1 }
101
102 1 Result<result_t> Callstack::run(Context& caller_ctx_to_save, gate_entrypoint_t entry_func, void* param) noexcept
103 {
104 1 result_t entry_result = results::Ok;
105 1 result_t result = gate_callstack_run(this->stackptr, this->stacksize, &caller_ctx_to_save, entry_func, param, &entry_result);
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (GATE_FAILED(result))
107 {
108 return makeErr(result);
109 }
110 else
111 {
112 1 return makeOk(entry_result);
113 }
114 }
115
116 1 Result<result_t> Callstack::run(Context& caller_ctx_to_save, IRunnable& runnable) noexcept
117 {
118 1 return this->run(caller_ctx_to_save, &callstack_run_runnable, &runnable);
119 }
120
121 1 VoidResult Callstack::switchTo(Context& current_to_save, Context& next_to_load) noexcept
122 {
123 1 result_t result = gate_callstack_switch(&current_to_save, &next_to_load);
124 return makeResult(result);
125 }
126
127 void* Callstack::getStack() const noexcept
128 {
129 return this->stackptr;
130 }
131
132 size_t Callstack::getSize() const noexcept
133 {
134 return this->stacksize;
135 }
136
137 }
138