cpu->proc_current cannot be NULL
This commit is contained in:
@@ -160,6 +160,23 @@ static void intr_exception (struct saved_regs* regs) {
|
|||||||
regs->error, regs->rip, regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3,
|
regs->error, regs->rip, regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3,
|
||||||
regs->rbx);
|
regs->rbx);
|
||||||
|
|
||||||
|
debugprintf ("call stack:\n");
|
||||||
|
|
||||||
|
uint64_t rbp = regs->rbp;
|
||||||
|
|
||||||
|
for (size_t depth = 0; depth < 20; depth++) {
|
||||||
|
if (rbp == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
uint64_t rip = *(uint64_t*)(rbp + 8);
|
||||||
|
debugprintf (" #%d %016lx\n", depth, rip);
|
||||||
|
|
||||||
|
rbp = *(uint64_t*)rbp;
|
||||||
|
|
||||||
|
if (rbp == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (regs->cs == (GDT_UCODE | 0x03)) {
|
if (regs->cs == (GDT_UCODE | 0x03)) {
|
||||||
struct reschedule_ctx rctx;
|
struct reschedule_ctx rctx;
|
||||||
memset (&rctx, 0, sizeof (rctx));
|
memset (&rctx, 0, sizeof (rctx));
|
||||||
@@ -200,14 +217,12 @@ void intr_handler (void* stack_ptr) {
|
|||||||
|
|
||||||
struct proc* proc_current = thiscpu->proc_current;
|
struct proc* proc_current = thiscpu->proc_current;
|
||||||
|
|
||||||
if (proc_current != NULL) {
|
spin_lock (&proc_current->lock, &fpc);
|
||||||
spin_lock (&proc_current->lock, &fpc);
|
memcpy (&proc_current->pdata.regs, regs, sizeof (struct saved_regs));
|
||||||
memcpy (&proc_current->pdata.regs, regs, sizeof (struct saved_regs));
|
|
||||||
|
|
||||||
fx_save (proc_current->pdata.fx_env);
|
fx_save (proc_current->pdata.fx_env);
|
||||||
|
|
||||||
spin_unlock (&proc_current->lock, fpc);
|
spin_unlock (&proc_current->lock, fpc);
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock (&thiscpu->lock, ftc);
|
spin_unlock (&thiscpu->lock, ftc);
|
||||||
}
|
}
|
||||||
|
|||||||
1
kernel/build/.gitignore
vendored
1
kernel/build/.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
*.elf
|
*.elf
|
||||||
*.json
|
*.json
|
||||||
|
*.map
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ static void ps2kb_irq (void* arg, void* regs, bool user, struct reschedule_ctx*
|
|||||||
|
|
||||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||||
|
|
||||||
if (node) {
|
if (node != NULL) {
|
||||||
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
|
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
|
||||||
struct proc* resumed_proc = sq_entry->proc;
|
struct proc* resumed_proc = sq_entry->proc;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ ifeq ($(buildtype),release)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ldflags += --nostdlib \
|
ldflags += --nostdlib \
|
||||||
--static
|
--static \
|
||||||
|
--Map=build/kernel.map
|
||||||
|
|
||||||
ifeq ($(buildtype),release)
|
ifeq ($(buildtype),release)
|
||||||
ldflags += --gc-sections \
|
ldflags += --gc-sections \
|
||||||
|
|||||||
@@ -12,12 +12,16 @@
|
|||||||
#include <sys/spin_lock.h>
|
#include <sys/spin_lock.h>
|
||||||
|
|
||||||
void proc_mutexes_cleanup (struct proc* proc, struct reschedule_ctx* rctx) {
|
void proc_mutexes_cleanup (struct proc* proc, struct reschedule_ctx* rctx) {
|
||||||
uint64_t fpg, fr;
|
uint64_t fpg, fr, fp;
|
||||||
|
|
||||||
spin_lock (&proc->procgroup->lock, &fpg);
|
spin_lock (&proc->lock, &fp);
|
||||||
|
struct procgroup* procgroup = proc->procgroup;
|
||||||
|
spin_unlock (&proc->lock, fp);
|
||||||
|
|
||||||
|
spin_lock (&procgroup->lock, &fpg);
|
||||||
|
|
||||||
struct rb_node_link* rnode;
|
struct rb_node_link* rnode;
|
||||||
rbtree_first (&proc->procgroup->resource_tree, rnode);
|
rbtree_first (&procgroup->resource_tree, rnode);
|
||||||
|
|
||||||
while (rnode) {
|
while (rnode) {
|
||||||
struct rb_node_link* next;
|
struct rb_node_link* next;
|
||||||
@@ -43,7 +47,7 @@ void proc_mutexes_cleanup (struct proc* proc, struct reschedule_ctx* rctx) {
|
|||||||
spin_unlock (&resource->lock, fr);
|
spin_unlock (&resource->lock, fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock (&proc->procgroup->lock, fpg);
|
spin_unlock (&procgroup->lock, fpg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_cleanup_resource_mutex (struct proc_resource* resource, struct reschedule_ctx* rctx) {
|
void proc_cleanup_resource_mutex (struct proc_resource* resource, struct reschedule_ctx* rctx) {
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
|
|||||||
if (!cpu->proc_run_q)
|
if (!cpu->proc_run_q)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (cpu->proc_current && cpu->proc_current->cpu_run_q_link.next)
|
if (cpu->proc_current->cpu_run_q_link.next)
|
||||||
current = cpu->proc_current->cpu_run_q_link.next;
|
current = cpu->proc_current->cpu_run_q_link.next;
|
||||||
else
|
else
|
||||||
current = cpu->proc_run_q;
|
current = cpu->proc_run_q;
|
||||||
@@ -282,7 +282,6 @@ retry:
|
|||||||
else
|
else
|
||||||
spin_unlock (&cpu->lock, fc);
|
spin_unlock (&cpu->lock, fc);
|
||||||
} else {
|
} else {
|
||||||
cpu->proc_current = NULL;
|
|
||||||
spin_unlock (&cpu->lock, fc);
|
spin_unlock (&cpu->lock, fc);
|
||||||
|
|
||||||
spin_lock_relax ();
|
spin_lock_relax ();
|
||||||
@@ -310,8 +309,6 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
|||||||
|
|
||||||
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
||||||
cpu->proc_run_q_count--;
|
cpu->proc_run_q_count--;
|
||||||
if (cpu->proc_current == proc)
|
|
||||||
cpu->proc_current = NULL;
|
|
||||||
|
|
||||||
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ int proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock_
|
|||||||
uint64_t lockflags, struct reschedule_ctx* rctx) {
|
uint64_t lockflags, struct reschedule_ctx* rctx) {
|
||||||
uint64_t fc, fp, fsq;
|
uint64_t fc, fp, fsq;
|
||||||
|
|
||||||
|
spin_lock (&proc->lock, &fp);
|
||||||
struct cpu* cpu = proc->cpu;
|
struct cpu* cpu = proc->cpu;
|
||||||
|
spin_unlock (&proc->lock, fp);
|
||||||
|
|
||||||
struct proc_sq_entry* sq_entry = malloc (sizeof (*sq_entry));
|
struct proc_sq_entry* sq_entry = malloc (sizeof (*sq_entry));
|
||||||
if (!sq_entry) {
|
if (!sq_entry) {
|
||||||
@@ -44,9 +46,6 @@ int proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock_
|
|||||||
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
||||||
cpu->proc_run_q_count--;
|
cpu->proc_run_q_count--;
|
||||||
|
|
||||||
if (cpu->proc_current == proc)
|
|
||||||
cpu->proc_current = NULL;
|
|
||||||
|
|
||||||
int state = proc->state;
|
int state = proc->state;
|
||||||
|
|
||||||
spin_unlock (&sq->lock, fsq);
|
spin_unlock (&sq->lock, fsq);
|
||||||
@@ -81,8 +80,6 @@ int proc_sq_resume (struct proc* proc, struct proc_sq_entry* sq_entry,
|
|||||||
proc->state = PROC_READY;
|
proc->state = PROC_READY;
|
||||||
|
|
||||||
list_append (cpu->proc_run_q, &proc->cpu_run_q_link);
|
list_append (cpu->proc_run_q, &proc->cpu_run_q_link);
|
||||||
if (cpu->proc_current == NULL)
|
|
||||||
cpu->proc_current = proc;
|
|
||||||
cpu->proc_run_q_count++;
|
cpu->proc_run_q_count++;
|
||||||
|
|
||||||
int state = proc->state;
|
int state = proc->state;
|
||||||
|
|||||||
@@ -480,8 +480,6 @@ DEFINE_SYSCALL (sys_exec_partial_fini) {
|
|||||||
|
|
||||||
cpu->proc_run_q_count++;
|
cpu->proc_run_q_count++;
|
||||||
list_append (cpu->proc_run_q, &target_proc->cpu_run_q_link);
|
list_append (cpu->proc_run_q, &target_proc->cpu_run_q_link);
|
||||||
if (cpu->proc_current == NULL)
|
|
||||||
cpu->proc_current = target_proc;
|
|
||||||
|
|
||||||
spin_unlock (&target_proc->lock, fp);
|
spin_unlock (&target_proc->lock, fp);
|
||||||
spin_unlock (&cpu->lock, fc);
|
spin_unlock (&cpu->lock, fc);
|
||||||
|
|||||||
Reference in New Issue
Block a user