20 #include "select-syscalls.h" 21 #include "net-syscalls.h" 22 #include "pedigree/kernel/Subsystem.h" 23 #include "pedigree/kernel/compiler.h" 24 #include "pedigree/kernel/processor/types.h" 25 #include "pedigree/kernel/syscallError.h" 26 #include "poll-syscalls.h" 27 #include <PosixSubsystem.h> 30 int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
34 "select(" << nfds <<
", " << readfds <<
", " << writefds <<
", " 35 << errorfds <<
", " << timeout <<
")");
36 bool bValidAddresses =
true;
40 reinterpret_cast<uintptr_t>(readfds),
41 sizeof(fd_set), PosixSubsystem::SafeWrite);
45 reinterpret_cast<uintptr_t>(writefds),
46 sizeof(fd_set), PosixSubsystem::SafeWrite);
50 reinterpret_cast<uintptr_t>(errorfds),
51 sizeof(fd_set), PosixSubsystem::SafeWrite);
55 reinterpret_cast<uintptr_t>(timeout),
56 sizeof(timeval), PosixSubsystem::SafeWrite);
60 SYSCALL_ERROR(InvalidArgument);
65 size_t trueFdCount = 0;
66 for (
int i = 0; i < nfds; ++i)
68 if ((readfds && FD_ISSET(i, readfds)) ||
69 (writefds && FD_ISSET(i, writefds)) ||
70 (errorfds && FD_ISSET(i, errorfds)))
72 POLL_NOTICE(
"fd " << i <<
" is acceptable");
78 struct pollfd *fds =
new struct pollfd[trueFdCount];
80 for (
int i = 0; i < nfds; ++i)
82 bool checkRead = readfds && FD_ISSET(i, readfds);
83 bool checkWrite = writefds && FD_ISSET(i, writefds);
84 bool checkError = errorfds && FD_ISSET(i, errorfds);
86 if (!(checkRead || checkWrite || checkError))
91 POLL_NOTICE(
"registering fd " << i <<
" in slot " << j);
96 fds[j].events |= POLLIN;
98 fds[j].events |= POLLOUT;
100 fds[j].events |= POLLERR;
111 timeoutMs = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000);
116 " -> redirecting select() to poll() with " << trueFdCount
118 int r = posix_poll_safe(fds, trueFdCount, timeoutMs);
122 for (
int i = 0; i < nfds; ++i)
125 bool checkRead = readfds && FD_ISSET(i, readfds);
126 bool checkWrite = writefds && FD_ISSET(i, writefds);
127 bool checkError = errorfds && FD_ISSET(i, errorfds);
129 if (!(checkRead || checkWrite || checkError))
136 if (fds[j].revents & POLLIN)
148 if (fds[j].revents & POLLOUT)
160 if (fds[j].revents & POLLERR)
175 POLL_NOTICE(
" -> select via poll returns " << r);
static bool checkAddress(uintptr_t addr, size_t extent, size_t flags)