summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-28 19:37:31 -0400
committerHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-28 19:37:31 -0400
commitff90341c64565ac7d8034d2f8cf460532a5b51fd (patch)
tree7056c18c075aa5b6a4bdef124342866973506eee
parent09cce089128de5f265ee6d4e68e196f85537ccc7 (diff)
fix
-rw-r--r--kern/inc/sched.h2
-rw-r--r--kern/sched.c10
-rw-r--r--kern/sched_asm.S6
-rw-r--r--kern/sync_asm.S39
-rw-r--r--kern/syscall_misc.c2
-rw-r--r--kern/usermem.c2
6 files changed, 43 insertions, 18 deletions
diff --git a/kern/inc/sched.h b/kern/inc/sched.h
index 754567e..38de1e4 100644
--- a/kern/inc/sched.h
+++ b/kern/inc/sched.h
@@ -77,6 +77,8 @@ typedef struct region_s {
typedef struct yield_frame_s {
reg_t ebp;
reg_t ebx;
+ reg_t esi;
+ reg_t edi;
reg_t eflags;
reg_t raddr;
} yield_frame_t;
diff --git a/kern/sched.c b/kern/sched.c
index 7764c26..f797409 100644
--- a/kern/sched.c
+++ b/kern/sched.c
@@ -647,15 +647,21 @@ void kill_current() {
if (p->refcount == 1) {
mutex_lock(&p->wait_lock);
/* reclaim dead childs */
+ queue_t* dead_childs = NULL;
while (p->dead_childs != NULL) {
queue_t* node = p->dead_childs;
queue_detach(&p->dead_childs, node);
+ queue_insert_tail(&dead_childs, node);
+ p->nchilds--;
+ }
+ mutex_unlock(&p->wait_lock);
+ while (dead_childs != NULL) {
+ queue_t* node = dead_childs;
+ queue_detach(&dead_childs, node);
process_t* child_process =
queue_data(node, process_t, sible_link);
sfree(child_process, sizeof(process_t));
- p->nchilds--;
}
- mutex_unlock(&p->wait_lock);
const char* init_args[] = {INIT_NAME};
thread_t* new_init =
create_process(current->rb_node.key, INIT_NAME, 1, init_args);
diff --git a/kern/sched_asm.S b/kern/sched_asm.S
index 7a994f5..d20f129 100644
--- a/kern/sched_asm.S
+++ b/kern/sched_asm.S
@@ -33,9 +33,9 @@ get_\name:
.global set_\name
.type set_\name, %function
set_\name:
- xor %esi, %esi
+ xor %ecx, %ecx
mov 0x4(%esp), %eax
- mov %eax, %fs:\offset(%esi)
+ mov %eax, %fs:\offset(%ecx)
ret
.endm
@@ -68,5 +68,7 @@ switch_stack_cleanup:
add $0x4, %esp
pop %ebp
pop %ebx
+ pop %esi
+ pop %edi
popf
ret
diff --git a/kern/sync_asm.S b/kern/sync_asm.S
index b3fc852..87fe7c6 100644
--- a/kern/sync_asm.S
+++ b/kern/sync_asm.S
@@ -29,26 +29,30 @@ restore_if:
.global spl_lock
.type spl_lock, %function
spl_lock:
+ push %ebx
pushf
- pop %edx
+ pop %ebx
cli
- mov 0x4(%esp), %esi
- mov $1, %edi
+ mov 0x8(%esp), %ecx
+ mov $1, %edx
.spl_lock_try:
- xor %eax, %eax
- lock cmpxchg %edi, (%esi)
+ mov (%ecx), %eax
+ test %eax, %eax
+ jnz .spl_lock_try
+ lock cmpxchg %edx, (%ecx)
test %eax, %eax
jnz .spl_lock_try
- mov %edx, %eax
+ mov %ebx, %eax
+ pop %ebx
ret
.global spl_unlock
.type spl_unlock, %function
spl_unlock:
mov 0x8(%esp), %eax
- mov 0x4(%esp), %esi
+ mov 0x4(%esp), %ecx
xor %edx, %edx
- mov %edx, (%esi)
+ mov %edx, (%ecx)
push %eax
popf
ret
@@ -56,20 +60,29 @@ spl_unlock:
.global yield_to_spl_unlock
.type yield_to_spl_unlock, %function
yield_to_spl_unlock:
- mov 0xc(%esp), %edi
- mov 0x8(%esp), %esi
+ mov 0xc(%esp), %edx
+ mov 0x8(%esp), %ecx
mov 0x4(%esp), %eax
- push %edi /* old_if, will be restored when switching back */
+ push %edx /* old_if, will be restored when switching back */
+ push %edi
+ push %esi
push %ebx
push %ebp
- mov %esi, %ebx
+ mov %eax, %ebp
+ mov %ecx, %ebx
+ call get_current
+ cmp %eax, %ebp
+ je .yield_to_spl_unlock_no_switch
push %esp
- push %eax
+ push %ebp
call save_and_setup_env
mov %eax, %esp
+.yield_to_spl_unlock_no_switch:
xor %eax, %eax
mov %eax, (%ebx)
pop %ebp
pop %ebx
+ pop %esi
+ pop %edi
popf
ret
diff --git a/kern/syscall_misc.c b/kern/syscall_misc.c
index 6bc91d6..b27a560 100644
--- a/kern/syscall_misc.c
+++ b/kern/syscall_misc.c
@@ -47,6 +47,7 @@ void sys_misbehave_real(stack_frame_t* f) {
void sys_halt_real(stack_frame_t* f) {
sim_halt();
hlt();
+ panic("Halted");
}
/**
@@ -96,6 +97,7 @@ void sys_readfile_real(stack_frame_t* f) {
if (fp == NULL) {
goto no_such_file;
}
+ free(filename);
if (offset > fp->execlen) {
goto offset_too_big;
}
diff --git a/kern/usermem.c b/kern/usermem.c
index 5e6b1e3..34b98b2 100644
--- a/kern/usermem.c
+++ b/kern/usermem.c
@@ -13,9 +13,9 @@
#include <x86/asm.h>
#include <x86/seg.h>
-#include <pts.h>
#include <mm.h>
#include <paging.h>
+#include <pts.h>
#include <sched.h>
/**