Software APIs
sw
device
lib
crypto
include
freestanding
absl_status.h
1
// Copyright lowRISC contributors (OpenTitan project).
2
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3
// SPDX-License-Identifier: Apache-2.0
4
5
#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_FREESTANDING_ABSL_STATUS_H_
6
#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_FREESTANDING_ABSL_STATUS_H_
7
8
// Note: the status definitions were taken directly from the abseil-cpp
9
// library, and in particular from the file:
10
// https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h
11
// The copyright is preserved below:
12
// -----------------------------------------------------------------------------
13
// Copyright 2019 The Abseil Authors.
14
//
15
// Licensed under the Apache License, Version 2.0 (the "License");
16
// you may not use this file except in compliance with the License.
17
// You may obtain a copy of the License at
18
//
19
// https://www.apache.org/licenses/LICENSE-2.0
20
//
21
// Unless required by applicable law or agreed to in writing, software
22
// distributed under the License is distributed on an "AS IS" BASIS,
23
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
// See the License for the specific language governing permissions and
25
// limitations under the License.
26
// -----------------------------------------------------------------------------
27
28
#ifdef __cplusplus
29
extern
"C"
{
30
#endif
31
32
/**
33
* This enum was taken directly from the abseil-cpp library:
34
* https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h
35
*
36
* These error codes serve as general error classifications which are used to
37
* build up more specific error codes.
38
*
39
* DO NOT USE THESE CODES DIRECTLY. Use these codes to build per-module error
40
* codes in error.h. Although these error codes are generally used at
41
* Google by RPC servers, the advice about how to use them and how to
42
* categorize errors is generally sound.
43
*/
44
typedef
enum
absl_status_code {
45
// StatusCode::kOk
46
//
47
// kOK (gRPC code "OK") does not indicate an error; this value is returned on
48
// success. It is typical to check for this value before proceeding on any
49
// given call across an API or RPC boundary. To check this value, use the
50
// `absl::Status::ok()` member function rather than inspecting the raw code.
51
kOk = 0,
52
53
// StatusCode::kCancelled
54
//
55
// kCancelled (gRPC code "CANCELLED") indicates the operation was cancelled,
56
// typically by the caller.
57
kCancelled = 1,
58
59
// StatusCode::kUnknown
60
//
61
// kUnknown (gRPC code "UNKNOWN") indicates an unknown error occurred. In
62
// general, more specific errors should be raised, if possible. Errors raised
63
// by APIs that do not return enough error information may be converted to
64
// this error.
65
kUnknown = 2,
66
67
// StatusCode::kInvalidArgument
68
//
69
// kInvalidArgument (gRPC code "INVALID_ARGUMENT") indicates the caller
70
// specified an invalid argument, such a malformed filename. Note that such
71
// errors should be narrowly limited to indicate to the invalid nature of the
72
// arguments themselves. Errors with validly formed arguments that may cause
73
// errors with the state of the receiving system should be denoted with
74
// `kFailedPrecondition` instead.
75
kInvalidArgument = 3,
76
77
// StatusCode::kDeadlineExceeded
78
//
79
// kDeadlineExceeded (gRPC code "DEADLINE_EXCEEDED") indicates a deadline
80
// expired before the operation could complete. For operations that may change
81
// state within a system, this error may be returned even if the operation has
82
// completed successfully. For example, a successful response from a server
83
// could have been delayed long enough for the deadline to expire.
84
kDeadlineExceeded = 4,
85
86
// StatusCode::kNotFound
87
//
88
// kNotFound (gRPC code "NOT_FOUND") indicates some requested entity (such as
89
// a file or directory) was not found.
90
//
91
// `kNotFound` is useful if a request should be denied for an entire class of
92
// users, such as during a gradual feature rollout or undocumented allow list.
93
// If, instead, a request should be denied for specific sets of users, such as
94
// through user-based access control, use `kPermissionDenied` instead.
95
kNotFound = 5,
96
97
// StatusCode::kAlreadyExists
98
//
99
// kAlreadyExists (gRPC code "ALREADY_EXISTS") indicates the entity that a
100
// caller attempted to create (such as file or directory) is already present.
101
kAlreadyExists = 6,
102
103
// StatusCode::kPermissionDenied
104
//
105
// kPermissionDenied (gRPC code "PERMISSION_DENIED") indicates that the caller
106
// does not have permission to execute the specified operation. Note that this
107
// error is different than an error due to an *un*authenticated user. This
108
// error code does not imply the request is valid or the requested entity
109
// exists or satisfies any other pre-conditions.
110
//
111
// `kPermissionDenied` must not be used for rejections caused by exhausting
112
// some resource. Instead, use `kResourceExhausted` for those errors.
113
// `kPermissionDenied` must not be used if the caller cannot be identified.
114
// Instead, use `kUnauthenticated` for those errors.
115
kPermissionDenied = 7,
116
117
// StatusCode::kResourceExhausted
118
//
119
// kResourceExhausted (gRPC code "RESOURCE_EXHAUSTED") indicates some resource
120
// has been exhausted, perhaps a per-user quota, or perhaps the entire file
121
// system is out of space.
122
kResourceExhausted = 8,
123
124
// StatusCode::kFailedPrecondition
125
//
126
// kFailedPrecondition (gRPC code "FAILED_PRECONDITION") indicates that the
127
// operation was rejected because the system is not in a state required for
128
// the operation's execution. For example, a directory to be deleted may be
129
// non-empty, an "rmdir" operation is applied to a non-directory, etc.
130
//
131
// Some guidelines that may help a service implementer in deciding between
132
// `kFailedPrecondition`, `kAborted`, and `kUnavailable`:
133
//
134
// (a) Use `kUnavailable` if the client can retry just the failing call.
135
// (b) Use `kAborted` if the client should retry at a higher transaction
136
// level (such as when a client-specified test-and-set fails, indicating
137
// the client should restart a read-modify-write sequence).
138
// (c) Use `kFailedPrecondition` if the client should not retry until
139
// the system state has been explicitly fixed. For example, if an "rmdir"
140
// fails because the directory is non-empty, `kFailedPrecondition`
141
// should be returned since the client should not retry unless
142
// the files are deleted from the directory.
143
kFailedPrecondition = 9,
144
145
// StatusCode::kAborted
146
//
147
// kAborted (gRPC code "ABORTED") indicates the operation was aborted,
148
// typically due to a concurrency issue such as a sequencer check failure or a
149
// failed transaction.
150
//
151
// See the guidelines above for deciding between `kFailedPrecondition`,
152
// `kAborted`, and `kUnavailable`.
153
kAborted = 10,
154
155
// StatusCode::kOutOfRange
156
//
157
// kOutOfRange (gRPC code "OUT_OF_RANGE") indicates the operation was
158
// attempted past the valid range, such as seeking or reading past an
159
// end-of-file.
160
//
161
// Unlike `kInvalidArgument`, this error indicates a problem that may
162
// be fixed if the system state changes. For example, a 32-bit file
163
// system will generate `kInvalidArgument` if asked to read at an
164
// offset that is not in the range [0,2^32-1], but it will generate
165
// `kOutOfRange` if asked to read from an offset past the current
166
// file size.
167
//
168
// There is a fair bit of overlap between `kFailedPrecondition` and
169
// `kOutOfRange`. We recommend using `kOutOfRange` (the more specific
170
// error) when it applies so that callers who are iterating through
171
// a space can easily look for an `kOutOfRange` error to detect when
172
// they are done.
173
kOutOfRange = 11,
174
175
// StatusCode::kUnimplemented
176
//
177
// kUnimplemented (gRPC code "UNIMPLEMENTED") indicates the operation is not
178
// implemented or supported in this service. In this case, the operation
179
// should not be re-attempted.
180
kUnimplemented = 12,
181
182
// StatusCode::kInternal
183
//
184
// kInternal (gRPC code "INTERNAL") indicates an internal error has occurred
185
// and some invariants expected by the underlying system have not been
186
// satisfied. This error code is reserved for serious errors.
187
kInternal = 13,
188
189
// StatusCode::kUnavailable
190
//
191
// kUnavailable (gRPC code "UNAVAILABLE") indicates the service is currently
192
// unavailable and that this is most likely a transient condition. An error
193
// such as this can be corrected by retrying with a backoff scheme. Note that
194
// it is not always safe to retry non-idempotent operations.
195
//
196
// See the guidelines above for deciding between `kFailedPrecondition`,
197
// `kAborted`, and `kUnavailable`.
198
kUnavailable = 14,
199
200
// StatusCode::kDataLoss
201
//
202
// kDataLoss (gRPC code "DATA_LOSS") indicates that unrecoverable data loss or
203
// corruption has occurred. As this error is serious, proper alerting should
204
// be attached to errors such as this.
205
kDataLoss = 15,
206
207
// StatusCode::kUnauthenticated
208
//
209
// kUnauthenticated (gRPC code "UNAUTHENTICATED") indicates that the request
210
// does not have valid authentication credentials for the operation. Correct
211
// the authentication and try again.
212
kUnauthenticated = 16,
213
214
// StatusCode::DoNotUseReservedForFutureExpansionUseDefaultInSwitchInstead_
215
//
216
// NOTE: this error code entry should not be used and you should not rely on
217
// its value, which may change.
218
//
219
// The purpose of this enumerated value is to force people who handle status
220
// codes with `switch()` statements to *not* simply enumerate all possible
221
// values, but instead provide a "default:" case. Providing such a default
222
// case ensures that code will compile when new codes are added.
223
kDoNotUseReservedForFutureExpansionUseDefaultInSwitchInstead_ = 20
224
} absl_status_t;
225
226
#ifdef __cplusplus
227
}
228
#endif
229
230
#endif
// OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_FREESTANDING_ABSL_STATUS_H_
Return to
OpenTitan Documentation