summaryrefslogtreecommitdiffstats
path: root/src/userprog
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-02-21 19:55:30 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-02-21 19:56:03 +0100
commit83b6103986c65ad580b4b7f038660bfa01f1d087 (patch)
tree61885e8c578113de674be0ef5352390fd1a62092 /src/userprog
parentec5c4ad0b9cb68c0405728c913c42a3f5f412b37 (diff)
downloadpintos-83b6103986c65ad580b4b7f038660bfa01f1d087.tar.gz
push child to parents list of children
Diffstat (limited to 'src/userprog')
-rw-r--r--src/userprog/process.c24
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. */