Update process_init_stack to return success, refactoring error handling to occur inside start_process
This commit is contained in:
@@ -60,8 +60,7 @@ process_execute (const char *file_name)
|
|||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_init_stack (void *file_name_, char *saveptr, void **esp,
|
static bool process_init_stack (char *saveptr, void **esp, char *file_name);
|
||||||
char *file_name);
|
|
||||||
static void *push_to_stack (void **esp, void *data, size_t data_size);
|
static void *push_to_stack (void **esp, void *data, size_t data_size);
|
||||||
|
|
||||||
/* A thread function that loads a user process and starts it
|
/* A thread function that loads a user process and starts it
|
||||||
@@ -97,8 +96,17 @@ start_process (void *file_name_)
|
|||||||
thread_exit ();
|
thread_exit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
process_init_stack (file_name_, saveptr, &if_.esp, file_name);
|
/* Initialize user process stack and free page used to store the
|
||||||
|
command that executed the process. */
|
||||||
|
success = process_init_stack (saveptr, &if_.esp, file_name);
|
||||||
palloc_free_page (file_name_);
|
palloc_free_page (file_name_);
|
||||||
|
|
||||||
|
/* If stack initialization failed, free resources and quit. */
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
process_exit ();
|
||||||
|
thread_exit ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Start the user process by simulating a return from an
|
/* Start the user process by simulating a return from an
|
||||||
interrupt, implemented by intr_exit (in
|
interrupt, implemented by intr_exit (in
|
||||||
@@ -111,10 +119,9 @@ start_process (void *file_name_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function that initializes the stack of a newly created
|
/* Helper function that initializes the stack of a newly created
|
||||||
user process. */
|
user process. Returns true if successful, false otherwise. */
|
||||||
static void
|
static bool
|
||||||
process_init_stack (void *file_name_, char *saveptr, void **esp,
|
process_init_stack (char *saveptr, void **esp, char *file_name)
|
||||||
char *file_name)
|
|
||||||
{
|
{
|
||||||
/* Load command line argument *data* to user process stack.
|
/* Load command line argument *data* to user process stack.
|
||||||
This can't cause overflow due to enforcing that the size of
|
This can't cause overflow due to enforcing that the size of
|
||||||
@@ -134,9 +141,7 @@ process_init_stack (void *file_name_, char *saveptr, void **esp,
|
|||||||
{
|
{
|
||||||
printf("ERROR: Couldn't allocate argument pointer memory for %s!\n",
|
printf("ERROR: Couldn't allocate argument pointer memory for %s!\n",
|
||||||
thread_current ()->name);
|
thread_current ()->name);
|
||||||
palloc_free_page (file_name_);
|
return false;
|
||||||
process_exit ();
|
|
||||||
thread_exit ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_elem->arg = *esp;
|
arg_elem->arg = *esp;
|
||||||
@@ -196,11 +201,12 @@ process_init_stack (void *file_name_, char *saveptr, void **esp,
|
|||||||
/* Push fake return address (null pointer). */
|
/* Push fake return address (null pointer). */
|
||||||
*esp -= sizeof (char *);
|
*esp -= sizeof (char *);
|
||||||
*(char *) *esp = 0;
|
*(char *) *esp = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function that pushes the first 'data_size' bytes stored in the
|
/* Helper function that pushes the first 'data_size' bytes stored in the
|
||||||
address '*data' into the stack given a pointer to the stack pointer
|
address '*data' into the stack given a pointer to the stack pointer '**esp'. */
|
||||||
'**esp'. */
|
|
||||||
static void *
|
static void *
|
||||||
push_to_stack (void **esp, void *data, size_t data_size)
|
push_to_stack (void **esp, void *data, size_t data_size)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user