Skip to content
Snippets Groups Projects
Commit 8913470e authored by y2-rhymansaib's avatar y2-rhymansaib
Browse files

split strtok_r and saved the first argument as the pro_name

established the setup_stack to include the argv and argc
parent de55c026
No related branches found
No related tags found
No related merge requests found
......@@ -36,13 +36,17 @@ process_execute (const char *file_name)
fn_copy = palloc_get_page (0);
if (fn_copy == NULL)
return TID_ERROR;
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)
if (tid == TID_ERROR){
palloc_free_page (fn_copy);
}
return tid;
}
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment