* @brief Monitors multiple file descriptors for readiness to perform I/O operations. * * This system call allows a program to monitor multiple file descriptors to see if * they are ready for reading, writing, or have exceptional conditions. It waits * for one or more of the file descriptors to become ready or for the specified * timeout to expire. * * @param nfds The highest-numbered file d
| 967 | * @see sys_poll(), sys_read(), sys_write(), poll(), select() |
| 968 | */ |
| 969 | sysret_t sys_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) |
| 970 | { |
| 971 | #ifdef ARCH_MM_MMU |
| 972 | int ret = -1; |
| 973 | fd_set *kreadfds = RT_NULL, *kwritefds = RT_NULL, *kexceptfds = RT_NULL; |
| 974 | |
| 975 | if (readfds) |
| 976 | { |
| 977 | if (!lwp_user_accessable((void *)readfds, sizeof *readfds)) |
| 978 | { |
| 979 | SET_ERRNO(EFAULT); |
| 980 | goto quit; |
| 981 | } |
| 982 | kreadfds = (fd_set *)kmem_get(sizeof *kreadfds); |
| 983 | if (!kreadfds) |
| 984 | { |
| 985 | SET_ERRNO(ENOMEM); |
| 986 | goto quit; |
| 987 | } |
| 988 | lwp_get_from_user(kreadfds, readfds, sizeof *kreadfds); |
| 989 | } |
| 990 | if (writefds) |
| 991 | { |
| 992 | if (!lwp_user_accessable((void *)writefds, sizeof *writefds)) |
| 993 | { |
| 994 | SET_ERRNO(EFAULT); |
| 995 | goto quit; |
| 996 | } |
| 997 | kwritefds = (fd_set *)kmem_get(sizeof *kwritefds); |
| 998 | if (!kwritefds) |
| 999 | { |
| 1000 | SET_ERRNO(ENOMEM); |
| 1001 | goto quit; |
| 1002 | } |
| 1003 | lwp_get_from_user(kwritefds, writefds, sizeof *kwritefds); |
| 1004 | } |
| 1005 | if (exceptfds) |
| 1006 | { |
| 1007 | if (!lwp_user_accessable((void *)exceptfds, sizeof *exceptfds)) |
| 1008 | { |
| 1009 | SET_ERRNO(EFAULT); |
| 1010 | goto quit; |
| 1011 | } |
| 1012 | kexceptfds = (fd_set *)kmem_get(sizeof *kexceptfds); |
| 1013 | if (!kexceptfds) |
| 1014 | { |
| 1015 | SET_ERRNO(EINVAL); |
| 1016 | goto quit; |
| 1017 | } |
| 1018 | lwp_get_from_user(kexceptfds, exceptfds, sizeof *kexceptfds); |
| 1019 | } |
| 1020 | |
| 1021 | ret = select(nfds, kreadfds, kwritefds, kexceptfds, timeout); |
| 1022 | if (kreadfds) |
| 1023 | { |
| 1024 | lwp_put_to_user(readfds, kreadfds, sizeof *kreadfds); |
| 1025 | } |
| 1026 | if (kwritefds) |
nothing calls this directly
no test coverage detected