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