19 #ifndef ASYLO_PLATFORM_PRIMITIVES_PRIMITIVE_STATUS_H_ 20 #define ASYLO_PLATFORM_PRIMITIVES_PRIMITIVE_STATUS_H_ 27 #include <type_traits> 29 #include "absl/status/status.h" 30 #include "asylo/util/error_codes.h" 57 static_assert(
sizeof(
size_t) == 8,
"Unexpected size for type size_t");
121 : error_code_(code) {
122 message_size = std::min(message_size, kMessageMax - 1);
123 memcpy(message_, message, message_size);
124 message_[message_size] =
'\0';
138 error_code_ = other.error_code_;
139 size_t size = std::min(strlen(other.message_), kMessageMax - 1);
140 memcpy(message_, other.message_, size);
141 message_[size] =
'\0';
168 static void CheckLayout() {
169 static_assert(std::is_standard_layout<PrimitiveStatus>::value,
170 "PrimitiveStatus must satisfy std::is_standard_layout");
171 static_assert(offsetof(PrimitiveStatus, error_code_) == 0x0,
172 "Unexpected layout for field PrimitiveStatus::error_code_");
173 static_assert(offsetof(PrimitiveStatus, message_) ==
sizeof(uint32_t),
174 "Unexpected layout for field PrimitiveStatus::message_");
static constexpr size_t kMessageMax
Maximum error string length in characters.
Definition: primitive_status.h:92
const char * error_message() const
Getter for this object's error message.
Definition: primitive_status.h:157
PrimitiveStatus(int code, const char *message, size_t message_size)
Builds a status with an error code and a message of size message_size.
Definition: primitive_status.h:120
Definition: primitive_status.h:75
Definition: primitive_status.h:70
Definition: primitive_status.h:79
Definition: primitive_status.h:69
Definition: primitive_status.h:74
Shared representation of a status code across the enclave boundary.
Definition: primitive_status.h:89
AbslStatusCode
This enum of error codes aliases absl::StatusCode.
Definition: primitive_status.h:64
Definition: primitive_status.h:67
PrimitiveStatus & operator=(const PrimitiveStatus &other)
Definition: primitive_status.h:137
int error_code() const
Getter for this object's error code.
Definition: primitive_status.h:152
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
Definition: primitive_status.h:81
PrimitiveStatus(int code, const std::string &message)
Builds a status with an error code and a message in string format.
Definition: primitive_status.h:128
static PrimitiveStatus OkStatus()
PrimitiveStatus::OkStatus() is the canonical name for an OK status.
Definition: primitive_status.h:147
Definition: primitive_status.h:65
Definition: primitive_status.h:72
Definition: primitive_status.h:73
bool ok() const
Predicate for non-error status.
Definition: primitive_status.h:162
Definition: primitive_status.h:76
Definition: primitive_status.h:78
PrimitiveStatus(int code)
Builds a status with an error code and an empty message.
Definition: primitive_status.h:101
Definition: primitive_status.h:80
PrimitiveStatus(const PrimitiveStatus &other)
Copy constructor.
Definition: primitive_status.h:134
Definition: primitive_status.h:71
PrimitiveStatus(int code, const char *message)
Builds a status with an error code and error message.
Definition: primitive_status.h:109
PrimitiveStatus()
Builds an OK status.
Definition: primitive_status.h:95
Definition: primitive_status.h:77
Definition: primitive_status.h:66
Definition: primitive_status.h:68