Skip to content

Commit 0cf3493

Browse files
committed
emscripten: Add epoll support
Emscripten restored the `sys/epoll.h` header in 6.0.2 and implements `epoll_create`, `epoll_create1`, `epoll_ctl`, `epoll_wait` and `epoll_pwait` in the JS filesystem as of 6.0.8. Version detection in libc-test now also tracks the tiny version component so that point releases can be distinguished, and parses the uppercase `__EMSCRIPTEN_MAJOR__` macro forms used since Emscripten 5.0.1, where the lowercase names became non-integer aliases. Link: https://github.com/emscripten-core/emscripten/blob/4483d70a78098ed5d860dff2dc21f3025b2da2ee/system/lib/libc/musl/include/sys/epoll.h#L17 Link: https://github.com/emscripten-core/emscripten/blob/4483d70a78098ed5d860dff2dc21f3025b2da2ee/system/lib/libc/musl/include/sys/epoll.h#L70-L74 Link: emscripten-core/emscripten#27206 Link: emscripten-core/emscripten#27207
1 parent df65648 commit 0cf3493

3 files changed

Lines changed: 83 additions & 17 deletions

File tree

libc-test/build/main.rs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,9 @@ fn test_emscripten(t: &Target) {
32113211
"stdio.h",
32123212
"stdlib.h",
32133213
"string.h",
3214+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3215+
// https://github.com/emscripten-core/emscripten/pull/27206
3216+
(emscripten >= (6, 0, 2), "sys/epoll.h"),
32143217
"sys/file.h",
32153218
"sys/ioctl.h",
32163219
"sys/ipc.h",
@@ -3284,15 +3287,15 @@ fn test_emscripten(t: &Target) {
32843287
}
32853288
});
32863289

3287-
cfg.skip_union(|union_| {
3290+
cfg.skip_union(move |union_| {
32883291
match union_.ident() {
32893292
// FIXME(emscripten): Investigate why the test fails.
32903293
// Skip for now to unblock CI.
32913294
"sigval" => true,
32923295

3293-
// No epoll support
3294-
// https://github.com/emscripten-core/emscripten/issues/5033
3295-
ty if ty.starts_with("epoll") => true,
3296+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3297+
// https://github.com/emscripten-core/emscripten/pull/27206
3298+
ty if ty.starts_with("epoll") => emscripten < (6, 0, 2),
32963299

32973300
_ => false,
32983301
}
@@ -3316,9 +3319,9 @@ fn test_emscripten(t: &Target) {
33163319
// Extern types
33173320
"DIR" | "FILE" | "fpos_t" | "fpos64_t" | "timezone" => true,
33183321

3319-
// No epoll support
3320-
// https://github.com/emscripten-core/emscripten/issues/5033
3321-
ty if ty.starts_with("epoll") => true,
3322+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3323+
// https://github.com/emscripten-core/emscripten/pull/27206
3324+
ty if ty.starts_with("epoll") => emscripten < (6, 0, 2),
33223325

33233326
ty if ty.starts_with("signalfd") => true,
33243327
_ => false,
@@ -3332,7 +3335,15 @@ fn test_emscripten(t: &Target) {
33323335
"execv" | "execve" | "execvp" | "execvpe" | "fexecve" | "wait4" => true,
33333336

33343337
// Emscripten's `pthread_kill` used to only be linkable when building with `-pthread`
3335-
"pthread_kill" if emscripten < (6, 0) => true,
3338+
"pthread_kill" if emscripten < (6, 0, 0) => true,
3339+
3340+
// epoll support was added in Emscripten 6.0.8
3341+
// https://github.com/emscripten-core/emscripten/pull/27207
3342+
"epoll_create" | "epoll_create1" | "epoll_ctl" | "epoll_wait" | "epoll_pwait"
3343+
if emscripten < (6, 0, 8) =>
3344+
{
3345+
true
3346+
}
33363347

33373348
_ => false,
33383349
}
@@ -3343,9 +3354,9 @@ fn test_emscripten(t: &Target) {
33433354
// FIXME(emscripten): emscripten uses different constants to constructs these
33443355
n if n.contains("__SIZEOF_PTHREAD") => true,
33453356

3346-
// No epoll support
3347-
// https://github.com/emscripten-core/emscripten/issues/5033
3348-
n if n.starts_with("EPOLL") => true,
3357+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3358+
// https://github.com/emscripten-core/emscripten/pull/27206
3359+
n if n.starts_with("EPOLL") => emscripten < (6, 0, 2),
33493360

33503361
// No ptrace.h
33513362
// https://github.com/emscripten-core/emscripten/pull/17704
@@ -6283,7 +6294,7 @@ struct Versions {
62836294
openbsd: Option<(u32, u32)>,
62846295
netbsd: Option<(u32, u32)>,
62856296
apple: Option<(u32, u32)>,
6286-
emscripten: Option<(u32, u32)>,
6297+
emscripten: Option<(u32, u32, u32)>,
62876298
wasi_sdk: Option<(u32, WasiVersion)>,
62886299
/// Android API level (no minor version).
62896300
android: Option<u32>,
@@ -6338,7 +6349,7 @@ impl Versions {
63386349
#endif
63396350
63406351
#ifdef __EMSCRIPTEN__
6341-
/* Provides __EMSCRIPTEN_MAJOR__, __EMSCRIPTEN_MINOR__ */
6352+
/* Provides __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__ */
63426353
#include "emscripten/version.h"
63436354
#endif
63446355
@@ -6433,11 +6444,23 @@ impl Versions {
64336444
let minor: u32 = caps[2].parse().unwrap();
64346445
ret.openbsd = Some((major, minor));
64356446
}
6436-
"__EMSCRIPTEN_major__" => {
6437-
ret.emscripten.get_or_insert_default().0 = value.parse().unwrap()
6447+
// Versions before 5.0.1 define the lowercase names as integers; 5.0.1 and
6448+
// later define the uppercase names as integers and the lowercase names as
6449+
// non-integer aliases of them.
6450+
"__EMSCRIPTEN_major__" | "__EMSCRIPTEN_MAJOR__" => {
6451+
if let Ok(v) = value.parse() {
6452+
ret.emscripten.get_or_insert_default().0 = v;
6453+
}
6454+
}
6455+
"__EMSCRIPTEN_minor__" | "__EMSCRIPTEN_MINOR__" => {
6456+
if let Ok(v) = value.parse() {
6457+
ret.emscripten.get_or_insert_default().1 = v;
6458+
}
64386459
}
6439-
"__EMSCRIPTEN_minor__" => {
6440-
ret.emscripten.get_or_insert_default().1 = value.parse().unwrap()
6460+
"__EMSCRIPTEN_tiny__" | "__EMSCRIPTEN_TINY__" => {
6461+
if let Ok(v) = value.parse() {
6462+
ret.emscripten.get_or_insert_default().2 = v;
6463+
}
64416464
}
64426465
"__wasi_sdk_major__" => {
64436466
ret.wasi_sdk.get_or_insert_default().0 = value.parse().unwrap()

libc-test/semver/emscripten.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
AT_EACCESS
2+
EPOLLERR
3+
EPOLLET
4+
EPOLLEXCLUSIVE
5+
EPOLLHUP
6+
EPOLLIN
7+
EPOLLMSG
8+
EPOLLONESHOT
9+
EPOLLOUT
10+
EPOLLPRI
11+
EPOLLRDBAND
12+
EPOLLRDHUP
13+
EPOLLRDNORM
14+
EPOLLWAKEUP
15+
EPOLLWRBAND
16+
EPOLLWRNORM
17+
EPOLL_CLOEXEC
18+
EPOLL_CTL_ADD
19+
EPOLL_CTL_DEL
20+
EPOLL_CTL_MOD
221
SIGEV_THREAD_ID
22+
epoll_create
23+
epoll_create1
24+
epoll_ctl
25+
epoll_event
26+
epoll_pwait
27+
epoll_wait
328
getentropy
429
getgrgid
530
getgrgid_r

src/unix/linux_like/emscripten/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ pub const O_TRUNC: c_int = 512;
807807
pub const O_NOATIME: c_int = 0o1000000;
808808
pub const O_CLOEXEC: c_int = 0x80000;
809809

810+
pub const EPOLL_CLOEXEC: c_int = 0x80000;
811+
810812
// Defined as wasi value.
811813
pub const EPERM: c_int = 63;
812814
pub const ENOENT: c_int = 44;
@@ -1477,6 +1479,22 @@ extern "C" {
14771479
timeout: *const crate::timespec,
14781480
) -> c_int;
14791481
pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
1482+
pub fn epoll_create(size: c_int) -> c_int;
1483+
pub fn epoll_create1(flags: c_int) -> c_int;
1484+
pub fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut crate::epoll_event) -> c_int;
1485+
pub fn epoll_wait(
1486+
epfd: c_int,
1487+
events: *mut crate::epoll_event,
1488+
maxevents: c_int,
1489+
timeout: c_int,
1490+
) -> c_int;
1491+
pub fn epoll_pwait(
1492+
epfd: c_int,
1493+
events: *mut crate::epoll_event,
1494+
maxevents: c_int,
1495+
timeout: c_int,
1496+
sigmask: *const crate::sigset_t,
1497+
) -> c_int;
14801498
}
14811499

14821500
// Alias <foo> to <foo>64 to mimic glibc's LFS64 support

0 commit comments

Comments
 (0)