Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void
- start_process (void *file_name_)
- {
- lock_acquire(&process_load_lock);
- char *file_name = file_name_;
- struct intr_frame if_;
- bool success;
- int nrOfArgs = -1;
- /* Initialize interrupt frame and load executable. */
- memset (&if_, 0, sizeof if_);
- if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
- if_.cs = SEL_UCSEG;
- if_.eflags = FLAG_IF | FLAG_MBS;
- char *token, *save_ptr;
- int i = 0;
- for (i=0,token = strtok_r (file_name, " ", &save_ptr);i<MAX_NR_ARGS && token != NULL; i++, token = strtok_r (NULL, " ", &save_ptr))
- {
- argv_global[i] = token;
- }
- nrOfArgs = i;
- success = load (file_name, &if_.eip, &if_.esp);
- if(success)
- {
- int tokenSize = 0;
- for(i= nrOfArgs-1 ; i>=0; i-- )
- {
- tokenSize = strlen( argv_global[i] );
- if_.esp = if_.esp - (tokenSize+1);
- strlcpy((char*)(if_.esp), argv_global[i], PGSIZE);
- argv_global[i] = (char*)(if_.esp);
- //printf("start address of array %i = %x\n",i,(int)(argv_global[i]));
- }
- int stackAddr = (int)(if_.esp);
- /* the only solution we found to word align the code ROUND_DOWN does not work , \
- * probably because of some compiler optimization*/
- while(stackAddr%4 != 0)
- {
- stackAddr--;
- *((char*)stackAddr) = 0;
- }
- if_.esp = (void*)stackAddr;
- if_.esp = if_.esp - 4;
- *((int*)if_.esp) = 0;
- for(i= nrOfArgs-1 ; i>=0; i-- )
- {
- if_.esp = if_.esp - 4;
- *((int*)if_.esp)= (int)argv_global[i];
- }
- //we save the address of argv
- stackAddr = (int)if_.esp;
- //we put argv on the stack
- if_.esp = if_.esp - 4;
- *((int*)if_.esp) = stackAddr;
- //we put argc on the stack
- if_.esp = if_.esp - 4;
- *((int*)if_.esp) = nrOfArgs;
- //we put the return address on the stack
- if_.esp = if_.esp - 4;
- *((int*)if_.esp) = 0;
- }
- for(i =0 ; i< MAX_NR_ARGS; i++ )
- argv_global[i] = NULL;
- lock_release(&process_load_lock);
- /* If load failed, quit. */
- palloc_free_page (file_name);
- thread_current()->statusForParent->loaded = success;
- sema_up(&thread_current()->statusForParent->sem);
- if (!success)
- thread_exit ();
- /* Start the user process by simulating a return from an
- interrupt, implemented by intr_exit (in
- threads/intr-stubs.S). Because intr_exit takes all of its
- arguments on the stack in the form of a `struct intr_frame',
- we just point the stack pointer (%esp) to our stack frame
- and jump to it. */
- asm volatile ("movl %0, %%esp; jmp intr_exit" : : "g" (&if_) : "memory");
- NOT_REACHED ();
- }
Add Comment
Please, Sign In to add comment