wip: fork and wait are almost working (missing child's stack)
This commit is contained in:
parent
e60969b37a
commit
1ca8c68cf5
@ -38,11 +38,8 @@ void clock_init(struct registers *regs)
|
||||
static void clock_handler(struct registers *regs)
|
||||
{
|
||||
(void)regs;
|
||||
if (scheduler_counter % 100 == 0) {
|
||||
cli();
|
||||
if (scheduler_counter % 100 == 0)
|
||||
scheduler();
|
||||
toris();
|
||||
}
|
||||
scheduler_counter++;
|
||||
sleep_counter--;
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ static void owo(void)
|
||||
|
||||
static void awa(void)
|
||||
{
|
||||
/* if (fork() < 0) */
|
||||
/* kprintf("camille il a une grosse bite (18cm)\n"); */
|
||||
if (fork() < 0)
|
||||
kprintf("camille il a une grosse bite (18cm)\n");
|
||||
kprintf("awaille\n");
|
||||
/* wait(); */
|
||||
wait();
|
||||
}
|
||||
|
||||
void kernel_main(multiboot_info_t *mbd, u32 magic)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "alloc.h"
|
||||
#include "debug.h"
|
||||
#include "interrupts.h"
|
||||
#include "kprintf.h"
|
||||
#include "task.h"
|
||||
#include "time.h"
|
||||
@ -10,6 +11,7 @@ struct task *current_task;
|
||||
|
||||
void scheduler(void)
|
||||
{
|
||||
cli();
|
||||
if (!current_task) // || current_task->next == current_task)
|
||||
return;
|
||||
struct task *it = current_task->next;
|
||||
@ -22,4 +24,5 @@ void scheduler(void)
|
||||
it = it->next;
|
||||
}
|
||||
switch_to_task(it);
|
||||
toris();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ struct task *create_task(u8 uid)
|
||||
new_task->next = current_task->next;
|
||||
new_task->prev = current_task;
|
||||
current_task->next = new_task;
|
||||
new_task->status = RUN;
|
||||
new_task->uid = uid;
|
||||
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
|
||||
if (!new_task->esp0) {
|
||||
@ -58,7 +59,6 @@ void exec_fn(void (*fn)(void))
|
||||
struct task *new_task = create_task(OWNER_KERNEL);
|
||||
if (!new_task)
|
||||
kpanic("failed to create new task");
|
||||
new_task->status = RUN;
|
||||
new_task->eip = (u32 *)fn;
|
||||
}
|
||||
|
||||
@ -69,9 +69,9 @@ void remove_task(struct task *task)
|
||||
if (task->child)
|
||||
remove_task(task->child);
|
||||
if (task->heap)
|
||||
vfree(task->heap);
|
||||
free_pages(task->heap, 4096);
|
||||
if (task->esp0)
|
||||
vfree(task->esp0);
|
||||
free_pages(task->esp0, STACK_SIZE);
|
||||
task->heap = NULL;
|
||||
task->esp0 = NULL;
|
||||
if (task->status != ZOMBIE) {
|
||||
@ -86,8 +86,11 @@ void exit_task(void)
|
||||
cli();
|
||||
if (current_task->daddy && current_task->daddy->status != WAIT)
|
||||
current_task->status = ZOMBIE;
|
||||
else
|
||||
else {
|
||||
if (current_task->daddy->status == WAIT)
|
||||
current_task->daddy->status = RUN;
|
||||
current_task->status = STOPPED;
|
||||
}
|
||||
toris();
|
||||
asm volatile("jmp scheduler");
|
||||
}
|
||||
|
@ -3,7 +3,15 @@
|
||||
|
||||
u16 wait(void)
|
||||
{
|
||||
if (current_task->child == NULL)
|
||||
return -1;
|
||||
cli();
|
||||
if (current_task->child->status == ZOMBIE)
|
||||
current_task->child->status = STOPPED;
|
||||
else
|
||||
current_task->status = WAIT;
|
||||
u16 child_pid = current_task->child->pid;
|
||||
toris();
|
||||
return 0;
|
||||
scheduler();
|
||||
return child_pid;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user