Skip to content

Commit 16584c2

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 bd53ab4 commit 16584c2

3 files changed

Lines changed: 82 additions & 17 deletions

File tree

libc-test/build/main.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,9 @@ fn test_emscripten(t: &Target) {
32023202
"stdio.h",
32033203
"stdlib.h",
32043204
"string.h",
3205+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3206+
// https://github.com/emscripten-core/emscripten/pull/27206
3207+
(emscripten >= (6, 0, 2), "sys/epoll.h"),
32053208
"sys/file.h",
32063209
"sys/ioctl.h",
32073210
"sys/ipc.h",
@@ -3275,15 +3278,15 @@ fn test_emscripten(t: &Target) {
32753278
}
32763279
});
32773280

3278-
cfg.skip_union(|union_| {
3281+
cfg.skip_union(move |union_| {
32793282
match union_.ident() {
32803283
// FIXME(emscripten): Investigate why the test fails.
32813284
// Skip for now to unblock CI.
32823285
"sigval" => true,
32833286

3284-
// No epoll support
3285-
// https://github.com/emscripten-core/emscripten/issues/5033
3286-
ty if ty.starts_with("epoll") => true,
3287+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3288+
// https://github.com/emscripten-core/emscripten/pull/27206
3289+
ty if ty.starts_with("epoll") => emscripten < (6, 0, 2),
32873290

32883291
_ => false,
32893292
}
@@ -3307,9 +3310,9 @@ fn test_emscripten(t: &Target) {
33073310
// Extern types
33083311
"DIR" | "FILE" | "fpos_t" | "fpos64_t" | "timezone" => true,
33093312

3310-
// No epoll support
3311-
// https://github.com/emscripten-core/emscripten/issues/5033
3312-
ty if ty.starts_with("epoll") => true,
3313+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3314+
// https://github.com/emscripten-core/emscripten/pull/27206
3315+
ty if ty.starts_with("epoll") => emscripten < (6, 0, 2),
33133316

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

33253328
// Emscripten's `pthread_kill` used to only be linkable when building with `-pthread`
3326-
"pthread_kill" if emscripten < (6, 0) => true,
3329+
"pthread_kill" if emscripten < (6, 0, 0) => true,
3330+
3331+
// epoll support was added in Emscripten 6.0.8
3332+
// https://github.com/emscripten-core/emscripten/pull/27207
3333+
"epoll_create" | "epoll_create1" | "epoll_ctl" | "epoll_wait" | "epoll_pwait"
3334+
if emscripten < (6, 0, 8) =>
3335+
{
3336+
true
3337+
}
33273338

33283339
_ => false,
33293340
}
@@ -3334,9 +3345,9 @@ fn test_emscripten(t: &Target) {
33343345
// FIXME(emscripten): emscripten uses different constants to constructs these
33353346
n if n.contains("__SIZEOF_PTHREAD") => true,
33363347

3337-
// No epoll support
3338-
// https://github.com/emscripten-core/emscripten/issues/5033
3339-
n if n.starts_with("EPOLL") => true,
3348+
// `sys/epoll.h` was restored in Emscripten 6.0.2
3349+
// https://github.com/emscripten-core/emscripten/pull/27206
3350+
n if n.starts_with("EPOLL") => emscripten < (6, 0, 2),
33403351

33413352
// No ptrace.h
33423353
// https://github.com/emscripten-core/emscripten/pull/17704
@@ -6274,7 +6285,7 @@ struct Versions {
62746285
openbsd: Option<(u32, u32)>,
62756286
netbsd: Option<(u32, u32)>,
62766287
macos: Option<(u32, u32)>,
6277-
emscripten: Option<(u32, u32)>,
6288+
emscripten: Option<(u32, u32, u32)>,
62786289
wasi_sdk: Option<(u32, WasiVersion)>,
62796290
/// Android API level (no minor version).
62806291
android: Option<u32>,
@@ -6326,7 +6337,7 @@ impl Versions {
63266337
#endif
63276338
63286339
#ifdef __EMSCRIPTEN__
6329-
/* Provides __EMSCRIPTEN_MAJOR__, __EMSCRIPTEN_MINOR__ */
6340+
/* Provides __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__ */
63306341
#include "emscripten/version.h"
63316342
#endif
63326343
@@ -6413,11 +6424,22 @@ impl Versions {
64136424
let minor: u32 = caps[2].parse().unwrap();
64146425
ret.openbsd = Some((major, minor));
64156426
}
6416-
"__EMSCRIPTEN_major__" => {
6417-
ret.emscripten.get_or_insert_default().0 = value.parse().unwrap()
6427+
// Old versions define the lowercase names as integers, new versions define
6428+
// the uppercase names as integers and the lowercase names as aliases of them.
6429+
"__EMSCRIPTEN_major__" | "__EMSCRIPTEN_MAJOR__" => {
6430+
if let Ok(v) = value.parse() {
6431+
ret.emscripten.get_or_insert_default().0 = v;
6432+
}
6433+
}
6434+
"__EMSCRIPTEN_minor__" | "__EMSCRIPTEN_MINOR__" => {
6435+
if let Ok(v) = value.parse() {
6436+
ret.emscripten.get_or_insert_default().1 = v;
6437+
}
64186438
}
6419-
"__EMSCRIPTEN_minor__" => {
6420-
ret.emscripten.get_or_insert_default().1 = value.parse().unwrap()
6439+
"__EMSCRIPTEN_tiny__" | "__EMSCRIPTEN_TINY__" => {
6440+
if let Ok(v) = value.parse() {
6441+
ret.emscripten.get_or_insert_default().2 = v;
6442+
}
64216443
}
64226444
"__wasi_sdk_major__" => {
64236445
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)