mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[reland][libc] add epoll_wait functions (#79635)
The epoll_wait functions are syscall wrappers that were requested by upstream users. This patch adds them, as well as their header and types. The tests are currently incomplete since they require epoll_create to properly test epoll_wait. That will be added in a followup patch since this one is already very large.
This commit is contained in:
@@ -179,6 +179,12 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
# sys/auxv.h entrypoints
|
||||
libc.src.sys.auxv.getauxval
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.src.sys.epoll.epoll_wait
|
||||
# libc.src.sys.epoll.epoll_pwait
|
||||
# libc.src.sys.epoll.epoll_pwait2
|
||||
|
||||
# termios.h entrypoints
|
||||
libc.src.termios.cfgetispeed
|
||||
libc.src.termios.cfgetospeed
|
||||
|
||||
@@ -25,4 +25,6 @@ set(TARGET_PUBLIC_HEADERS
|
||||
libc.include.unistd
|
||||
|
||||
libc.include.sys_ioctl
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.include.sys_epoll
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
include "config/public_api.td"
|
||||
|
||||
include "spec/bsd_ext.td"
|
||||
include "spec/gnu_ext.td"
|
||||
include "spec/linux.td"
|
||||
include "spec/llvm_libc_ext.td"
|
||||
include "spec/posix.td"
|
||||
include "spec/stdc.td"
|
||||
include "spec/posix.td"
|
||||
include "spec/linux.td"
|
||||
include "spec/gnu_ext.td"
|
||||
include "spec/bsd_ext.td"
|
||||
include "spec/llvm_libc_ext.td"
|
||||
|
||||
def AssertMacro : MacroDef<"assert"> {
|
||||
let Defn = [{
|
||||
@@ -242,6 +242,10 @@ def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {
|
||||
let Types = ["struct utsname"];
|
||||
}
|
||||
|
||||
def SysEpollAPI : PublicAPI<"sys/epoll.h"> {
|
||||
let Types = ["struct epoll_event", "struct epoll_data", "sigset_t", "struct timespec"];
|
||||
}
|
||||
|
||||
def SpawnAPI : PublicAPI<"spawn.h"> {
|
||||
let Types = ["mode_t", "pid_t", "posix_spawnattr_t", "posix_spawn_file_actions_t"];
|
||||
}
|
||||
|
||||
@@ -102,6 +102,13 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
|
||||
# sys/prctl.h entrypoints
|
||||
libc.src.sys.prctl.prctl
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.src.sys.epoll.epoll_wait
|
||||
# libc.src.sys.epoll.epoll_pwait
|
||||
# libc.src.sys.epoll.epoll_pwait2
|
||||
|
||||
)
|
||||
|
||||
set(TARGET_LIBM_ENTRYPOINTS
|
||||
|
||||
@@ -10,4 +10,7 @@ set(TARGET_PUBLIC_HEADERS
|
||||
libc.include.string
|
||||
libc.include.strings
|
||||
libc.include.search
|
||||
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.include.sys_epoll
|
||||
)
|
||||
|
||||
@@ -185,6 +185,12 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
# sys/auxv.h entrypoints
|
||||
libc.src.sys.auxv.getauxval
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.src.sys.epoll.epoll_wait
|
||||
# libc.src.sys.epoll.epoll_pwait
|
||||
# libc.src.sys.epoll.epoll_pwait2
|
||||
|
||||
# termios.h entrypoints
|
||||
libc.src.termios.cfgetispeed
|
||||
libc.src.termios.cfgetospeed
|
||||
|
||||
@@ -30,6 +30,8 @@ set(TARGET_PUBLIC_HEADERS
|
||||
libc.include.arpa_inet
|
||||
|
||||
libc.include.sys_auxv
|
||||
# Disabled due to epoll_wait syscalls not being available on this platform.
|
||||
# libc.include.sys_epoll
|
||||
libc.include.sys_ioctl
|
||||
libc.include.sys_mman
|
||||
libc.include.sys_prctl
|
||||
|
||||
@@ -258,6 +258,10 @@
|
||||
#define SYS_epoll_pwait __NR_epoll_pwait
|
||||
#endif
|
||||
|
||||
#ifdef __NR_epoll_pwait2
|
||||
#define SYS_epoll_pwait2 __NR_epoll_pwait2
|
||||
#endif
|
||||
|
||||
#ifdef __NR_epoll_wait
|
||||
#define SYS_epoll_wait __NR_epoll_wait
|
||||
#endif
|
||||
|
||||
@@ -143,6 +143,11 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.stdio.scanf
|
||||
libc.src.stdio.fscanf
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
libc.src.sys.epoll.epoll_wait
|
||||
libc.src.sys.epoll.epoll_pwait
|
||||
libc.src.sys.epoll.epoll_pwait2
|
||||
|
||||
# sys/mman.h entrypoints
|
||||
libc.src.sys.mman.madvise
|
||||
libc.src.sys.mman.mmap
|
||||
|
||||
@@ -30,6 +30,7 @@ set(TARGET_PUBLIC_HEADERS
|
||||
libc.include.arpa_inet
|
||||
|
||||
libc.include.sys_auxv
|
||||
libc.include.sys_epoll
|
||||
libc.include.sys_ioctl
|
||||
libc.include.sys_mman
|
||||
libc.include.sys_prctl
|
||||
|
||||
@@ -341,6 +341,17 @@ add_gen_header(
|
||||
.llvm-libc-macros.sys_auxv_macros
|
||||
)
|
||||
|
||||
add_gen_header(
|
||||
sys_epoll
|
||||
DEF_FILE sys/epoll.h.def
|
||||
GEN_HDR sys/epoll.h
|
||||
DEPENDS
|
||||
.llvm_libc_common_h
|
||||
.llvm-libc-types.struct_epoll_event
|
||||
.llvm-libc-types.struct_epoll_data
|
||||
.llvm-libc-types.sigset_t
|
||||
)
|
||||
|
||||
add_gen_header(
|
||||
sys_ioctl
|
||||
DEF_FILE sys/ioctl.h.def
|
||||
|
||||
@@ -96,3 +96,5 @@ add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
|
||||
add_header(ACTION HDR ACTION.h)
|
||||
add_header(ENTRY HDR ENTRY.h)
|
||||
add_header(struct_hsearch_data HDR struct_hsearch_data.h)
|
||||
add_header(struct_epoll_event HDR struct_epoll_event.h)
|
||||
add_header(struct_epoll_data HDR struct_epoll_data.h)
|
||||
|
||||
21
libc/include/llvm-libc-types/struct_epoll_data.h
Normal file
21
libc/include/llvm-libc-types/struct_epoll_data.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//===-- Definition of epoll_data type -------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef __LLVM_LIBC_TYPES_EPOLL_DATA_H__
|
||||
#define __LLVM_LIBC_TYPES_EPOLL_DATA_H__
|
||||
|
||||
union epoll_data {
|
||||
void *ptr;
|
||||
int fd;
|
||||
__UINT32_TYPE__ u32;
|
||||
__UINT64_TYPE__ u64;
|
||||
};
|
||||
|
||||
typedef union epoll_data epoll_data_t;
|
||||
|
||||
#endif // __LLVM_LIBC_TYPES_EPOLL_DATA_H__
|
||||
19
libc/include/llvm-libc-types/struct_epoll_event.h
Normal file
19
libc/include/llvm-libc-types/struct_epoll_event.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//===-- Definition of epoll_event type ------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
|
||||
#define __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
|
||||
|
||||
#include <llvm-libc-types/struct_epoll_data.h>
|
||||
|
||||
typedef struct epoll_event {
|
||||
__UINT32_TYPE__ events;
|
||||
epoll_data_t data;
|
||||
} epoll_event;
|
||||
|
||||
#endif // __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
|
||||
16
libc/include/sys/epoll.h.def
Normal file
16
libc/include/sys/epoll.h.def
Normal file
@@ -0,0 +1,16 @@
|
||||
//===-- Linux header epoll.h ----------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SYS_EPOLL_H
|
||||
#define LLVM_LIBC_SYS_EPOLL_H
|
||||
|
||||
#include <__llvm-libc-common.h>
|
||||
|
||||
%%public_api()
|
||||
|
||||
#endif // LLVM_LIBC_SYS_EPOLL_H
|
||||
@@ -238,7 +238,9 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
|
||||
[], // Macros
|
||||
[], // Types
|
||||
[], // Enumerations
|
||||
[] // Functions
|
||||
[
|
||||
//TODO: Add getauxval here
|
||||
] // Functions
|
||||
>;
|
||||
|
||||
HeaderSpec SendFile = HeaderSpec<
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
def StructEpollEvent : NamedType<"struct epoll_event">;
|
||||
def StructEpollEventPtr : PtrType<StructEpollEvent>;
|
||||
|
||||
def StructEpollData : NamedType<"struct epoll_data">;
|
||||
|
||||
def Linux : StandardSpec<"Linux"> {
|
||||
HeaderSpec Errno = HeaderSpec<
|
||||
"errno.h",
|
||||
@@ -137,6 +142,77 @@ def Linux : StandardSpec<"Linux"> {
|
||||
[] // Functions
|
||||
>;
|
||||
|
||||
|
||||
HeaderSpec SysEpoll = HeaderSpec<
|
||||
"sys/epoll.h",
|
||||
[], // Macros
|
||||
[
|
||||
StructEpollEvent,
|
||||
StructEpollData,
|
||||
SigSetType,
|
||||
StructTimeSpec,
|
||||
], // Types
|
||||
[], // Enumerations
|
||||
[
|
||||
FunctionSpec<
|
||||
"epoll_create",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>
|
||||
]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"epoll_create1",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>
|
||||
]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"epoll_ctl",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<StructEpollEventPtr>
|
||||
]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"epoll_wait",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<StructEpollEventPtr>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<IntType>
|
||||
]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"epoll_pwait",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<StructEpollEventPtr>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<SigSetPtrType>
|
||||
]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"epoll_pwait2",
|
||||
RetValSpec<IntType>,
|
||||
[
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<StructEpollEventPtr>,
|
||||
ArgSpec<IntType>,
|
||||
ArgSpec<ConstStructTimeSpecPtr>,
|
||||
ArgSpec<SigSetPtrType>
|
||||
]
|
||||
>,
|
||||
] // Functions
|
||||
>;
|
||||
|
||||
HeaderSpec Signal = HeaderSpec<
|
||||
"signal.h",
|
||||
[
|
||||
@@ -181,6 +257,7 @@ def Linux : StandardSpec<"Linux"> {
|
||||
|
||||
let Headers = [
|
||||
Errno,
|
||||
SysEpoll,
|
||||
SysMMan,
|
||||
SysPrctl,
|
||||
SysRandom,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
add_subdirectory(auxv)
|
||||
add_subdirectory(epoll)
|
||||
add_subdirectory(mman)
|
||||
add_subdirectory(random)
|
||||
add_subdirectory(resource)
|
||||
|
||||
24
libc/src/sys/epoll/CMakeLists.txt
Normal file
24
libc/src/sys/epoll/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
|
||||
endif()
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_wait
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_wait
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_pwait
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_pwait
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_pwait2
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_pwait2
|
||||
)
|
||||
26
libc/src/sys/epoll/epoll_pwait.h
Normal file
26
libc/src/sys/epoll/epoll_pwait.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//===-- Implementation header for epoll_pwait function ----------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/sigset_t.h"
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
// TODO: sigmask should be nullable
|
||||
int epoll_pwait(int epfd, epoll_event *events, int maxevents, int timeout,
|
||||
const sigset_t *sigmask);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
|
||||
27
libc/src/sys/epoll/epoll_pwait2.h
Normal file
27
libc/src/sys/epoll/epoll_pwait2.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//===-- Implementation header for epoll_pwait2 function ---------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/sigset_t.h"
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
// #include "include/llvm-libc-types/struct_timespec.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
// TODO: sigmask and timeout should be nullable
|
||||
int epoll_pwait2(int epfd, epoll_event *events, int maxevents,
|
||||
const timespec *timeout, const sigset_t *sigmask);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
|
||||
23
libc/src/sys/epoll/epoll_wait.h
Normal file
23
libc/src/sys/epoll/epoll_wait.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//===-- Implementation header for epoll_wait function -----------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int epoll_wait(int epfd, epoll_event *events, int maxevents, int timeout);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
|
||||
41
libc/src/sys/epoll/linux/CMakeLists.txt
Normal file
41
libc/src/sys/epoll/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
add_entrypoint_object(
|
||||
epoll_wait
|
||||
SRCS
|
||||
epoll_wait.cpp
|
||||
HDRS
|
||||
../epoll_wait.h
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_pwait
|
||||
SRCS
|
||||
epoll_pwait.cpp
|
||||
HDRS
|
||||
../epoll_pwait.h
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.include.signal
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_pwait2
|
||||
SRCS
|
||||
epoll_pwait2.cpp
|
||||
HDRS
|
||||
../epoll_pwait2.h
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.include.signal
|
||||
libc.include.time
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
42
libc/src/sys/epoll/linux/epoll_pwait.cpp
Normal file
42
libc/src/sys/epoll/linux/epoll_pwait.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//===---------- Linux implementation of the epoll_pwait function ----------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_pwait.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/sigset_t.h"
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_pwait,
|
||||
(int epfd, struct epoll_event *events, int maxevents,
|
||||
int timeout, const sigset_t *sigmask)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
|
||||
reinterpret_cast<long>(sigmask), sizeof(sigset_t));
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
44
libc/src/sys/epoll/linux/epoll_pwait2.cpp
Normal file
44
libc/src/sys/epoll/linux/epoll_pwait2.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//===---------- Linux implementation of the epoll_pwait2 function ---------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_pwait2.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/sigset_t.h"
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
// #include "include/llvm-libc-types/struct_timespec.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_pwait2,
|
||||
(int epfd, struct epoll_event *events, int maxevents,
|
||||
const struct timespec *timeout, const sigset_t *sigmask)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents,
|
||||
reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask),
|
||||
sizeof(sigset_t));
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
40
libc/src/sys/epoll/linux/epoll_wait.cpp
Normal file
40
libc/src/sys/epoll/linux/epoll_wait.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//===---------- Linux implementation of the epoll_wait function -----------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_wait.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
// TODO: Use this include once the include headers are also using quotes.
|
||||
// #include "include/llvm-libc-types/struct_epoll_event.h"
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_wait,
|
||||
(int epfd, struct epoll_event *events, int maxevents,
|
||||
int timeout)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_wait, epfd, reinterpret_cast<long>(events), maxevents, timeout);
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
@@ -9,3 +9,4 @@ add_subdirectory(utsname)
|
||||
add_subdirectory(wait)
|
||||
add_subdirectory(prctl)
|
||||
add_subdirectory(auxv)
|
||||
add_subdirectory(epoll)
|
||||
|
||||
3
libc/test/src/sys/epoll/CMakeLists.txt
Normal file
3
libc/test/src/sys/epoll/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
|
||||
add_subdirectory(${LIBC_TARGET_OS})
|
||||
endif()
|
||||
39
libc/test/src/sys/epoll/linux/CMakeLists.txt
Normal file
39
libc/test/src/sys/epoll/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
add_custom_target(libc_sys_epoll_unittests)
|
||||
add_libc_unittest(
|
||||
epoll_wait_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_wait_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_wait
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_pwait_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_pwait_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_pwait
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_pwait2_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_pwait2_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_pwait2
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
20
libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp
Normal file
20
libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//===-- Unittests for epoll_pwait2 ----------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_pwait2.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, nullptr, 0, nullptr, nullptr),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
20
libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp
Normal file
20
libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//===-- Unittests for epoll_pwait -----------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_pwait.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, nullptr, 0, 0, nullptr),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
20
libc/test/src/sys/epoll/linux/epoll_wait_test.cpp
Normal file
20
libc/test/src/sys/epoll/linux/epoll_wait_test.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//===-- Unittests for epoll_wait ------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_wait.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_wait(-1, nullptr, 0, 0),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
@@ -2942,3 +2942,35 @@ libc_function(
|
||||
":vfprintf_internal",
|
||||
],
|
||||
)
|
||||
|
||||
############################## sys/epoll targets ###############################
|
||||
|
||||
libc_function(
|
||||
name = "epoll_wait",
|
||||
srcs = ["src/sys/epoll/linux/epoll_wait.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_wait.h"],
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "epoll_pwait",
|
||||
srcs = ["src/sys/epoll/linux/epoll_pwait.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_pwait.h"],
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "epoll_pwait2",
|
||||
srcs = ["src/sys/epoll/linux/epoll_pwait2.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_pwait2.h"],
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
# Tests for LLVM libc string.h functions.
|
||||
|
||||
load("//libc/test:libc_test_rules.bzl", "libc_test")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
libc_test(
|
||||
name = "epoll_wait_test",
|
||||
srcs = ["linux/epoll_wait_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_wait",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "epoll_pwait_test",
|
||||
srcs = ["linux/epoll_pwait_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_pwait",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "epoll_pwait2_test",
|
||||
srcs = ["linux/epoll_pwait2_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_pwait2",
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user