Skip to content

Implement epoll for FS#27201

Open
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:epoll
Open

Implement epoll for FS#27201
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:epoll

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

Resolves #5033, #10556.

With all the poll work, it kind of makes sense to just implement actual epoll at this point for compat and the extra functionality.

This adds the functions - epoll_create1, epoll_ctl, epoll_wait, epoll_pwait.

With -sNODERAWSOCKETS and -SNODERAWFS this allows real epolling on the file descriptors, without the once-style semantics of poll() being a requirement.

In the process this includes some of the refactorings from #27181 in unifying the notification / listener system for JS.

Supports EPOLLONESHOT, but EPOLLEXCLUSIVE is effectively ignored for the pthreads case still currently.

It does not yet support epoll for WASMFS, which would be a follow-on.

PR made with AI assistance, under my review

Implements epoll_create1/epoll_ctl/epoll_wait/epoll_pwait in the JS
syscall layer on a unified fd-readiness wait-queue shared with poll().

- epoll instances are real FS fds, so close(2) and nesting work for free
- level- and edge-triggered (EPOLLET), EPOLLONESHOT, EPOLLRDHUP, and the
  EPOLLEXCLUSIVE ctl restriction (its wakeup-limiting is a no-op, single-
  threaded; only the EPOLL_CTL_MOD restriction is enforced)
- blocking epoll_wait suspends under PROXY_TO_PTHREAD, ASYNCIFY and JSPI
- sockets and pipes feed readiness via a producer wait-queue
- WASMFS epoll is out of scope (fails at link time)

Only sockets and pipes derive real readiness; every other stream type
(regular files across MEMFS/NODEFS/NODERAWFS, devices, ttys) has no poll
handler and is treated as always readable+writable, so epoll_ctl rejects
it with EPERM. This also fixes poll() crashing on a NODERAWFS regular
file, whose stream carries no stream_ops at all. Known limitation: as
before, ttys are not pollable (no poll handler), unlike Linux.
@@ -0,0 +1,59 @@
#ifndef _SYS_EPOLL_H
#define _SYS_EPOLL_H
#ifdef __cplusplus

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you grab this from upstream musl?

(Also delete epoll.h from the exclude list in system/lib/update_musl.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

epoll support

2 participants