Better proc_kill () and process cleanup
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
This commit is contained in:
@@ -9,5 +9,6 @@
|
||||
|
||||
#define SCHED_PREEMPT_TIMER 80
|
||||
#define TLB_SHOOTDOWN 81
|
||||
#define CPU_REQUEST_SCHED 82
|
||||
|
||||
#endif // _KERNEL_AMD64_INTR_DEFS_H
|
||||
|
||||
@@ -88,3 +88,4 @@ make_intr_stub(no_err, 47)
|
||||
|
||||
make_intr_stub(no_err, SCHED_PREEMPT_TIMER)
|
||||
make_intr_stub(no_err, TLB_SHOOTDOWN)
|
||||
make_intr_stub(no_err, CPU_REQUEST_SCHED)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <amd64/gdt.h>
|
||||
#include <aux/elf.h>
|
||||
#include <libk/list.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <limine/requests.h>
|
||||
@@ -41,10 +42,8 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
|
||||
pmm_free (kernel_stack, USTACK_SIZE / PAGE_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
uintptr_t user_stack = proc->pdata.user_stack;
|
||||
proc->pdata.user_stack += USTACK_SIZE;
|
||||
|
||||
proc_map (proc, user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
|
||||
proc_map (proc, proc->pdata.user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
|
||||
MM_PG_USER | MM_PG_PRESENT | MM_PG_RW);
|
||||
|
||||
struct elf_aux aux = proc_load_segments (proc, elf_contents);
|
||||
@@ -60,3 +59,26 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
void proc_cleanup (struct proc* proc) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
struct proc_mapping *mapping, *mapping_tmp;
|
||||
spin_lock (&proc->pd.lock);
|
||||
|
||||
linklist_foreach (proc->mappings, mapping, mapping_tmp) {
|
||||
pmm_free (mapping->paddr, mapping->size / PAGE_SIZE);
|
||||
linklist_remove (struct proc_mapping*, proc->mappings, mapping);
|
||||
free (mapping);
|
||||
}
|
||||
|
||||
spin_unlock (&proc->pd.lock);
|
||||
|
||||
pmm_free (proc->pd.cr3_paddr, 1);
|
||||
|
||||
pmm_free (proc->pdata.kernel_stack - (uintptr_t)hhdm->offset - KSTACK_SIZE,
|
||||
KSTACK_SIZE / PAGE_SIZE);
|
||||
pmm_free (proc->pdata.user_stack, USTACK_SIZE / PAGE_SIZE);
|
||||
|
||||
free (proc);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <amd64/apic.h>
|
||||
#include <amd64/init.h>
|
||||
#include <amd64/intr_defs.h>
|
||||
#include <amd64/mm.h>
|
||||
#include <amd64/msr-index.h>
|
||||
#include <amd64/msr.h>
|
||||
@@ -40,6 +41,17 @@ struct cpu* cpu_get (void) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void cpu_request_sched (struct cpu* cpu) {
|
||||
struct limine_mp_response* mp = limine_mp_request.response;
|
||||
|
||||
for (size_t i = 0; i < mp->cpu_count; i++) {
|
||||
if (cpu->id == i) {
|
||||
amd64_lapic_ipi (mp->cpus[i]->lapic_id, CPU_REQUEST_SCHED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bootstrap code for non-BSP CPUs
|
||||
static void amd64_smp_bootstrap (struct limine_mp_info* mp_info) {
|
||||
amd64_load_kernel_cr3 ();
|
||||
|
||||
@@ -37,7 +37,7 @@ struct cpu {
|
||||
|
||||
struct cpu* cpu_make (void);
|
||||
struct cpu* cpu_get (void);
|
||||
void amd64_thiscpu_set_init (void);
|
||||
void cpu_request_sched (struct cpu* cpu);
|
||||
|
||||
#define thiscpu (cpu_get ())
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
.global amd64_spin
|
||||
amd64_spin:
|
||||
hlt
|
||||
jmp amd64_spin
|
||||
|
||||
Reference in New Issue
Block a user