trapslab initialized

This commit is contained in:
2025-06-12 10:45:04 +08:00
parent 2a8fad821b
commit 028cf61d61
40 changed files with 366 additions and 3188 deletions

View File

@@ -23,46 +23,10 @@ struct {
struct run *freelist;
} kmem;
struct super_run {
struct super_run *next;
};
struct {
struct spinlock lock;
struct super_run *freelist;
} skmem;
void superfree(void *pa) {
struct super_run *r;
if(((uint64)pa % SUPERPGSIZE) != 0 || (char*)pa < end || (uint64)pa >= PHYSTOP)
panic("superfree");
// Fill with junk to catch dangling refs.
memset(pa, 1, SUPERPGSIZE);
r = (struct super_run *)pa;
acquire(&skmem.lock);
r->next = skmem.freelist;
skmem.freelist = r;
release(&skmem.lock);
}
void* superalloc() {
struct super_run *r;
acquire(&skmem.lock);
r = skmem.freelist;
if(r) skmem.freelist = r->next;
release(&skmem.lock);
if(r) memset((void*)r, 0, SUPERPGSIZE);
return (void*)r;
}
void
kinit()
{
initlock(&kmem.lock, "kmem");
initlock(&skmem.lock, "skmem");
freerange(end, (void*)PHYSTOP);
}
@@ -71,22 +35,9 @@ freerange(void *pa_start, void *pa_end)
{
char *p;
p = (char*)PGROUNDUP((uint64)pa_start);
for(; p + PGSIZE <= (char*)pa_end - 12 * 1024 * 1024; p += PGSIZE) //留5个巨页
for(; p + PGSIZE <= (char*)pa_end; p += PGSIZE)
kfree(p);
p = (char*)SUPERPGROUNDUP((uint64)p);
for (; p + SUPERPGSIZE <= (char *)pa_end; p += SUPERPGSIZE) {
superfree(p);
}
}
// void
// freerange(void *pa_start, void *pa_end)
// {
// char *p;
// p = (char*)PGROUNDUP((uint64)pa_start);
// for(; p + PGSIZE <= (char*)pa_end; p += PGSIZE)
// kfree(p);
// }
// Free the page of physical memory pointed at by pa,
// which normally should have been returned by a