Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-07-11[wasm] fix Debug configuration compilation (#71929)Radek Doulik
Current emcc compiler has problems with unicode chars in JS comments. Update our sources as workaround, before we have better solution.
2022-07-10[wasm]: JavaScript interop with [JSImport] and [JSExport] attributes and ↵Pavel Savara
Roslyn (#66304) Co-authored-by: Marek Fišera <mara@neptuo.com> Co-authored-by: Katelyn Gadd <kg@luminance.org>
2022-07-10[wasm-mt] Fixup after Emscripten 3.1.12 bump (#71893)Aleksey Kliger (λgeek)
Emscripten 3.1.12 library_pthread.js renamed PThread["threadInit"] to PThread["threadInitTLS"]
2022-07-09Enable Rfc2898DeriveBytes on Browser WASM (#71768)Eric Erhardt
* Enable Rfc2898DeriveBytes on Browser WASM Marks the APIs as supported on Browser, and enables Rfc2898 tests on Browser WASM. Use SubtleCrypto deriveBits API to implement one shot Pbkdf2. * Mark HKDF as supported on Browser and enable tests Contributes to #40074
2022-07-09Add an Azure NPM registry (#71393)Andy Gocke
* Add an Azure NPM registry * Get verbose output for 'npm audit' * Audit against a registry that supports auditing Co-authored-by: Ankit Jain <radical@gmail.com> Co-authored-by: Larry Ewing <lewing@microsoft.com>
2022-07-08[wasm] fix V8 events (#71834)Pavel Savara
2022-07-07Better error handling in SubtleCrypto workers (#71693)Eric Erhardt
* Better error handling in SubtleCrypto workers Handle exceptions from SubtleCrypto by catching and logging exceptions coming from the crypto stack. Reset web worker when a request fails. Also, fix race conditions where the web worker can read its own response as part of the next request. Contributes to #69740
2022-07-06Use crypto.subtle for AES on Browser WASM (#71501)Eric Erhardt
* Use crypto.subtle for AES on Browser WASM Implement the browser "native" portion for AES on Browser WASM. There are two issues to solve .NET's Aes API on crypto.subtle: 1. The .NET API supports streaming while crypto.subtle only supports "one shot" APIs. 2. The .NET API supports multiple padding modes while crypto.subtle only supports PKCS7. To solve these issues, we use the following approach: 1. We only invoke crypto.subtle with complete AES "blocks" of data. This allows us to make assumptions about the padding behavior. 2. To implement streaming, remember the last block of the previous cipher text to use as the IV for the next stream of data. 3. When encrypting, since we have a complete block of data and crypto.subtle uses PKCS7 padding, strip off the last block of cipher text which will always be a full block of padding. 4. When decrypting do the inverse of encrypting - append an encrypted block of padding to the cipher text so crypto.subtle will return the full message as plain text. Other changes: - Make a few refactoring / simplifications where necessary. - SubtleCrypto doesn't support 192 bit AES keys, so no longer support AES-192 on Browser. Contributes to #40074 * Use an empty array to create encrypted padding block.
2022-07-02[wasm] Don't pollute VS Code TS suggestions with node (#71540)Aleksey Kliger (λgeek)
* [wasm] Don't pollute VS Code TS suggestions with node Set `types` explicitly to [], so that we don't get globalThis bindings from node_modules/@types/node. This affects the type inference for functions like `setTimeout` which should have return type `number` in browsers, not `NodeJS.Timer`. * fix a couple of incorrect types * we use Node's Buffer type to type some of Emscripten's APIs
2022-07-01[wasm-mt] Add MessageChannel between browser thread and new pthreads (#70908)Aleksey Kliger (λgeek)
Add a mechanism for creating a communication channel between the browser thread and new pthreads (running in webworkers - note, Emscripten may recycle workers after a pthread exits). This is done by adding our own event listener to the webworker (in the main thread) and to globalThis (in the worker). This conflicts with emscripten's message handlers (although it's considered a bug by Emscripten upstream that their event handler doesn't ignore unrecognized messages). One potential problem here is that for any communication to happen, the worker must service its event loop. If it's just busy running a loop in wasm, it might never handle the messages. On the other hand, posting messages back to main should work. Once we have our message handlers in place, the rest is straightforward, the worker creates a MessageChannel and transfers one of the ports to the browser thread. With the browser-to-pthread channel established, we can build up cross-thread channels by asking the main thread to transfer ports on our behalf. This part isn't done yet. --- Additionally in the worker, create an `EventTarget` that fires `dotnet:pthread:created` and `dotnet:pthread:attached` events whenever Emscripten begins running a new thread on one of its workers, and whenever that worker attaches to Mono. This lets runtime subsystems be notified on the JS side whenever threads come into existence or may potentially begin to run managed code. --- Also re-organizes our `tsconfig.json` into `tsconfig.shared.json` (common flags), `tsconfig.worker.json` (uses the `esnext` and `worker` libs, so VS Code doesn't offer DOM completions and types, for example), and `tsconfig.json` (uses the `esnext` and `dom` libs). Subsystems with their own subdirectories (like `pthreads/worker` `pthreads/browser`, etc) can use the `tsconfig` `extends` property to include the appropriate root-directory config. --- * outline of a dedicated channel between JS main thread and pthreads * add JS entrypoints for pthread-channel * wire up the MessageChannel to native thread attach * debug printfs etc * split up into pthread-channel module into worker, browser and shared * pthreads modules * add ENVIRONMENT_IS_PTHREAD; mono_wasm_pthread_worker_init * Fixup names; call MessagePort.start; remove printfs * remove whitespace and extra printfs * Exclude threading exports in non-threaded runtime Use the `USE_THREADS` emscripten library ifdef to prevent the entrypoints from being saved. Use a new `MonoWasmThreads` rollup constant to remove JS roots. Verified that a Release build single-threaded dotnet.js doesn't include any of the new pthread support code * Add replacement for PThread.loadWasmModuleToWorker This will allow us to install a message handler when the worker is created, before it has any pthreads assigned to it. We can therefore simplify how we set up our own MessageChannel to simply send a single event from the worker to the browser thread, instead of having to lazily install the event handler on the main thread by queueing async work to the browser thread. * Simplify the dedicated channel creation now that we can add a message handler to a worker when Emscripten creates it, skip the complicated atomic notification process * Don't forget the GC transition out to JS * fix browser-eventpipe default import * move mono_threads_wasm_on_thread_attached later in register_thread Actually attach the thread to the runtime (so that GC transitions work) before calling out to JS * also fix default import in browser-mt-eventpipe * Add replacement for Module.PThread.threadInit Use it to call mono_wasm_pthread_on_pthread_created Rename the previous callback to mono_wasm_pthread_on_pthread_attached - it gets called but it's unused. This is enough to get the diagnostic sever worker started up and pinging. * Cleanup mono_wasm_pthread_on_pthread_created * Share tsconfig parts using "extends" property * Use an EventTarget and custom events for worker thread lifecycle notifications * pass portToMain in ThreadEvents; update README this lets pthread lifecycle event handlers post messages and setup listeners on the message port back to the main browser thread. Also update the README to describe the current design * make pthread/worker/events friendlier to tree shaking and node * another approach to tree shaking rollup doesn't understand fallthru. In the following (which is what `mono_assert` ammounts to) it retains `C`: ``` if (condition) throw new Error (...); // fallthru return new C(); ``` Solution is to use an if-then-else ``` if (condition) throw new Error (...); else return new C(); // C is not retained if 'condition' is false ``` * fix annoying VSCode ESLint toast Cannot read property 'loc' of undefined See https://github.com/microsoft/vscode-eslint/issues/1149 and a proposed workaround in https://github.com/eslint/eslint/issues/14538#issuecomment-862280037 * Add Event and EventTarget polyfill for v8 * fix whitespace and comments
2022-07-01[wasm] Clean up debugger tests output (#71483)Ankit Jain
2022-06-30[wasm] Preparation for public API in ↵Pavel Savara
System.Runtime.InteropServices.JavaScript (#71332) * new ref assembly System.Runtime.InteropServices.JavaScript - empty * new src assembly System.Runtime.InteropServices.JavaScript moved all implementation from System.Private.Runtime.InteropServices.JavaScript into it * added IMPORTS, EXPORTS to js API * refactored setup_managed_proxy and teardown_managed_proxy in JS * added more range assert for working with wasm memory in JS
2022-06-24[wasm][debugger] Fixing entrypoint breakpoint on release mode. (#71235)Thays Grazia
* Fixing entrypoint breakpoint on release mode. * Remove unnecessary code and adding comments. * changing console.log to console.trace. * Adding comments
2022-06-24[wasm] Switch default modules to es6 (#70746)Pavel Savara
switched dotnet.js to be ES6 module by making <WasmEnableES6> default true updated all samples updated functional tests updated debugger tests updated test-main updated templates Co-authored-by: Marek Fišera <mara@neptuo.com> Co-authored-by: Ankit Jain <radical@gmail.com>
2022-06-22Use crypto.subtle for HMAC on Browser WASM (#70745)Eric Erhardt
* Use crypto.subtle for HMAC on Browser WASM Implement the browser "native" portion for HMAC on Browser WASM. I also made a few refactoring / simplifications where necessary. Contributes to #40074
2022-06-21[wasm] Migrate to ref/out param while reading data from typed array (#70823)Marek Fišera
Use js_typed_array_to_array_root in mono_wasm_typed_array_to_array_ref
2022-06-14[wasm][debugger] Implement get bytes from loaded_files using debugger ↵Thays Grazia
protocol. (#69072) * Implement get bytes from loaded_files using debugger protocol. * fix pdb size == nul * Adressing @radical comments. * Fix build. * fix compilation * Addressing @radical comments. Co-authored-by: Ankit Jain <radical@gmail.com>
2022-06-14[wasm] Make runtime_is_initialized promise callbacks one-shot (#70694)Aleksey Kliger (λgeek)
* [wasm] Make runtime_is_initialized promise callbacks one-shot Throw if runtime_is_initialized_resolve or runtime_is_initialized_reject is called more than once * Add a slightly generalized GuardedPromise<T> object Protects against multiple-resolve, multiple-reject, reject after resolve and resolve after reject. Does not protect against the executor throwing.
2022-06-14[wasm] Fix Debug configuration builds (#70683)Aleksey Kliger (λgeek)
* Fix cmake error ``` Manually-specified variables were not used by the project: CONFIGURATION_WASM_OPT_FLAGS ``` * Build the interpreter with -O1 on Wasm in Debug configs Otherwise `interp_exec_method` and `generate_code` can easily overflow the stack in some browsers with even a few recursive calls (for example during .cctor initializaiton)
2022-06-10[wasm] Add infrastructure for building WebWorkers (#70220)Aleksey Kliger (λgeek)
* [wasm] Add infrastructure for building WebWorkers - Modify the rollup.config.js script to look for webworkers and to roll them up into IIFE js files in the ${nativeBinDir}/src artifacts directory - A "webworker" is any file in `src/mono/wasm/runtime/workers/` that looks like `dotnet-{workerName}-worker.ts` or `.js`. It can also include other files (ideally by defining them in files in subdirectories for that worker `src/mono/wasm/runtime/workers/dotnet-{workerName}-worker/utility.ts`) - Other changes still have to be done manually in wasm.proj, and elsewhere in order to place the bundled JS file in the right place. - Adds a tsconfig.json for the workers to typecheck using the DedicatedWorkerGlobalScope and without the DOM globals (`window`, etc) - This doesn't convert dotnet-crypto-worker.js into TypeScript, but it does turn on TypeScript checking using a JSDoc comment. To convert that file to typescript: 1. rename `workers/dotnet-crypto-worker.js` to `workers/dotnet-crypto-worker.ts` 2. replace uses of `var` by `let` or `const` 3. add `:any` in various places. * use fast-glob instead of fs.readdir * add fast-glob to devDependencies
2022-06-08[wasm] Add legs to build wasm with internal threads only and full threading ↵Steve Pfister
enabled (#68787) This change adds two build-only lanes to `runtime` and two full build+test lanes to `runtime-wasm` that builds wasm with internal threads only (`WasmEnablePerfTracing`) and full threading (`WasmEnableThreads`). The `runtime-wasm` additions can only be manually triggered at this time. Co-authored-by: Aleksey Kliger (λgeek) <alklig@microsoft.com> Co-authored-by: Ankit Jain <radical@gmail.com>
2022-06-07Fix race condition in WASM crypto worker (#70185)Eric Erhardt
When sending a message between LibraryChannel and ChannelWorker, there is a race condition where both threads are reading/writing to shared memory at the same time. This can cause message pages to be skipped. To fix this, add a shared mutex lock so only one side is reading/writing to shared memory at the same time. Fix #69806
2022-06-06[wasm][debugger]Fix entrypoint breakpoint when it's an async method (#69856)Thays Grazia
* Fix entrypoint when it's an async method. Add methods in the type even if there isn't source information. * Update src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs Co-authored-by: Ankit Jain <radical@gmail.com> * Addressing @radical comments. * Addressing @radical comment * Update src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs Co-authored-by: Ankit Jain <radical@gmail.com> * Address @radical comments. * Revert @radical suggestion. * Addressing @radical comment. * Addressing @radical comments offline. * Addressing @radical comments offline. Co-authored-by: Ankit Jain <radical@gmail.com>
2022-06-06[wasm] Initial SIMD support (#70086)Radek Doulik
Add initial SIMD support for wasm. This is subset of the original [draft PR](https://github.com/dotnet/runtime/pull/67848) without the public API additions. Add `WasmSIMD` property to enable SIMD in AOT builds. With the property enabled, the apps built with AOT get SIMD intrinsics inlined for parts of `S.R.I.Vector128` and `S.R.I.Vector128<T>` API. Add test to build and run a simple app with SIMD enabled. * Initial wasm SIMD support * Enable Vector intrinsic on wasm The llvm code generator works nicely with them. * Add missing files * Make SIMD support conditional * Remove test code * Fix debug build * Update after merge * Add Splat and ExcractLane methods * Switch i64 values for Constant method So that C# WasmBase.Constant(0xff11ff22ff33ff44, 0xff55ff66ff77ff88) is compiled into wasm code v128.const 0xff11ff22ff33ff44ff55ff66ff77ff88 [SIMD] * Update PlatformNotSupported version of WasmBase * Fix CI build * Add ReplaceLane and Swizzle * Change WasmBase.Constant to get Vector128 as input * Add Shuffle methods This will need more work, as it crashes clang during 'WebAssembly Instruction Selection' pass: WasmApp.Native.targets(353,5): error : 3. Running pass 'WebAssembly Instruction Selection' on function '@corlib_System_Runtime_Intrinsics_Wasm_WasmBase_Shuffle_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte' * Handle SN_Shuffle * Fix crash in OP_STOREX_MEMBASE * Add build test * Set WasmSIMD to false as default value Also add "experimental" to the property comment * Remove public API, it will be part of another PR * Add link to the llvm issue * Review feedback * Review feedback
2022-06-02[wasm] Add support for symbolicating traces via XHarness (#66226)Ankit Jain
* [wasm] Add `WasmSymbolicator` project - this can be used to symbolicate traces using patterns from `src/mono/wasm/data/wasm-symbol-patterns.txt`. - Includes a wrapper that can be passed to xharness for symbolicating traces in the output. - This can be used as a command line tool also: `dotnet run /path/to/dotnet.js.symbols /path/to/traces` If `-` is passed instead of the last argument, then it reads the messages from stdin. * [wasm] Enable xharness+symbolicator for library tests * [wasm ] startup.ts: improve printing errors * [wasm] test-main.js: print 'WASM EXIT' message even for non-browser cases * [wasm] Enable symbols file generation for samples in Release config * [wasm] Fix file check * Fix build * fix dotnet-linker-tests build * Update condition for using wasmsymbolicator with xharness * Update build-commons.sh Revert unnecessary change * Update gen-buildsys.sh Revert unnecessary change * Update build.sh Revert unnecessary change
2022-06-02[wasm-ep] Implement EventSource counters support; add an ↵Aleksey Kliger (λgeek)
EventPipeSessionOptions builder to TS (#69567) 1. Implements support for creating event counters in WebAssembly apps. **Important change** adds `Thread.IsInternalThreadStartSupported` and `Thread.InternalUnsafeStart()` to `System.Threading.Thread` that can be used by System.Private.CoreLib to start threads on a runtime where `Thread.IsThreadStartSupported` is false. This is used to create the event counters polling thread. This is in addition to the native runtime being able to create threads using `mono_thread_create_internal` 2. Coop thread suspend: STW calls `mono_threads_platform_stw_defer_initial_suspend` which postpones suspending a thread until the next GC suspend phase. Doesn't do anything on most platforms. On WASM, suspend the main browser thread after all the other threads are suspended. This helps prevent deadlocks where the main thread is suspended while another thread is doing a call that is proxied to the main thread and cannot complete. By suspending the main thread last, we give it a chance to service the other threads' requests. 2. Adds a `MONO.diagnostics.SessionOptionsBuilder` class that can be used to create an `EventPipeSessionOptions` instance and populate the provider string for an event pipe session. 3. Updated the `browser-eventpipe` sample to create an EventSource and some counters. The sample is now interactive so you have to click "Start Work" in a browser for things to happen. There's an outstanding issue https://github.com/dotnet/runtime/issues/69568 that will be investigated in a follow-up PR * Add custom EventSource and counter - Added a method for coop GC to suspend the main browser thread in the second phase (so that other threads are less likely to deadlock if they delegate work to it) - Added an event provider builder - Added a Thread.InternalUnsafeStart() method and a IsInternalThreadStartSupported property. This allows EventSource to start a thread to poll the counter values. - The sample with counters can now record counter values. But not at the same time as the default configuration (runtime, runtime private, sample profiler). Not sure if it's a wasm issue or a limitation of EventPipe. * Change ProvidersConfigBuilder to SessionOptionsBuilder it creates an entire EventPipeSessionOptions object, not just the providers config * checkout interactive demo * Add docs; fix whitespace * more whitespace fixes * add default arg value to ThrowIfNoThreadStart * fix build * Review feedback
2022-05-30[wasm] Process WebSocket connection errors on NodeJS (#69858)Marek Fišera
2022-05-28[MONO] Factor marshal-lightweight out of marshal-ilgen (#69208)Nathan Ricci
Refactor marshaling code into marshal-ilgen and marshal-lightweight.
2022-05-25Reimplement I52/U52 in C, clean up and optimize range checks (#69624)Katelyn Gadd
This PR reimplements the I52/U52 memory accessors in C since the JS got really complicated and we kept finding bugs. It also simplifies some of the range checks in the other accessors so they will have less overhead, and uses some unchecked accessors in a few hot paths. - Move _zero_region to memory and export it. Zero the stack-allocated buffer used by converters
2022-05-25[wasm] Consolidate interop tables generators (#69620)Marek Fišera
Combine PInvoke, icall and ManagedToNative generators to a single MSBuild task.
2022-05-25[wasm] fix negative scenarios (#69742)Pavel Savara
Fixed more scenarios for int52 and improved tests
2022-05-25Use SubtleCrypto API on browser DOM scenarios (#65966)Layomi Akinrinade
* Use SubtleCrypto API on browser DOM scenarios * Add sync over async implementation * Address misc feedback and make fixes * Address pinvoke errors * [Attempt] Correct execution of native digest API call at wasm layer * [Fix up] Correct execution of native digest API call at wasm layer * Update src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs * Address feedback and clean up * Re-implement the crypto worker in ts * Address feedback * Revert "Re-implement the crypto worker in ts" This reverts commit 6a743909605fb5b1194cae6bf571c2e6ff059409. * * moved stuff around and renamed it * initialization bit later * Add code to handle errors in worker (particularly on init) * Clean up * Add crypto dll to wasm native project * Add e2e test * Adjust test to reflect lack of SharedArrayBuffer for Chrome in test harness * Enable Chrome test and validate hashed value in tests * fix merge to track assert being renamed to mono_assert Co-authored-by: Eric StJohn <ericstj@microsoft.com> Co-authored-by: pavelsavara <pavel.savara@gmail.com> Co-authored-by: Ankit Jain <radical@gmail.com>
2022-05-24Switch from malloc to stackAlloc for bindings invokes and optimize themKatelyn Gadd
* Change converters to use a stack-allocated buffer instead of a malloced one. Works around heap corruption bug (#69681) and improves performance/reduces code size * Remove the args rootbuffer for bindings calls, because stack-allocating the pointers pins them automatically * Manually save/restore the stack offset when entering/exiting a bindings invoke * When doing rooted argument conversion in the bindings use an external root to directly write into the stack
2022-05-23Fix typos (#69537)Adeel Mujahid
* Fix typos * Fix typo: seperate -> separate * Rename ApplicationNameSetFromArgument * Update src/coreclr/vm/methodtablebuilder.cpp * Update docs/coding-guidelines/clr-code-guide.md Co-authored-by: Dan Moseley <danmose@microsoft.com> * Update src/mono/mono/tests/verifier/make_tests.sh Co-authored-by: Dan Moseley <danmose@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
2022-05-22[wasm-mt] Add coop GC transitions to various EMSCRIPTEN_KEEPALIVE functions; ↵Aleksey Kliger (λgeek)
define to noop if no threads (#69515) * [wasm-mt] fix GC transition in mono_set_timeout_exec It's called from JS * Add GC transitions to other EMSCRIPTEN_KEEPALIVE functions in the runtime * define GC Safe / Unsafe macros to no-ops if DISABLE_THREADS is defined We don't need to do GC transitions if there's no threading since we won't ever suspend ourselves
2022-05-20[wasm] improve memory access and marshaling range checks (#64845)Pavel Savara
* new memory accessors setI52, setI64Big, getI52, getI64Big * removed support for long form automatic marshaler. It has impact to mono_bind_static_method * made assert silent on Release config * test for not marshaling long from C# to JS * negative test for marshaling NaN as long * fixed marshaling of uint32, uint16 and byte to be unsigned * implemented range check on all set memory operations * implemented also uint52 * differentiated bool marshaling because it shoud have different validation and message * inlined asserts * rename assert to mono_assert
2022-05-19[wasm-ep] Minimal diagnostic tracing configuration and sample (#69158)Aleksey Kliger (λgeek)
* Adds a `/p:WasmEnablePerfTracing=true` configuration. In this configuration the runtime is built with threading (`MonoWasmThreads` property is true), but user C# code is not allowed to start threads and doesn't use the portable threadpool (`MonoWasmThreadsNoUser` property is also true). The upshot is that EventPipe can start threads but user code is still single-threaded. * Adds a `MONO.diagnostics` interface in JavaScript. There's a single method for now `createEventPipeSession` which creates a session that can save a trace to a file on the virtual file system. JS code (or a user in a dev console) needs to call `start()` and `stop()` on the session object to begin collecting samples. The data is saved temporarily to the Emscripten VFS and can be retrived into a JavaScript Blob (and from there downloaded to a file outside the browser). * Adds a sample that runs an async task for five seconds and collects samples and then triggers a `click()` to download the trace file out of the browser. * Adds a TS module to help with working with uint64_t values in the emscripten heap. * Exposes empscripten Module.stackSave, stackRestore and stackAlloc operations to the runtime TS modules. Use for working with event pipe session ID outparam. --- * add DISABLE_WASM_USER_THREADS mono cmake option * Disable Thread.StartInternal icall if DISABLE_WASM_USER_THREADS if threading is enabled for the runtime internally, but disabled for user code, throw PNSE * add an eventpipe sample * [wasm-ep] (browser-eventpipe sample) run loop for longer * [samples/wasm-eventpipe] make an async task sample change the sample to do some work asynchronously using setTimeout instead of blocking * [wasm] Add MONO.diagnostics interface Binds enable, start, disable methods defaulting to non-streaming FILE mode * if wasm threads are disabled, but perftracing is enabled, don't log overlapped io events * fix whitespace and nits * don't need try/finally in the sample anymore * more whitespace * add start method to EventPipeSession interface * don't run wasm-eventpipe sample on CI lanes without perftracing * more whitespace * fix eslint warnings, default rundown to true, allow callback for traceFilePath option * add EventPipeSession.getTraceBlob for retrieving the collected traces instead of exposing the emscripten VFS directly. update the sample to use URL.createObjectURL (session.getTraceBlob()) to create the download link * [browser-eventpipe sample] remove unnecessary ref assemblies * use ep_char8_t for C decls of event pipe wasm exports * Use stack allocation for temporaries Expose the emscripten stack allocation API * Use 32-bit EventPipe session ID on WASM 64 bit integers are awkward to work with in JavaScript. The EventPipe session ID is derived from a pointer address, so even though it is nominally a 64-bit value, in practice the top bits are zero. Use a 32-bit int to represent the session ID on the javascript side and convert to 64-bit in C when calling down to the EventPipe APIs * Make the sample do more work in managed give the sample profiler some non-empty samples to collect * Move withStackAlloc to memory.ts * simplify VFS .nettrace file naming Just use consecutive integers to uniquify the session traces. Dont' need a fancy timestamp in the VFS (which would also not be unique if you create sessions below the timestamp resolution) * Add overloads to memory.withStackAlloc to avoid creating closures Pass additional arguments to the callback function * sample: explain why there's a 10s pause * move createEventPipeSession callback to a function ensures the closure is created once * Use a tuple type for withStackAlloc * use unsigned 32-bit get/set in cuint64 get/set * fix whitespace
2022-05-18[wasm] Give is_nullish() a type guard type (#69473)Aleksey Kliger (λgeek)
* [wasm] Give is_nullish() a type guard type allow callers to refine the type of the argument to just `T` on the false brach ``` let obj: number | null | undefined = ... if (is_nullish (obj)) return; // otherwise obj is known to TS to be 'number'. ```
2022-05-17Wasm conditional audit + remove CompileFunction (#69283)Katelyn Gadd
* Revise some if statements that implicitly treat the empty string as null Add is_nullish utility function Fix string decoder's handling of empty strings and query of string length * Fix some uses of the logical or operator * Remove unused CompileFunction interop API
2022-05-13[wasm] Misc debugger improvements (#68988)Ankit Jain
* [wasm] Move the browser provisioning stuff to a new targets file .. from `DebuggerTestSuite.csproj`. This will allow other projects to use this too. * [wasm][debugger] Handle failure to connect to the browser * [wasm] Improve the browser path lookup so it can be used outside the debugger tests project too. For example, with Wasm.Build.Tests+playwright . * [wasm][debugger] Throw exceptions from tasks correctly .. using `ExceptionDispatchInfo.Capture` so we get the original stack trace. * [wasm][debugger] General improvements in debug proxy - like logging - updated API to make it easier to use by other projects, like the upcoming wasm-app-host . * [wasm][debugger] Add support for setting an automatic breakpoint .. on the first line of the entrypoint method (`Main`). This will be useful for debugging with the upcoming wasm-app-host, along with the use of `wait-for-debugger`. Implemented by @thaystg . * [wasm][debugger] Add support for wait_for_debugger If requested, then it will cause invocation of `main` to be delayed till a debugger is attached. Implemented by @thaystg * [wasm] Cleanup in Wasm.Build.Tests .. in the lead up to wasm-app-host tests. * [wasm] Update the default paths used to trigger builds on CI .. to include templates, and provisioning props. * disable non-wasm builds * [wasm][debugger] Fix path to artifacts dir * [wasm] Emit message with bundle path * [wasm][templates] Make the project use the target dir's name as the .. project name, instead of always creating `browser.dll`, and `console.dll`. * [wasm][debugger] Use a single static instance of HttpClient .. as recommended by the documentation. * Revert "disable non-wasm builds" This reverts commit 7b8b60d58c886e7e66cf2fea910f1feb4d6374f1. * Address review feedback, and improve the autogenerated bpid
2022-05-10fix(wasm): Discriminate satellite assemblies loading based on culture (#68195)Jérôme Laban
* fix(wasm): Discriminate satellite assemblies loading based on culture * add `--fetch-random-delay` test parameter * enable emscripten ASSERTIONS=1 on SatelliteAssembliesTests.ResourcesFromMainAssembly Co-authored-by: pavelsavara <pavel.savara@gmail.com>
2022-04-29Fixing firefox implementation to avoid this warning: "Addind an id that ↵Thays Grazia
already exists in commands_received" (#68618)
2022-04-29[wasm] Migrate rest of the JS interop functions to out params (#68642)Marek Fišera
Migrate rest of the JS interop functions to out params instead of return. A follow up on the https://github.com/dotnet/runtime/pull/65994. - `mono_wasm_invoke_js_with_args` - `mono_wasm_cancel_promise` - `mono_wasm_compile_function`
2022-04-26[wasm][debugger] Debug on firefox (#61776)Thays Grazia
* First compiling and working version just proxying messages. * almost working, already showing the cs files * Working on firefox. * Use internal e not public. * Debugging on firefox working. * Working after the merge * Keep the TcpListener open and use a random port. * Show null value. * - Show JS Callstack - Skip properties - Get array value from evaluateAsyncJS and not use the preview value. * Fix compilation * Infrastructure to run debugger tests. * fix merge * run test. * Skipping tests that are not passing on Firefox. * Skipping tests that are not passing on Firefox. * Passing 13 steppingtests. * Passing 13 steppingtests. * Passing 13 steppingtests. * Failed: 0, Passed: 39, Skipped: 203, Total: 242, Duration: 5 m 6 s - DebuggerTestSuite.dll (net6.0) * Failed: 0, Passed: 66, Skipped: 195, Total: 261, Duration: 9 m 29 s - DebuggerTestSuite.dll (net6.0) * Using ConditionalTheory and ConditionalFact implemented by @radical. * Fixing side effect. * Implemented conditional breakpoints. Failed: 0, Passed: 74, Skipped: 189, Total: 263, Duration: 8 m 41 s - DebuggerTestSuite.dll (net6.0) * Fix special characters and pointers. Failed: 0, Passed: 116, Skipped: 177, Total: 293 * Fix merge * Run debugger-tests on firefox using codespace * Starting firefox correctly not stopping in the breakpoint yet. * Remove unnecessary change * Fix pause behavior (now showing correctly, pause on breakpoint, pause while stepping) Start implementing evaluate expressions, working correctly on VSCode. * Fix local tests. * Fix missing ) * Passing 190 tests, evaluate expressions working. * Remove Task.Delays. Move some attributes from FirefoxMonoProxy to FirefoxExecutionContext. * Fix container creation * Trying to run firefox tests on CI. * Moving file to the right place. * Trying to run debugger-tests using firefox on CI. * fixing path * Missing url to download firefox on helix. * On run the tests only on linux. * Trying to download firefox on helix. * fix error on helix-wasm.targets. * trying to fix ci * trying to install firefox on helix. * Fixing firefox path * Fix debugger tests on firefox * fixing profile path * Install libdbus-glib-1-2 on docker and on codespace * Trying to run using firefox on CI * update docker image * Adding more messages to see errors on CI * Trying to make it work on CI * Real test on CI * Trying to use the firefox machine only to run firefox tests Retrying connection to Proxy Remove extra messages added to help to fix CI * Fix CI * Fix CI * Fix CI. * Remove unnecessary changes. * Using machine with sudo installed * Addressing @lewing comments * Fix run tests on codespace Using image with python3 * Use default image to build and new image only to run firefox tests * Fix unrelated change * Fix ci * check python version * Print python versions * Using image with PIP installed * Using image with pip updated * Remove unrelated changes Increase time to wait for firefox to be ready * Trying to fix evaluate tests. * Fix evaluateoncallframe tests * Trying to fix evaluation tests. * trying to fix evaluateoncallframetests * fiz evaluateoncallframetests * Trying to kill firefox to avoid errors. * Trying to fix EvaluateOnCallFrameTests * Fix CI * Remove failing test * Fix misctests * Fix other build errors. * Trying to fix CI. * Fix CI * Remove unecessary message. * Update src/tests/BuildWasmApps/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj Co-authored-by: Ankit Jain <radical@gmail.com> * Addressing @radical comments * Merge error while accept @radical suggestion * Merge error while accept @radical suggestion * Update src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs Co-authored-by: Ankit Jain <radical@gmail.com> * Apply suggestions from code review Co-authored-by: Ankit Jain <radical@gmail.com> * Addressing @radical comments * Abort the tcp connection if the proxy throws an exception * Refactor a bit * Use more compile time checks for chrome vs firefox * fix pipeline * Make debugger job names unique by including the browser * fix runtime-wasm pipeline * fix firefox ci job * split into more files * cleanup * Add support for running chrome, and firefox tests in the same job * fix yml * fix build * fix build * fix windows build * Don't delete profile folder nor pkill firefox * Delete and create a new profile folder for each execution * fix helix command line * [wasm][debugger] Fix tests broken on 'main' This test broke because it was checking for the number of members on `System.TimeSpan`, and that changed with https://github.com/dotnet/runtime/pull/67666 , which added new members like `TotalNanoseconds`. The test shouldn't depend on this number anyway, so remove that. ``` Failed DebuggerTests.MiscTests.InspectLocalsForToStringDescriptions(line: 137, col: 12, method_name: "MethodWithLocalsForToStringTest", call_other: False, invoke_async: False) [758 ms] Error Message: [ts_props] Number of fields don't match, Expected: 12, Actual: 16 Expected: True Actual: False Stack Trace: at DebuggerTests.DebuggerTestBase.CheckProps(JToken actual, Object exp_o, String label, Int32 num_fields) in /_/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs:line 800 at DebuggerTests.DebuggerTestBase.CompareObjectPropertiesFor(JToken locals, String name, Object o, String label, Int32 num_fields) in /_/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs:line 908 at DebuggerTests.MiscTests.InspectLocalsForToStringDescriptions(Int32 line, Int32 col, String method_name, Boolean call_other, Boolean invoke_async) in /_/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs:line 559 ``` * wip * big refactor * chrome runs * ff runs * ff runs * cleanup * cleanup * cleanup * change console verbosity to info, for proxy * More refactoring * More refactoring, and fix some issues with connections, and other cleanup * some cleanup * fix file name * Improve cleanup after tests * some refactoring, fixing some hangs, faster failures etc * Fix BrowserCrash test for chrome * fix up logging * Improve error handling for the proxy running independently * fix debugging from vscode * proxy host: add --log-path for logs * support canceling for the proxy host too, and distinguish different instances of the proxy * Fix debugger after refreshing the debugged page. * Fixing chrome debugging. * Fix startup to work on chrome and also on firefox. Co-authored-by: Ankit Jain <radical@gmail.com>
2022-04-26[mono] merge wasm-threading-eventpipe into main (#68232)Aleksey Kliger (λgeek)
Merge initial work on multi-threaded WebAssembly. The normal wasm build is single-threaded. There should be no functional changes to its behavior. To enable a multi-threaded build pass `/p:WasmEnableThreads=true`. See `src/mono/wasm/threads.md` for details. The big changes are: 1. The normal ref assemblies related to threading retain `[UnsupportedOSPlatform("browser")]` attributes for various threading-related functions 2. In System.Private.CoreLib, the `[UnsupportedOSPlatform]` attributes are removed, and functions that used to always throw PNSE nwo do a runtime check using `System.Threading.Thread.IsThreadStartSupported` to check if threading is enabled in the current build. 3. A new nuget `Microsoft.NET.WebAssembly.Threading` is created. It contains experimental ref assemblies without the `[UnsupportedOSPlatform]` attributes. The intention is that code opting into experimenting with multithreading will include this nuget by setting some property that will be used by the wasm MSBuild SDK to pick a multi-threaded runtime build and configure things appropriately. (The SDK updates don't exist yet). 4. In the multi-threaded runtime we don't use Emscripten's "main thread" option (ie: the browser thread is the main one); we also continue to run certain runtime-internal jobs (finalizers, GC pump) on the main thread even in the multi-threaded runtime. Remaining work is tracked in the related issue https://github.com/dotnet/runtime/issues/68162 --- * Initial changes for emscripten 2.0.34 * Use emcc-link.rsp in build targets * Use updated docker images * Fix compiler warnings * Put `--profiling-funcs` to `_EmccLinkFlags` * Fix build src/mono/mono/mini/mini-runtime.c:3407:25: error: ‘invoke’ undeclared (first use in this function); did you mean ‘revoke’? 3407 | invoke = mono_marshal_get_runtime_invoke_dynamic (); * Add shell to the environment Environment setting https://github.com/emscripten-core/emscripten/blob/2.0.34/src/settings.js#L616-L641 From emscripten 2.0.25 release notes - Support for the 'shell' environment is now disabled by default. Running under `d8`, `js`, or `jsc` is not something that most emscripten users ever want to do, so including the support code is, more often than not, unnecessary. Users who want shell support can enable it by including 'shell' in `-s ENVIRONMENT` (#14535). Example of the the size increase for bench sample: -a--- 12/10/2021 3:35 PM 382113 dotnet.js -a--- 12/13/2021 10:37 AM 383589 dotnet.js * Add emcc-link.rsp to PlatformManifestFileEntry * Feedback https://github.com/emscripten-core/emscripten/blob/2fda25eea756c78c8cb024aa5b6c2b188bf7990f/src/settings.js#L1173-L1176 -s EXPORT_ES6 is link option * Bump emscripten version * Bump llvm package version and use its libclang * Use newer docker images with emscripten 3.1.1 * Remove unused variable * Add runtime support for threads in the wasm build To enable, pass `/p:WasmEnableThreads` when building the runtime ./build.sh -Subset mono+libs -os Browser -arch wasm /p:WasmEnableThreads=true * Prevent runtime from starting twice when loaded in a web worker * Automatically populate the emscripten mainScriptUrlOrBlob property so that worker initialization can find dotnet.js * Add compatibility shim so that emscripten's generated worker.js can properly get a Module instance, since we broke the API * Checkpoint * Bring back threadpool and add some tracing in diagnostics * Add comments and fix a typo * Introduce 'MonoObjectRef' ts type. Migrate mono_string_intern to not have a retval * Checkpoint (strings are broken for some reason) * Fix string interning * Migrate ObjectToString and GetDateValue * Checkpoint gc safe/unsafe region work * More ref conversion * Checkpoint (broken?) * Fix missing method * Fix incorrect signatures * Fix lint * Add new 'R' signature char for 'ref object' * Remove AddEventListener and RemoveEventListener Checkpoint * eslint fixes * Update call_method signature to avoid passing raw object pointers * Ref-ify one websocket API and fix types and incorrect rooting of two others * Deprecation metadata * More ref * Remove outdated comments * Convert typed_array_new to ref * Add volatile modifiers, satisfy eslint * Update src/mono/wasm/runtime/corebindings.c * Missing conflict * Fix build, set coop gc, and always copy dotnet.worker.js when it's around for apps * Disable sample profiler, add some functions that were missing from katelyn's PR. * Add safepoint around ep_rt_wait_event_set. Tweak sample to explicitly exit wasm in order to properly flush event to the nettrace file (w/ rundown events). * [gc] Start the GC Finalizer thread on threaded WASM * [mono] add GC Unsafe in mono_assembly_load; remove in EventPipe Remove GC Unsafe hack in ep_rt_wait_event_set * post-merge cleanup: delete duplicated definitions * [sample] Env vars should be stringy * updated dotnet.d.ts * Add mono_threads_wasm_async_run_in_main_thread; do background work on main Don't start a finalizer thread Queue all background work to run on the main thread * [mono] Fix non-threaded wasm build * Add a System.Threading.Thread.WebAssembly.Threading ref assembly * Update the browser sample to use System.Threading.Thread.WebAssembly.Threading * Rationalize System.Threading.Thread build In CoreLib, never add the [UnsupportedOSPlatform("browser")] attribute. Rely on runtime checks (`ThrowIfNoThreadStart()`). In System.Threading.Thread ref assembly, always add the unsupported platform attribute. Add mismatches to ApiCompat baseline. In System.Threading.Thread.WebAssembly.Threading don't add the attributes, and also set DisablePackageBaselineValidation to prevent Restore from looking for a System.Threading.Thread.WebAssembly.Threading nuget (fixes in-tree ProjectReferences for testing) * only turn on analyzers for the browser sample not all wasm samples * Make a single Microsoft.NET.WebAssembly.Threading nupkg that holds all the special ref assemblies * works: sample has ProjectReference to the Microsoft.NET.WebAssembly.Threading.proj * Add System.Threading.ThreadPool.WebAssembly.Threading ref assembly * ThreadPool: throw PNSE if no thread start * Update wasm threads.md * apicompat: correct warnings for System.Threading.ThreadPool * Add dotnet.worker.js to the runtime pack; update PlatformManifestFileEntry * [wasm] startup: detect Blazor dotnet.[version].[hash].js location Blazor injects a `<link rel="modulepreload" />` element into the header when it boots; detect it and extract the URL of the script. This is needed by Emscripten's dotnet.worker.js to run WorkerGlobalScope.importScripts * one more fix to Microsoft.NET.WebAssembly.Threading Seems to be necessary in order for the resulting .nupkg not to reference non-existent nugets for the ProjectReferences * rename sample to browser-mt-eventpipe * bring back unmodified browser sample The multithreading sample is browser-mt-eventpipe * update browser-mt-eventpipe sample to use ref assembly refs Referencing the rollup Microsoft.NET.WebAssembly.Threading.proj doesn't work (it ends up bundling the ref assemblies into the publish dir and breaking the app) * Use correct ifdef in AppContext.AnyOS.cs * [build] support WasmEnableThreads and WasmEnablePerfTracing These toplevel options either turn on multi-threading in general, or turn on multithreading only for eventpipe internals. For libraries these define `FeatureWasmThreads` and `FeatureWasmPerfTracing` properties and the `FEATURE_WASM_THREADS` and `FEATURE_WASM_PERFTRACING` compiler constants. For the native code, they control `DISABLE_THREADS` and `DISABLE_WASM_USER_THREADS` cmake and preprocessor settings. * Only add the portable threadpool on wasm if threading is enabled * rename browser-mt-eventpipe csproj and main assembly Give it a unique name distinct from Wasm.Browser.CJS.Sample.csproj * fix /p:WasmEnableThreads=false build after merge * now fix the WasmEnableThreads=true build * we need two ThreadPoolBoundHandle implementation stubs one for PortableThreadPool when threads are enabled, one for single-threaded wasm * Add a System.Diagnostics.Tracing ref assembly gated by FeatureWasmPerfTracing * [eventpipe] use the correct cmake option name see src/mono/mono.proj * revert debug printf and commented out code * turn off additional logging * hack: set FeatureWasmPerfTracing in the browser-mt-eventpipe sample It would be better to drive this (the inclusion of the tracing runtime component) from a user-visible flag. not the FeatureWasmPerfTracing implementation detail * remove unused variable, remove unneeded configure checks, revert line damage; add better comment in export.ts * Exclude Microsoft.NET.WebAssembly.Threading from testPackages.proj * review feedback, Apply suggestions from code review * Use a testPackages settings file to skip package runtime item verification * remove unneeded Directory.Build.props for ref package since ti doesn't compile its own assembly, none of these properties are needed * use one ProjectReference item to share metadata for the ref assemblies * remove ProjectReference comment and NoTargetsDoNotReferenceOutputAssemblies prop * Remove unneeded target * packaging simplification - move `_ExperimentalUpdateFileVersion` target to packaging.targets, conditioned on a new `IsExperimentalRefAssembly` attribute. (The target increments the file version of the ref assembly to make it easier to distinguish from the real non-experimental ref assembly) - Remove unneeded src subdirectories in ref assembly libraries - Move properties that are only used in the ref assembly projects directory into the projects and delete Directory.Build.props in the experimental ref assembly subdirectories. * move and rename UpdateExperimentalRefAssemblyFileVersion target packages.targets is only included for IsPackable=true projects, and these ref assemblies are not packable. * Assorted code review nits * Don't build/pack the multi-threaded sample on single-threaded runtime * remove gratuitous debug printfs * Apply suggestions from code review * merge followup: nullable is enabled by default now * make eslint happy * include wasm-config.h in wasm runtime host * include wasm-config.h into the runtime pack fixes aot compilation * Add wasm-config.h to manifest * put wasm-config.h into include/wasm from the outset * put back noExitRuntime replacement for CJS Co-authored-by: Radek Doulik <radekdoulik@gmail.com> Co-authored-by: Radek Doulik <radekdoulik@google.com> Co-authored-by: Zoltan Varga <vargaz@gmail.com> Co-authored-by: Steve Pfister <steve.pfister@microsoft.com> Co-authored-by: Katelyn Gadd <kg@luminance.org> Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
2022-04-15[mono] Cleanup assembly loading (#67984)Alexander Köplinger
- Remove parameters specifying the "runtime version" since that no longer makes sense in dotnet/runtime - Remove mono_config related logic, there is no app.config/machine.config anymore - Remove leftover code from GAC support - Remove probing for embedded (bundled) assemblies from mini/main.c, we don't use mkbundle in dotnet/runtime
2022-04-06Introduce write barriers in wasm bindings, migrate to ref/out params, add gc ↵Katelyn Gadd
safe regions (#65994) Introduce write barriers in key parts of the wasm bindings and migrate most code to use ref/out parameters instead of passing raw managed pointers as arguments or return values. Introduced MonoObjectRef typescript type and corresponding 'R' signature char (for 'ref/out object') Marked various old/unsafe code as deprecated Fixed some incorrect rooting in websocket APIs Introduced 'volatile' attribute on various C pointers in the bindings Added GC unsafe/safe regions in key parts of the C bindings Expanded exported APIs
2022-03-29[wasm] Dead code removal, minor fixes (#66418)Pavel Savara
* - treat jsHandle and gcHandle as IntPtr on C# icall definition - removed IJSObject, HostObject, CoreObject empty private classes - removed Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, Uint16Array, Uint32Array, Uint8ClampedArray, SharedArrayBuffer, Map unused private classes and their tests - moved Length property to Array and TypedArray types - removed unused eventListener helpers and it's tests - added Module.stackSave, Module.stackRestore, Module.stackAlloc imports - fixed promise reject signature - fixed cwrap of mono_wasm_invoke_method and mono_wasm_try_unbox_primitive_and_get_type - fixed string interning on StringDecoder path - improved assert helper * feedeback from @kg
2022-03-29feat: Add support for emscripten module exports (#66868)Jérôme Laban
2022-03-29Perform type/layout verification on some mono-config elements to avoid ↵Katelyn Gadd
silent failures or crashes later (#65449) Perform type/layout verification on some mono-config elements to avoid silent failures or crashes later