Skip to main content

LockError

Enum LockError 

Source
#[non_exhaustive]
pub enum LockError { Map { bytes: usize, source: Error, }, Guard { source: Error, }, Refused { bytes: usize, limit: Option<u64>, source: Error, }, Dump { source: Error, }, Unavailable, Forked, Untracked { source: Error, }, Alignment { align: usize, page: usize, }, }
Expand description

Why a Locked value could not be created, or why its memory is not locked.

Refused, Dump, Untracked, Unavailable and Forked describe a degraded value that exists: under LockPolicy::BestEffort the first four are reported by Locked::lock_error from construction on, and Forked from the moment a forked child looks. Locked::require_locked turns any of them into an error and drops the value. The other variants mean no value was created.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Map

The operating system would not map the region at all.

Fields

§bytes: usize

The size of the mapping requested, guard pages included.

§source: Error

The OS error.

§

Guard

The region was mapped but a guard page could not be protected.

Fields

§source: Error

The OS error.

§

Refused

mlock refused the interior, almost always because it would exceed RLIMIT_MEMLOCK (64 KiB by default on many Linux hosts). Every value costs at least one page of that limit whatever its size, so the default holds sixteen 4 KiB-page values, or a single one where pages are 64 KiB. Raise the limit with ulimit -l, LimitMEMLOCK= in a systemd unit, or the container runtime’s ulimit setting.

Fields

§bytes: usize

The bytes that would have been locked.

§limit: Option<u64>

The soft RLIMIT_MEMLOCK at the time, when it is finite and readable.

§source: Error

The OS error.

§

Dump

The region is locked but could not be excluded from core dumps (madvise(MADV_DONTDUMP) on Linux or Android was refused, which a seccomp filter can do). The bytes would appear in a core dump.

Fields

§source: Error

The OS error.

§

Unavailable

This platform or build has no memory locking: non-Unix targets, Miri (which maps the region but cannot lock it) and Kani. The value is wiped on drop as usual.

§

Forked

The value was created in another process. Memory locks are not inherited across fork, so in the child the region is unlocked until Locked::relock is called there.

§

Untracked

This process cannot tell its values when they cross a fork: the atfork handler that counts forks could not be registered (only want of memory makes pthread_atfork fail). A forked child would then inherit a lock it does not have with nothing to say so, so the value is treated as unlocked here.

Fields

§source: Error

The OS error.

§

Alignment

T needs an alignment larger than a page, which the region cannot provide.

Fields

§align: usize

T’s alignment.

§page: usize

The page size, or 0 when the backend has no pages.

Trait Implementations§

Source§

impl Debug for LockError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LockError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for LockError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.