mmap #8

Merged
mathieu merged 22 commits from mmap into master 2024-02-11 15:29:59 +01:00
Showing only changes of commit 62a1c1cefb - Show all commits

View File

@ -1,27 +1,41 @@
#include "alloc.h"
#include "klibc.h"
#include "zero.h" #include "zero.h"
#include "alloc.h"
#include "kernel.h"
#include "klibc.h"
struct zeroMappedEntry { struct zeroMappedEntry {
int refCnt; int refCnt;
}; };
static int zeroOpen(struct uAddrVirtualReg *vreg) static int zeroOpen(struct uAddrVirtualReg *vreg)
{ {
(void)vreg; struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
return 0; ent->refCnt++;
return 0;
} }
static int zeroClose(struct uAddrVirtualReg *vreg) static int zeroClose(struct uAddrVirtualReg *vreg)
{ {
(void)vreg; struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
return 0; ent->refCnt--;
return 0;
} }
static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right) static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right)
{ {
(void)vreg; (void)vreg;
(void)addr;
(void)right; int ret = 0;
return 0; paddr_t ppage = allocPhyPage(1);
ret = pageMap(ALIGN_DOWN(addr, PAGE_SIZE), ppage, right | PAGING_MEM_USER) ;
unrefPhyPage(ppage);
if (ret) {
return ret;
}
memset((void *)ALIGN_DOWN(addr, PAGE_SIZE), 0, PAGE_SIZE);
return ret;
} }
static struct mappedRessourceOps zeroOps = { static struct mappedRessourceOps zeroOps = {