1//===---------- Linux implementation of the epoll_wait function -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "src/sys/epoll/epoll_wait.h"
10
11#include "hdr/signal_macros.h" // for NSIG
12#include "hdr/types/sigset_t.h"
13#include "hdr/types/struct_epoll_event.h"
14#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
15#include "src/__support/common.h"
16#include "src/errno/libc_errno.h"
17
18#include <sys/syscall.h> // For syscall numbers.
19
20namespace LIBC_NAMESPACE {
21
22LLVM_LIBC_FUNCTION(int, epoll_wait,
23 (int epfd, struct epoll_event *events, int maxevents,
24 int timeout)) {
25#ifdef SYS_epoll_wait
26 int ret = LIBC_NAMESPACE::syscall_impl<int>(
27 SYS_epoll_wait, ts: epfd, ts: reinterpret_cast<long>(events), ts: maxevents, ts: timeout);
28#elif defined(SYS_epoll_pwait)
29 int ret = LIBC_NAMESPACE::syscall_impl<int>(
30 SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
31 reinterpret_cast<long>(nullptr), NSIG / 8);
32#else
33#error "epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait."
34#endif
35 // A negative return value indicates an error with the magnitude of the
36 // value being the error code.
37 if (ret < 0) {
38 libc_errno = -ret;
39 return -1;
40 }
41
42 return ret;
43}
44
45} // namespace LIBC_NAMESPACE
46

source code of libc/src/sys/epoll/linux/epoll_wait.cpp