def sys_fdwait(self, cpu, nfds, readfds, writefds, timeout, readyfds):
logger.debug("<STR_LIT>" % (nfds, readfds, writefds, timeout, readyfds))<EOL>if timeout:<EOL><INDENT>if timeout not in cpu.memory:  <EOL><INDENT>logger.info("<STR_LIT>")<EOL>return Decree.CGC_EFAULT<EOL><DEDENT><DEDENT>if readyfds:<EOL><INDENT>if readyfds not in cpu.memory:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>return Decree.CGC_EFAULT<EOL><DEDENT><DEDENT>writefds_wait = set()<EOL>writefds_ready = set()<EOL>fds_bitsize = (nfds + <NUM_LIT:7>) & ~<NUM_LIT:7><EOL>if writefds:<EOL><INDENT>if writefds not in cpu.memory:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>return Decree.CGC_EFAULT<EOL><DEDENT>bits = cpu.read_int(writefds, fds_bitsize)<EOL>for fd in range(nfds):<EOL><INDENT>if (bits & <NUM_LIT:1> << fd):<EOL><INDENT>if self.files[fd].is_full():<EOL><INDENT>writefds_wait.add(fd)<EOL><DEDENT>else:<EOL><INDENT>writefds_ready.add(fd)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>readfds_wait = set()<EOL>readfds_ready = set()<EOL>if readfds:<EOL><INDENT>if readfds not in cpu.memory:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>return Decree.CGC_EFAULT<EOL><DEDENT>bits = cpu.read_int(readfds, fds_bitsize)<EOL>for fd in range(nfds):<EOL><INDENT>if (bits & <NUM_LIT:1> << fd):<EOL><INDENT>if self.files[fd].is_empty():<EOL><INDENT>readfds_wait.add(fd)<EOL><DEDENT>else:<EOL><INDENT>readfds_ready.add(fd)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>n = len(readfds_ready) + len(writefds_ready)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>if timeout != <NUM_LIT:0>:<EOL><INDENT>seconds = cpu.read_int(timeout, <NUM_LIT:32>)<EOL>microseconds = cpu.read_int(timeout + <NUM_LIT:4>, <NUM_LIT:32>)<EOL>logger.info("<STR_LIT>", repr(<EOL>list(readfds_wait)), repr(list(writefds_wait)), microseconds + <NUM_LIT:1000> * seconds)<EOL>to = microseconds + <NUM_LIT:1000> * seconds<EOL><DEDENT>else:<EOL><INDENT>to = None<EOL>logger.info("<STR_LIT>",<EOL>repr(list(readfds_wait)), repr(list(writefds_wait)))<EOL><DEDENT>cpu.PC -= cpu.instruction.size<EOL>self.wait(readfds_wait, writefds_wait, to)<EOL>raise RestartSyscall()  <EOL><DEDENT>if readfds:<EOL><INDENT>bits = <NUM_LIT:0><EOL>for fd in readfds_ready:<EOL><INDENT>bits |= <NUM_LIT:1> << fd<EOL><DEDENT>for byte in range(<NUM_LIT:0>, nfds, <NUM_LIT:8>):<EOL><INDENT>cpu.write_int(readfds, (bits >> byte) & <NUM_LIT>, <NUM_LIT:8>)<EOL><DEDENT><DEDENT>if writefds:<EOL><INDENT>bits = <NUM_LIT:0><EOL>for fd in writefds_ready:<EOL><INDENT>bits |= <NUM_LIT:1> << fd<EOL><DEDENT>for byte in range(<NUM_LIT:0>, nfds, <NUM_LIT:8>):<EOL><INDENT>cpu.write_int(writefds, (bits >> byte) & <NUM_LIT>, <NUM_LIT:8>)<EOL><DEDENT><DEDENT>logger.info("<STR_LIT>", readyfds)<EOL>if readyfds:<EOL><INDENT>cpu.write_int(readyfds, n, <NUM_LIT:32>)<EOL><DEDENT>self.syscall_trace.append(("<STR_LIT>", -<NUM_LIT:1>, None))<EOL>return <NUM_LIT:0><EOL>
fdwait - wait for file descriptors to become ready