Skip to content

[wasm] Unmanaged structs are considered blittable if module has DisableRuntimeMarshallingAttribute - #73310

Merged
radical merged 18 commits into
dotnet:mainfrom
maraf:WasmPInvokeGeneratorDisableRuntimeMarshalling
Aug 15, 2022
Merged

[wasm] Unmanaged structs are considered blittable if module has DisableRuntimeMarshallingAttribute#73310
radical merged 18 commits into
dotnet:mainfrom
maraf:WasmPInvokeGeneratorDisableRuntimeMarshalling

Conversation

@maraf

@marafmaraf commented Aug 3, 2022

Copy link
Copy Markdown
Member

Consider all types in pinvokes from assembly marked with DisableRuntimeMarshallingAttribute as blittable.
Based on API proposal in #60639.

  • PInvokeTableGenerator: Avoid crash when processing unmanaged callbacks with function pointers.

Fixes#61146.

@marafmaraf added arch-wasm WebAssembly architecture area-Interop-mono labels Aug 3, 2022
@marafmaraf added this to the 7.0.0 milestone Aug 3, 2022
@marafmaraf self-assigned this Aug 3, 2022
@maraf

maraf commented Aug 3, 2022

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ghost

ghost commented Aug 3, 2022

Copy link
Copy Markdown

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Consider all types from assembly marked with DisableRuntimeMarshallingAttribute as blittable.
Based on #60639.

Fixes #61146.

Author:maraf
Assignees:maraf
Labels:

arch-wasm, area-Interop-mono

Milestone:7.0.0

@jkoritzinsky

Copy link
Copy Markdown
Member

This is not entirely true. An unmanaged struct defined in an assembly with DisableRuntimeMarshalling isn't necessarily blittable if it is used in a P/Invoke in an assembly without DisableRuntimeMarshallingAttribute.

@maraf
marafforce-pushed the WasmPInvokeGeneratorDisableRuntimeMarshalling branch from e32a7b8 to 4e044cfCompareAugust 4, 2022 07:51
@maraf

maraf commented Aug 4, 2022

Copy link
Copy Markdown
MemberAuthor

This is not entirely true. An unmanaged struct defined in an assembly with DisableRuntimeMarshalling isn't necessarily blittable if it is used in a P/Invoke in an assembly without DisableRuntimeMarshallingAttribute.

Thanks!
Must both struct and p/invoke assemblies be marked with DisableRuntimeMarshallingAttribute?

@jkoritzinsky

Copy link
Copy Markdown
Member

Only the P/Invoke assembly must be marked with the attribute.

@marafmaraf left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look for the DisableRuntimeMarshallingAttribute on the assembly where pinvoke method is declared.
Mistake...

@maraf

maraf commented Aug 5, 2022

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@maraf
maraf requested review from lambdageek and radicalAugust 5, 2022 15:54
@maraf
maraf marked this pull request as ready for review August 5, 2022 15:54
@maraf

maraf commented Aug 5, 2022

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@maraf

maraf commented Aug 9, 2022

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@maraf

maraf commented Aug 9, 2022

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment threadsrc/tasks/WasmAppBuilder/PInvokeTableGenerator.cs Outdated
Co-authored-by: Ankit Jain <radical@gmail.com>
@maraf

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@maraf

maraf commented Aug 12, 2022

Copy link
Copy Markdown
MemberAuthor

@maraf
maraf requested a review from radicalAugust 12, 2022 12:37
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
Comment threadsrc/tests/BuildWasmApps/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Outdated
@radical

Copy link
Copy Markdown
Member

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@radical

Copy link
Copy Markdown
Member

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@radical

Copy link
Copy Markdown
Member

The wasm EAT/AOT test failures are #73932 .
The Perftracing build failure is #73933 .

@radical

Copy link
Copy Markdown
Member

The Linux_musl x64 coreclr failure is #73930 .

@radical
radical merged commit 058bed7 into dotnet:mainAug 15, 2022
@maraf
maraf deleted the WasmPInvokeGeneratorDisableRuntimeMarshalling branch August 15, 2022 08:55
{
_assemblyDisableRuntimeMarshallingAttributeCache[assembly] = value = assembly
.GetCustomAttributesData()
.Any(d => d.AttributeType.Name == "DisableRuntimeMarshallingAttribute");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use nameof(DisableRuntimeMarshallingAttribute) with using System.Runtime.CompilerServices;

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assembly is also compiled for net47 and the attribute is not available there.

@ghostghost locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-Interop-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(Unmanaged) Structs are not considered blittable by Emscripten / Blazor WASM AOT

5 participants

@maraf@jkoritzinsky@radical@lambdageek@kasperk81