Allow to unref unrefered page

This commit is contained in:
Mathieu Maret 2021-10-26 22:08:36 +02:00
parent 4aa093034b
commit 2c6ffe34a1
2 changed files with 7 additions and 3 deletions

View File

@ -1,8 +1,9 @@
#include "mem.h"
#include "assert.h"
#include "errno.h"
#include "kernel.h"
#include "klibc.h"
#include "list.h"
#include "mem.h"
#include "types.h"
static struct phyMemDesc *pageDesc = (struct phyMemDesc *)&__ld_kernel_end;
@ -139,9 +140,10 @@ int unrefPhyPage(paddr_t addr)
{
struct phyMemDesc *mem = addr2memDesc(addr);
if (!mem) {
return -1;
return -EINVAL;
}
assert(mem->ref > 0);
if(mem->ref <= 0)
return -EINVAL;
mem->ref--;
if (mem->ref == 0) {
allocatedPage--;

View File

@ -7,6 +7,8 @@
#define PAGE_SHIFT 12U
#define PAGE_SIZE (1U << PAGE_SHIFT)
#define PAGE_MASK (PAGE_SIZE - 1)
// Defined in linker.ld script
extern uint32_t __ld_kernel_begin;