From a03abab06afc8ea84f1b19f59109e36c4fe59b61 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 8 Feb 2024 20:54:29 +0100 Subject: [PATCH] Assign a mapped ressource to init prog --- core/elf.c | 7 +++++++ drivers/zero.c | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/elf.c b/core/elf.c index 7837143..8f4ccc1 100644 --- a/core/elf.c +++ b/core/elf.c @@ -5,6 +5,7 @@ #include "paging.h" #include "thread.h" #include "types.h" +#include "zero.h" /** * Make sure the program is in a valid ELF format, map it into memory, @@ -17,6 +18,7 @@ uaddr_t loadElfProg(const char *prog, struct process *proc) { int i; uaddr_t lastUserAddr = 0; + struct uAddrSpace *as = processGetAddrSpace(proc); /* e_ident value */ #define ELFMAG0 0x7f @@ -136,6 +138,11 @@ uaddr_t loadElfProg(const char *prog, struct process *proc) unrefPhyPage(ppage); } + // Hack: Even if already allocated mark the adresse space as managed by a ressource + // So this address space is not used by another ressource. + uaddr = elf_phdrs[i].p_vaddr; + zeroMmap(as, &uaddr, elf_phdrs[i].p_memsz, PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ, 0); + /* Copy segment into memory */ memcpy((void *)elf_phdrs[i].p_vaddr, (void *)(prog + elf_phdrs[i].p_offset), elf_phdrs[i].p_filesz); diff --git a/drivers/zero.c b/drivers/zero.c index 60235a6..9799517 100644 --- a/drivers/zero.c +++ b/drivers/zero.c @@ -57,6 +57,7 @@ int zeroOnMapped(struct uAddrVirtualReg *vreg) int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights, uint32_t flags) { + int ret = 0; struct mappedRessource *res = (struct mappedRessource *)zalloc(sizeof(struct mappedRessource)); struct zeroMappedEntry *cust = @@ -67,5 +68,12 @@ int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights res->customData = cust; res->onResMapped = zeroOnMapped; - return uAddrSpaceMmap(as, uaddr, size, rights, flags, res, 0); + ret = uAddrSpaceMmap(as, uaddr, size, rights, flags, res, 0); + + if (ret) { + free(res); + free(cust); + } + + return ret; }