Skip to content

Commit 23430c0

Browse files
nickdesaulniersIcohedron
authored andcommitted
[libc][POSIX][poll.h] implement poll (llvm#125118)
Simple syscall. Fixes: llvm#124647
1 parent 02eeee9 commit 23430c0

27 files changed

+402
-22
lines changed

Diff for: libc/config/linux/aarch64/entrypoints.txt

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3232
libc.src.fcntl.open
3333
libc.src.fcntl.openat
3434

35+
# poll.h entrypoints
36+
libc.src.poll.poll
37+
3538
# sched.h entrypoints
3639
libc.src.sched.sched_get_priority_max
3740
libc.src.sched.sched_get_priority_min

Diff for: libc/config/linux/aarch64/headers.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,31 @@ set(TARGET_PUBLIC_HEADERS
88
libc.include.features
99
libc.include.fenv
1010
libc.include.float
11-
libc.include.stdint
1211
libc.include.inttypes
1312
libc.include.limits
1413
libc.include.link
1514
libc.include.malloc
1615
libc.include.math
16+
libc.include.poll
1717
libc.include.pthread
18+
libc.include.search
1819
libc.include.signal
19-
libc.include.stdckdint
2020
libc.include.stdbit
21+
libc.include.stdckdint
22+
libc.include.stdint
2123
libc.include.stdio
2224
libc.include.stdlib
2325
libc.include.string
2426
libc.include.strings
25-
libc.include.search
2627
libc.include.sys_mman
2728
libc.include.sys_socket
2829
libc.include.sys_syscall
2930
libc.include.sys_time
3031
libc.include.threads
3132
libc.include.time
33+
libc.include.uchar
3234
libc.include.unistd
3335
libc.include.wchar
34-
libc.include.uchar
3536

3637
libc.include.sys_ioctl
3738
# Disabled due to epoll_wait syscalls not being available on this platform.

Diff for: libc/config/linux/arm/entrypoints.txt

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ set(TARGET_LIBC_ENTRYPOINTS
2020
# errno.h entrypoints
2121
libc.src.errno.errno
2222

23+
# poll.h entrypoints
24+
libc.src.poll.poll
25+
2326
# string.h entrypoints
2427
libc.src.string.memccpy
2528
libc.src.string.memchr

Diff for: libc/config/linux/riscv/entrypoints.txt

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3232
libc.src.fcntl.open
3333
libc.src.fcntl.openat
3434

35+
# poll.h entrypoints
36+
libc.src.poll.poll
37+
3538
# sched.h entrypoints
3639
libc.src.sched.sched_get_priority_max
3740
libc.src.sched.sched_get_priority_min

Diff for: libc/config/linux/x86_64/entrypoints.txt

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3232
libc.src.fcntl.open
3333
libc.src.fcntl.openat
3434

35+
# poll.h entrypoints
36+
libc.src.poll.poll
37+
3538
# sched.h entrypoints
3639
libc.src.sched.sched_get_priority_max
3740
libc.src.sched.sched_get_priority_min

Diff for: libc/config/linux/x86_64/headers.txt

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(TARGET_PUBLIC_HEADERS
2+
libc.include.arpa_inet
23
libc.include.assert
34
libc.include.complex
45
libc.include.ctype
@@ -10,35 +11,27 @@ set(TARGET_PUBLIC_HEADERS
1011
libc.include.features
1112
libc.include.fenv
1213
libc.include.float
13-
libc.include.stdint
1414
libc.include.inttypes
1515
libc.include.limits
1616
libc.include.link
17+
libc.include.locale
1718
libc.include.malloc
1819
libc.include.math
20+
libc.include.poll
1921
libc.include.pthread
2022
libc.include.sched
23+
libc.include.search
24+
libc.include.setjmp
2125
libc.include.signal
2226
libc.include.spawn
23-
libc.include.setjmp
24-
libc.include.stdckdint
2527
libc.include.stdbit
28+
libc.include.stdckdint
2629
libc.include.stdfix
30+
libc.include.stdint
2731
libc.include.stdio
2832
libc.include.stdlib
2933
libc.include.string
3034
libc.include.strings
31-
libc.include.search
32-
libc.include.termios
33-
libc.include.threads
34-
libc.include.time
35-
libc.include.unistd
36-
libc.include.wchar
37-
libc.include.uchar
38-
libc.include.locale
39-
40-
libc.include.arpa_inet
41-
4235
libc.include.sys_auxv
4336
libc.include.sys_epoll
4437
libc.include.sys_ioctl
@@ -56,4 +49,10 @@ set(TARGET_PUBLIC_HEADERS
5649
libc.include.sys_types
5750
libc.include.sys_utsname
5851
libc.include.sys_wait
52+
libc.include.termios
53+
libc.include.threads
54+
libc.include.time
55+
libc.include.uchar
56+
libc.include.unistd
57+
libc.include.wchar
5958
)

Diff for: libc/hdr/types/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,19 @@ add_proxy_header_library(
342342
libc.include.llvm-libc-types.struct_iovec
343343
libc.include.sys_uio
344344
)
345+
346+
add_proxy_header_library(
347+
nfds_t
348+
HDRS
349+
nfds_t.h
350+
FULL_BUILD_DEPENDS
351+
libc.include.llvm-libc-types.nfds_t
352+
)
353+
354+
add_proxy_header_library(
355+
struct_pollfd
356+
HDRS
357+
struct_pollfd.h
358+
FULL_BUILD_DEPENDS
359+
libc.include.llvm-libc-types.struct_pollfd
360+
)

Diff for: libc/hdr/types/nfds_t.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Definition of nfds_t ----------------------------------------------===//
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+
10+
#ifndef LLVM_LIBC_HDR_TYPES_NFDS_T_H
11+
#define LLVM_LIBC_HDR_TYPES_NFDS_T_H
12+
13+
#ifdef LIBC_FULL_BUILD
14+
15+
#include "include/llvm-libc-types/nfds_t.h"
16+
17+
#else // overlay mode
18+
19+
#include <poll.h>
20+
21+
#endif // LLVM_LIBC_FULL_BUILD
22+
23+
#endif // LLVM_LIBC_HDR_TYPES_NFDS_T_H

Diff for: libc/hdr/types/struct_pollfd.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Definition of struct pollfd ---------------------------------------===//
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+
10+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_POLLFD_H
11+
#define LLVM_LIBC_HDR_TYPES_STRUCT_POLLFD_H
12+
13+
#ifdef LIBC_FULL_BUILD
14+
15+
#include "include/llvm-libc-types/struct_pollfd.h"
16+
17+
#else // overlay mode
18+
19+
#include <poll.h>
20+
21+
#endif // LLVM_LIBC_FULL_BUILD
22+
23+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_POLLFD_H

Diff for: libc/include/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,16 @@ add_header_macro(
704704
.llvm-libc-types.struct_lconv
705705
)
706706

707+
add_header_macro(
708+
poll
709+
../libc/include/poll.yaml
710+
poll.h
711+
DEPENDS
712+
.llvm-libc-types.struct_pollfd
713+
.llvm-libc-types.nfds_t
714+
.llvm-libc-macros.poll-macros
715+
)
716+
707717
if(NOT LLVM_LIBC_FULL_BUILD)
708718
# We don't install headers in non-fullbuild mode.
709719
return()

Diff for: libc/include/llvm-libc-macros/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,9 @@ add_macro_header(
321321
HDR
322322
pthread-macros.h
323323
)
324+
325+
add_macro_header(
326+
poll-macros
327+
HDR
328+
poll-macros.h
329+
)

Diff for: libc/include/llvm-libc-macros/linux/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ add_header(
1010
fcntl-macros.h
1111
)
1212

13+
add_header(
14+
poll-macros
15+
HDR
16+
poll-macros.h
17+
)
18+
1319
add_header(
1420
sched_macros
1521
HDR

Diff for: libc/include/llvm-libc-macros/linux/poll-macros.h

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===-- Macros defined in poll.h header file ------------------------------===//
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+
#ifndef LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H
10+
#define LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H
11+
12+
// From asm-generic/poll.h, redefined here to avoid redeclaring struct pollfd.
13+
#ifndef POLLIN
14+
#define POLLIN 0x0001
15+
#endif
16+
17+
#ifndef POLLPRI
18+
#define POLLPRI 0x0002
19+
#endif
20+
21+
#ifndef POLLOUT
22+
#define POLLOUT 0x0004
23+
#endif
24+
25+
#ifndef POLLERR
26+
#define POLLERR 0x0008
27+
#endif
28+
29+
#ifndef POLLHUP
30+
#define POLLHUP 0x0010
31+
#endif
32+
33+
#ifndef POLLNVAL
34+
#define POLLNVAL 0x0020
35+
#endif
36+
37+
#ifndef POLLRDNORM
38+
#define POLLRDNORM 0x0040
39+
#endif
40+
41+
#ifndef POLLRDBAND
42+
#define POLLRDBAND 0x0080
43+
#endif
44+
45+
#ifndef POLLWRNORM
46+
#define POLLWRNORM 0x0100
47+
#endif
48+
49+
#ifndef POLLWRBAND
50+
#define POLLWRBAND 0x0200
51+
#endif
52+
53+
#ifndef POLLMSG
54+
#define POLLMSG 0x0400
55+
#endif
56+
57+
#ifndef POLLREMOVE
58+
#define POLLREMOVE 0x1000
59+
#endif
60+
61+
#ifndef POLLRDHUP
62+
#define POLLRDHUP 0x2000
63+
#endif
64+
65+
#endif // LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H

Diff for: libc/include/llvm-libc-macros/poll-macros.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Macros defined in poll.h header file ------------------------------===//
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+
#ifndef LLVM_LIBC_MACROS_POLL_MACROS_H
10+
#define LLVM_LIBC_MACROS_POLL_MACROS_H
11+
12+
#ifdef __linux__
13+
#include "linux/poll-macros.h"
14+
#endif
15+
16+
#endif // LLVM_LIBC_MACROS_POLL_MACROS_H

Diff for: libc/include/llvm-libc-types/CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_header(jmp_buf HDR jmp_buf.h)
4444
add_header(mbstate_t HDR mbstate_t.h)
4545
add_header(mode_t HDR mode_t.h)
4646
add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
47+
add_header(nfds_t HDR nfds_t.h)
4748
add_header(nlink_t HDR nlink_t.h)
4849
add_header(off_t HDR off_t.h)
4950
add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
@@ -67,14 +68,15 @@ else()
6768
endif()
6869
add_header(stack_t HDR stack_t.h DEPENDS .size_t)
6970
add_header(suseconds_t HDR suseconds_t.h)
71+
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
72+
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
7073
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
7174
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
72-
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
73-
add_header(struct_timeval HDR struct_timeval.h DEPENDS .suseconds_t .time_t)
75+
add_header(struct_pollfd HDR struct_pollfd.h)
7476
add_header(struct_rlimit HDR struct_rlimit.h DEPENDS .rlim_t)
75-
add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
76-
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
7777
add_header(struct_sched_param HDR struct_sched_param.h)
78+
add_header(struct_timeval HDR struct_timeval.h DEPENDS .suseconds_t .time_t)
79+
add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
7880
add_header(union_sigval HDR union_sigval.h)
7981
add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t)
8082
add_header(sig_atomic_t HDR sig_atomic_t.h)

Diff for: libc/include/llvm-libc-types/nfds_t.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Definition of type nfds_t -----------------------------------------===//
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+
#ifndef LLVM_LIBC_TYPES_NFDS_T_H
10+
#define LLVM_LIBC_TYPES_NFDS_T_H
11+
12+
typedef unsigned int nfds_t;
13+
14+
#endif // LLVM_LIBC_TYPES_NFDS_T_H

Diff for: libc/include/llvm-libc-types/struct_pollfd.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Definition of type struct pollfd ----------------------------------===//
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+
#ifndef LLVM_LIBC_TYPES_STRUCT_POLLFD_H
10+
#define LLVM_LIBC_TYPES_STRUCT_POLLFD_H
11+
12+
struct pollfd {
13+
int fd;
14+
short events;
15+
short revents;
16+
};
17+
18+
#endif // LLVM_LIBC_TYPES_STRUCT_POLLFD_H

0 commit comments

Comments
 (0)