重构内存分配器、增加中断支持、整理rust运行时环境 #4

Merged
pointer-to-bios merged 39 commits from downstream into main 2024-04-11 00:36:14 +08:00
2 changed files with 25 additions and 14 deletions
Showing only changes of commit 2aaa592636 - Show all commits

View File

@ -79,6 +79,10 @@ typedef void (*memm_free_t)(void *allocator, void *mem);
*
* ****使
*
* @internal magic
*
* `MEMM_ALLOCATOR_MAGIC_NUM`
*
* @internal full
*
* `allocate``nullptr``true`
@ -88,6 +92,10 @@ typedef void (*memm_free_t)(void *allocator, void *mem);
*
* 0
*
* @internal userspace
*
*
*
* @internal type
*
* `include/kernel/memm/allocator`
@ -107,17 +115,21 @@ typedef void (*memm_free_t)(void *allocator, void *mem);
*/
typedef struct __allocator_t
{
#define MEMM_ALLOCATOR_MAGIC_NUM 0x271fe441
#ifndef MEMM_ALLOCATOR_MAGIC
#define MEMM_ALLOCATOR_MAGIC 0x271fe441
#endif
// 分配器有效性由此检验,不为`MEMM_ALLOCATOR_MAGIC_NUM`说明获得了一个错误的分配器地址。
// 此值在编译时通过各种方式确定,若
u32 magic;
bool initialized;
// 调用分配器的`allocate`方法后,在返回`nullptr`时会设为`true`。
// 调用分配器的`free`方法时设为`false`。
bool full;
// 进程标志服表示此分配器所属的进程为0代表属于内核。
usize pid;
// 若分配器不属于内核,此成员储存此分配器的用户空间地址。
void *userspace;
// 分配器类型。在目录`include/kernel/memm/allocator`中对每个分配器分别定义一个唯一值。
usize type;
usize size;

View File

@ -77,8 +77,7 @@ memory_manager_t *memm_get_manager()
allocator_t *memm_allocator_new(void *start, usize length, usize type, usize pid)
{
allocator_t *allocator = start;
allocator->magic = MEMM_ALLOCATOR_MAGIC_NUM;
allocator->initialized = true;
allocator->magic = MEMM_ALLOCATOR_MAGIC;
allocator->full = false;
allocator->pid = 0;
allocator->size = length;
@ -91,14 +90,14 @@ allocator_t *memm_allocator_new(void *start, usize length, usize type, usize pid
allocator->free = (memm_free_t)raw_allocator_free;
break;
default:
allocator->initialized = false;
allocator->magic = 0;
break;
}
}
void memm_allocator_destruct(allocator_t *allocator)
{
allocator->initialized = false;
allocator->magic = 0;
// TODO 从分配器树中删除这个分配器
KERNEL_TODO();
}
@ -226,7 +225,7 @@ void *memm_user_allocate(usize size, usize pid)
void memm_free(void *mem)
{
allocator_t *allocator = memm_addr_get_allocator(mem);
if (allocator->magic != MEMM_ALLOCATOR_MAGIC_NUM)
if (allocator->magic != MEMM_ALLOCATOR_MAGIC)
return;
if (is_user_address((u64)mem))
{ // TODO 对于用户空间的地址需要先转换到内核地址后释放