Enum r3_core::kernel::ResultCode
source · #[repr(i8)]
#[non_exhaustive]
pub enum ResultCode {
Success,
NotSupported,
BadParam,
NoAccess,
BadContext,
NotOwner,
WouldDeadlock,
BadObjectState,
QueueOverflow,
Abandoned,
Interrupted,
Timeout,
}
Expand description
All result codes (including the one indicating success) that a kernel function can return.
Relation to Other Specifications: The error variants were loosely inspired from μITRON4.0 for no particular reasons.
Rationale: Giving them explicit and stable discriminants makes it possible to produce them directly in foreign code.
The discriminants are assigned in a way that maximizes the execution efficiency based on the following assumptions:
Some variants, such as
BadContext
andNoAccess
, are more likely to be handled byunwrap
-ing than other variants. Therefore, sorting theiru8
interpretations in the increasing order of the likelihood of being handled byunwrap
-ing increases the likelihood of the evaluation of anunwrap
condition being compiled down to a single integer comparison.The discriminants are tightly arranged so that the membership test with a compile-time result code set can be implemented by a bitfield look-up table on a general-purpose register.
Most of the error types including subsets of
ResultCode
includeBadContext
, hence by assigning-1
to it,Result<(), $ErrorType>::Ok
will get0
as its discriminant, which improves the execution efficiency because comparison to zero can be done efficiently on most instruction set architectures.
Stability
This type is covered by the application-side API stability guarantee. The explicit discriminants are only covered by the kernel-side API stability guarantee. Adding new variants or changing the representation size is not considered a breaking change.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Success
The operation was successful. No additional information is available.
NotSupported
The operation is not supported.
BadParam
A parameter is invalid in a way that is no covered by any other error codes.
NoAccess
The current operation was rejected by an optional protection
mechanism, e.g., because the specified object identifier (Id
) is
invalid, or the caller lacks the necessary privileges to complete
the operation.
This error usually indicates an object safety or memory safety violation. A kernel implementation is not required to report this as it’s not practical in general cases. It’s strongly recommended that application code not rely on this error code being returned and, should it be returned, escalate it to a panic or abort immediately unless the code is written for a specific kernel implementation that makes a special provision.
Rationale: In the original design, R3 was limited to a specific kernel implementation, and this kernel implementation always validated input object identifiers as it was trivial to do so. Now that R3 is being redesigned as a pure interface for unknown kernels, requiring this property might pose a considerable burden on kernel implementations. In addition, the provided object handle types enforces object safety, and creating them from raw object IDs is impossible in safe code. It’s for this reason that detecting this error is now optional.
One of the avenues being explored is to support RTOS kernels with a security-oriented protection mechanism. From a security point of view, it’s preferable not to disclose the state of other protection domains (e.g., if the object IDs were memory addresses, exposing them would undermine the security benefits of address space layout randomization), hence the intentional lack of error code distinction between invalid IDs and inaccessible IDs.
Since it’s most likely escalated to a panic or abort, it was also considered to remove this error code altogether. However, since error codes are not extensible, this would unnecessarily complicate the rare cases where it can be reasonably handled in other ways.
BadContext
The current context disallows the operation.
NotOwner
The caller does not own the resource.
WouldDeadlock
Resource deadlock would occur.
BadObjectState
A target object is in a state that disallows the operation.
QueueOverflow
An operation or an object couldn’t be enqueued because there are too many of such things that already have been enqueued.
Abandoned
The owner of a mutex exited while holding the mutex lock.
Interrupted
The wait operation was interrupted by Task::interrupt
.
Timeout
The operation timed out.
Implementations§
source§impl ResultCode
impl ResultCode
Trait Implementations§
source§impl Clone for ResultCode
impl Clone for ResultCode
source§fn clone(&self) -> ResultCode
fn clone(&self) -> ResultCode
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ResultCode
impl Debug for ResultCode
source§impl From<ActivateTaskError> for ResultCode
impl From<ActivateTaskError> for ResultCode
source§fn from(x: ActivateTaskError) -> Self
fn from(x: ActivateTaskError) -> Self
source§impl From<AdjustTimeError> for ResultCode
impl From<AdjustTimeError> for ResultCode
source§fn from(x: AdjustTimeError) -> Self
fn from(x: AdjustTimeError) -> Self
source§impl From<BoostPriorityError> for ResultCode
impl From<BoostPriorityError> for ResultCode
source§fn from(x: BoostPriorityError) -> Self
fn from(x: BoostPriorityError) -> Self
source§impl From<ClearInterruptLineError> for ResultCode
impl From<ClearInterruptLineError> for ResultCode
source§fn from(x: ClearInterruptLineError) -> Self
fn from(x: ClearInterruptLineError) -> Self
source§impl From<CpuLockError> for ResultCode
impl From<CpuLockError> for ResultCode
source§fn from(x: CpuLockError) -> Self
fn from(x: CpuLockError) -> Self
source§impl From<DrainSemaphoreError> for ResultCode
impl From<DrainSemaphoreError> for ResultCode
source§fn from(x: DrainSemaphoreError) -> Self
fn from(x: DrainSemaphoreError) -> Self
source§impl From<EnableInterruptLineError> for ResultCode
impl From<EnableInterruptLineError> for ResultCode
source§fn from(x: EnableInterruptLineError) -> Self
fn from(x: EnableInterruptLineError) -> Self
source§impl From<ExitTaskError> for ResultCode
impl From<ExitTaskError> for ResultCode
source§fn from(x: ExitTaskError) -> Self
fn from(x: ExitTaskError) -> Self
source§impl From<GetCurrentTaskError> for ResultCode
impl From<GetCurrentTaskError> for ResultCode
source§fn from(x: GetCurrentTaskError) -> Self
fn from(x: GetCurrentTaskError) -> Self
source§impl From<GetEventGroupError> for ResultCode
impl From<GetEventGroupError> for ResultCode
source§fn from(x: GetEventGroupError) -> Self
fn from(x: GetEventGroupError) -> Self
source§impl From<GetSemaphoreError> for ResultCode
impl From<GetSemaphoreError> for ResultCode
source§fn from(x: GetSemaphoreError) -> Self
fn from(x: GetSemaphoreError) -> Self
source§impl From<GetTaskPriorityError> for ResultCode
impl From<GetTaskPriorityError> for ResultCode
source§fn from(x: GetTaskPriorityError) -> Self
fn from(x: GetTaskPriorityError) -> Self
source§impl From<InterruptTaskError> for ResultCode
impl From<InterruptTaskError> for ResultCode
source§fn from(x: InterruptTaskError) -> Self
fn from(x: InterruptTaskError) -> Self
source§impl From<LockMutexError> for ResultCode
impl From<LockMutexError> for ResultCode
source§fn from(x: LockMutexError) -> Self
fn from(x: LockMutexError) -> Self
source§impl From<LockMutexTimeoutError> for ResultCode
impl From<LockMutexTimeoutError> for ResultCode
source§fn from(x: LockMutexTimeoutError) -> Self
fn from(x: LockMutexTimeoutError) -> Self
source§impl From<MarkConsistentMutexError> for ResultCode
impl From<MarkConsistentMutexError> for ResultCode
source§fn from(x: MarkConsistentMutexError) -> Self
fn from(x: MarkConsistentMutexError) -> Self
source§impl From<ParkError> for ResultCode
impl From<ParkError> for ResultCode
source§impl From<ParkTimeoutError> for ResultCode
impl From<ParkTimeoutError> for ResultCode
source§fn from(x: ParkTimeoutError) -> Self
fn from(x: ParkTimeoutError) -> Self
source§impl From<PendInterruptLineError> for ResultCode
impl From<PendInterruptLineError> for ResultCode
source§fn from(x: PendInterruptLineError) -> Self
fn from(x: PendInterruptLineError) -> Self
source§impl From<PollEventGroupError> for ResultCode
impl From<PollEventGroupError> for ResultCode
source§fn from(x: PollEventGroupError) -> Self
fn from(x: PollEventGroupError) -> Self
source§impl From<PollSemaphoreError> for ResultCode
impl From<PollSemaphoreError> for ResultCode
source§fn from(x: PollSemaphoreError) -> Self
fn from(x: PollSemaphoreError) -> Self
source§impl From<QueryInterruptLineError> for ResultCode
impl From<QueryInterruptLineError> for ResultCode
source§fn from(x: QueryInterruptLineError) -> Self
fn from(x: QueryInterruptLineError) -> Self
source§impl From<QueryMutexError> for ResultCode
impl From<QueryMutexError> for ResultCode
source§fn from(x: QueryMutexError) -> Self
fn from(x: QueryMutexError) -> Self
source§impl From<Result<(), ActivateTaskError>> for ResultCode
impl From<Result<(), ActivateTaskError>> for ResultCode
source§impl From<Result<(), AdjustTimeError>> for ResultCode
impl From<Result<(), AdjustTimeError>> for ResultCode
source§impl From<Result<(), BoostPriorityError>> for ResultCode
impl From<Result<(), BoostPriorityError>> for ResultCode
source§impl From<Result<(), ClearInterruptLineError>> for ResultCode
impl From<Result<(), ClearInterruptLineError>> for ResultCode
source§impl From<Result<(), CpuLockError>> for ResultCode
impl From<Result<(), CpuLockError>> for ResultCode
source§impl From<Result<(), DrainSemaphoreError>> for ResultCode
impl From<Result<(), DrainSemaphoreError>> for ResultCode
source§impl From<Result<(), EnableInterruptLineError>> for ResultCode
impl From<Result<(), EnableInterruptLineError>> for ResultCode
source§impl From<Result<(), ExitTaskError>> for ResultCode
impl From<Result<(), ExitTaskError>> for ResultCode
source§impl From<Result<(), GetCurrentTaskError>> for ResultCode
impl From<Result<(), GetCurrentTaskError>> for ResultCode
source§impl From<Result<(), GetEventGroupError>> for ResultCode
impl From<Result<(), GetEventGroupError>> for ResultCode
source§impl From<Result<(), GetSemaphoreError>> for ResultCode
impl From<Result<(), GetSemaphoreError>> for ResultCode
source§impl From<Result<(), GetTaskPriorityError>> for ResultCode
impl From<Result<(), GetTaskPriorityError>> for ResultCode
source§impl From<Result<(), InterruptTaskError>> for ResultCode
impl From<Result<(), InterruptTaskError>> for ResultCode
source§impl From<Result<(), LockMutexError>> for ResultCode
impl From<Result<(), LockMutexError>> for ResultCode
source§impl From<Result<(), LockMutexTimeoutError>> for ResultCode
impl From<Result<(), LockMutexTimeoutError>> for ResultCode
source§impl From<Result<(), MarkConsistentMutexError>> for ResultCode
impl From<Result<(), MarkConsistentMutexError>> for ResultCode
source§impl From<Result<(), ParkTimeoutError>> for ResultCode
impl From<Result<(), ParkTimeoutError>> for ResultCode
source§impl From<Result<(), PendInterruptLineError>> for ResultCode
impl From<Result<(), PendInterruptLineError>> for ResultCode
source§impl From<Result<(), PollEventGroupError>> for ResultCode
impl From<Result<(), PollEventGroupError>> for ResultCode
source§impl From<Result<(), PollSemaphoreError>> for ResultCode
impl From<Result<(), PollSemaphoreError>> for ResultCode
source§impl From<Result<(), QueryInterruptLineError>> for ResultCode
impl From<Result<(), QueryInterruptLineError>> for ResultCode
source§impl From<Result<(), QueryMutexError>> for ResultCode
impl From<Result<(), QueryMutexError>> for ResultCode
source§impl From<Result<(), SetInterruptLinePriorityError>> for ResultCode
impl From<Result<(), SetInterruptLinePriorityError>> for ResultCode
source§impl From<Result<(), SetTaskPriorityError>> for ResultCode
impl From<Result<(), SetTaskPriorityError>> for ResultCode
source§impl From<Result<(), SetTimerDelayError>> for ResultCode
impl From<Result<(), SetTimerDelayError>> for ResultCode
source§impl From<Result<(), SetTimerPeriodError>> for ResultCode
impl From<Result<(), SetTimerPeriodError>> for ResultCode
source§impl From<Result<(), SignalSemaphoreError>> for ResultCode
impl From<Result<(), SignalSemaphoreError>> for ResultCode
source§impl From<Result<(), SleepError>> for ResultCode
impl From<Result<(), SleepError>> for ResultCode
source§impl From<Result<(), StartTimerError>> for ResultCode
impl From<Result<(), StartTimerError>> for ResultCode
source§impl From<Result<(), StopTimerError>> for ResultCode
impl From<Result<(), StopTimerError>> for ResultCode
source§impl From<Result<(), TryLockMutexError>> for ResultCode
impl From<Result<(), TryLockMutexError>> for ResultCode
source§impl From<Result<(), UnlockMutexError>> for ResultCode
impl From<Result<(), UnlockMutexError>> for ResultCode
source§impl From<Result<(), UnparkError>> for ResultCode
impl From<Result<(), UnparkError>> for ResultCode
source§impl From<Result<(), UnparkExactError>> for ResultCode
impl From<Result<(), UnparkExactError>> for ResultCode
source§impl From<Result<(), UpdateEventGroupError>> for ResultCode
impl From<Result<(), UpdateEventGroupError>> for ResultCode
source§impl From<Result<(), WaitEventGroupError>> for ResultCode
impl From<Result<(), WaitEventGroupError>> for ResultCode
source§impl From<Result<(), WaitEventGroupTimeoutError>> for ResultCode
impl From<Result<(), WaitEventGroupTimeoutError>> for ResultCode
source§impl From<Result<(), WaitSemaphoreError>> for ResultCode
impl From<Result<(), WaitSemaphoreError>> for ResultCode
source§impl From<Result<(), WaitSemaphoreTimeoutError>> for ResultCode
impl From<Result<(), WaitSemaphoreTimeoutError>> for ResultCode
source§impl From<Result<(), WaitTimeoutError>> for ResultCode
impl From<Result<(), WaitTimeoutError>> for ResultCode
source§impl From<SetInterruptLinePriorityError> for ResultCode
impl From<SetInterruptLinePriorityError> for ResultCode
source§fn from(x: SetInterruptLinePriorityError) -> Self
fn from(x: SetInterruptLinePriorityError) -> Self
source§impl From<SetTaskPriorityError> for ResultCode
impl From<SetTaskPriorityError> for ResultCode
source§fn from(x: SetTaskPriorityError) -> Self
fn from(x: SetTaskPriorityError) -> Self
source§impl From<SetTimerDelayError> for ResultCode
impl From<SetTimerDelayError> for ResultCode
source§fn from(x: SetTimerDelayError) -> Self
fn from(x: SetTimerDelayError) -> Self
source§impl From<SetTimerPeriodError> for ResultCode
impl From<SetTimerPeriodError> for ResultCode
source§fn from(x: SetTimerPeriodError) -> Self
fn from(x: SetTimerPeriodError) -> Self
source§impl From<SignalSemaphoreError> for ResultCode
impl From<SignalSemaphoreError> for ResultCode
source§fn from(x: SignalSemaphoreError) -> Self
fn from(x: SignalSemaphoreError) -> Self
source§impl From<SleepError> for ResultCode
impl From<SleepError> for ResultCode
source§fn from(x: SleepError) -> Self
fn from(x: SleepError) -> Self
source§impl From<StartTimerError> for ResultCode
impl From<StartTimerError> for ResultCode
source§fn from(x: StartTimerError) -> Self
fn from(x: StartTimerError) -> Self
source§impl From<StopTimerError> for ResultCode
impl From<StopTimerError> for ResultCode
source§fn from(x: StopTimerError) -> Self
fn from(x: StopTimerError) -> Self
source§impl From<TimeError> for ResultCode
impl From<TimeError> for ResultCode
source§impl From<TryLockMutexError> for ResultCode
impl From<TryLockMutexError> for ResultCode
source§fn from(x: TryLockMutexError) -> Self
fn from(x: TryLockMutexError) -> Self
source§impl From<UnlockMutexError> for ResultCode
impl From<UnlockMutexError> for ResultCode
source§fn from(x: UnlockMutexError) -> Self
fn from(x: UnlockMutexError) -> Self
source§impl From<UnparkError> for ResultCode
impl From<UnparkError> for ResultCode
source§fn from(x: UnparkError) -> Self
fn from(x: UnparkError) -> Self
source§impl From<UnparkExactError> for ResultCode
impl From<UnparkExactError> for ResultCode
source§fn from(x: UnparkExactError) -> Self
fn from(x: UnparkExactError) -> Self
source§impl From<UpdateEventGroupError> for ResultCode
impl From<UpdateEventGroupError> for ResultCode
source§fn from(x: UpdateEventGroupError) -> Self
fn from(x: UpdateEventGroupError) -> Self
source§impl From<WaitError> for ResultCode
impl From<WaitError> for ResultCode
source§impl From<WaitEventGroupError> for ResultCode
impl From<WaitEventGroupError> for ResultCode
source§fn from(x: WaitEventGroupError) -> Self
fn from(x: WaitEventGroupError) -> Self
source§impl From<WaitEventGroupTimeoutError> for ResultCode
impl From<WaitEventGroupTimeoutError> for ResultCode
source§fn from(x: WaitEventGroupTimeoutError) -> Self
fn from(x: WaitEventGroupTimeoutError) -> Self
source§impl From<WaitSemaphoreError> for ResultCode
impl From<WaitSemaphoreError> for ResultCode
source§fn from(x: WaitSemaphoreError) -> Self
fn from(x: WaitSemaphoreError) -> Self
source§impl From<WaitSemaphoreTimeoutError> for ResultCode
impl From<WaitSemaphoreTimeoutError> for ResultCode
source§fn from(x: WaitSemaphoreTimeoutError) -> Self
fn from(x: WaitSemaphoreTimeoutError) -> Self
source§impl From<WaitTimeoutError> for ResultCode
impl From<WaitTimeoutError> for ResultCode
source§fn from(x: WaitTimeoutError) -> Self
fn from(x: WaitTimeoutError) -> Self
source§impl Hash for ResultCode
impl Hash for ResultCode
source§impl Ord for ResultCode
impl Ord for ResultCode
source§fn cmp(&self, other: &ResultCode) -> Ordering
fn cmp(&self, other: &ResultCode) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<ResultCode> for ResultCode
impl PartialEq<ResultCode> for ResultCode
source§fn eq(&self, other: &ResultCode) -> bool
fn eq(&self, other: &ResultCode) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<ResultCode> for ResultCode
impl PartialOrd<ResultCode> for ResultCode
source§fn partial_cmp(&self, other: &ResultCode) -> Option<Ordering>
fn partial_cmp(&self, other: &ResultCode) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more