mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
* update * 添加rt调度器的rust初步实现 * 完善rt调度逻辑 * 调试rt调度器 * 修改sched的返回值 * cargo fmt 格式化 * 删除无用代码,修补rt bug * 删除无用的代码,和重复的逻辑 * 软中断bugfix * 删除一些代码 * 添加kthread_run_rt文档 * 解决sphinix警告_static目录不存在的问题 Co-authored-by: longjin <longjin@RinGoTek.cn>
56 lines
1.8 KiB
Rust
56 lines
1.8 KiB
Rust
use super::gfp::__GFP_ZERO;
|
|
use crate::include::bindings::bindings::{gfp_t, kfree, kmalloc, PAGE_2M_SIZE};
|
|
|
|
use core::alloc::{GlobalAlloc, Layout};
|
|
|
|
/// 类kmalloc的分配器应当实现的trait
|
|
pub trait LocalAlloc {
|
|
unsafe fn local_alloc(&self, layout: Layout, gfp: gfp_t) -> *mut u8;
|
|
unsafe fn local_alloc_zeroed(&self, layout: Layout, gfp: gfp_t) -> *mut u8;
|
|
unsafe fn local_dealloc(&self, ptr: *mut u8, layout: Layout);
|
|
}
|
|
|
|
pub struct KernelAllocator {}
|
|
|
|
/// 为内核SLAB分配器实现LocalAlloc的trait
|
|
impl LocalAlloc for KernelAllocator {
|
|
unsafe fn local_alloc(&self, layout: Layout, gfp: gfp_t) -> *mut u8 {
|
|
if layout.size() > (PAGE_2M_SIZE as usize / 2) {
|
|
return core::ptr::null_mut();
|
|
}
|
|
return kmalloc(layout.size() as u64, gfp) as *mut u8;
|
|
}
|
|
|
|
unsafe fn local_alloc_zeroed(&self, layout: Layout, gfp: gfp_t) -> *mut u8 {
|
|
if layout.size() > (PAGE_2M_SIZE as usize / 2) {
|
|
return core::ptr::null_mut();
|
|
}
|
|
return kmalloc(layout.size() as u64, gfp | __GFP_ZERO) as *mut u8;
|
|
}
|
|
#[allow(unused_variables)]
|
|
unsafe fn local_dealloc(&self, ptr: *mut u8, layout: Layout) {
|
|
kfree(ptr as *mut ::core::ffi::c_void);
|
|
}
|
|
}
|
|
|
|
/// 为内核slab分配器实现GlobalAlloc特性
|
|
unsafe impl GlobalAlloc for KernelAllocator {
|
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
self.local_alloc(layout, 0)
|
|
}
|
|
|
|
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
|
self.local_alloc_zeroed(layout, 0)
|
|
}
|
|
|
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
|
self.local_dealloc(ptr, layout);
|
|
}
|
|
}
|
|
|
|
/// 内存分配错误处理函数
|
|
#[alloc_error_handler]
|
|
pub fn global_alloc_err_handler(_layout: Layout) -> ! {
|
|
panic!("global_alloc_error");
|
|
}
|