mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
add a function that gets called after every system call and make all threads quit on program exit
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
#include <kernel/sched.h>
|
||||||
|
|
||||||
|
void postsyscall(){
|
||||||
|
sched_threadexitcheck();
|
||||||
|
}
|
||||||
@@ -175,23 +175,30 @@ asm_syscall_entry:
|
|||||||
|
|
||||||
call [func_table + rax * 8]
|
call [func_table + rax * 8]
|
||||||
|
|
||||||
; restore entry state
|
push rax
|
||||||
|
push rdx
|
||||||
|
|
||||||
; DEBUG STUFF
|
; DEBUG STUFF
|
||||||
|
|
||||||
;push rax
|
|
||||||
;push rdx
|
|
||||||
|
|
||||||
;mov rsi,rdx
|
;mov rsi,rdx
|
||||||
;mov rdi,r15
|
;mov rdi,r15
|
||||||
;extern syscalllogger
|
;extern syscalllogger
|
||||||
;call syscalllogger
|
;call syscalllogger
|
||||||
|
|
||||||
;pop rdx
|
extern postsyscall
|
||||||
;pop rax
|
call postsyscall
|
||||||
|
|
||||||
|
|
||||||
; DEBUG STUFF END
|
; DEBUG STUFF END
|
||||||
|
|
||||||
|
pop rdx
|
||||||
|
pop rax
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; restore entry state
|
||||||
|
|
||||||
mov r11, 0x43 ; user data
|
mov r11, 0x43 ; user data
|
||||||
mov es,r11
|
mov es,r11
|
||||||
mov ds,r11
|
mov ds,r11
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <kernel/vfs.h>
|
#include <kernel/vfs.h>
|
||||||
#include <kernel/vmm.h>
|
#include <kernel/vmm.h>
|
||||||
#include <kernel/fd.h>
|
#include <kernel/fd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define THREAD_PRIORITY_INTERRUPT 0
|
#define THREAD_PRIORITY_INTERRUPT 0
|
||||||
#define THREAD_PRIORITY_KERNEL 1
|
#define THREAD_PRIORITY_KERNEL 1
|
||||||
@@ -44,6 +45,7 @@ typedef struct _thread_t{
|
|||||||
int priority;
|
int priority;
|
||||||
int umemoperror;
|
int umemoperror;
|
||||||
void (*umemopfailaddr)();
|
void (*umemopfailaddr)();
|
||||||
|
bool shouldexit;
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
|
||||||
typedef struct _proc_t{
|
typedef struct _proc_t{
|
||||||
@@ -82,4 +84,5 @@ void sched_runinit();
|
|||||||
void sched_eventsignal(event_t* event, thread_t* thread);
|
void sched_eventsignal(event_t* event, thread_t* thread);
|
||||||
void sched_block(bool interruptible);
|
void sched_block(bool interruptible);
|
||||||
void sched_yield();
|
void sched_yield();
|
||||||
|
void sched_threadexitcheck();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -380,6 +380,12 @@ __attribute__((noreturn)) int sched_die(){
|
|||||||
sched_dequeue();
|
sched_dequeue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sched_threadexitcheck(){
|
||||||
|
if(arch_getcls()->thread->shouldexit)
|
||||||
|
sched_die();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void sched_block(bool interruptible){
|
void sched_block(bool interruptible){
|
||||||
|
|
||||||
thread_t* thread = arch_getcls()->thread;
|
thread_t* thread = arch_getcls()->thread;
|
||||||
|
|||||||
+24
-3
@@ -7,17 +7,38 @@
|
|||||||
#include <arch/interrupt.h>
|
#include <arch/interrupt.h>
|
||||||
|
|
||||||
void syscall_exit(int status){
|
void syscall_exit(int status){
|
||||||
proc_t* proc = arch_getcls()->thread->proc;
|
|
||||||
|
|
||||||
|
thread_t* thread = arch_getcls()->thread;
|
||||||
|
proc_t* proc = thread->proc;
|
||||||
|
|
||||||
|
|
||||||
proc_t* init = sched_getinit();
|
proc_t* init = sched_getinit();
|
||||||
|
|
||||||
|
if(proc == init)
|
||||||
|
_panic("Init exit", NULL);
|
||||||
|
|
||||||
spinlock_acquire(&init->lock);
|
spinlock_acquire(&init->lock);
|
||||||
spinlock_acquire(&proc->lock);
|
spinlock_acquire(&proc->lock);
|
||||||
|
|
||||||
// TODO make all other threads exit
|
while(1){
|
||||||
|
bool ok = true;
|
||||||
|
for(uintmax_t i = 0; i < proc->threadcount; ++i){
|
||||||
|
if(proc->threads[i] == thread)
|
||||||
|
continue;
|
||||||
|
if(thread->state != THREAD_STATE_DEAD)
|
||||||
|
ok = false;
|
||||||
|
proc->threads[i]->shouldexit = true;
|
||||||
|
}
|
||||||
|
|
||||||
free(proc->threads);
|
if(ok)
|
||||||
|
break;
|
||||||
|
|
||||||
|
arch_interrupt_disable();
|
||||||
|
sched_yield();
|
||||||
|
arch_interrupt_enable();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
for(uintmax_t fd = 0; fd < proc->fdtable.fdcount; ++ fd)
|
for(uintmax_t fd = 0; fd < proc->fdtable.fdcount; ++ fd)
|
||||||
fd_free(&proc->fdtable, fd);
|
fd_free(&proc->fdtable, fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user