Skip to content

Commit b384663

Browse files
authored
Move __syscall__newselect to native code. NFC (#25985)
After #25523 this function is no longer proxied itself and therefore doesn't need to live in JS at all.
1 parent aa78593 commit b384663

File tree

6 files changed

+25
-45
lines changed

6 files changed

+25
-45
lines changed

src/lib/libsigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ sigs = {
229229
__handle_stack_overflow__sig: 'vp',
230230
__pthread_create_js__sig: 'ipppp',
231231
__resumeException__sig: 'vp',
232-
__syscall__newselect__sig: 'iipppj',
233232
__syscall_accept4__sig: 'iippiii',
234233
__syscall_bind__sig: 'iippiii',
235234
__syscall_chdir__sig: 'ip',

src/lib/libsyscall.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -599,31 +599,6 @@ var SyscallsLibrary = {
599599
FS.chdir(stream.path);
600600
return 0;
601601
},
602-
__syscall__newselect__i53abi: true,
603-
__syscall__newselect__proxy: 'none',
604-
__syscall__newselect__deps: ['_newselect_js',
605-
#if PTHREADS
606-
'_emscripten_proxy_newselect',
607-
#endif
608-
],
609-
__syscall__newselect: (nfds, readfds, writefds, exceptfds, timeoutInMillis) => {
610-
#if PTHREADS
611-
if (ENVIRONMENT_IS_PTHREAD) {
612-
return __emscripten_proxy_newselect(nfds,
613-
{{{ to64('readfds') }}},
614-
{{{ to64('writefds') }}},
615-
{{{ to64('exceptfds') }}},
616-
{{{ splitI64('timeoutInMillis') }}});
617-
}
618-
#endif
619-
return __newselect_js({{{ to64('0') }}},
620-
{{{ to64('0') }}},
621-
nfds,
622-
{{{ to64('readfds') }}},
623-
{{{ to64('writefds') }}},
624-
{{{ to64('exceptfds') }}},
625-
{{{ splitI64('timeoutInMillis') }}});
626-
},
627602
_newselect_js__i53abi: true,
628603
_newselect_js__proxy: 'none',
629604
_newselect_js__deps: ['$parseSelectFDSet',

system/lib/libc/proxying_select.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
*/
77

88
#include <assert.h>
9+
#include <sys/select.h>
910
#include <emscripten/proxying.h>
1011
#include <emscripten/threading.h>
1112

1213
#include "emscripten_internal.h"
1314

15+
#if _REENTRANT
1416
typedef struct proxied_select_t {
1517
int n;
16-
void *rfds;
17-
void *wfds;
18-
void *efds;
18+
fd_set *rfds;
19+
fd_set *wfds;
20+
fd_set *efds;
1921
int64_t timeout;
2022
int result;
2123
} proxied_select_t;
@@ -31,7 +33,7 @@ void _emscripten_proxy_newselect_finish(em_proxying_ctx* ctx, void* arg, int ret
3133
emscripten_proxy_finish(ctx);
3234
}
3335

34-
int _emscripten_proxy_newselect(int n, void *rfds, void *wfds, void *efds, int64_t timeout) {
36+
static int proxy_newselect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, int64_t timeout) {
3537
em_proxying_queue* q = emscripten_proxy_get_system_queue();
3638
pthread_t target = emscripten_main_runtime_thread_id();
3739
proxied_select_t t = {.n = n, .rfds = rfds, .wfds = wfds, .efds = efds, .timeout = timeout};
@@ -41,3 +43,17 @@ int _emscripten_proxy_newselect(int n, void *rfds, void *wfds, void *efds, int64
4143
}
4244
return t.result;
4345
}
46+
#endif
47+
48+
// Marked as weak since libwasmfs needs to be able to override this.
49+
weak int __syscall__newselect(int nfds, intptr_t _readfds, intptr_t _writefds, intptr_t _exceptfds, int64_t timeout) {
50+
fd_set* readfds = (fd_set*)_readfds;
51+
fd_set* writefds = (fd_set*)_writefds;
52+
fd_set* exceptfds = (fd_set*)_exceptfds;
53+
#if _REENTRANT
54+
if (!emscripten_is_main_runtime_thread()) {
55+
return proxy_newselect(nfds, readfds, writefds, exceptfds, timeout);
56+
}
57+
#endif
58+
return _newselect_js(0, 0, nfds, readfds, writefds, exceptfds, timeout);
59+
}

system/lib/wasmfs/syscalls.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,8 +1848,4 @@ int __syscall__newselect(int nfds,
18481848
return count;
18491849
}
18501850

1851-
int _newselect_js(void* ctx, void* arg, int n, void *rfds, void *wfds, void *efds, int64_t timeout) {
1852-
return -ENOSYS;
1853-
}
1854-
18551851
} // extern "C"

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245771,
3-
"a.out.nodebug.wasm": 573904,
4-
"total": 819675,
2+
"a.out.js": 245592,
3+
"a.out.nodebug.wasm": 573702,
4+
"total": 819294,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",
@@ -215,7 +215,6 @@
215215
"__asctime_r",
216216
"__assert_fail",
217217
"__call_sighandler",
218-
"__syscall__newselect",
219218
"__syscall_accept4",
220219
"__syscall_bind",
221220
"__syscall_chdir",
@@ -1406,7 +1405,6 @@
14061405
"GOT.func.emscripten_out",
14071406
"env.__assert_fail",
14081407
"env.__call_sighandler",
1409-
"env.__syscall__newselect",
14101408
"env.__syscall_accept4",
14111409
"env.__syscall_bind",
14121410
"env.__syscall_chdir",
@@ -1865,6 +1863,7 @@
18651863
"__subvsi3",
18661864
"__subvti3",
18671865
"__synccall",
1866+
"__syscall__newselect",
18681867
"__syscall_acct",
18691868
"__syscall_getegid32",
18701869
"__syscall_geteuid32",
@@ -1963,8 +1962,6 @@
19631962
"_emscripten_find_dylib",
19641963
"_emscripten_memcpy_bulkmem",
19651964
"_emscripten_memset_bulkmem",
1966-
"_emscripten_proxy_newselect",
1967-
"_emscripten_proxy_newselect_finish",
19681965
"_emscripten_run_callback_on_thread",
19691966
"_emscripten_set_offscreencanvas_size_on_thread",
19701967
"_emscripten_stack_alloc",
@@ -3740,6 +3737,7 @@
37403737
"$__subvsi3",
37413738
"$__subvti3",
37423739
"$__synccall",
3740+
"$__syscall__newselect",
37433741
"$__syscall_acct",
37443742
"$__syscall_getgroups32",
37453743
"$__syscall_getpid",
@@ -3826,8 +3824,6 @@
38263824
"$_emscripten_find_dylib",
38273825
"$_emscripten_memcpy_bulkmem",
38283826
"$_emscripten_memset_bulkmem",
3829-
"$_emscripten_proxy_newselect",
3830-
"$_emscripten_proxy_newselect_finish",
38313827
"$_emscripten_run_callback_on_thread",
38323828
"$_emscripten_set_offscreencanvas_size_on_thread",
38333829
"$_emscripten_stack_alloc",
@@ -3911,7 +3907,6 @@
39113907
"$cacoshl",
39123908
"$cacosl",
39133909
"$call",
3914-
"$call_newselect",
39153910
"$call_once",
39163911
"$carg",
39173912
"$cargf",

tools/emscripten.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,6 @@ def create_pointer_conversion_wrappers(metadata):
12021202
'_emscripten_dlsync_self_async': '_p',
12031203
'_emscripten_proxy_dlsync_async': '_pp',
12041204
'_emscripten_wasm_worker_initialize': '_p_',
1205-
'_emscripten_proxy_newselect': '__ppp_',
12061205
'_emscripten_proxy_newselect_finish': '_pp_',
12071206
'_wasmfs_rename': '_pp',
12081207
'_wasmfs_readlink': '_pp',

0 commit comments

Comments
 (0)