[browser] throw PNSE from GetFunctionPointerForDelegate#116107
[browser] throw PNSE from GetFunctionPointerForDelegate#116107pavelsavara wants to merge 11 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to 'arch-wasm': @lewing |
There was a problem hiding this comment.
Pull Request Overview
Adds support for throwing a PlatformNotSupportedException when GetFunctionPointerForDelegate is called on methods without an [UnmanagedCallersOnly] attribute, and wires up end-to-end tests in the Wasm Basic Test App and build tests.
- Introduces a null‐wrapper check in
interp_create_method_pointerto produce a PNSE with a descriptive message. - Extends
main.jsand the WebAssembly test app to invoke the new scenario. - Adds both an in-browser unit test (
MiscTests.cs) and a build‐time Xunit test.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/mono/mono/mini/interp/interp.c | Checks for missing native‐to‐managed wrapper and throws PNSE |
| src/mono/browser/runtime/runtime.c | Adds an assertion to ensure method is not null |
| src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | Adds “GetFunctionPointerForDelegate” case to the browser harness |
| src/mono/wasm/testassets/WasmBasicTestApp/App/MiscTests.cs | JSExport method to call GetFunctionPointerForDelegate |
| src/mono/wasm/Wasm.Build.Tests/MiscTests.cs | Xunit test to verify the PNSE and its message |
Comments suppressed due to low confidence (2)
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js:292
- [nitpick] The variable name
retMicsis ambiguous; consider renaming it to something more descriptive (e.g.,resultorreturnValue).
const retMics = testGetFunctionPointerForDelegate();
src/mono/mono/mini/interp/interp.c:3475
- The variable
erroris not defined in this scope (the parameter is namede). This should callmono_error_set_platform_not_supported(e, msg).
mono_error_set_platform_not_supported (error, msg);
Should GetFunctionPointerForDelegate throw PNSE unconditionally on browser? GetFunctionPointerForDelegate does not work on methods with UnmanagedCallersOnly either (outside browser at least). For example, the following will fail to compile with |
Hmmm, good point. I'm looking at mono/mono#20076 but I'm not any wiser. @lewing do you know why we have runtime/src/mono/mono/mini/interp/interp.c Lines 3468 to 3499 in e5866fe Is this for interp->AOT transitions only ? |
|
#56883 introduced the message about |
|
I'd need to a few minutes to investigate to be sure, but I suspect this just a case where we are ending up in interp_create_method_pointer from different paths. We do expect a native to interp trampoline to exist for UCO methods (if the native build is enabled), that does not mean we intended GetFunctionPointerForDelegate to succeed if the attribute exists. |
|
BTW: You can reuse message added in https://github.com/dotnet/runtime/pull/116010/files#diff-d9a9b46d55b2e1fddcd071cc75b0408f92f33befa5ea92d5b6aa0c67ad437071R4365 to make this API unsupported on wasm. |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
Outdated
Show resolved
Hide resolved
|
dotnet/dotnet-api-docs#11401 is a docs updated related to this change: |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
Outdated
Show resolved
Hide resolved
27fed36 to
a25e98d
Compare
| { | ||
| _managed = managed; | ||
| _native.sizeofcallback = sizeof(Native); | ||
| #pragma warning disable CA1416 // This call site is reachable on all platforms. |
There was a problem hiding this comment.
Should the Wasm compat check be disabled in .csproj files for libraries like Ldap instead?
Fixes #104391
Fixes #39187