Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
faults.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// helper defines/data structures for fault reporting/handling in Realm
19
20#ifndef REALM_FAULTS_H
21#define REALM_FAULTS_H
22
23#include "realm/bytearray.h"
24#include "realm/event.h"
25
26#include <vector>
27#include <iostream>
28
29#include <stdint.h>
30
31#ifdef REALM_ON_WINDOWS
32// winerror.h defines this, polluting all namespaces, so get it out of the way now
33#include <winerror.h>
34#undef ERROR_CANCELLED
35#endif
36
37namespace Realm {
38
39 class ProfilingMeasurementCollection;
40
41 namespace Faults {
42
43 // faults are reported with an integer error code - negative codes are internal to
44 // Realm, while positive ones are reserved for applications
45 enum
46 {
47 ERROR_POISONED_EVENT = -1000, // querying a poisoned event without handling poison
48 ERROR_POISONED_PRECONDITION, // precondition to an operation was poisoned
49 ERROR_CANCELLED, // cancelled by request from application
50
51 // application can use its own error codes too, but start
52 // here so we don't get any conflicts
54 };
55
56 }; // namespace Faults
57
59 public:
60 Backtrace(void);
62
63 Backtrace(const Backtrace &copy_from);
64 Backtrace &operator=(const Backtrace &copy_from);
65
66 bool operator==(const Backtrace &rhs) const;
67
68 uintptr_t hash(void) const;
69
70 bool empty(void) const;
71
72 size_t size(void) const;
73
74 std::vector<uintptr_t> get_pcs(void) const;
75
76 // operator[] for const access, it is not allowed to change the value of pcs
77 const uintptr_t &operator[](size_t index) const;
78
79 // attempts to prune this backtrace by removing frames that appear
80 // in the other one
81 bool prune(const Backtrace &other);
82
83 // captures the current back trace, skipping 'skip' frames, and optionally
84 // limiting the total depth - this isn't as simple as as stack walk any more,
85 // so you probably don't want to ask for these during any normal execution paths
86 void capture_backtrace(int skip = 0, int max_depth = 0);
87
88 // attempts to map the pointers in the back trace to symbol names and print them out
89 // this can be more expensive than capture and print the raw trace
90 void print_symbols(std::vector<std::string> &symbols) const;
91
92 void print_symbols(std::ostream &os) const;
93
94 // this only prints the pcs
96 friend std::ostream &operator<<(std::ostream &os, const Backtrace &bt);
97
98 protected:
99 uintptr_t compute_hash(int depth = 0) const;
100
101 uintptr_t pc_hash = 0; // used for fast comparisons
102 std::vector<uintptr_t> pcs;
103 };
104
105 // Realm execution exceptions
106
107 // an abstract intermediate class that captures all Realm-generated exceptions
108 class REALM_PUBLIC_API ExecutionException : public std::exception {
109 public:
110 ExecutionException(int _error_code, const void *_detail_data, size_t _detail_size,
111 bool capture_backtrace = true);
113
114 virtual const char *what(void) const REALM_NOEXCEPT = 0;
115
116 virtual void
118
122 ExecutionException &operator=(ExecutionException &&) noexcept = default;
123
124 int error_code;
125 ByteArray details;
126 Backtrace backtrace;
127 };
128
129 // the result of an explicit application request to cancel the task
131 public:
133
134 virtual const char *what(void) const REALM_NOEXCEPT;
135 };
136
137 // the result of testing a poisoned event
139 public:
141
142 virtual const char *what(void) const REALM_NOEXCEPT;
143
144 protected:
146 };
147
148 // generated by Processor::report_execution_fault()
150 public:
151 ApplicationException(int _error_code, const void *_detail_data, size_t _detail_size);
152
153 virtual const char *what(void) const REALM_NOEXCEPT;
154 };
155
156}; // namespace Realm
157
158#endif // REALM_FAULTS_H
Definition faults.h:149
virtual const char * what(void) const REALM_NOEXCEPT
ApplicationException(int _error_code, const void *_detail_data, size_t _detail_size)
Definition faults.h:58
Backtrace(const Backtrace &copy_from)
const uintptr_t & operator[](size_t index) const
std::vector< uintptr_t > get_pcs(void) const
REALM_PUBLIC_API friend std::ostream & operator<<(std::ostream &os, const Backtrace &bt)
void print_symbols(std::ostream &os) const
std::vector< uintptr_t > pcs
Definition faults.h:102
uintptr_t compute_hash(int depth=0) const
Backtrace & operator=(const Backtrace &copy_from)
size_t size(void) const
bool prune(const Backtrace &other)
bool operator==(const Backtrace &rhs) const
uintptr_t hash(void) const
void print_symbols(std::vector< std::string > &symbols) const
void capture_backtrace(int skip=0, int max_depth=0)
bool empty(void) const
Definition bytearray.h:53
Definition faults.h:130
virtual const char * what(void) const REALM_NOEXCEPT
Definition event.h:50
Definition faults.h:108
virtual ~ExecutionException(void) REALM_NOEXCEPT
ExecutionException(ExecutionException &&) noexcept=default
ExecutionException(const ExecutionException &)=default
virtual void populate_profiling_measurements(ProfilingMeasurementCollection &pmc) const
ExecutionException & operator=(const ExecutionException &)=default
ExecutionException(int _error_code, const void *_detail_data, size_t _detail_size, bool capture_backtrace=true)
virtual const char * what(void) const REALM_NOEXCEPT=0
Definition faults.h:138
PoisonedEventException(Event _event)
Event event
Definition faults.h:145
virtual const char * what(void) const REALM_NOEXCEPT
Definition profiling.h:393
#define REALM_PUBLIC_API
Definition compiler_support.h:217
#define REALM_NOEXCEPT
Definition compiler_support.h:65
@ ERROR_POISONED_PRECONDITION
Definition faults.h:48
@ ERROR_CANCELLED
Definition faults.h:49
@ ERROR_APPLICATION_DEFINED
Definition faults.h:53
@ ERROR_POISONED_EVENT
Definition faults.h:47
Definition activemsg.h:38