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
1416typedef 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+ }
0 commit comments