/** * * Terminate the current process (maybe). If the current process has * more than one running thread, only terminate the current thread. * The process is only completely terminated (as per process_join * wakeup and page table deallocation) when the final thread calls * process_finish(). * * @param The return value of the process. This is only used when the * final thread exits. * */ void process_finish(int retval) { interrupt_status_t intr_status; thread_table_t *thread = thread_get_current_thread_entry(); process_id_t pid = thread->process_id; if (retval < 0) { /* Not permitted! */ retval = 0; } intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); /* Mark the stack as free so new threads can reuse it. */ process_free_stack(thread); if (--process_table[pid].threads == 0) { /* We are the last thread - kill process! */ vm_destroy_pagetable(thread->pagetable); finish_given_process(pid, retval); } thread->pagetable = NULL; spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); thread_finish(); }
void process_run(process_id_t pid) { context_t user_context; thread_table_t *my_thread = thread_get_current_thread_entry(); /* If my process is a zombie, that means initialisation failed. */ if (process_table[pid].state == PROCESS_ZOMBIE) { if (my_thread->pagetable) { vm_destroy_pagetable(my_thread->pagetable); my_thread->pagetable = NULL; } thread_finish(); } process_set_pagetable(my_thread->pagetable); my_thread->process_id = pid; my_thread->pagetable = my_thread->pagetable; /* Initialize the user context. (Status register is handled by thread_goto_userland) */ memoryset(&user_context, 0, sizeof(user_context)); _context_set_ip(&user_context, process_table[pid].entry_point); _context_set_sp(&user_context, process_table[pid].stack_top); thread_goto_userland(&user_context); }
void process_finish(int retval) { interrupt_status_t intr_status; thread_table_t *thr = thread_get_current_thread_entry(); process_id_t pid = process_get_current_process(); int i; // remove parent references in other processes for (i = 0; i < PROCESS_MAX_PROCESSES; ++i) { intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); if (process_table[i].parent_id == pid) process_table[i].parent_id = -1; spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); } intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); process_table[pid].retval = retval; process_table[pid].state = PROCESS_ZOMBIE; spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); // clean up virtual memory vm_destroy_pagetable(thr->pagetable); thr->pagetable = NULL; thread_finish(); }
/* Stop the process and the thread it runs in. Sets the return value as well */ void process_finish(int retval) { thread_table_t *thr; thr = thread_get_current_thread_entry(); process_table[process_get_current_process()].state = ZOMBIE; process_table[process_get_current_process()].retval = retval; vm_destroy_pagetable(thr->pagetable); thr->pagetable = NULL; thread_finish(); }
/* Stop the current process and the kernel thread in which it runs Argument: return value */ void process_exit(int retval){ process_id_t pid; thread_table_t * thr; kprintf("starten af exit. reval: %d \n",retval); if (retval < 0){ return; } // gets the process id pid = process_get_current_process(); thr = thread_get_current_thread_entry(); //spinlock spinlock_acquire(&process_table_slock); //Disbale interrupt _interrupt_set_state(_interrupt_disable()); // set the process state to ZOMBIE process_table[pid].state = STATE_ZOMBIE; // Set the process retval to given retval process_table[pid].retval = retval; //cleanup vm_destroy_pagetable(thr->pagetable); thr->pagetable = NULL; /* Wake process */ sleepq_wake_all(&process_table[pid]); /* Unlock the process table */ spinlock_release(&process_table_slock); //enable interrupts _interrupt_set_state(_interrupt_disable()); kprintf("slutningen af exit :O \n"); thread_finish(); }
void process_finish(int retval) { interrupt_status_t intr_status; process_id_t cur = process_get_current_process(); thread_table_t *thread = thread_get_current_thread_entry(); intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); process_table[cur].state = PROCESS_ZOMBIE; process_table[cur].retval = retval; /* Remember to destroy the pagetable! */ vm_destroy_pagetable(thread->pagetable); thread->pagetable = NULL; sleepq_wake_all(&process_table[cur]); spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); thread_finish(); }
/** * Terminates the current process and sets a return value */ void process_finish(uint32_t retval) { interrupt_status_t intr_status; process_id_t pid; thread_table_t *my_thread; // Find out who we are. pid = process_get_current_process(); my_thread = thread_get_current_thread_entry(); // Ensure that we're the only ones touching the process table. intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); // Mark the stack as free so new threads can reuse it. process_free_stack(my_thread); if(--process_table[pid].threads == 0) { // Last thread in process; now we die. // Mark ourself as dying. process_table[pid].retval = retval; process_table[pid].state = PROCESS_DYING; vm_destroy_pagetable(my_thread->pagetable); // Wake whomever may be sleeping for the process sleepq_wake(&process_table[pid]); } // Free our locks. spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); my_thread->pagetable = NULL; // Kill the thread. thread_finish(); }
/** * * Terminate the current process (maybe). If the current process has * more than one running thread, only terminate the current thread. * The process is only completely terminated (as per process_join * wakeup and page table deallocation) when the final thread calls * process_finish(). * * @param The return value of the process. This is only used when the * final thread exits. * */ void process_finish(int retval) { interrupt_status_t intr_status; thread_table_t *thread = thread_get_current_thread_entry(); process_id_t pid = thread->process_id; if (retval < 0) { /* Not permitted! */ retval = 0; } intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); vm_destroy_pagetable(thread->pagetable); finish_given_process(pid, retval); thread->pagetable = NULL; spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); thread_finish(); }