diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 13:38:00 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 13:38:00 +0200 |
| commit | d517f3d39142615ec3db9925f4db848d52817ebf (patch) | |
| tree | e349d6501c554d791666db02c5e3ab6562dfb016 | |
| parent | e5411659d94a35bbf329164928408b34afa3f201 (diff) | |
| download | progos-d517f3d39142615ec3db9925f4db848d52817ebf.tar.gz progos-d517f3d39142615ec3db9925f4db848d52817ebf.tar.bz2 progos-d517f3d39142615ec3db9925f4db848d52817ebf.zip | |
userprocess threads should be named by their executable and not their
full commandline string
| -rw-r--r-- | env.sh | 2 | ||||
| -rw-r--r-- | userprog/process.c | 25 |
2 files changed, 14 insertions, 13 deletions
| @@ -1,3 +1,3 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | export PATH="$PATH:$(dirname "${BASH_SOURCE[0]}")/utils" | 2 | export PATH="$PATH:$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/utils" |
| 3 | export PATH="/opt/bochs/bin:$PATH" | 3 | export PATH="/opt/bochs/bin:$PATH" |
diff --git a/userprog/process.c b/userprog/process.c index adb6b66..af7e0b3 100644 --- a/userprog/process.c +++ b/userprog/process.c | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | /* data structure to communicate with the thread initializing a new process */ | 22 | /* data structure to communicate with the thread initializing a new process */ |
| 23 | struct start_aux_data { | 23 | struct start_aux_data { |
| 24 | char *filename; | 24 | char *args; |
| 25 | struct semaphore startup_sem; | 25 | struct semaphore startup_sem; |
| 26 | struct thread *parent_thread; | 26 | struct thread *parent_thread; |
| 27 | struct process *new_process; | 27 | struct process *new_process; |
| @@ -32,7 +32,7 @@ struct lock filesys_lock; | |||
| 32 | 32 | ||
| 33 | /* prototypes */ | 33 | /* prototypes */ |
| 34 | static thread_func start_process NO_RETURN; | 34 | static thread_func start_process NO_RETURN; |
| 35 | static bool load (char *filename, void (**eip) (void), void **esp); | 35 | static bool load (char *args, void (**eip) (void), void **esp); |
| 36 | static bool setup_stack (void **esp); | 36 | static bool setup_stack (void **esp); |
| 37 | static bool init_fd_table (struct fd_table * table); | 37 | static bool init_fd_table (struct fd_table * table); |
| 38 | 38 | ||
| @@ -64,25 +64,27 @@ process_current () | |||
| 64 | and support command strings such as "echo A B C". You | 64 | and support command strings such as "echo A B C". You |
| 65 | will also need to change `load` and `setup_stack`. */ | 65 | will also need to change `load` and `setup_stack`. */ |
| 66 | tid_t | 66 | tid_t |
| 67 | process_execute (const char *filename) | 67 | process_execute (const char *cmd) |
| 68 | { | 68 | { |
| 69 | tid_t tid = TID_ERROR; | 69 | tid_t tid = TID_ERROR; |
| 70 | char *fn_copy = NULL; | 70 | char *fn_copy = NULL; |
| 71 | struct start_aux_data *aux_data = NULL; | 71 | struct start_aux_data *aux_data = NULL; |
| 72 | char *name, *args; | ||
| 72 | 73 | ||
| 73 | /* Setup the auxiliary data for starting up the new process */ | 74 | /* Setup the auxiliary data for starting up the new process */ |
| 74 | fn_copy = palloc_get_page (0); | 75 | fn_copy = palloc_get_page (0); |
| 75 | aux_data = palloc_get_page (0); | 76 | aux_data = palloc_get_page (0); |
| 76 | if (aux_data == NULL || fn_copy == NULL) | 77 | if (aux_data == NULL || fn_copy == NULL) |
| 77 | goto done; | 78 | goto done; |
| 78 | strlcpy (fn_copy, filename, PGSIZE); | 79 | strlcpy (fn_copy, cmd, PGSIZE); |
| 79 | aux_data->filename = fn_copy; | 80 | name = strtok_r (fn_copy, " ", &args); |
| 81 | aux_data->args = args; | ||
| 80 | aux_data->parent_thread = thread_current (); | 82 | aux_data->parent_thread = thread_current (); |
| 81 | aux_data->new_process = NULL; | 83 | aux_data->new_process = NULL; |
| 82 | sema_init (&aux_data->startup_sem, 0); | 84 | sema_init (&aux_data->startup_sem, 0); |
| 83 | 85 | ||
| 84 | /* Create a new thread to execute FILE_NAME. */ | 86 | /* Create a new thread to execute FILE_NAME. */ |
| 85 | tid = thread_create (fn_copy, PRI_DEFAULT, start_process, aux_data); | 87 | tid = thread_create (name, PRI_DEFAULT, start_process, aux_data); |
| 86 | if (tid == TID_ERROR) | 88 | if (tid == TID_ERROR) |
| 87 | goto done; | 89 | goto done; |
| 88 | 90 | ||
| @@ -131,7 +133,7 @@ start_process (void *aux) | |||
| 131 | if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; | 133 | if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; |
| 132 | if_.cs = SEL_UCSEG; | 134 | if_.cs = SEL_UCSEG; |
| 133 | if_.eflags = FLAG_IF | FLAG_MBS; | 135 | if_.eflags = FLAG_IF | FLAG_MBS; |
| 134 | if (! load (aux_data->filename, &if_.eip, &if_.esp)) { | 136 | if (! load (aux_data->args, &if_.eip, &if_.esp)) { |
| 135 | thread->process = NULL; | 137 | thread->process = NULL; |
| 136 | } else { | 138 | } else { |
| 137 | aux_data->new_process = thread->process; | 139 | aux_data->new_process = thread->process; |
| @@ -347,13 +349,12 @@ static bool load_segment (struct file *file, off_t ofs, uint8_t *upage, | |||
| 347 | uint32_t read_bytes, uint32_t zero_bytes, | 349 | uint32_t read_bytes, uint32_t zero_bytes, |
| 348 | bool writable); | 350 | bool writable); |
| 349 | 351 | ||
| 350 | /* Loads an ELF executable from file_name (the first word of | 352 | /* Loads an ELF executable from t->name into the current thread. |
| 351 | cmd) into the current thread. | ||
| 352 | Stores the executable's entry point into *EIP | 353 | Stores the executable's entry point into *EIP |
| 353 | and its initial stack pointer into *ESP. | 354 | and its initial stack pointer into *ESP. |
| 354 | Returns true if successful, false otherwise. */ | 355 | Returns true if successful, false otherwise. */ |
| 355 | bool | 356 | bool |
| 356 | load (char *file_name, void (**eip) (void), void **esp) | 357 | load (char *args, void (**eip) (void), void **esp) |
| 357 | { | 358 | { |
| 358 | struct thread *t = thread_current (); | 359 | struct thread *t = thread_current (); |
| 359 | struct Elf32_Ehdr ehdr; | 360 | struct Elf32_Ehdr ehdr; |
| @@ -372,7 +373,7 @@ load (char *file_name, void (**eip) (void), void **esp) | |||
| 372 | lock_acquire (&filesys_lock); | 373 | lock_acquire (&filesys_lock); |
| 373 | 374 | ||
| 374 | /* Open executable file. */ | 375 | /* Open executable file. */ |
| 375 | file = filesys_open (file_name); | 376 | file = filesys_open (t->name); |
| 376 | if (file == NULL) | 377 | if (file == NULL) |
| 377 | goto done; | 378 | goto done; |
| 378 | 379 | ||
| @@ -388,7 +389,7 @@ load (char *file_name, void (**eip) (void), void **esp) | |||
| 388 | || ehdr.e_phentsize != sizeof (struct Elf32_Phdr) | 389 | || ehdr.e_phentsize != sizeof (struct Elf32_Phdr) |
| 389 | || ehdr.e_phnum > 1024) | 390 | || ehdr.e_phnum > 1024) |
| 390 | { | 391 | { |
| 391 | printf ("load: %s: error loading executable\n", file_name); | 392 | printf ("load: %s: error loading executable\n", t->name); |
| 392 | goto done; | 393 | goto done; |
| 393 | } | 394 | } |
| 394 | 395 | ||
