curiOS/kernel/src/lib.rs

49 lines
1.2 KiB
Rust

#![no_std]
#![feature(const_trait_impl, const_default)]
pub mod limine;
pub mod serial;
pub mod sync;
pub mod x86_64;
/// # 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);
}
}
}
#[macro_export]
macro_rules! drop_guard {
($($stmts:stmt)*) => {
{
struct __DropGuard<F: FnOnce()>(::core::mem::ManuallyDrop<F>);
impl<F: FnOnce()> __DropGuard<F> {
#[allow(dead_code)]
fn forget(self) {
let mut this = ::core::mem::ManuallyDrop::new(self);
unsafe {
ManuallyDrop::drop(&mut this.0);
}
}
}
impl<F: FnOnce()> Drop for __DropGuard<F> {
fn drop(&mut self) {
unsafe { ::core::ptr::read(&*self.0)() }
}
}
__DropGuard(::core::mem::ManuallyDrop::new(|| {
$($stmts)*
}))
}
};
}