void segmentation_handler(vaddr_t faultaddress, int faulttype, vaddr_t heap_start, vaddr_t stacktop, vaddr_t segment1_top, vaddr_t segment1_bottom, vaddr_t segment2_top, vaddr_t segment2_bottom ) { /* check the faultaddress within valid region*/ if((faultaddress >= segment1_bottom && faultaddress <= segment1_top)) { /* check protection fault*/ if( faulttype == VM_FAULT_READONLY ) { /*segmentation fault*/ freePid(curthread->pid); thread_exit(); } } else if((faultaddress >= segment2_bottom && faultaddress <= segment2_top)) { /* check protection fault*/ if( faulttype == VM_FAULT_READONLY ) { /*segmentation fault*/ freePid(curthread->pid); thread_exit(); } } /* *temporary work, did not consider malloc heap region */ else if((faultaddress >= heap_start && faultaddress <= stacktop)) { /* check protection fault*/ if( faulttype == VM_FAULT_READONLY ) { /*segmentation fault*/ freePid(curthread->pid); thread_exit(); } } else { /*not in valid region , segmentation fault*/ freePid(curthread->pid); thread_exit(); } }
static void freeAll() { int i = 0; for (i = 0; i < cmpQty; ++i) { freeCompany(cmp[i]); } free(cmp); freeMap(map); freePid(); free(semMsg); free(procQty); }
int waitpid(pid_t pid, int * status, int options, int *wait_pid) { struct process * p_node; int invalid_status_ptr1; int invalid_status_ptr2; int result; invalid_status_ptr1 = 0x80000000; invalid_status_ptr2 = 0x40000000; /* check the validity of parameter pid*/ if(pid > PID_MAX || pid <= 0 || pid > (array_getnum(pid_table) - 1) || options != 0) { return EINVAL; } if(status == NULL || status == (int *)invalid_status_ptr1 || status == (int *)invalid_status_ptr2) { return EFAULT; } /* if we didnot find the specific pid value in our pid_table*/ if(array_getguy(pid_table, pid) == NULL) { kprintf("process does not exist\n"); return EINVAL; } /* parent process can ONLY interested in own child process*/ if(((struct process *)array_getguy(pid_table, pid))->parent_pid != curthread->pid ) { kprintf("parent process NOT interested in own child process\n") ; return EINVAL; } /* get the process guy with specific pid*/ p_node = (struct process *)array_getguy(pid_table, pid); /* check if the child process has exited*/ P(p_node->exit_lock); /* child already really exit*/ /*return the exit code*/ *status = p_node->exit_code; /*return the child process id*/ *wait_pid = pid; result = freePid(pid); if(result) { return result; } return 0; }