Next Generation WASM Microkernel Operating System
at trap_handler 36 lines 1.2 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use core::ptr::NonNull; 9 10pub mod atomic_cell; 11pub mod either; 12pub mod zip_eq; 13 14/// Helper to construct a `NonNull<T>` from a raw pointer to `T`, with null 15/// checks elided in release mode. 16#[cfg(debug_assertions)] 17#[track_caller] 18#[inline(always)] 19pub(crate) unsafe fn non_null<T>(ptr: *mut T) -> NonNull<T> { 20 NonNull::new(ptr).expect( 21 "/!\\ constructed a `NonNull` from a null pointer! /!\\ \n\ 22 in release mode, this would have called `NonNull::new_unchecked`, \ 23 violating the `NonNull` invariant!", 24 ) 25} 26 27/// Helper to construct a `NonNull<T>` from a raw pointer to `T`, with null 28/// checks elided in release mode. 29/// 30/// This is the release mode version. 31#[cfg(not(debug_assertions))] 32#[inline(always)] 33pub(crate) unsafe fn non_null<T>(ptr: *mut T) -> NonNull<T> { 34 // Safety: ensured by caller 35 unsafe { NonNull::new_unchecked(ptr) } 36}