[browser] native - no process, no signals, no threads, no blocking#123962
[browser] native - no process, no signals, no threads, no blocking#123962pavelsavara merged 2 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
Pull request overview
This pull request adds support for the browser (WASM) target by providing stub implementations for features not available in the browser environment, specifically: no sockets, no threads, and no blocking operations.
Changes:
- Added browser-specific stub implementations for networking, interface addresses, network statistics, and console APIs
- Updated error messages in WASM-specific files from "WASI" to "WASM" for clarity
- Modified CoreCLR PAL to prevent blocking operations and thread suspension in single-threaded WASM
- Updated build configuration to disable socket support for browser targets and include browser-specific source files
- Added perftracing configuration for browser builds
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/libs/System.Native/pal_signal_wasm.c | Updated error messages from "WASI" to "WASM" |
| src/native/libs/System.Native/pal_networkstatistics_wasm.c | New file with stub implementations returning "not supported" for network statistics APIs |
| src/native/libs/System.Native/pal_networking_browser.c | New file with comprehensive stub implementations for all networking APIs, returning ENOTSUP |
| src/native/libs/System.Native/pal_io.c | Added early return for pipe() on WASM targets with ENOTSUP |
| src/native/libs/System.Native/pal_interfaceaddresses_browser.c | New file with stub implementations for interface enumeration APIs |
| src/native/libs/System.Native/pal_dynamicload_wasm.c | Updated error messages from "WASI" to "WASM" |
| src/native/libs/System.Native/pal_console_wasm.c | New console implementation for WASM with some working features (stdin/isatty) and stubs for unsupported features |
| src/native/libs/System.Native/CMakeLists.txt | Updated build configuration to differentiate between browser and WASI targets, using browser-specific source files |
| src/native/eventpipe/ds-ipc-pal-websocket.c | Added string duplication helper functions for eventpipe |
| src/mono/mono/profiler/log.c | Changed sys/socket.h include guard from HOST_WIN32 to HAVE_SYS_SOCKET_H |
| src/mono/mono/profiler/helper.c | Changed sys/socket.h include guard from HOST_WIN32 to HAVE_SYS_SOCKET_H |
| src/mono/mono/profiler/CMakeLists.txt | Disabled AOT profiler for browser targets |
| src/mono/mono/mini/cfgdump.c | Added guard for sys/socket.h include |
| src/mono/browser/runtime/dotnet.d.ts | Formatting fix: removed space before parentheses in function signatures |
| src/coreclr/pal/src/thread/threadsusp.cpp | Added guard to prevent thread suspension in single-threaded WASM |
| src/coreclr/pal/src/thread/thread.cpp | Added guard to prevent CREATE_SUSPENDED flag in single-threaded WASM |
| src/coreclr/pal/src/synchmgr/wait.cpp | Added guards to prevent blocking waits and made Sleep return immediately in WASM |
| src/coreclr/pal/src/synchmgr/synchmanager.cpp | Added assertion to prevent waiting on non-signaled objects in WASM |
| src/coreclr/pal/src/debug/debug.cpp | Added WASM-specific implementation of PAL_ProbeMemory using emscripten heap size |
| eng/native/tryrun.browser.cmake | Disabled HAVE_SYS_SOCKET_H for browser targets |
| eng/native.wasm.targets | Added perftracing configuration flags for browser builds |
|
Whole this PR makes emscripten emulator smaller only by 20KB of JavaScript - from 154KB to 134KB. I hoped for more, I'm not sure I want to merge this... |
|
These are JS emulators of The rest of the JS support is OK. See https://gist.github.com/pavelsavara/f11dd1078548a16fc923de444f1c9d9b All the symbols in the wasm files are https://gist.github.com/pavelsavara/b7653066a83554168739558630d34847 Among them these caught my eye |
#117813 is the main offender. |
4524608 to
9ad87e2
Compare
noahfalk
left a comment
There was a problem hiding this comment.
I hoped for more, I'm not sure I want to merge this...
Is there anything you were particularly concerned about? Most of the changes looked like we are just making it clearer what is supported. Those aspects seemed benign and help raise visibility about the platform constraints even if they had no size benefits.
I didn't review everything, but to the degree this intersected the diagnostics stuff it seemed fine to me.
I hoped that there will be larger reduction in size of the native binary. And I was not sure about the added code complexity. The 20KB of JavaScript is good win (with the sockets part I split to separate PR), because that file is on critical path during startup. |
|
/ba-g failed CI is infra |
Contributes to #122506