9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4387497cba74b53fc5dd3858d985327d0e8a8a94
parent 31f0ece115a4b80a6fa447626e5226bf826fdea1
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date:   Sat, 19 Nov 2022 17:16:03 +0100

os9: Copy page content in newmap()

When we duplicate a map we have to map a new set of pages
but we also have to duplicate the actual content of the
pages.

Diffstat:
Minclude/os9/os9.h | 1+
Msrc/os9/hosted/arch.c | 7+++++++
Msrc/os9/map.c | 17++++++++++++++++-
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/include/os9/os9.h b/include/os9/os9.h @@ -319,6 +319,7 @@ extern void ictx(Task *, void *); extern int dupctx(Task *); extern char *getconf(char *); extern void idle(void); +extern char bufto[], buffrom[]; /* dev functions */ extern void idev(void); diff --git a/src/os9/hosted/arch.c b/src/os9/hosted/arch.c @@ -11,6 +11,13 @@ jmp_buf recover; noreturn void abort(void); noreturn void longjmp(jmp_buf env, int val); +char bufto[PAGESIZE], buffrom[PAGESIZE]; + +void +barrier(int what) +{ +} + void halt(void) { diff --git a/src/os9/map.c b/src/os9/map.c @@ -2,6 +2,8 @@ #include <libk.h> +#include <string.h> + Map * newstack(Task *tp) { @@ -121,13 +123,26 @@ Map * newmap(Map *from) { Map *mp; + Page *pfrom, *pto; if ((mp = allocmap()) == NULL) return NULL; *mp = *from; + mp->pages = NULL; + mp->next = NULL; initref(&mp->ref); - mapseg(mp); /* FIXME: we have to duplicate the pages */ + mapseg(mp); + + pto = mp->pages; + for (pfrom = from->pages; pfrom; pfrom = pfrom->next) { + assert(pfrom->va == pto->va); + vmap(pto->pa, (uintptr_t) bufto, MW); + vmap(pfrom->pa, (uintptr_t) buffrom, MR); + memcpy(bufto, buffrom, PAGESIZE); + barrier(DATA); + pto = pto->next; + } return mp; }