curiOS/kernel/src/lib.rs

63 lines
1.4 KiB
Rust

#![no_std]
#![feature(
const_trait_impl,
const_default,
const_range,
debug_closure_helpers,
allocator_api,
ptr_cast_slice,
likely_unlikely,
never_type
)]
#![cfg_attr(test, feature(custom_test_frameworks))]
#![cfg_attr(test, test_runner(crate::tests::test_runner))]
#![cfg_attr(test, no_main)]
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
extern crate alloc;
pub mod bits;
pub mod limine;
pub mod serial;
pub mod sync;
pub mod x86_64;
pub mod boot;
pub mod memory;
pub mod testing;
#[cfg(test)]
mod tests;
/// # Safety
pub unsafe fn volatile_copy<T: Sized>(src: *const T, dst: *mut T, count: usize) {
unsafe {
for i in 0..count {
let src_ptr = src.add(i);
let dst_ptr = dst.add(i);
let val = src_ptr.read();
dst_ptr.write_volatile(val);
}
}
}
pub struct DropGuard<F: FnOnce()>(::core::mem::ManuallyDrop<F>);
impl<F: FnOnce()> DropGuard<F> {
pub fn new(f: F) -> Self {
DropGuard(::core::mem::ManuallyDrop::new(f))
}
#[allow(dead_code)]
pub fn forget(self) {
let mut this = ::core::mem::ManuallyDrop::new(self);
unsafe {
::core::mem::ManuallyDrop::drop(&mut this.0);
}
}
}
impl<F: FnOnce()> Drop for DropGuard<F> {
fn drop(&mut self) {
unsafe { ::core::ptr::read(&*self.0)() }
}
}