diff --git a/src/userprog/process.c b/src/userprog/process.c index d51339a4aff8ec7aae340ae87035ef64358853fd..1ff6873e2db5a2534d1fda1f92375cdd3e5767c5 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -36,15 +36,19 @@ process_execute (const char *file_name) fn_copy = palloc_get_page (0); if (fn_copy == NULL) return TID_ERROR; - strlcpy (fn_copy, file_name, PGSIZE); + + char *save_ptr, *pro_name; /*extracting file name from cmd*/ + strlcpy (fn_copy, file_name, PGSIZE); + pro_name = strtok_r(file_name, " ", &save_ptr);/*cuts the file_name and saves the first argument as real name */ /* Create a new thread to execute FILE_NAME. */ - tid = thread_create (file_name, PRI_DEFAULT, start_process, fn_copy); + tid = thread_create (pro_name, PRI_DEFAULT, start_process, fn_copy); - if (tid == TID_ERROR) - palloc_free_page (fn_copy); - return tid; + if (tid == TID_ERROR){ + palloc_free_page (fn_copy); } + return tid; + } /* A thread function that loads a user process and starts it running. */ @@ -119,6 +123,7 @@ process_exit (void) pagedir_activate (NULL); pagedir_destroy (pd); } + printf ("%s: exit(%d)\n", cur->name, cur->exit_code); /*prints out program name and exit code*/ } /* Sets up the CPU for running user code in the current @@ -197,10 +202,12 @@ struct Elf32_Phdr /* Flags for p_flags. See [ELF3] 2-3 and 2-4. */ #define PF_X 1 /* Executable. */ -#define PF_W 2 /* Writable. */ +/bin/bash: :q: command not found #define PF_R 4 /* Readable. */ -static bool setup_stack (void **esp); +static bool setup_stack (void **esp, char **argv, int argc);/* argv(listing all arguments) + argc(no. of arguments passed including program name*/ + static bool validate_segment (const struct Elf32_Phdr *, struct file *); static bool load_segment (struct file *file, off_t ofs, uint8_t *upage, uint32_t read_bytes, uint32_t zero_bytes, @@ -219,6 +226,24 @@ load (const char *file_name, void (**eip) (void), void **esp) off_t file_ofs; bool success = false; int i; + struct kernel_thread_frame *kf + + char file_name_echo[100]; + strlcpy(file_name_echo, file_name, 100); + char *pro_name = file_name; + char *argv[255]; + int argc; + char *save_ptr; + + argv[0] = strtok_r(file_name, " ", &save_ptr); + + if (DEBUG) printf("1st strtok_r\n); + char *token; + argc = 1; + + while((token = strtok_r(NULL, " ", &save_ptr))!=NULL){ + argv[argc++] = token; + } /* Allocate and activate page directory. */ t->pagedir = pagedir_create (); @@ -231,7 +256,6 @@ load (const char *file_name, void (**eip) (void), void **esp) if (file == NULL) { - printf ("load: %s: open failed\n", file_name); goto done; } @@ -308,7 +332,7 @@ load (const char *file_name, void (**eip) (void), void **esp) } /* Set up stack. */ - if (!setup_stack (esp)) + if (!setup_stack (esp, argv, argc)) goto done; /* Start address. */ @@ -433,7 +457,7 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage, /* Create a minimal stack by mapping a zeroed page at the top of user virtual memory. */ static bool -setup_stack (void **esp) +setup_stack (void **esp, char **argv, int argc) { uint8_t *kpage; bool success = false; @@ -444,6 +468,10 @@ setup_stack (void **esp) success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true); if (success) { *esp = PHYS_BASE; + int i = argc; + uint32_t *arr[argc]; + + } else palloc_free_page (kpage); }