Skip to content

Commit

Permalink
fixed the buf of p_ofile
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 committed Mar 12, 2011
1 parent 2bfde26 commit 50385d9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int do_open(char *path, uint flag, uint mode){
break;
case S_IFCHR:
(*cdevsw[MAJOR(dev)].d_open)(&tty[MINOR(dev)]);
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kern/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int do_exec(char *path, char **argv){
// close all the file descriptors with FD_CLOEXEC
for (fd=0; fd<NOFILE; fd++) {
fp = cu->p_ofile[fd];
if (fp!=NULL && (fp->f_fdflag & FD_CLOEXEC)) {
if ((fp!=NULL) && (fp->f_fdflag & FD_CLOEXEC)) {
do_close(fd);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/kern/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ struct proc* kspawn(void (*func)()){
fp = cu->p_ofile[fd];
if (fp != NULL) {
fp->f_ino->i_count++;
p->p_ofile[fd] = fp;
}
p->p_ofile[fd] = fp;
}
// signals
p->p_sig = cu->p_sig;
Expand Down Expand Up @@ -133,6 +133,8 @@ int do_fork(struct trap *tf){
* and make current as proc[0]
*/
void proc0_init(){
int fd;

struct proc *p = cu = proc[0] = (struct proc *)(uint) kstack0;
p->p_pid = 0;
p->p_ppid = 0;
Expand All @@ -150,7 +152,9 @@ void proc0_init(){
// init tss
tss.ss0 = KERN_DS;
tss.esp0 = (uint)p + PAGE;
// init its ldt
for (fd=0; fd<NOFILE; fd++){
p->p_ofile[fd] = NULL;
}
}

/* --------------------------------------------------- */
Expand Down
4 changes: 4 additions & 0 deletions src/kern/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ void psig(){
}
// on SIG_DFL
switch(n){
// ignored on default
case SIGCHLD:
case SIGCONT:
return;
// exited on default
case SIGSEGV:
printk("seg fault.\n");
case SIGINT:
case SIGKILL:
default:
Expand Down
16 changes: 6 additions & 10 deletions src/mm/pgfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void do_no_page(uint vaddr){
// else
vp = find_vma(vaddr);
if (vp==NULL) {
printk("vaddr: %x\n", vaddr);
panic("bad mem;");
sigsend(cu->p_pid, SIGSEGV, 1);
return;
}
// demand zero
Expand Down Expand Up @@ -74,8 +73,7 @@ void do_wp_page(uint vaddr){

vp = find_vma(vaddr);
if (vp->v_flag & VMA_RDONLY) {
printk("vaddr: %x\n", vaddr);
panic("do_wp_page(): rdonly vma.");
sigsend(cu->p_pid, SIGSEGV, 1);
return;
}
if (vp->v_flag & VMA_PRIVATE) {
Expand Down Expand Up @@ -108,18 +106,16 @@ void do_pgfault(struct trap *tf){
// invalid page
if ((tf->err_code & PFE_P)==0) {
do_no_page(addr);
return;
return ;
}
// write procted page
if (tf->err_code & PFE_W) {
do_wp_page(addr);
return;
return ;
}
// TODO: raise a signal here, hence segmention fault.
// raise a signal here, hence segmention fault.
if (tf->err_code & PFE_U) {
dump_tf(tf);
//printk("do_pgfault(): eip: %x addr: %x\n", tf->eip, addr);
panic("PFE_U");
sigsend(cu->p_pid, SIGSEGV, 1);
}
}

8 changes: 4 additions & 4 deletions usr/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include <unistd.h>

int main(int argc, char **argv){
uint ret;
uint ret, pid;
if (fork()==0) {
exec("/bin/hello", NULL);
return 0;
exec("/bin/test_exit", NULL);
}
while(1) {
waitpid(0, &ret, 0);
pid = waitpid(0, &ret, 0);
printf("%d exited (%x)\n", pid, ret);
}
}
7 changes: 4 additions & 3 deletions usr/test_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ int main(int argc, char **argv) {
printf("child2\n");
_exit(0);
}
while(1){
pid = wait(&ret);
printf("--pid:%d ret:%x\n", pid, ret);
if (fork()==0){
int *badmem = (int *)0;
*badmem = 1;
printf("so bad~~~\n");
}
return 1;
}

0 comments on commit 50385d9

Please sign in to comment.