From ec5c4ad0b9cb68c0405728c913c42a3f5f412b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 21 Feb 2021 19:34:35 +0100 Subject: child reports success of load to parent --- src/userprog/process.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/userprog/process.c') diff --git a/src/userprog/process.c b/src/userprog/process.c index 437d6c0..5897c84 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -25,6 +25,9 @@ struct start_process_args // parent -> child char *file_name; + + // child -> parent + bool success; }; static thread_func start_process NO_RETURN; @@ -55,11 +58,15 @@ process_execute (const char *file_name) If thread_create fails we free and return immediately since we know that the thread didn't start. Otherwise, the child thread can be scheduled freely so we explicitly - wait for the child to signal that it has read the args. Only then can - we free resources and return the tid. */ + wait for the child to signal that it has read from and written to + the args. Only then can we free resources and return the tid. */ tid = thread_create (file_name, PRI_DEFAULT, start_process, &args); if (tid != TID_ERROR) { sema_down (&args.sema); + + //TODO push to list of children + if (!args.success) + tid = -1; } palloc_free_page (args.file_name); return tid; @@ -82,15 +89,12 @@ start_process (void *args_) printf("reading\n"); success = load (args->file_name, &if_.eip, &if_.esp); + args->success = success; sema_up (&args->sema); /* If load failed, quit. */ - if (success) { - //TODO report success - } else { - //TODO report failure + if (!success) thread_exit (); - } /* Start the user process by simulating a return from an interrupt, implemented by intr_exit (in -- cgit v1.2.1