Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries -->
<ItemGroup Condition="'$(IsWindowsSpecific)' == 'true' and '$(IsTestProject)' != 'true'">
<ItemGroup Condition="('$(IsWindowsSpecific)' == 'true' or '$(TargetsWindows)' == 'true') and '$(IsTestProject)' != 'true'">
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
<_Parameter1>windows</_Parameter1>
</AssemblyAttribute>
Expand All @@ -33,9 +33,9 @@
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
</ItemGroup>

<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild" Condition="'@(_unsupportedOSPlatforms)' != '' and '$(IsTestProject)' != 'true'">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != ''">
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform">
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Runtime.Versioning;

//
// Types in this file marked as 'public' are done so only to aid in
Expand Down Expand Up @@ -108,6 +109,7 @@ public static unsafe ComActivationContext Create(ref ComActivationContextInterna
}
}

[SupportedOSPlatform("windows")]
public static class ComActivator
{
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
[SupportedOSPlatform("windows")]
internal class ComEventsInfo
{
private ComEventsSink? _sinks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

namespace System.Runtime.InteropServices.CustomMarshalers
{
internal static class ComDataHelpers
{
[SupportedOSPlatform("windows")]
public static TView GetOrCreateManagedViewFromComData<T, TView>(object comObject, Func<T, TView> createCallback)
{
object key = typeof(TView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices.CustomMarshalers
{
[SupportedOSPlatform("windows")]
internal class EnumerableToDispatchMarshaler : ICustomMarshaler
{
private static readonly EnumerableToDispatchMarshaler s_enumerableToDispatchMarshaler = new EnumerableToDispatchMarshaler();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.InteropServices.ComTypes;

namespace System.Runtime.InteropServices.CustomMarshalers
Expand Down Expand Up @@ -38,6 +39,7 @@ public System.Collections.IEnumerator GetEnumerator()
IntPtr.Zero);
}

Debug.Assert(OperatingSystem.IsWindows());
IntPtr enumVariantPtr = IntPtr.Zero;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Runtime.Versioning;
using ComTypes = System.Runtime.InteropServices.ComTypes;

namespace System.Runtime.InteropServices.CustomMarshalers
{
[SupportedOSPlatform("windows")]
internal class EnumeratorToEnumVariantMarshaler : ICustomMarshaler
{
private static readonly EnumeratorToEnumVariantMarshaler s_enumeratorToEnumVariantMarshaler = new EnumeratorToEnumVariantMarshaler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4234,6 +4234,7 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
aArgs[i] = new UnknownWrapper(aArgs[i]);
break;
case DispatchWrapperType.Dispatch:
Debug.Assert(OperatingSystem.IsWindows());
aArgs[i] = new DispatchWrapper(aArgs[i]);
break;
case DispatchWrapperType.Error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private static ThreadPoolBoundHandle BindHandleCore(SafeHandle handle)

try
{
Debug.Assert(OperatingSystem.IsWindows());
// ThreadPool.BindHandle will always return true, otherwise, it throws. See the underlying FCall
// implementation in ThreadPoolNative::CorBindIoCompletionCallback to see the implementation.
bool succeeded = ThreadPool.BindHandle(handle);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/src/System.Private.CoreLib/src/System/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public Variant(object? obj)
else if (obj is DispatchWrapper)
{
vt = VarEnum.VT_DISPATCH;
Debug.Assert(OperatingSystem.IsWindows());
obj = ((DispatchWrapper)obj).WrappedObject;
}
else if (obj is ErrorWrapper)
Expand Down Expand Up @@ -401,6 +402,7 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
switch (vt)
{
case 9: /*VT_DISPATCH*/
Debug.Assert(OperatingSystem.IsWindows());
v = new Variant(new DispatchWrapper(pValue));
break;

Expand Down Expand Up @@ -442,7 +444,9 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
6 => /*VT_CY*/ new Variant(new CurrencyWrapper(iv.ToDecimal(provider))),
7 => /*VT_DATE*/ new Variant(iv.ToDateTime(provider)),
8 => /*VT_BSTR*/ new Variant(iv.ToString(provider)),
#pragma warning disable CA1416 // Validate platform compatibility
9 => /*VT_DISPATCH*/ new Variant(new DispatchWrapper((object)iv)),
#pragma warning restore CA1416
10 => /*VT_ERROR*/ new Variant(new ErrorWrapper(iv.ToInt32(provider))),
11 => /*VT_BOOL*/ new Variant(iv.ToBoolean(provider)),
12 => /*VT_VARIANT*/ new Variant((object)iv),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Runtime.Versioning;

namespace System
{
/// <summary>
/// __ComObject is the root class for all COM wrappers. This class defines only
/// the basics. This class is used for wrapping COM objects accessed from managed.
/// </summary>
[SupportedOSPlatform("windows")]
internal class __ComObject : MarshalByRefObject
{
private Hashtable? m_ObjectToDataMap; // Do not rename (runtime relies on this name).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#nullable enable

using System.Diagnostics;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
/// <summary>
/// Part of ComEventHelpers APIs which allow binding
/// managed delegates to COM's connection point based events.
/// </summary>
[SupportedOSPlatform("windows")]
internal partial class ComEventsSink : IDispatch, ICustomQueryInterface
{
private Guid _iidSourceItf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable enable

using System.Diagnostics;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
Expand All @@ -13,6 +14,7 @@ namespace System.Runtime.InteropServices
/// to and from COM calls.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
[SupportedOSPlatform("windows")]
internal partial struct Variant
{
#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFrameworks>net461-Windows_NT</TargetFrameworks>
<Nullable>enable</Nullable>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ public partial class PermissiveModifyControl : System.DirectoryServices.Protocol
public partial class QuotaControl : System.DirectoryServices.Protocols.DirectoryControl
{
public QuotaControl() : base (default(string), default(byte[]), default(bool), default(bool)) { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public QuotaControl(System.Security.Principal.SecurityIdentifier querySid) : base (default(string), default(byte[]), default(bool), default(bool)) { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public System.Security.Principal.SecurityIdentifier QuerySid { get { throw null; } set { } }
public override byte[] GetValue() { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Runtime.Versioning;

namespace System.DirectoryServices.Protocols
{
Expand Down Expand Up @@ -1026,11 +1027,13 @@ public class QuotaControl : DirectoryControl

public QuotaControl() : base("1.2.840.113556.1.4.1852", null, true, true) { }

[SupportedOSPlatform("windows")]
public QuotaControl(SecurityIdentifier querySid) : this()
{
QuerySid = querySid;
}

[SupportedOSPlatform("windows")]
public SecurityIdentifier QuerySid
{
get => _sid == null ? null : new SecurityIdentifier(_sid, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected StandardOleMarshalObject()

private IntPtr GetStdMarshaler(ref Guid riid, int dwDestContext, int mshlflags)
{
Debug.Assert(OperatingSystem.IsWindows());
IntPtr pUnknown = Marshal.GetIUnknownForObject(this);
if (pUnknown != IntPtr.Zero)
{
Expand Down Expand Up @@ -69,6 +70,7 @@ unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContex
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
Expand All @@ -91,6 +93,7 @@ unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>netstandard2.0;netstandard2.0-Windows_NT</TargetFrameworks>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Runtime\Caching\_shims.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace System.Runtime.CompilerServices
public sealed partial class IDispatchConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute
{
public IDispatchConstantAttribute() { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public override object Value { get { throw null; } }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace System.Runtime.CompilerServices
{
Expand All @@ -10,6 +11,7 @@ public sealed partial class IDispatchConstantAttribute : CustomConstantAttribute
{
public IDispatchConstantAttribute() { }

[SupportedOSPlatform("windows")]
public override object Value => new DispatchWrapper(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class PasswordDeriveBytes : DeriveBytes
private HashAlgorithm? _hash;
private readonly CspParameters? _cspParams;

#pragma warning disable CA1416 // Validate platform compatibility, CspParametersis is windows only type, we might want to annotate this constructors windows only, suppressing for now
public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt) : this(strPassword, rgbSalt, new CspParameters()) { }

public PasswordDeriveBytes(byte[] password, byte[]? salt) : this(password, salt, new CspParameters()) { }
Expand All @@ -34,6 +35,7 @@ public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashNa

public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations) :
this(password, salt, hashName, iterations, new CspParameters()) { }
#pragma warning restore CA1416

public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, CspParameters? cspParams) :
this(strPassword, rgbSalt, "SHA1", 100, cspParams) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Nullable>enable</Nullable>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-Windows_NT;netstandard2.0;netcoreapp2.0-Windows_NT;netstandard2.0-Windows_NT;net461-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<!-- Generator for code mapping table, target to invoke is GenerateEncodingSource -->
<PropertyGroup>
Expand Down