aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-11-13 15:15:22 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2022-11-13 15:15:22 +0200
commite6dc962ef7758c438039d7f8ac7e2bf3ebcb5c10 (patch)
tree9484a801bc205e0e5f921ebeaba0a15e4d561400 /common
parentb36e3b83b402ee054c319f0472b16a2bd64bba7e (diff)
downloadkmi-e6dc962ef7758c438039d7f8ac7e2bf3ebcb5c10.tar.gz
kmi-e6dc962ef7758c438039d7f8ac7e2bf3ebcb5c10.zip
improve documentation on new features
Diffstat (limited to 'common')
-rw-r--r--common/tcb.c39
-rw-r--r--common/uapi/ipc.c5
-rw-r--r--common/vmem.c5
3 files changed, 37 insertions, 12 deletions
diff --git a/common/tcb.c b/common/tcb.c
index 201b15e..5121940 100644
--- a/common/tcb.c
+++ b/common/tcb.c
@@ -149,6 +149,9 @@ struct tcb *create_thread(struct tcb *p)
if (likely(p)) {
t->pid = p->pid;
+ /** @todo I'm assuming two threads can share the same vmem
+ * structure, this works on riscv but in the event that other
+ * systems don't we can easily turn this into a clone_uvmem. */
t->proc.vmem = p->proc.vmem;
} else {
init_uvmem(t, UVMEM_START, UVMEM_END);
@@ -259,23 +262,24 @@ stat_t destroy_proc(struct tcb *p)
*
* @param name name of function to define.
* @param type Field name of type \c tcb_ctx.
+ * @param root Root \ref tcb_ctx to attach to.
*/
-#define DEFINE_ATTACH(name, type) \
+#define DEFINE_ATTACH(name, type, root) \
stat_t name(struct tcb *r, struct tcb *t) \
{ \
hard_assert(r != t, ERR_INVAL); \
- struct tcb *next = r->type.next; \
+ struct tcb *next = r->root.next; \
t->type.next = next; \
\
if (next) { next->type.prev = t; } \
\
t->type.prev = r; \
- r->type.next = t; \
+ r->root.next = t; \
return OK; \
}
-DEFINE_ATTACH(attach_rpc, rpc);
-DEFINE_ATTACH(attach_proc, proc);
+DEFINE_ATTACH(attach_rpc, rpc, server);
+DEFINE_ATTACH(attach_proc, proc, proc);
/**
* Convenience marco for defining function to detach a thread from either process
@@ -283,8 +287,9 @@ DEFINE_ATTACH(attach_proc, proc);
*
* @param name name of function to define.
* @param type Field name of type \c tcb_ctx.
+ * @param root Root \ref tcb_ctx to detach from.
*/
-#define DEFINE_DETACH(name, type) \
+#define DEFINE_DETACH(name, type, root) \
stat_t name(struct tcb *r, struct tcb *t) \
{ \
MAYBE_UNUSED(r); \
@@ -298,8 +303,8 @@ DEFINE_ATTACH(attach_proc, proc);
return OK; \
}
-DEFINE_DETACH(detach_rpc, rpc);
-DEFINE_DETACH(detach_proc, proc);
+DEFINE_DETACH(detach_rpc, rpc, server);
+DEFINE_DETACH(detach_proc, proc, proc);
/* weak to allow optimisation on risc-v, but provide fallback for future */
__weak struct tcb *cur_tcb()
@@ -402,18 +407,32 @@ static void mark_rpc_accessible(struct tcb *t, vm_t start, vm_t end)
set_vpage_flags(t->rpc.vmem, start + pages * page_size, VM_U);
}
+/** Structure for maintaingin the required context data for an rpc call. */
struct call_ctx {
+ /** Execution continuation point. */
vm_t exec;
+
+ /** Register save area. */
vm_t regs;
+
+ /** Position in rpc stack. */
vm_t rpc_stack;
- id_t eid, pid;
+
+ /** Effective process ID. */
+ id_t eid;
+
+ /** Current process ID. */
+ id_t pid;
};
void save_context(struct tcb *t)
{
vm_t rpc_stack = t->rpc_stack;
if (is_rpc(t))
- /** @todo what if user uses their own stack? */
+ /** @todo what if user uses their own stack? Or is a dick and
+ * sets the stack pointer to RPC_STACK_TOP or something? It'll
+ * likely only cause a fuckup in the process who did the dumb
+ * thing, so maybe just consider it user error? */
rpc_stack = align_down(get_stack(t), BASE_PAGE_SIZE);
diff --git a/common/uapi/ipc.c b/common/uapi/ipc.c
index e9a6e6b..052e0ad 100644
--- a/common/uapi/ipc.c
+++ b/common/uapi/ipc.c
@@ -55,8 +55,7 @@ static struct sys_ret do_ipc(sys_arg_t pid,
save_context(t);
set_return(t, r->callback);
- /** @todo associate thread with new proc, should be done in tcb.c I
- * think */
+ attach_rpc(r, t);
if (!fwd)
t->eid = t->pid;
@@ -110,7 +109,9 @@ SYSCALL_DEFINE4(ipc_resp)(sys_arg_t d0, sys_arg_t d1, sys_arg_t d2,
sys_arg_t d3)
{
struct tcb *t = cur_tcb();
+ struct tcb *r = cur_proc();
load_context(t);
+ detach_rpc(r, t);
if (is_rpc(t))
use_vmem(t->rpc.vmem);
diff --git a/common/vmem.c b/common/vmem.c
index 458624c..56bc01a 100644
--- a/common/vmem.c
+++ b/common/vmem.c
@@ -140,6 +140,8 @@ vm_t alloc_fixed_uvmem(struct tcb *t, vm_t start, size_t size, vmflags_t flags)
const vm_t v = alloc_fixed_region(&t->sp_r, start, size, &size, flags);
const vm_t w = map_allocd_region(t->proc.vmem, v, size, flags, &status);
+ /** @todo should probably update rpc maps even if the thread that does
+ * the allocation isn't in an ipc? */
if (is_rpc(t) && status == INFO_SEFF)
clone_rpc_maps(t);
@@ -273,6 +275,9 @@ stat_t free_uvmem_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
if (order != v_order)
return INFO_TRGN;
+ /** @todo we might need to cause an ipi to flush the tlb for other
+ * cores */
+
stat_t *status = (stat_t *)data, ret;
ret = unmap_vpage(b, vaddr);
if (status)