firework and report

This commit is contained in:
ridethepig 2022-11-30 10:21:29 +08:00
parent f886476139
commit ce1293fd48
3 changed files with 9 additions and 20 deletions

Binary file not shown.

View File

@ -127,6 +127,7 @@ kern_fork(PROCESS_0 *p_fa)
xchg(&p_fa->lock, 0); xchg(&p_fa->lock, 0);
return -EAGAIN; return -EAGAIN;
} }
assert(proc_child->pcb.lock == 0);
while (xchg(&proc_child->pcb.lock, 1) == 1) while (xchg(&proc_child->pcb.lock, 1) == 1)
schedule(); schedule();
PROCESS_0 *p_child = &proc_child->pcb; PROCESS_0 *p_child = &proc_child->pcb;
@ -150,7 +151,7 @@ kern_fork(PROCESS_0 *p_fa)
// p_fa shares the same base addr as its padding // p_fa shares the same base addr as its padding
// anyways, copy the whole proc_table item(8K?) // anyways, copy the whole proc_table item(8K?)
DISABLE_INT(); // make sure this process is never interrupted DISABLE_INT(); // make sure this process is never interrupted
memset(proc_child, 0, sizeof(PROCESS)); // clear child's kernel stack // memset(proc_child, 0, sizeof(PROCESS)); // clear child's kernel stack //? seem to be useless
// the commented fields below will be set later // the commented fields below will be set later
// p_child->cr3 // p_child->cr3
p_child->exit_code = p_fa->exit_code; p_child->exit_code = p_fa->exit_code;
@ -163,7 +164,7 @@ kern_fork(PROCESS_0 *p_fa)
p_child->statu = INITING; //! important!!! if you copied this from parent, haha, waste one hour p_child->statu = INITING; //! important!!! if you copied this from parent, haha, waste one hour
p_child->ticks = p_fa->ticks; p_child->ticks = p_fa->ticks;
p_child->user_regs = p_fa->user_regs; p_child->user_regs = p_fa->user_regs;
ENABLE_INT(); ENABLE_INT(); // TODO: may be a useless atomic block, try to remove and test again
//? 2. ALLOC PAGES AND COPY PHYSICAL MEMORY //? 2. ALLOC PAGES AND COPY PHYSICAL MEMORY
copy_parent_pages(p_child, p_fa); copy_parent_pages(p_child, p_fa);
// panic("Unimplement! soul torture1"); // panic("Unimplement! soul torture1");

View File

@ -21,18 +21,6 @@ on failure, -1 is returned.
ssize_t ssize_t
kern_wait(int *wstatus) kern_wait(int *wstatus)
{ {
// 相比于fork来说wait的实现简单很多
// 语义实现比较清晰没有fork那么多难点要处理所以这里并不会给大家太多引导
// 需要大家自己思考wait怎么实现。
// 在实现之前你必须得读一遍文档`man 2 wait`
// 了解到wait大概要做什么
// panic("Unimplement! Read The F**king Manual");
// 当然读文档是一方面,最重要的还是代码实现
// wait系统调用与exit系统调用关系密切所以在实现wait之前需要先读一遍exit为好
// 可能读完exit的代码你可能知道wait该具体做什么了
// panic("Unimplement! Read The F**king Source Code");
again: again:
while (xchg(&p_proc_ready->pcb.lock, 1) == 1) while (xchg(&p_proc_ready->pcb.lock, 1) == 1)
schedule(); schedule();
@ -44,8 +32,6 @@ again:
return -ECHILD; return -ECHILD;
} }
assert(p_son->pre == NULL); // make sure it is the head of the list assert(p_son->pre == NULL); // make sure it is the head of the list
while (p_son != NULL) {
if (p_son->p_son->statu == ZOMBIE) {
/* /*
struct s_proc { struct s_proc {
user_regs; // let it be user_regs; // let it be
@ -61,6 +47,8 @@ ticks; // let it be
fork_tree; // already cleared fork_tree; // already cleared
}; };
*/ */
while (p_son != NULL) {
if (p_son->p_son->statu == ZOMBIE) {
while (xchg(&p_son->p_son->lock, 1) == 1) while (xchg(&p_son->p_son->lock, 1) == 1)
schedule(); schedule();
// just use this value, which is '(status & 0xFF) << 8' in exit.c::do_exit // just use this value, which is '(status & 0xFF) << 8' in exit.c::do_exit
@ -68,8 +56,6 @@ fork_tree; // already cleared
*wstatus = p_son->p_son->exit_code; *wstatus = p_son->p_son->exit_code;
// recycle_pages in pmap.c // recycle_pages in pmap.c
recycle_pages(p_son->p_son->page_list); recycle_pages(p_son->p_son->page_list);
// free it in proc table, 'cause in fork I judge free by statu
p_son->p_son->statu = IDLE;
// remove p_son from p_fa's son list // remove p_son from p_fa's son list
if (p_son->pre != NULL) { if (p_son->pre != NULL) {
p_son->pre->nxt = p_son->nxt; p_son->pre->nxt = p_son->nxt;
@ -82,14 +68,16 @@ fork_tree; // already cleared
} }
// keep p_son's pid for retval, 'cause the pointer will get freed before return // keep p_son's pid for retval, 'cause the pointer will get freed before return
child_pid = p_son->p_son->pid; child_pid = p_son->p_son->pid;
xchg(&p_son->p_son->lock, 0);
kfree(p_son); kfree(p_son);
// free it in proc table, 'cause in fork I judge free by statu
xchg(&proc_table[child_pid].pcb.lock, 0);
proc_table[child_pid].pcb.statu = IDLE; // ! set status be the last state, or die
goto done; goto done;
} }
p_son = p_son->nxt; p_son = p_son->nxt;
} }
p_fa->statu = SLEEP;
xchg(&p_fa->lock, 0); xchg(&p_fa->lock, 0);
p_fa->statu = SLEEP; //! sleep after release lock, or it will deadlock
schedule(); schedule();
goto again; goto again;
// 接下来就是你自己的实现了,我们在设计的时候这段代码不会有太大问题 // 接下来就是你自己的实现了,我们在设计的时候这段代码不会有太大问题