summaryrefslogtreecommitdiff
path: root/src/sys/arch/amd64/os/os_proc.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-17 18:04:28 -0400
committerIan Moffett <ian@osmora.org>2025-09-17 18:12:05 -0400
commitc46767abb634d600dc5cb1ef5922ec3459ae4cf8 (patch)
tree2dac8bea2acfee9a4621d08be2c62a4dc0ca7b8b /src/sys/arch/amd64/os/os_proc.c
parentcf5672399eedbfc231fbf650e9bfb944f34e87a2 (diff)
kern/amd64: proc: Add proc_kill() routine
Add a new function to kill processes and clean them up. They will then be marked as EXITING and it is up to the parent to do the rest. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/arch/amd64/os/os_proc.c')
-rw-r--r--src/sys/arch/amd64/os/os_proc.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/sys/arch/amd64/os/os_proc.c b/src/sys/arch/amd64/os/os_proc.c
index 8c7b6f3..1064c10 100644
--- a/src/sys/arch/amd64/os/os_proc.c
+++ b/src/sys/arch/amd64/os/os_proc.c
@@ -39,6 +39,8 @@
#include <machine/lapic.h>
#include <string.h>
+extern struct proc g_rootproc;
+
/*
* Put the current process into userland for its first
* run. The catch is that we have never been in userland
@@ -212,3 +214,41 @@ done:
lapic_eoi();
lapic_timer_oneshot_us(SCHED_QUANTUM);
}
+
+/*
+ * Commit procedural murder
+ */
+int
+md_proc_kill(struct proc *procp, int flags)
+{
+ struct proc *self;
+ struct pcore *core = this_core();
+ struct md_pcb *pcbp;
+
+ if (core == NULL) {
+ return -ENXIO;
+ }
+
+ /* Default to ourself */
+ if (procp == NULL) {
+ procp = core->curproc;
+ }
+
+ /* Release the VAS */
+ pcbp = &procp->pcb;
+ mmu_free_vas(&pcbp->vas);
+
+ /* Sanity check */
+ if ((self = core->curproc) == NULL) {
+ printf("kill: could not get self, using rootproc\n");
+ self = &g_rootproc;
+ }
+
+ /* If this is us, spin time */
+ if (self->pid == procp->pid) {
+ core->curproc = NULL;
+ md_proc_yield();
+ }
+
+ return 0;
+}