Skip to content

Commit

Permalink
Merge pull request #54 from Sergio0694/dev/disable-runtime-marshalling
Browse files Browse the repository at this point in the history
Add [DisableRuntimeMarshalling] polyfill
  • Loading branch information
Sergio0694 authored Jan 21, 2023
2 parents 7821fdf + 8960e97 commit d6f1e47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ It also includes the following optional runtime-supported polyfills:
- `[UnsupportedOSPlatform]`
- `[UnsupportedOSPlatformGuard]`
- `[SuppressGCTransition]` (see [here](https://devblogs.microsoft.com/dotnet/improvements-in-native-code-interop-in-net-5-0/))
- `[DisableRuntimeMarshalling]` (see [here](https://learn.microsoft.com/dotnet/standard/native-interop/disabled-marshalling))

# Options ⚙️

Expand Down
1 change: 1 addition & 0 deletions src/PolySharp.Package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ It also includes the following optional runtime-supported polyfills:
- `[UnsupportedOSPlatform]`
- `[UnsupportedOSPlatformGuard]`
- `[SuppressGCTransition]` (see [here](https://devblogs.microsoft.com/dotnet/improvements-in-native-code-interop-in-net-5-0/))
- `[DisableRuntimeMarshalling]` (see [here](https://learn.microsoft.com/dotnet/standard/native-interop/disabled-marshalling))

# Options ⚙️

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// <auto-generated/>
#pragma warning disable
#nullable enable annotations

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Disables the built-in runtime managed/unmanaged marshalling subsystem for
/// P/Invokes, Delegate types, and unmanaged function pointer invocations.
/// </summary>
/// <remarks>
/// The built-in marshalling subsystem has some behaviors that cannot be changed due to
/// backward-compatibility requirements. This attribute allows disabling the built-in
/// subsystem and instead uses the following rules for P/Invokes, Delegates,
/// and unmanaged function pointer invocations:
///
/// - All value types that do not contain reference type fields recursively (<c>unmanaged</c> in C#) are blittable
/// - Value types that recursively have any fields that have <c>[StructLayout(LayoutKind.Auto)]</c> are disallowed from interop.
/// - All reference types are disallowed from usage in interop scenarios.
/// - SetLastError support in P/Invokes is disabled.
/// - varargs support is disabled.
/// - LCIDConversionAttribute support is disabled.
/// </remarks>
[global::System.AttributeUsage(global::System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
internal sealed class DisableRuntimeMarshallingAttribute : global::System.Attribute
{
}
}
3 changes: 3 additions & 0 deletions tests/PolySharp.Tests/RuntimeSupport.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

[assembly: TargetPlatform("windows6.1")]

[assembly: DisableRuntimeMarshalling]

namespace PolySharp.Tests;

internal class RandomApis
Expand Down

0 comments on commit d6f1e47

Please sign in to comment.