int io_select(int64_t *remain, int64_t *timeout) { struct timeval tv; struct timeval *tp = NULL; int ret, i; /* timeout is present, set timeout pointer */ if(timeout) if(*timeout >= 0LL) { timer_to_timeval(&tv, (uint64_t *)timeout); tp = &tv; } /* Do the actual select() */ io_rfds_r = io_rfds; io_wfds_r = io_wfds; io_efds_r = io_efds; ret = syscall_select(io_top + 1, &io_rfds_r, &io_wfds_r, &io_efds_r, tp); /* Update system time */ timer_update(); /* Now set the returned events */ if(io_top >= 0) for(i = 0; i <= io_top; i++) { if(!io_list[i].type) continue; io_set_revents(i); } /* If there was timeout value then return remaining time */ if(tp && remain) timer_to_msec((uint64_t *)remain, tp); return ret; }
/** @brief Handles all syscalls of the tracked pid until it does a blocking action. * * Blocking actions are stuff that must be reported to the simulator and which * completion takes time. The most prominent examples are related to sending and * receiving data. * * The tracked pid can run more than one syscall in this function if theses calls * are about the metadata that we maintain in simterpose without exposing them to * simgrid. For example, if you call socket() or accept(), we only have to maintain * our metadata but there is no need to inform the simulator, nor to ask for the * completion time of these things. */ int process_handle(process_descriptor_t * proc) { reg_s arg; pid_t pid = proc->pid; XBT_DEBUG("PROCESS HANDLE MSG"); while (1) { ptrace_get_register(pid, &arg); int ret; XBT_DEBUG("found syscall: [%d] %s (%ld) = %ld, in_syscall = %d", pid, syscall_list[arg.reg_orig], arg.reg_orig, arg.ret, proc->in_syscall); switch (arg.reg_orig) { case SYS_creat: syscall_creat(&arg, proc); break; case SYS_open: XBT_DEBUG("On open"); XBT_DEBUG("Valeur des registres dans l'AS:"); XBT_DEBUG("Valeur de retour %lu", arg.ret); XBT_DEBUG("Valeur des arg %lu %lu %lu %lu %lu %lu", arg.arg[0], arg.arg[1], arg.arg[2], arg.arg[3], arg.arg[4], arg.arg[5]); syscall_open(&arg, proc); break; case SYS_close: syscall_close(&arg, proc); break; case SYS_read: syscall_read(&arg, proc); break; case SYS_write: XBT_DEBUG("On write"); XBT_DEBUG("Valeur des registres dans l'AS:"); XBT_DEBUG("Valeur de retour %lu", arg.ret); XBT_DEBUG("Valeur des arg %lu %lu %lu %lu %lu %lu", arg.arg[0], arg.arg[1], arg.arg[2], arg.arg[3], arg.arg[4], arg.arg[5]); if ((ret = syscall_write(&arg, proc))) return ret; break; case SYS_dup: syscall_dup(&arg, proc); break; case SYS_dup2: syscall_dup2(&arg, proc); break; case SYS_fcntl: syscall_fcntl(&arg, proc); break; case SYS_lseek: syscall_lseek(&arg, proc); break; case SYS_poll: syscall_poll(&arg, proc); break; case SYS_select: syscall_select(&arg, proc); break; case SYS_pipe: syscall_pipe(&arg, proc); case SYS_brk: syscall_brk(&arg, proc); break; case SYS_socket: syscall_socket(&arg, proc); break; case SYS_connect: syscall_connect(&arg, proc); break; case SYS_bind: syscall_bind(&arg, proc); break; case SYS_listen: syscall_listen(&arg, proc); break; case SYS_accept: syscall_accept(&arg, proc); break; #if UINTPTR_MAX == 0xffffffff /* 32-bit architecture */ case SYS_send: ret = syscall_send(&arg, proc); if (ret) return ret; break; case SYS_recv: syscall_recv(&arg, proc); break; #endif case SYS_sendto: ret = syscall_sendto(&arg, proc); if (ret) return ret; break; case SYS_recvfrom: syscall_recvfrom(&arg, proc); break; case SYS_sendmsg: if ((ret = syscall_sendmsg( &arg, proc))) return ret; break; case SYS_recvmsg: syscall_recvmsg(&arg, proc); break; case SYS_shutdown: syscall_shutdown(&arg, proc); break; case SYS_getpeername: syscall_getpeername(&arg, proc); break; case SYS_getsockopt: syscall_getsockopt(&arg, proc); break; case SYS_setsockopt: syscall_setsockopt(&arg, proc); break; case SYS_clone: syscall_clone(&arg, proc); break; case SYS_execve: syscall_execve(&arg, proc); break; case SYS_exit: XBT_DEBUG("exit(%ld) called", arg.arg[0]); return syscall_exit(&arg, proc); break; case SYS_exit_group: XBT_DEBUG("exit_group(%ld) called", arg.arg[0]); return syscall_exit(&arg, proc); break; case SYS_getpid: syscall_getpid(&arg, proc); break; case SYS_tuxcall: syscall_tuxcall(&arg, proc); break; default: syscall_default(pid, &arg, proc); break; } // Step the traced process ptrace_resume_process(pid); // XBT_DEBUG("process resumed, waitpid"); waitpid(pid, &(proc->status), __WALL); } // while(1) THROW_IMPOSSIBLE; //There's no way to quit the loop return 0; }