From 16624a0cfdc7ffd8db0c24cfd33f47482a08f21e Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 7 Feb 2024 23:15:56 +0100 Subject: [PATCH] zero: finish implementation --- drivers/zero.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/zero.c b/drivers/zero.c index 9610658..60235a6 100644 --- a/drivers/zero.c +++ b/drivers/zero.c @@ -1,27 +1,41 @@ -#include "alloc.h" -#include "klibc.h" #include "zero.h" +#include "alloc.h" +#include "kernel.h" +#include "klibc.h" + struct zeroMappedEntry { - int refCnt; + int refCnt; }; static int zeroOpen(struct uAddrVirtualReg *vreg) { - (void)vreg; - return 0; + struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData; + ent->refCnt++; + return 0; } + static int zeroClose(struct uAddrVirtualReg *vreg) { - (void)vreg; - return 0; + struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData; + ent->refCnt--; + return 0; } + static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right) { - (void)vreg; - (void)addr; - (void)right; - return 0; + (void)vreg; + + int ret = 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 = {