diff --git a/src/lib/libsigs.js b/src/lib/libsigs.js index a13b0fb3075fc..d986f4965cf46 100644 --- a/src/lib/libsigs.js +++ b/src/lib/libsigs.js @@ -237,6 +237,9 @@ sigs = { __syscall_connect__sig: 'iipiiii', __syscall_dup__sig: 'ii', __syscall_dup3__sig: 'iiii', + __syscall_epoll_create1__sig: 'ii', + __syscall_epoll_ctl__sig: 'iiiip', + __syscall_epoll_pwait__sig: 'iipiipp', __syscall_faccessat__sig: 'iipii', __syscall_fallocate__sig: 'iiijj', __syscall_fchdir__sig: 'ii', diff --git a/src/lib/libsyscall.js b/src/lib/libsyscall.js index d38357a67eb5e..46267660a2eee 100644 --- a/src/lib/libsyscall.js +++ b/src/lib/libsyscall.js @@ -715,6 +715,13 @@ var SyscallsLibrary = { __syscall_poll_nonblocking: (fds, nfds) => { return doPoll(fds, nfds, 0, undefined); }, + // epoll is not yet implemented in the legacy (non-WASMFS) JS syscall layer. + __syscall_epoll_create1__nothrow: true, + __syscall_epoll_create1: (flags) => -{{{ cDefs.ENOSYS }}}, + __syscall_epoll_ctl__nothrow: true, + __syscall_epoll_ctl: (epfd, op, fd, ev) => -{{{ cDefs.ENOSYS }}}, + __syscall_epoll_pwait__nothrow: true, + __syscall_epoll_pwait: (epfd, ev, maxevents, timeout, sigmask, sigsetsize) => -{{{ cDefs.ENOSYS }}}, __syscall_getcwd__deps: ['$lengthBytesUTF8', '$stringToUTF8'], __syscall_getcwd: (buf, size) => { if (size === 0) return -{{{ cDefs.EINVAL }}}; diff --git a/system/include/emscripten/syscalls.h b/system/include/emscripten/syscalls.h index 3a7a52a9e0b86..7864de1efc33f 100644 --- a/system/include/emscripten/syscalls.h +++ b/system/include/emscripten/syscalls.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -120,6 +121,9 @@ int __syscall_sendmsg(int sockfd, const struct msghdr *msg, int flags, int unuse int __syscall_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen); int __syscall_recvmsg(int sockfd, struct msghdr *msg, int flags, int unused1, int unused2, int unused3); int __syscall_shutdown(int sockfd, int how, int unused1, int unused2, int unused3, int unused4); +int __syscall_epoll_create1(int flags); +int __syscall_epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev); +int __syscall_epoll_pwait(int epfd, struct epoll_event *ev, int maxevents, int timeout, const sigset_t *sigmask, size_t sigsetsize); #ifdef __cplusplus } diff --git a/system/lib/libc/musl/arch/emscripten/bits/syscall.h b/system/lib/libc/musl/arch/emscripten/bits/syscall.h index f78cf22e63536..b827d74bee262 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/syscall.h +++ b/system/lib/libc/musl/arch/emscripten/bits/syscall.h @@ -86,3 +86,6 @@ #define SYS_recvfrom __syscall_recvfrom #define SYS_recvmsg __syscall_recvmsg #define SYS_shutdown __syscall_shutdown +#define SYS_epoll_create1 __syscall_epoll_create1 +#define SYS_epoll_ctl __syscall_epoll_ctl +#define SYS_epoll_pwait __syscall_epoll_pwait diff --git a/system/lib/libc/musl/include/sys/epoll.h b/system/lib/libc/musl/include/sys/epoll.h new file mode 100644 index 0000000000000..5f975c4a0f227 --- /dev/null +++ b/system/lib/libc/musl/include/sys/epoll.h @@ -0,0 +1,81 @@ +#ifndef _SYS_EPOLL_H +#define _SYS_EPOLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +#define __NEED_sigset_t + +#include + +#define EPOLL_CLOEXEC O_CLOEXEC +#define EPOLL_NONBLOCK O_NONBLOCK + +enum EPOLL_EVENTS { __EPOLL_DUMMY }; +#define EPOLLIN 0x001 +#define EPOLLPRI 0x002 +#define EPOLLOUT 0x004 +#define EPOLLRDNORM 0x040 +#define EPOLLNVAL 0x020 +#define EPOLLRDBAND 0x080 +#define EPOLLWRNORM 0x100 +#define EPOLLWRBAND 0x200 +#define EPOLLMSG 0x400 +#define EPOLLERR 0x008 +#define EPOLLHUP 0x010 +#define EPOLLRDHUP 0x2000 +#define EPOLLEXCLUSIVE (1U<<28) +#define EPOLLWAKEUP (1U<<29) +#define EPOLLONESHOT (1U<<30) +#define EPOLLET (1U<<31) + +#define EPOLL_CTL_ADD 1 +#define EPOLL_CTL_DEL 2 +#define EPOLL_CTL_MOD 3 + +typedef union epoll_data { + void *ptr; + int fd; + uint32_t u32; + uint64_t u64; +} epoll_data_t; + +struct epoll_event { + uint32_t events; + epoll_data_t data; +} +#ifdef __x86_64__ +__attribute__ ((__packed__)) +#endif +; + +struct epoll_params { + uint32_t busy_poll_usecs; + uint16_t busy_poll_budget; + uint8_t prefer_busy_poll; + + uint8_t __pad; +}; + +#define EPOLL_IOC_TYPE 0x8A +#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params) +#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) + +int epoll_create(int); +int epoll_create1(int); +int epoll_ctl(int, int, int, struct epoll_event *); +int epoll_wait(int, struct epoll_event *, int, int); +int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); + + +#ifdef __cplusplus +} +#endif + +#endif /* sys/epoll.h */ diff --git a/system/lib/update_musl.py b/system/lib/update_musl.py index 1e5ab4d01ad76..838685c378b25 100755 --- a/system/lib/update_musl.py +++ b/system/lib/update_musl.py @@ -42,7 +42,6 @@ 'aio.h', 'auxv.h', 'cachectl.h', - 'epoll.h', 'eventfd.h', 'fanotify.h', 'fsuid.h', diff --git a/system/lib/wasmfs/syscalls.cpp b/system/lib/wasmfs/syscalls.cpp index c13f88fdeb23a..66bfb0e2fd9ba 100644 --- a/system/lib/wasmfs/syscalls.cpp +++ b/system/lib/wasmfs/syscalls.cpp @@ -1846,4 +1846,20 @@ int __syscall_fadvise64(int fd, off_t offset, off_t len, int advice) { return 0; } +// epoll is implemented in the legacy (non-WASMFS) JS syscall layer only. +int __syscall_epoll_create1(int flags) { return -ENOSYS; } + +int __syscall_epoll_ctl(int epfd, int op, int fd, struct epoll_event* ev) { + return -ENOSYS; +} + +int __syscall_epoll_pwait(int epfd, + struct epoll_event* ev, + int maxevents, + int timeout, + const sigset_t* sigmask, + size_t sigsetsize) { + return -ENOSYS; +} + } // extern "C" diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index c42ac86d512c3..bf78bf56b759b 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 268445, - "a.out.nodebug.wasm": 587520, - "total": 855965, + "a.out.js": 268603, + "a.out.nodebug.wasm": 587900, + "total": 856503, "sent": [ "IMG_Init", "IMG_Load", @@ -222,6 +222,9 @@ "__syscall_connect", "__syscall_dup", "__syscall_dup3", + "__syscall_epoll_create1", + "__syscall_epoll_ctl", + "__syscall_epoll_pwait", "__syscall_faccessat", "__syscall_fallocate", "__syscall_fchdir", @@ -1744,6 +1747,9 @@ "env.__syscall_connect", "env.__syscall_dup", "env.__syscall_dup3", + "env.__syscall_epoll_create1", + "env.__syscall_epoll_ctl", + "env.__syscall_epoll_pwait", "env.__syscall_faccessat", "env.__syscall_fallocate", "env.__syscall_fchdir", @@ -2596,6 +2602,11 @@ "endpwent", "endservent", "environ", + "epoll_create", + "epoll_create1", + "epoll_ctl", + "epoll_pwait", + "epoll_wait", "erand48", "erf", "erfc", @@ -4460,6 +4471,11 @@ "$emutls_key_destructor", "$encrypt", "$endmntent", + "$epoll_create", + "$epoll_create1", + "$epoll_ctl", + "$epoll_pwait", + "$epoll_wait", "$erand48", "$erf", "$erfc", diff --git a/tools/native_sigs.py b/tools/native_sigs.py index 45b0b08d66fff..f9a7cde215c56 100644 --- a/tools/native_sigs.py +++ b/tools/native_sigs.py @@ -419,6 +419,8 @@ '__syscall_chdir': '_p', '__syscall_chmod': '_p_', '__syscall_connect': '__p____', + '__syscall_epoll_ctl': '____p', + '__syscall_epoll_pwait': '__p__pp', '__syscall_faccessat': '__p__', '__syscall_fchmodat2': '__p__', '__syscall_fchownat': '__p___', @@ -872,6 +874,9 @@ 'emscripten_wget': '_pp', 'encrypt': '_p_', 'endmntent': '_p', + 'epoll_ctl': '____p', + 'epoll_pwait': '__p__p', + 'epoll_wait': '__p__', 'erand48': '_p', 'erfcl': '_p__', 'erfl': '_p__', diff --git a/tools/system_libs.py b/tools/system_libs.py index b041e8a90d212..3d06ff7348a06 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1338,7 +1338,7 @@ def get_files(self): libc_files += files_in_path( path='system/lib/libc/musl/src/linux', - filenames=['getdents.c', 'gettid.c', 'utimes.c', 'statx.c', 'wait4.c', 'wait3.c']) + filenames=['getdents.c', 'gettid.c', 'utimes.c', 'statx.c', 'wait4.c', 'wait3.c', 'epoll.c']) libc_files += files_in_path( path='system/lib/libc/musl/src/malloc',