mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 21:58:20 +00:00
mm: refactor pmm -> page
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <limine.h>
|
||||
#include <logging.h>
|
||||
#include <string.h>
|
||||
@@ -14,10 +14,10 @@ static size_t pagecount;
|
||||
size_t freepagecount;
|
||||
|
||||
static mutex_t freelistmutex;
|
||||
static page_t *freelists[PMM_SECTION_COUNT];
|
||||
static page_t *freetails[PMM_SECTION_COUNT];
|
||||
static page_t *standbylists[PMM_SECTION_COUNT];
|
||||
static page_t *standbytails[PMM_SECTION_COUNT];
|
||||
static page_t *freelists[MEMORY_SECTION_COUNT];
|
||||
static page_t *freetails[MEMORY_SECTION_COUNT];
|
||||
static page_t *standbylists[MEMORY_SECTION_COUNT];
|
||||
static page_t *standbytails[MEMORY_SECTION_COUNT];
|
||||
|
||||
typedef struct {
|
||||
uintmax_t baseid;
|
||||
@@ -28,7 +28,7 @@ typedef struct {
|
||||
#define TOP_1MB (0x100000 / PAGE_SIZE)
|
||||
#define TOP_4GB ((uint64_t)0x100000000 / PAGE_SIZE)
|
||||
|
||||
static section_t sections[PMM_SECTION_COUNT] = {
|
||||
static section_t sections[MEMORY_SECTION_COUNT] = {
|
||||
{0, TOP_1MB, 0},
|
||||
{TOP_1MB, TOP_4GB, TOP_1MB},
|
||||
{TOP_4GB, 0xffffffffffffffffl, TOP_4GB}
|
||||
@@ -39,7 +39,7 @@ static volatile struct limine_hhdm_request hhdmreq = {
|
||||
.revision = 0
|
||||
};
|
||||
|
||||
volatile struct limine_memmap_request pmm_liminemap = {
|
||||
volatile struct limine_memmap_request mm_page_limine_map = {
|
||||
.id = LIMINE_MEMMAP_REQUEST_ID,
|
||||
.revision = 0
|
||||
};
|
||||
@@ -59,11 +59,11 @@ static void insertinfreelist(page_t *page) {
|
||||
int section;
|
||||
|
||||
if (pageid < TOP_1MB)
|
||||
section = PMM_SECTION_1MB;
|
||||
section = MEMORY_SECTION_1MB;
|
||||
else if (pageid < TOP_4GB)
|
||||
section = PMM_SECTION_4GB;
|
||||
section = MEMORY_SECTION_4GB;
|
||||
else
|
||||
section = PMM_SECTION_DEFAULT;
|
||||
section = MEMORY_SECTION_DEFAULT;
|
||||
|
||||
list = page->backing ? &standbylists[section] : &freelists[section];
|
||||
tail = page->backing ? &standbytails[section] : &freetails[section];
|
||||
@@ -91,11 +91,11 @@ static void removefromfreelist(page_t *page) {
|
||||
int section;
|
||||
|
||||
if (pageid < TOP_1MB)
|
||||
section = PMM_SECTION_1MB;
|
||||
section = MEMORY_SECTION_1MB;
|
||||
else if (pageid < TOP_4GB)
|
||||
section = PMM_SECTION_4GB;
|
||||
section = MEMORY_SECTION_4GB;
|
||||
else
|
||||
section = PMM_SECTION_DEFAULT;
|
||||
section = MEMORY_SECTION_DEFAULT;
|
||||
|
||||
list = page->backing ? &standbylists[section] : &freelists[section];
|
||||
tail = page->backing ? &standbytails[section] : &freetails[section];
|
||||
@@ -124,15 +124,15 @@ static void internalhold(page_t *page) {
|
||||
}
|
||||
}
|
||||
|
||||
page_t *pmm_getpage(void *address) {
|
||||
page_t *mm_get_page(void *address) {
|
||||
return &pages[((uintptr_t)address / PAGE_SIZE)];
|
||||
}
|
||||
|
||||
void *pmm_getpageaddress(page_t *page) {
|
||||
void *mm_get_page_address(page_t *page) {
|
||||
return (void *)(PAGE_GETID(page) * PAGE_SIZE);
|
||||
}
|
||||
|
||||
void pmm_hold(void *addr) {
|
||||
void mm_hold_page(void *addr) {
|
||||
page_t *page = &pages[((uintptr_t)addr / PAGE_SIZE)];
|
||||
|
||||
MUTEX_ACQUIRE(&freelistmutex);
|
||||
@@ -140,7 +140,7 @@ void pmm_hold(void *addr) {
|
||||
MUTEX_RELEASE(&freelistmutex);
|
||||
}
|
||||
|
||||
void pmm_release(void *addr) {
|
||||
void mm_release_page(void *addr) {
|
||||
page_t *page = &pages[(uintptr_t)addr / PAGE_SIZE];
|
||||
|
||||
MUTEX_ACQUIRE(&freelistmutex);
|
||||
@@ -160,7 +160,7 @@ static void doalloc(page_t *page) {
|
||||
page->refcount = 1;
|
||||
}
|
||||
|
||||
void *pmm_allocpage(int section) {
|
||||
void *mm_alloc_page(int section) {
|
||||
retry:
|
||||
MUTEX_ACQUIRE(&freelistmutex);
|
||||
page_t *page = NULL;
|
||||
@@ -193,7 +193,7 @@ void *pmm_allocpage(int section) {
|
||||
|
||||
if (cachepage && vmmcache_takepage(page) == EAGAIN) {
|
||||
// someone already got the page from the cache between us holding it and taking it
|
||||
pmm_release(pmm_getpageaddress(page));
|
||||
mm_release_page(mm_get_page_address(page));
|
||||
page = NULL;
|
||||
// retry it from the start, as an anonymous page could have been released while the lock was not held
|
||||
goto retry;
|
||||
@@ -212,7 +212,7 @@ void *pmm_allocpage(int section) {
|
||||
return address;
|
||||
}
|
||||
|
||||
void pmm_makefree(void *address, size_t count) {
|
||||
void mm_force_free_page(void *address, size_t count) {
|
||||
MUTEX_ACQUIRE(&freelistmutex);
|
||||
memorysize += PAGE_SIZE * count;
|
||||
__assert(((uintptr_t)address % PAGE_SIZE) == 0);
|
||||
@@ -227,18 +227,18 @@ void pmm_makefree(void *address, size_t count) {
|
||||
MUTEX_RELEASE(&freelistmutex);
|
||||
}
|
||||
|
||||
void pmm_init() {
|
||||
void mm_page_init() {
|
||||
__assert(hhdmreq.response);
|
||||
hhdmbase = hhdmreq.response->offset;
|
||||
__assert(pmm_liminemap.response);
|
||||
__assert(mm_page_limine_map.response);
|
||||
|
||||
// get size of memory, top of usable memory, biggest section and print memory map
|
||||
size_t top = 0;
|
||||
struct limine_memmap_entry *biggest = NULL;
|
||||
printf("pmm: ranges:\n");
|
||||
for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = pmm_liminemap.response->entries[i];
|
||||
printf("pmm: %016p -> %016p: %d\n", e->base, e->base + e->length, e->type);
|
||||
printf("mm: ranges:\n");
|
||||
for (size_t i = 0; i < mm_page_limine_map.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = mm_page_limine_map.response->entries[i];
|
||||
printf("mm: %016p -> %016p: %d\n", e->base, e->base + e->length, e->type);
|
||||
if (e->type == LIMINE_MEMMAP_USABLE || e->type == LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE || e->type == LIMINE_MEMMAP_EXECUTABLE_AND_MODULES) {
|
||||
size_t sectiontop = e->base + e->length;
|
||||
if (sectiontop > top)
|
||||
@@ -254,11 +254,11 @@ void pmm_init() {
|
||||
pages = MAKE_HHDM((page_t *)biggest->base);
|
||||
pagecount = ROUND_UP(top, PAGE_SIZE) / PAGE_SIZE;
|
||||
memset(pages, 0, pagecount * sizeof(page_t));
|
||||
printf("pmm: %d pages used for page list\n", ROUND_UP(pagecount * sizeof(page_t), PAGE_SIZE) / PAGE_SIZE);
|
||||
printf("mm: %d pages used for page list\n", ROUND_UP(pagecount * sizeof(page_t), PAGE_SIZE) / PAGE_SIZE);
|
||||
|
||||
// initialize usable memory
|
||||
for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = pmm_liminemap.response->entries[i];
|
||||
for (size_t i = 0; i < mm_page_limine_map.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = mm_page_limine_map.response->entries[i];
|
||||
if (e->type == LIMINE_MEMMAP_USABLE) {
|
||||
int firstusablepage = e == biggest ? ROUND_UP(e->base + pagecount * sizeof(page_t), PAGE_SIZE) / PAGE_SIZE : e->base / PAGE_SIZE;
|
||||
for (int i = firstusablepage; i < (e->base + e->length) / PAGE_SIZE; ++i) {
|
||||
@@ -276,15 +276,15 @@ void pmm_init() {
|
||||
MUTEX_INIT(&freelistmutex);
|
||||
}
|
||||
|
||||
INIT_ROUTINE_DEFINE(pmm, INIT_ROUTINE_FLAGS_NONE, pmm_init, arch_early);
|
||||
INIT_ROUTINE_DEFINE(mm_page, INIT_ROUTINE_FLAGS_NONE, mm_page_init, arch_early);
|
||||
|
||||
// XXX pmm_alloc won't be able to take pages from the page cache when the allocation size is over 1 page
|
||||
// XXX mm_alloc_pages won't be able to take pages from the page cache when the allocation size is over 1 page
|
||||
|
||||
void *pmm_alloc(size_t size, int section) {
|
||||
void *mm_alloc_pages(size_t size, int section) {
|
||||
__assert(size);
|
||||
// pmm_allocpage is more suited for single page allocations, so use that instead
|
||||
// mm_alloc_page is more suited for single page allocations, so use that instead
|
||||
if (size == 1)
|
||||
return pmm_allocpage(section);
|
||||
return mm_alloc_page(section);
|
||||
|
||||
MUTEX_ACQUIRE(&freelistmutex);
|
||||
|
||||
@@ -322,15 +322,15 @@ void *pmm_alloc(size_t size, int section) {
|
||||
return addr;
|
||||
}
|
||||
|
||||
void pmm_free(void *addr, size_t size) {
|
||||
void mm_release_range(void *addr, size_t size) {
|
||||
__assert(size);
|
||||
// release multiple pages at once
|
||||
__assert(((uintptr_t)addr % PAGE_SIZE) == 0);
|
||||
for (int i = 0; i < size; ++i)
|
||||
pmm_release((void *)((uintptr_t)addr + PAGE_SIZE * i));
|
||||
mm_release_page((void *)((uintptr_t)addr + PAGE_SIZE * i));
|
||||
}
|
||||
|
||||
void pmm_getinfo(size_t *total_pages, size_t *free_pages) {
|
||||
void mm_get_page_statistics(size_t *total_pages, size_t *free_pages) {
|
||||
*total_pages = memorysize / PAGE_SIZE;
|
||||
*free_pages = freepagecount;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/vmm.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <logging.h>
|
||||
#include <util.h>
|
||||
#include <arch/smp.h>
|
||||
@@ -28,7 +28,7 @@ static inline bool grow_cache(scache_t *cache) {
|
||||
slab_t *slab;
|
||||
|
||||
if (cache->size < SLAB_INDIRECT_CUTOFF) {
|
||||
void *slab_hhdm = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *slab_hhdm = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (unlikely(slab_hhdm == NULL))
|
||||
return false;
|
||||
|
||||
@@ -465,7 +465,7 @@ static scache_t *create_new_from_vmm(size_t size, size_t alignment, bool (*ctor)
|
||||
scache_t *slab_create_new_cache_from_pmm(size_t size, size_t alignment, bool (*ctor)(scache_t *, void *), void (*dtor)(scache_t *, void *)) {
|
||||
__assert(size < SLAB_INDIRECT_CUTOFF);
|
||||
size_t cache_size = sizeof(scache_t) + sizeof(cache_per_cpu_t) * arch_smp_get_cpu_count();
|
||||
scache_t *cache = pmm_alloc(ROUND_UP(cache_size, PAGE_SIZE) / PAGE_SIZE, PMM_SECTION_DEFAULT);
|
||||
scache_t *cache = mm_alloc_pages(ROUND_UP(cache_size, PAGE_SIZE) / PAGE_SIZE, MEMORY_SECTION_DEFAULT);
|
||||
__assert(cache);
|
||||
cache = MAKE_HHDM(cache);
|
||||
__assert(slab_initialize(cache, size, alignment, ctor, dtor));
|
||||
@@ -490,4 +490,4 @@ void slab_init(void) {
|
||||
}
|
||||
|
||||
INIT_ROUTINE_DEFINE(slab, INIT_ROUTINE_FLAGS_NONE, slab_init, vmm);
|
||||
INIT_ROUTINE_DEFINE(slab_early, INIT_ROUTINE_FLAGS_NONE, slab_early_init, pmm);
|
||||
INIT_ROUTINE_DEFINE(slab_early, INIT_ROUTINE_FLAGS_NONE, slab_early_init, mm_page);
|
||||
|
||||
+26
-26
@@ -1,6 +1,6 @@
|
||||
#include <kernel/vmm.h>
|
||||
#include <logging.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <util.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <limine.h>
|
||||
@@ -175,19 +175,19 @@ static void destroyrange(vmmrange_t *range, uintmax_t _offset, size_t size, int
|
||||
// dirty page cache mapping
|
||||
arch_mmu_unmap(current_vmm_context()->pagetable, vaddr);
|
||||
VOP_LOCK(range->vnode);
|
||||
vmmcache_makedirty(pmm_getpage(physical));
|
||||
vmmcache_makedirty(mm_get_page(physical));
|
||||
VOP_UNLOCK(range->vnode);
|
||||
pmm_release(physical);
|
||||
mm_release_page(physical);
|
||||
} else {
|
||||
// non dirty page mapping
|
||||
arch_mmu_unmap(current_vmm_context()->pagetable, vaddr);
|
||||
pmm_release(physical);
|
||||
mm_release_page(physical);
|
||||
}
|
||||
} else {
|
||||
// anonymous, physical or private non character device mapping
|
||||
arch_mmu_unmap(current_vmm_context()->pagetable, vaddr);
|
||||
if ((range->flags & VMM_FLAGS_PHYSICAL) == 0)
|
||||
pmm_release(physical);
|
||||
mm_release_page(physical);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ static void changemmurange(vmmrange_t *range, void *base, size_t size, mmuflags_
|
||||
if ((range->flags & VMM_FLAGS_FILE) && (range->flags & VMM_FLAGS_SHARED) && (mask & ARCH_MMU_FLAGS_WRITE) && vfs_iscacheable(range->vnode)) {
|
||||
// removing write permissions from a writeable dirty shared mapped page, mark it as dirty, as
|
||||
// it won't be marked dirty upon a vmm_unmap after this
|
||||
page_t *page = pmm_getpage(physical);
|
||||
page_t *page = mm_get_page(physical);
|
||||
VOP_LOCK(range->vnode);
|
||||
vmmcache_makedirty(page);
|
||||
VOP_UNLOCK(range->vnode);
|
||||
@@ -566,10 +566,10 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
printf("vmm: error on vmmcache_getpage(): %d\n", error);
|
||||
status = false;
|
||||
} else {
|
||||
status = arch_mmu_map(current_vmm_context()->pagetable, pmm_getpageaddress(res), addr, range->mmuflags & ~ARCH_MMU_FLAGS_WRITE);
|
||||
status = arch_mmu_map(current_vmm_context()->pagetable, mm_get_page_address(res), addr, range->mmuflags & ~ARCH_MMU_FLAGS_WRITE);
|
||||
if (!status) {
|
||||
printf("vmm: out of memory to map file into address space (sending SIGBUS)\n");
|
||||
pmm_release(pmm_getpageaddress(res));
|
||||
mm_release_page(mm_get_page_address(res));
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
status = true;
|
||||
}
|
||||
@@ -580,7 +580,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
// anonymous memory.
|
||||
if (range->mmuflags & ARCH_MMU_FLAGS_WRITE) {
|
||||
// writeable range: allocate a new page, zero it and map it
|
||||
void *new_page = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *new_page = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (new_page == NULL) {
|
||||
printf("vmm: out of memory to allocate page to satisfy anonymous page-in (sending SIGBUS)\n");
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
@@ -592,7 +592,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
if (!arch_mmu_map(current_vmm_context()->pagetable, new_page, addr, range->mmuflags)) {
|
||||
printf("vmm: out of memory to map page (sending SIGBUS)\n");
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
pmm_release(new_page);
|
||||
mm_release_page(new_page);
|
||||
}
|
||||
} else {
|
||||
// read-only range: map a shared zero page
|
||||
@@ -600,14 +600,14 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
printf("vmm: out of memory to map zero page into address space (sending SIGBUS)\n");
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
} else {
|
||||
pmm_hold(zeropage);
|
||||
mm_hold_page(zeropage);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (arch_mmu_iswritable(current_vmm_context()->pagetable, addr) == false) {
|
||||
// page present but not writeable in the page tables
|
||||
void *oldphys = arch_mmu_getphysical(current_vmm_context()->pagetable, addr);
|
||||
page_t *oldpage = pmm_getpage(oldphys);
|
||||
page_t *oldpage = mm_get_page(oldphys);
|
||||
|
||||
if ( ((range->flags & VMM_FLAGS_FILE) && (range->flags & VMM_FLAGS_SHARED)) ||
|
||||
((range->flags & VMM_FLAGS_FILE) == 0 && oldpage->refcount == 1)) {
|
||||
@@ -617,14 +617,14 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
if ((range->flags & VMM_FLAGS_FILE) && vfs_iscacheable(range->vnode)) {
|
||||
// and if its a cache page, mark it as dirty
|
||||
VOP_LOCK(range->vnode);
|
||||
vmmcache_makedirty(pmm_getpage(oldphys));
|
||||
vmmcache_makedirty(mm_get_page(oldphys));
|
||||
VOP_UNLOCK(range->vnode);
|
||||
}
|
||||
|
||||
status = true;
|
||||
} else {
|
||||
// do copy on write
|
||||
void *newphys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *newphys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (newphys == NULL) {
|
||||
printf("vmm: out of memory to do copy on write on address space (sending SIGBUS)\n");
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
@@ -634,7 +634,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
arch_mmu_remap(current_vmm_context()->pagetable, newphys, addr, range->mmuflags);
|
||||
arch_mmu_invalidate_range(addr, PAGE_SIZE);
|
||||
if ((range->flags & VMM_FLAGS_FILE) == 0 || vfs_iscacheable(range->vnode))
|
||||
pmm_release(oldphys);
|
||||
mm_release_page(oldphys);
|
||||
|
||||
status = true;
|
||||
}
|
||||
@@ -667,7 +667,7 @@ static int lock_page(vmmspace_t *space, void *vaddr) {
|
||||
// TODO shared anonymous mappings are not handled properly by the kernel
|
||||
if (present && writable == false && private)) {
|
||||
// CoW cases (private mapping)
|
||||
real_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
real_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (real_phys == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -676,10 +676,10 @@ static int lock_page(vmmspace_t *space, void *vaddr) {
|
||||
arch_mmu_remap(current_vmm_context()->pagetable, real_phys, vaddr, range->mmuflags);
|
||||
arch_mmu_invalidate_range(vaddr, PAGE_SIZE);
|
||||
if (file_mapping == false || vfs_iscacheable(range->vnode))
|
||||
pmm_release(mapped_address);
|
||||
mm_release_page(mapped_address);
|
||||
} else if (present == false && private) {
|
||||
// not present private mapping case
|
||||
real_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
real_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (real_phys == NULL)
|
||||
}
|
||||
}
|
||||
@@ -704,7 +704,7 @@ void *vmm_getphysical(void *addr, int flags) {
|
||||
physical = arch_mmu_getphysical(current_vmm_context()->pagetable, aligned_addr);
|
||||
|
||||
if (flags & VMM_GET_PHYSICAL_FLAGS_HOLD)
|
||||
pmm_hold(physical);
|
||||
mm_hold_page(physical);
|
||||
|
||||
leave:
|
||||
MUTEX_RELEASE(&space->lock);
|
||||
@@ -791,7 +791,7 @@ void *vmm_map(void *addr, volatile size_t size, int flags, mmuflags_t mmuflags,
|
||||
} else if (flags & VMM_FLAGS_ALLOCATE) {
|
||||
// allocate to virtual memory
|
||||
for (uintmax_t i = 0; i < size; i += PAGE_SIZE) {
|
||||
void *allocated = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *allocated = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (allocated == NULL) {
|
||||
retaddr = NULL;
|
||||
goto cleanup;
|
||||
@@ -803,7 +803,7 @@ void *vmm_map(void *addr, volatile size_t size, int flags, mmuflags_t mmuflags,
|
||||
void *physical = arch_mmu_getphysical(current_vmm_context()->pagetable, virt);
|
||||
|
||||
if (physical) {
|
||||
pmm_release(physical);
|
||||
mm_release_page(physical);
|
||||
arch_mmu_unmap(current_vmm_context()->pagetable, virt);
|
||||
}
|
||||
}
|
||||
@@ -926,7 +926,7 @@ vmmcontext_t *vmm_fork(vmmcontext_t *oldcontext) {
|
||||
if (arch_mmu_map(newcontext->pagetable, phys, vaddr, newrange->mmuflags & ~ARCH_MMU_FLAGS_WRITE) == false)
|
||||
goto error;
|
||||
|
||||
pmm_hold(phys);
|
||||
mm_hold_page(phys);
|
||||
|
||||
arch_mmu_remap(oldcontext->pagetable, phys, vaddr, newrange->mmuflags & ~ARCH_MMU_FLAGS_WRITE);
|
||||
}
|
||||
@@ -959,7 +959,7 @@ extern void *_text_end;
|
||||
extern void *_data_end;
|
||||
extern void *_rodata_end;
|
||||
|
||||
extern volatile struct limine_memmap_request pmm_liminemap;
|
||||
extern volatile struct limine_memmap_request mm_page_limine_map;
|
||||
|
||||
void vmm_init() {
|
||||
// set up initial state
|
||||
@@ -976,8 +976,8 @@ void vmm_init() {
|
||||
vmm_switchcontext(&vmm_kernelctx);
|
||||
|
||||
// map HHDM
|
||||
for (uint64_t i = 0; i < pmm_liminemap.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = pmm_liminemap.response->entries[i];
|
||||
for (uint64_t i = 0; i < mm_page_limine_map.response->entry_count; ++i) {
|
||||
struct limine_memmap_entry *e = mm_page_limine_map.response->entries[i];
|
||||
|
||||
if (e->type != LIMINE_MEMMAP_USABLE && e->type != LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE && e->type != LIMINE_MEMMAP_EXECUTABLE_AND_MODULES && e->type != LIMINE_MEMMAP_FRAMEBUFFER)
|
||||
continue;
|
||||
@@ -998,7 +998,7 @@ void vmm_init() {
|
||||
vmm_map(MAKE_HHDM(NULL), PAGE_SIZE, VMM_FLAGS_EXACT, ARCH_MMU_FLAGS_NOEXEC, NULL);
|
||||
|
||||
// zero page
|
||||
zeropage = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
zeropage = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
memset(MAKE_HHDM(zeropage), 0, PAGE_SIZE);
|
||||
|
||||
printspace(&kernelspace);
|
||||
|
||||
@@ -114,12 +114,12 @@ int vmmcache_getpage(vnode_t *vnode, uintmax_t offset, page_t **res) {
|
||||
retry:
|
||||
if (page) {
|
||||
// page is present in the page cache
|
||||
pmm_hold(pmm_getpageaddress((page_t *)page));
|
||||
mm_hold_page(mm_get_page_address((page_t *)page));
|
||||
RELEASE_LOCK();
|
||||
|
||||
// in the case of a retry, release the allocated page here
|
||||
if (newpage)
|
||||
pmm_release(pmm_getpageaddress(newpage));
|
||||
mm_release_page(mm_get_page_address(newpage));
|
||||
|
||||
eventlistener_t listener;
|
||||
EVENT_INITLISTENER(&listener);
|
||||
@@ -133,7 +133,7 @@ int vmmcache_getpage(vnode_t *vnode, uintmax_t offset, page_t **res) {
|
||||
|
||||
if (page->flags & PAGE_FLAGS_ERROR) {
|
||||
// the thread handling the page in failed to read it, we should retry it and see whats up
|
||||
pmm_release(pmm_getpageaddress((page_t *)page));
|
||||
mm_release_page(mm_get_page_address((page_t *)page));
|
||||
goto retry_err;
|
||||
}
|
||||
|
||||
@@ -142,11 +142,11 @@ int vmmcache_getpage(vnode_t *vnode, uintmax_t offset, page_t **res) {
|
||||
// page is not present in the cache, we will have to load it in
|
||||
RELEASE_LOCK();
|
||||
|
||||
void *address = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *address = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (address == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
newpage = pmm_getpage(address);
|
||||
newpage = mm_get_page(address);
|
||||
|
||||
HOLD_LOCK();
|
||||
|
||||
@@ -180,7 +180,7 @@ int vmmcache_getpage(vnode_t *vnode, uintmax_t offset, page_t **res) {
|
||||
newpage->offset = 0;
|
||||
|
||||
RELEASE_LOCK();
|
||||
pmm_release(pmm_getpageaddress(newpage));
|
||||
mm_release_page(mm_get_page_address(newpage));
|
||||
EVENT_SIGNAL(&pagereadyevent);
|
||||
return error;
|
||||
}
|
||||
@@ -289,7 +289,7 @@ int vmmcache_truncate(vnode_t *vnode, uintmax_t offset) {
|
||||
page_t *page = pagelist;
|
||||
pagelist = pagelist->vnodenext;
|
||||
if (page->flags & PAGE_FLAGS_PINNED)
|
||||
pmm_release(pmm_getpageaddress(page));
|
||||
mm_release_page(mm_get_page_address(page));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -318,7 +318,7 @@ static int syncpage(page_t *page, bool backinglock) {
|
||||
VOP_RELEASE(page->backing);
|
||||
}
|
||||
|
||||
pmm_release(pmm_getpageaddress((page_t *)page));
|
||||
mm_release_page(mm_get_page_address((page_t *)page));
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ int vmmcache_makedirty(page_t *page) {
|
||||
dirtylist = page;
|
||||
}
|
||||
|
||||
pmm_hold(pmm_getpageaddress(page));
|
||||
mm_hold_page(mm_get_page_address(page));
|
||||
__assert(page->backing);
|
||||
VOP_HOLD(page->backing);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user