commit 8410cbe6340a2fd39da4866ce239b95f81569bda
parent 435ac77bd3b15f28e5f7f511e77de3eecf368a77
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Thu, 17 Nov 2022 07:14:26 +0100
os9: Use a Map for kstack
We have to switch the map for the kernel stack too.
Diffstat:
5 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/include/bits/amd64/arch/types.h b/include/bits/amd64/arch/types.h
@@ -1,6 +1,7 @@
/* TODO: Move these bits to other place */
#define STACKADDR 0x7FFFFFFFFFFFFFF0
+#define KSTACKADDR 0xFFFFFFFFFFFFFFF0
#define MAXTID 32767
#define NR_TASKS 16
#define NR_WINS 32
diff --git a/include/bits/arm64/arch/types.h b/include/bits/arm64/arch/types.h
@@ -1,6 +1,7 @@
/* TODO: Move these bits to other place */
#define STACKADDR 0x7FFFFFFFFFFFFFF0
+#define KSTACKADDR 0xFFFFFFFFFFFFFFF0
#define MAXTID 32767
#define NR_TASKS 16
#define NR_WINS 32
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -210,11 +210,11 @@ struct task {
Context ctx;
Ptable ptable;
- void *kstack;
Map *text;
Map *data;
Map stack;
+ Map kstack;
Nspace *ns;
Fdset *fds;
diff --git a/src/os9/hosted/arch.c b/src/os9/hosted/arch.c
@@ -74,8 +74,6 @@ idle(void)
int
ictx(Task *tp, void *fn)
{
- if (!newstack(tp))
- return -1;
tp->ctx.stack = (void *) tp->stack.va;
tp->ctx.entry = fn;
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -175,6 +175,25 @@ newstack(Task *tp)
return mp;
}
+Map *
+newkstack(Task *tp)
+{
+ Map *mp = &tp->kstack;
+
+ initref(&mp->ref);
+ mp->name = "kstack";
+ mp->perm = MW | MR;
+
+ mp->pa = -1;
+ mp->va = KSTACKADDR & (STACKADDR-1);
+ mp->siz = PAGESIZE;
+
+ if (mapseg(mp) < 0)
+ return NULL;
+
+ return mp;
+}
+
static Task *
newslot(void)
{
@@ -183,10 +202,8 @@ newslot(void)
lock(&procm);
for (tp = tasktab; tp < &tasktab[NR_TASKS]; tp++) {
lock(&tp->m);
- if (tp->state == TFREE) {
- tp->state = TINIT;
+ if (tp->state == TFREE)
break;
- }
unlock(&tp->m);
}
unlock(&procm);
@@ -226,10 +243,13 @@ newtask(void)
if ((tp = newslot()) == NULL)
goto err;
+ if (!newkstack(tp))
+ goto err;
last = pid;
tp->pid = pid;
tp->ppid = (proc) ? proc->pid : 0;
+ tp->state = TINIT;
unlock(&m);
@@ -270,12 +290,24 @@ newfds(Fdset *from)
}
static Map *
-newmap(Map *from)
+newmap(void)
{
Map *mp;
if ((mp = alloc(sizeof(*mp))) == NULL)
return NULL;
+ return mp;
+}
+
+static Map *
+dupmap(Map *from)
+{
+ Map *mp;
+
+ mp = newmap();
+ if (!mp)
+ return NULL;
+
*mp = *from;
initref(&mp->ref);
mapseg(mp); /* FIXME: we have to duplicate the pages */
@@ -386,7 +418,7 @@ rfork(int flags)
goto err;
}
if ((flags & RFMEM) == 0) {
- if ((data = newmap(parent->data)) == NULL)
+ if ((data = dupmap(parent->data)) == NULL)
goto err;
}
@@ -461,14 +493,11 @@ kproc(void *fn)
tp->flags = 0;
- tp->state = TREADY;
-
- if ((tp->kstack = allocb(1)) == NULL)
- goto err;
-
if (ictx(tp, fn) < 0)
goto err;
+ tp->state = TREADY;
+
return tp;
err: