增加内核日志功能 #3

Merged
pointer-to-bios merged 17 commits from pointer-to-bios/metaverse-dev:main into main 2024-02-05 22:10:26 +08:00
4 changed files with 22 additions and 10 deletions
Showing only changes of commit 831c7a689f - Show all commits

View File

@ -143,6 +143,10 @@ void *memm_allocate(usize size, usize pid);
#define memm_addr_get_allocator(mem) \ #define memm_addr_get_allocator(mem) \
((*(allocator_t **)(mem - 16))) ((*(allocator_t **)(mem - 16)))
void *memm_kernel_allocate(usize size);
void *memm_user_allocate(usize size, usize pid);
/* /*
*/ */

View File

@ -192,7 +192,7 @@ void *memm_allocate(usize size, usize pid)
MEMM_RAW_ALLOCATOR, pid); MEMM_RAW_ALLOCATOR, pid);
allocator = new_allocator; allocator = new_allocator;
allocator_iterator_t *allind = memm_allocate(sizeof(allocator_iterator_t), 0); allocator_iterator_t *allind = memm_kernel_allocate(sizeof(allocator_iterator_t));
allind->allocator = new_allocator; allind->allocator = new_allocator;
allind->left = nullptr; allind->left = nullptr;
allind->right = nullptr; allind->right = nullptr;
@ -201,14 +201,21 @@ void *memm_allocate(usize size, usize pid)
after_allocation: after_allocation:
memm_addr_set_allocator(ptr, allocator); memm_addr_set_allocator(ptr, allocator);
if (pid != 0)
{ // TODO 进程管理中应该有一个用户地址-内核地址映射表
// 在进程分配时将页映射到用户空间中,并将这个映射关系记录进这个表中
// 需要返回的是用户空间的地址
}
return ptr; return ptr;
} }
void *memm_kernel_allocate(usize size)
{
return memm_allocate(size, 0);
}
void *memm_user_allocate(usize size, usize pid)
{
void *res = memm_allocate(size, pid);
// TODO 将内存空间映射到用户空间
return res;
}
void memm_free(void *mem) void memm_free(void *mem)
{ {
allocator_t *allocator = memm_addr_get_allocator(mem); allocator_t *allocator = memm_addr_get_allocator(mem);

View File

@ -3,7 +3,8 @@ extern crate core;
use core::alloc::{GlobalAlloc, Layout}; use core::alloc::{GlobalAlloc, Layout};
extern "C" { extern "C" {
pub fn memm_allocate(size: usize, pid: usize) -> *mut u8; pub fn memm_kernel_allocate(size: usize) -> *mut u8;
pub fn memm_user_allocate(size: usize, pid: usize);
pub fn memm_free(mem: *mut u8); pub fn memm_free(mem: *mut u8);
} }
@ -11,7 +12,7 @@ pub struct KernelAllocator {}
unsafe impl GlobalAlloc for KernelAllocator { unsafe impl GlobalAlloc for KernelAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
memm_allocate(layout.size(), 0) memm_kernel_allocate(layout.size())
} }
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {

View File

@ -7,7 +7,7 @@
lst_iterator_t *lst_new(usize start, usize end) lst_iterator_t *lst_new(usize start, usize end)
{ {
lst_iterator_t *lst = memm_allocate(sizeof(lst_iterator_t), 0); lst_iterator_t *lst = memm_kernel_allocate(sizeof(lst_iterator_t), 0);
lst->line.left = start; lst->line.left = start;
lst->line.right = end; lst->line.right = end;
lst->next = nullptr; lst->next = nullptr;
@ -128,7 +128,7 @@ bool lst_add(lst_iterator_t *lst, usize left, usize right, bool force)
lst->line.left = left; lst->line.left = left;
else else
{ {
lst_iterator_t *new_node = memm_allocate(sizeof(lst_iterator_t), 0); lst_iterator_t *new_node = memm_kernel_allocate(sizeof(lst_iterator_t));
new_node->line = line; new_node->line = line;
new_node->next = lst; new_node->next = lst;
if (last != nullptr) if (last != nullptr)