Skip to content

Commit 035836d

Browse files
[libc][POSIX][poll.h] implement poll
Simple syscall. Fixes: #124647
1 parent 953354c commit 035836d

File tree

19 files changed

+309
-4
lines changed

19 files changed

+309
-4
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
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

libc/hdr/types/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
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+
)

libc/hdr/types/nfds_t.h

Lines changed: 23 additions & 0 deletions
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

libc/hdr/types/struct_pollfd.h

Lines changed: 23 additions & 0 deletions
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

libc/include/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
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()

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
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+
)

libc/include/llvm-libc-macros/linux/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
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
Lines changed: 65 additions & 0 deletions
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
Lines changed: 16 additions & 0 deletions
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

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
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)

0 commit comments

Comments
 (0)