新的内存管理模块 (#301)

  实现了具有优秀架构设计的新的内存管理模块,对内核空间和用户空间的内存映射、分配、释放、管理等操作进行了封装,使得内核开发者可以更加方便地进行内存管理。

  内存管理模块主要由以下类型的组件组成:

- **硬件抽象层(MemoryManagementArch)** - 提供对具体处理器架构的抽象,使得内存管理模块可以在不同的处理器架构上运行
- **页面映射器(PageMapper)**- 提供对虚拟地址和物理地址的映射,以及页表的创建、填写、销毁、权限管理等操作。分为两种类型:内核页表映射器(KernelMapper)和用户页表映射器(位于具体的用户地址空间结构中)
- **页面刷新器(PageFlusher)** - 提供对页表的刷新操作(整表刷新、单页刷新、跨核心刷新)
- **页帧分配器(FrameAllocator)** - 提供对页帧的分配、释放、管理等操作。具体来说,包括BumpAllocator、BuddyAllocator
- **小对象分配器** - 提供对小内存对象的分配、释放、管理等操作。指的是内核里面的SlabAllocator (SlabAllocator的实现目前还没有完成)
- **MMIO空间管理器** - 提供对MMIO地址空间的分配、管理操作。(目前这个模块待进一步重构)
- **用户地址空间管理机制** - 提供对用户地址空间的管理。
    - VMA机制 - 提供对用户地址空间的管理,包括VMA的创建、销毁、权限管理等操作
    - 用户映射管理 - 与VMA机制共同作用,管理用户地址空间的映射
- **系统调用层** - 提供对用户空间的内存管理系统调用,包括mmap、munmap、mprotect、mremap等
- **C接口兼容层** - 提供对原有的C代码的接口,是的C代码能够正常运行。


除上面的新增内容以外,其它的更改内容:
- 新增二进制加载器,以及elf的解析器
- 解决由于local_irq_save、local_irq_restore函数的汇编不规范导致影响栈行为的bug。
- 解决local_irq_save未关中断的错误。
- 修复sys_gettimeofday对timezone参数的处理的bug
This commit is contained in:
LoGin
2023-07-22 16:22:17 +08:00
committed by GitHub
parent 0663027b11
commit d8ad0a5e77
124 changed files with 8277 additions and 5150 deletions

View File

@ -625,7 +625,7 @@ pub fn clocksource_resume() {
match ele.resume() {
Ok(_) => continue,
Err(_) => {
kdebug!("clocksource {:?} resume failed", data.name)
kdebug!("clocksource {:?} resume failed", data.name);
}
}
}
@ -641,7 +641,7 @@ pub fn clocksource_suspend() {
match ele.suspend() {
Ok(_) => continue,
Err(_) => {
kdebug!("clocksource {:?} suspend failed", data.name)
kdebug!("clocksource {:?} suspend failed", data.name);
}
}
}

View File

@ -3,7 +3,7 @@ use alloc::{
sync::{Arc, Weak},
};
use crate::{kdebug, libs::spinlock::SpinLock, syscall::SystemError};
use crate::{kerror, kinfo, libs::spinlock::SpinLock, syscall::SystemError};
use super::{
clocksource::{Clocksource, ClocksourceData, ClocksourceFlags, ClocksourceMask, CycleNum, HZ},
@ -89,9 +89,13 @@ pub fn jiffies_init() {
//注册jiffies
let jiffies = clocksource_default_clock() as Arc<dyn Clocksource>;
match jiffies.register() {
Ok(_) => kdebug!("jiffies_init sccessfully"),
Err(_) => kdebug!("jiffies_init failed, no default clock running"),
}
Ok(_) => {
kinfo!("jiffies_init sccessfully");
}
Err(_) => {
kerror!("jiffies_init failed, no default clock running");
}
};
}
#[no_mangle]

View File

@ -4,7 +4,6 @@ use core::{
};
use crate::{
kdebug,
syscall::{Syscall, SystemError},
time::{sleep::nanosleep, TimeSpec},
};
@ -79,10 +78,10 @@ impl Syscall {
pub fn gettimeofday(
tv: *mut PosixTimeval,
_timezone: &PosixTimeZone,
timezone: *mut PosixTimeZone,
) -> Result<usize, SystemError> {
// TODO; 处理时区信息
kdebug!("enter sys_do_gettimeofday");
// kdebug!("enter sys_do_gettimeofday");
if tv == null_mut() {
return Err(SystemError::EFAULT);
}
@ -91,7 +90,13 @@ impl Syscall {
(*tv).tv_sec = posix_time.tv_sec;
(*tv).tv_usec = posix_time.tv_usec;
}
kdebug!("exit sys_do_gettimeofday");
if !timezone.is_null() {
unsafe {
*timezone = SYS_TIMEZONE;
}
}
// kdebug!("exit sys_do_gettimeofday");
return Ok(0);
}
}

View File

@ -5,7 +5,7 @@ use x86_64::align_up;
use crate::{
arch::CurrentIrqArch,
exception::InterruptArch,
kdebug,
kdebug, kinfo,
libs::rwlock::RwLock,
time::{jiffies::clocksource_default_clock, timekeep::ktime_get_real_ns, TimeSpec},
};
@ -118,6 +118,7 @@ impl Timekeeper {
timekeeper.cycle_interval = CycleNum(temp);
timekeeper.xtime_interval = temp * clock_data.mult as u64;
// 这里可能存在下界溢出问题debug模式下会报错panic
timekeeper.xtime_remainder = (ntpinterval - timekeeper.xtime_interval) as i64;
timekeeper.raw_interval = (timekeeper.xtime_interval >> clock_data.shift) as i64;
timekeeper.xtime_nsec = 0;
@ -154,7 +155,7 @@ pub fn timekeeper_init() {
///
/// * 'TimeSpec' - 时间戳
pub fn getnstimeofday() -> TimeSpec {
kdebug!("enter getnstimeofday");
// kdebug!("enter getnstimeofday");
// let mut nsecs: u64 = 0;0
let mut _xtime = TimeSpec {
@ -201,6 +202,7 @@ pub fn do_gettimeofday() -> PosixTimeval {
/// # 初始化timekeeping模块
pub fn timekeeping_init() {
kinfo!("Initializing timekeeping module...");
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
timekeeper_init();
@ -229,7 +231,7 @@ pub fn timekeeping_init() {
__ADDED_SEC.store(0, Ordering::SeqCst);
drop(irq_guard);
kdebug!("timekeeping_init successfully");
kinfo!("timekeeping_init successfully");
}
/// # 使用当前时钟源增加wall time

View File

@ -12,4 +12,5 @@ extern int64_t rs_timer_get_first_expire();
extern uint64_t rs_timer_next_n_ms_jiffies(uint64_t expire_ms);
extern int64_t rs_schedule_timeout(int64_t timeout);
extern uint64_t rs_clock();
extern uint64_t rs_clock();
extern void rs_jiffies_init();

View File

@ -17,7 +17,7 @@ use crate::{
InterruptArch,
},
include::bindings::bindings::{process_control_block, process_wakeup, PROC_RUNNING},
kdebug, kerror,
kdebug, kerror, kinfo,
libs::spinlock::SpinLock,
syscall::SystemError,
};
@ -105,7 +105,6 @@ impl Timer {
break;
}
}
let mut temp_list: LinkedList<Arc<Timer>> = timer_list.split_off(split_pos);
timer_list.push_back(inner_guard.self_ref.upgrade().unwrap());
timer_list.append(&mut temp_list);
@ -216,7 +215,7 @@ pub fn timer_init() {
softirq_vectors()
.register_softirq(SoftirqNumber::TIMER, do_timer_softirq)
.expect("Failed to register timer softirq");
kdebug!("timer initiated successfully");
kinfo!("timer initialized successfully");
}
/// 计算接下来n毫秒对应的定时器时间片