Skip to content

riscv: Consider strategy for exception safe code #212

Closed
@rmsyn

Description

@rmsyn

From the Rustinomicon section on exception safety:

In unsafe code, we must be exception safe to the point of not violating memory safety. 

We'll call this minimal exception safety.

There are a number of locations in the code that use explicit panics (e.g. unimplemented!, assert.*! macros). Sometime, these panicing calls are made within safe functions, which users may call inside an unsafe context.

riscv should convert all explicit and implicit panicing code into fallible code that returns an Option or Result.

For example, Mcounteren::hpm could be changed from:

    /// Supervisor "hpm\[x\]" Enable (bits 3-31)
    #[inline]
    pub fn hpm(&self, index: usize) -> bool {
        assert!((3..32).contains(&index));
        self.bits & (1 << index) != 0
    }

To the fallible:

    /// Supervisor "hpm\[x\]" Enable (bits 3-31)
    #[inline]
    pub fn hpm(&self, index: usize) -> Option<bool> {
        if (3..32).contains(&index) {
            Some(self.bits & (1 << index) != 0)
        } else {
            None
        }
    }

Any strategy will almost definitely require breaking changes, and a version bump.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions