diff options
Diffstat (limited to 'src/userprog/process.c')
| -rw-r--r-- | src/userprog/process.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/userprog/process.c b/src/userprog/process.c index 5897c84..5f7448b 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -28,6 +28,7 @@ struct start_process_args // child -> parent bool success; + struct list_elem *child_elem; // list_elem to insert into list of children }; static thread_func start_process NO_RETURN; @@ -41,9 +42,11 @@ tid_t process_execute (const char *file_name) { struct start_process_args args; // stack allocated since we know we wait for thread_create to finish reading + struct thread *t; tid_t tid; - printf("%s starting %s\n", thread_current ()->name, file_name); + t = thread_current (); + printf("%s starting %s\n", t->name, file_name); sema_init (&args.sema, 0); @@ -64,9 +67,11 @@ process_execute (const char *file_name) if (tid != TID_ERROR) { sema_down (&args.sema); - //TODO push to list of children - if (!args.success) + if (args.success) { + list_push_back (&t->children, args.child_elem); + } else { tid = -1; + } } palloc_free_page (args.file_name); return tid; @@ -79,17 +84,26 @@ start_process (void *args_) { struct start_process_args *args = args_; struct intr_frame if_; + struct thread *t; bool success; + t = thread_current (); + /* Initialize interrupt frame and load executable. */ memset (&if_, 0, sizeof if_); if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; if_.cs = SEL_UCSEG; if_.eflags = FLAG_IF | FLAG_MBS; - printf("reading\n"); success = load (args->file_name, &if_.eip, &if_.esp); - args->success = success; + + if (success) { + sema_init (&t->parent.exit_sema, 0); + lock_init (&t->parent.l); + + args->child_elem = &t->parent.elem; + } + sema_up (&args->sema); /* If load failed, quit. */ |
