1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Diagnostics
{
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics.CodeAnalysis;
class Utility
{
ExceptionUtility exceptionUtility;
[Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.Utility instead")]
internal Utility(ExceptionUtility exceptionUtility)
{
this.exceptionUtility = exceptionUtility;
}
// Call this when a p/invoke with an 'out SafeHandle' parameter returns an error. This will safely clean up the handle.
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.TransparentMethodsMustNotReferenceCriticalCode)] // we got APTCA approval with no requirement to fix this transparency warning
internal static void CloseInvalidOutSafeHandle(SafeHandle handle)
{
// Workaround for 64-bit CLR bug VSWhidbey 546830 - sometimes invalid SafeHandles come back null.
if (handle != null)
{
#pragma warning disable 618
Fx.Assert(handle.IsInvalid, "CloseInvalidOutSafeHandle called with a valid handle!");
#pragma warning restore 618
// Calls SuppressFinalize.
handle.SetHandleAsInvalid();
}
}
// Copy of the above for CriticalHandles.
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.TransparentMethodsMustNotReferenceCriticalCode)] // we got APTCA approval with no requirement to fix this transparency warning. plus, the callers of this method are not supported in partial trust.
internal static void CloseInvalidOutCriticalHandle(CriticalHandle handle)
{
if (handle != null)
{
#pragma warning disable 618
Fx.Assert(handle.IsInvalid, "CloseInvalidOutCriticalHandle called with a valid handle!");
#pragma warning restore 618
handle.SetHandleAsInvalid();
}
}
internal Guid CreateGuid(string guidString)
{
return Fx.CreateGuid(guidString);
}
internal bool TryCreateGuid(string guidString, out Guid result)
{
return Fx.TryCreateGuid(guidString, out result);
}
internal byte[] AllocateByteArray(int size)
{
return Fx.AllocateByteArray(size);
}
internal char[] AllocateCharArray(int size)
{
return Fx.AllocateCharArray(size);
}
}
}
|