aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-04 22:52:47 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-04 22:52:47 +0300
commitfdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6 (patch)
tree2eb538b9ecc2898d1f94305fe56d0625060834de /include
parentb82479a69cd6110c9099031e133fda62f8e11222 (diff)
downloadkmi-fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6.tar.gz
kmi-fdbc5adf83741d7e3af0c3f0ffdb59bdf42493b6.zip
generalize orphants
+ Allow threads to make themselves become orphants
Diffstat (limited to 'include')
-rw-r--r--include/arch/tcb.h8
-rw-r--r--include/kmi/orphanage.h9
-rw-r--r--include/kmi/syscalls.h3
-rw-r--r--include/kmi/tcb.h20
-rw-r--r--include/kmi/uapi.h15
5 files changed, 40 insertions, 15 deletions
diff --git a/include/arch/tcb.h b/include/arch/tcb.h
index 115f49d..22d3b59 100644
--- a/include/arch/tcb.h
+++ b/include/arch/tcb.h
@@ -40,13 +40,17 @@ void setup_rpc_stack(struct tcb *t);
void destroy_rpc_stack(struct tcb *t);
/**
- * Maximum size of one individual RPC stack instance.
- *
* @return Max size of one individual RPC stack instance.
*/
size_t max_rpc_size();
/**
+ * @param addr Address of current top of stack, generally from `ctx->rpc_stack`.
+ * @return \ref true if next rpc return would be into the root process.
+ */
+bool rpc_stack_empty(pm_t addr);
+
+/**
* Current highest address in RPC stack. Allowed to be inaccurate to one base page.
*
* @param t Thread whose position in the RPC stack is to be determined.
diff --git a/include/kmi/orphanage.h b/include/kmi/orphanage.h
index 530d10c..09e36b3 100644
--- a/include/kmi/orphanage.h
+++ b/include/kmi/orphanage.h
@@ -23,6 +23,13 @@
bool orphan(struct tcb *t);
/**
+ * Mark \p t orphaned.
+ *
+ * @param t Thread to orphanize.
+ */
+void orphanize(struct tcb *t);
+
+/**
* Assign \p t to the init process and jump to it.
* \p t must be an orphan!
* \p t must be in the process of swapping to its root process, either by
@@ -30,6 +37,6 @@ bool orphan(struct tcb *t);
*
* @param t Orphaned thread.
*/
-__noreturn void orphanize(struct tcb *t);
+__noreturn void unorphanize(struct tcb *t);
#endif /* KMI_OPRHANAGE_H */
diff --git a/include/kmi/syscalls.h b/include/kmi/syscalls.h
index 3619469..93d0ac9 100644
--- a/include/kmi/syscalls.h
+++ b/include/kmi/syscalls.h
@@ -157,6 +157,9 @@ enum sys_code {
/** Request a thread exits. */
SYS_EXIT,
+ /** Detach a thread from its root process, becoming an orphant. */
+ SYS_DETACH,
+
/** @} */
SYS_NUM,
diff --git a/include/kmi/tcb.h b/include/kmi/tcb.h
index fac9df7..df161b3 100644
--- a/include/kmi/tcb.h
+++ b/include/kmi/tcb.h
@@ -72,16 +72,13 @@ struct tcb_ctx {
struct vmem *vmem;
};
-/** Enum for notification states. */
-enum tcb_notify {
- /** Thread is free to be notified. */
- NOTIFY_WAITING = 0,
+/** State of thread. */
+enum tcb_state {
+ /** Thread is a zombie. */
+ TCB_ZOMBIE = (1 << 0),
- /** Thread has notifcations queued. */
- NOTIFY_QUEUED,
-
- /** Thread is running notification handler. */
- NOTIFY_RUNNING,
+ /** Thread is an orphan. */
+ TCB_ORPHAN = (1 << 1),
};
/** Thread control block. Main way to handle threads. */
@@ -180,9 +177,8 @@ struct tcb {
/** Queue that connects together threads waiting for an ipi */
struct queue_head ipi_queue;
- /** Whether thread is dead. If thread is process, then corresponds to
- * whole process. */
- bool dead;
+ /** Current state of thread. */
+ enum tcb_state state;
};
/**
diff --git a/include/kmi/uapi.h b/include/kmi/uapi.h
index 684f0da..76a759f 100644
--- a/include/kmi/uapi.h
+++ b/include/kmi/uapi.h
@@ -841,6 +841,21 @@ SYSCALL_DECLARE1(irq_req, id);
*/
SYSCALL_DECLARE1(exit, tid);
+/**
+ * Request that a thread becomes orphant, i.e. eventually attached to the init
+ * process. Can be used to stop threads within a process by sending an
+ * appropriate signal to the troublesome thread which then detaches itself from
+ * its root process.
+ *
+ * @param t Current tcb.
+ * @param a Unused.
+ * @param b Unused.
+ * @param c Unused.
+ * @param d Unused.
+ * @param e Unused.
+ */
+SYSCALL_DECLARE0(detach);
+
/** @} */
/**