int wait_pids() { struct trace_data data; int count, continued, terminated; pid_t pid; int wait_status; a_flagged_each(&waitproc_options.pids, &attach_process, trace_data_init(&data)); waitproc_flags_setc(WAITPROC_FLAG_ERROROCCURED, data.error_occured); if (data.count <= 0) return data.count; count = data.count; if (waitproc_flags_test(WAITPROC_FLAG_TERMINATE)) { data.target_state = STATE_ATTACHED; data.d.signal = termination_signals; a_flagged_each(&waitproc_options.pids, &send_signal, trace_data_init(&data)); waitproc_flags_setc(WAITPROC_FLAG_ERROROCCURED, data.error_occured); if (data.count <= 0) return data.count; } continued = 0; terminated = 0; do { pid = waitpid(-1, &wait_status, WUNTRACED); } while (handle_wait(pid, wait_status, count, &continued, &terminated)); if (waitproc_flags_test(WAITPROC_FLAG_KILL)) { data.target_state = STATE_TERMINATED; data.d.trace_type = PTRACE_KILL; terminated = count; } else { data.target_state = STATE_DETACHED; data.d.trace_type = PTRACE_DETACH; } a_flagged_each(&waitproc_options.pids, &detach_process, trace_data_init(&data)); waitproc_flags_setc(WAITPROC_FLAG_ERROROCCURED, data.error_occured); return terminated; }
/* * System call handler * * retrieves system call number from user space * and invokes the requested method */ static void syscall_handler (struct intr_frame *f) { /* retrieve system call number and switch to corresponding method */ unsigned int syscall_number = *((unsigned int*) syscall_get_kernel_address(f->esp)); switch(syscall_number) { /* process system calls */ case SYS_HALT: handle_halt(f); break; case SYS_EXIT: handle_exit(f); break; case SYS_EXEC: handle_exec(f); break; case SYS_WAIT: handle_wait(f); break; /* file system calls */ case SYS_CREATE: handle_create(f); break; case SYS_REMOVE: handle_remove(f); break; case SYS_OPEN: handle_open(f); break; case SYS_FILESIZE: handle_filesize(f); break; case SYS_READ: handle_read(f); break; case SYS_WRITE: handle_write(f); break; case SYS_SEEK: handle_seek(f); break; case SYS_TELL: handle_tell(f); break; case SYS_CLOSE: handle_close(f); break; case SYS_CHDIR: handle_chdir(f); break; case SYS_MKDIR: handle_mkdir(f); break; case SYS_READDIR: handle_readdir(f); break; case SYS_ISDIR: handle_isdir(f); break; case SYS_INUMBER: handle_inumber(f); break; default: /* SYSCALL_ERROR: */ handle_no_such_syscall(f); break; } }