Skip to content
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

Fix new warnings #43097

Merged
merged 13 commits into from
Oct 16, 2020
4 changes: 2 additions & 2 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'">
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
<_Parameter1>windows</_Parameter1>
</AssemblyAttribute>
Expand All @@ -35,7 +35,7 @@

<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != ''">
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != '' and '$(IsTestProject)' != 'true'">
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInte
{
var cxt = ComActivationContext.Create(ref cxtInt);
object cf = GetClassFactoryForType(cxt);
Debug.Assert(OperatingSystem.IsWindows());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
IntPtr nativeIUnknown = Marshal.GetIUnknownForObject(cf);
Marshal.WriteIntPtr(cxtInt.ClassFactoryDest, nativeIUnknown);
}
Expand Down Expand Up @@ -496,6 +497,7 @@ public static Type GetValidatedInterfaceType(Type classType, ref Guid riid, obje
public static IntPtr GetObjectAsInterface(object obj, Type interfaceType)
{
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
Debug.Assert(OperatingSystem.IsWindows());
// If the requested "interface type" is type object then return as IUnknown
if (interfaceType == typeof(object))
{
Expand Down Expand Up @@ -528,6 +530,7 @@ public static object CreateAggregatedObject(object pUnkOuter, object comObject)
{
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
Debug.Assert(pUnkOuter != null && comObject != null);
Debug.Assert(OperatingSystem.IsWindows());
IntPtr outerPtr = Marshal.GetIUnknownForObject(pUnkOuter);

try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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;

namespace System.Runtime.InteropServices
{
internal class ComEventsInfo
Expand All @@ -21,6 +23,7 @@ private ComEventsInfo(object rcw)

public static ComEventsInfo? Find(object rcw)
{
Debug.Assert(OperatingSystem.IsWindows());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
return (ComEventsInfo?)Marshal.GetComObjectData(rcw, typeof(ComEventsInfo));
}

Expand All @@ -31,6 +34,7 @@ public static ComEventsInfo FromObject(object rcw)
if (eventsInfo == null)
{
eventsInfo = new ComEventsInfo(rcw);
Debug.Assert(OperatingSystem.IsWindows());
Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), eventsInfo);
}
return eventsInfo;
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());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
// 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,6 +4,7 @@
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;

namespace System
{
Expand Down Expand Up @@ -87,6 +88,7 @@ internal void ReleaseAllData()
if (o is IDisposable DisposableObj)
DisposableObj.Dispose();

Debug.Assert(OperatingSystem.IsWindows());
// If the object is a derived from __ComObject, then call Marshal.ReleaseComObject on it.
if (o is __ComObject ComObj)
Marshal.ReleaseComObject(ComObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ unsafe void IDispatch.Invoke(
// convert result to VARIANT
if (pVarResult != IntPtr.Zero)
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.GetNativeVariantForObject(result, pVarResult);
}

Expand All @@ -237,6 +238,7 @@ CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out
ppv = IntPtr.Zero;
if (iid == _iidSourceItf || iid == typeof(IDispatch).GUID)
{
Debug.Assert(OperatingSystem.IsWindows());
ppv = Marshal.GetComInterfaceForObject(this, typeof(IDispatch), CustomQueryInterfaceMode.Ignore);
return CustomQueryInterfaceResult.Handled;
}
Expand Down Expand Up @@ -267,6 +269,7 @@ private void Unadvise()
try
{
_connectionPoint.Unadvise(_cookie);
Debug.Assert(OperatingSystem.IsWindows());
Marshal.ReleaseComObject(_connectionPoint);
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public unsafe void CopyFromIndirect(object value)
if ((vt & VarEnum.VT_ARRAY) != 0)
{
Variant vArray;
Debug.Assert(OperatingSystem.IsWindows());
Marshal.GetNativeVariantForObject(value, (IntPtr)(void*)&vArray);
*(IntPtr*)this._typeUnion._unionTypes._byref = vArray._typeUnion._unionTypes._byref;
return;
Expand Down Expand Up @@ -198,10 +199,12 @@ public unsafe void CopyFromIndirect(object value)
break;

case VarEnum.VT_UNKNOWN:
Debug.Assert(OperatingSystem.IsWindows());
*(IntPtr*)this._typeUnion._unionTypes._byref = Marshal.GetIUnknownForObject(value);
break;

case VarEnum.VT_DISPATCH:
Debug.Assert(OperatingSystem.IsWindows());
*(IntPtr*)this._typeUnion._unionTypes._byref = Marshal.GetComInterfaceForObject<object, IDispatch>(value);
break;

Expand All @@ -218,6 +221,7 @@ public unsafe void CopyFromIndirect(object value)
break;

case VarEnum.VT_VARIANT:
Debug.Assert(OperatingSystem.IsWindows());
Marshal.GetNativeVariantForObject(value, this._typeUnion._unionTypes._byref);
break;

Expand Down Expand Up @@ -269,6 +273,7 @@ public unsafe void CopyFromIndirect(object value)
{
fixed (void* pThis = &this)
{
Debug.Assert(OperatingSystem.IsWindows());
return Marshal.GetObjectForNativeVariant((System.IntPtr)pThis);
}
}
Expand Down Expand Up @@ -654,6 +659,7 @@ public object? AsUnknown
{
return null;
}
Debug.Assert(OperatingSystem.IsWindows());
return Marshal.GetObjectForIUnknown(_typeUnion._unionTypes._unknown);
}
set
Expand All @@ -666,6 +672,7 @@ public object? AsUnknown
}
else
{
Debug.Assert(OperatingSystem.IsWindows());
_typeUnion._unionTypes._unknown = Marshal.GetIUnknownForObject(value);
}
}
Expand All @@ -682,6 +689,7 @@ public object? AsDispatch
{
return null;
}
Debug.Assert(OperatingSystem.IsWindows());
return Marshal.GetObjectForIUnknown(_typeUnion._unionTypes._dispatch);
}
set
Expand All @@ -694,6 +702,7 @@ public object? AsDispatch
}
else
{
Debug.Assert(OperatingSystem.IsWindows());
_typeUnion._unionTypes._dispatch = Marshal.GetComInterfaceForObject<object, IDispatch>(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This assembly is referenced from rid agnostic configurations therefore we can't make it RID specific
and instead use runtime checks.
-->
<TargetFrameworks>$(NetCoreAppCurrent);net461</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\AdminHelpers.cs" />
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>
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
</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")]
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
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());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
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")]
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
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
Loading