-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[browser] throw PNSE from GetFunctionPointerForDelegate #116107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to 'arch-wasm': @lewing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_pointer
to produce a PNSE with a descriptive message. - Extends
main.js
and 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
retMics
is ambiguous; consider renaming it to something more descriptive (e.g.,result
orreturnValue
).
const retMics = testGetFunctionPointerForDelegate();
src/mono/mono/mini/interp/interp.c:3475
- The variable
error
is 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
@@ -244,9 +244,11 @@ public void FromManaged(LdapReferralCallback managed) | |||
{ | |||
_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Wasm compat check be disabled in .csproj files for libraries like Ldap instead?
Fixes #104391
Fixes #39187