mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-10 18:11:04 +09:00
Use public implementation WindowsRuntime ExceptionSupport (dotnet/corefx#30440)
Commit migrated from 585a9306ec
This commit is contained in:
parent
2e059ef327
commit
0819981fbc
6 changed files with 12 additions and 85 deletions
|
@ -62,16 +62,9 @@
|
|||
<Compile Include="System\InternalHelpers.CoreCLR.cs" />
|
||||
<Compile Include="System\IO\StreamOperationAsyncResult.CoreCLR.cs" />
|
||||
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\MarshalingHelpers.cs" />
|
||||
<Compile Include="System\Runtime\InteropServices\WindowsRuntime\RestrictedErrorInfoHelper.cs" />
|
||||
<Compile Include="System\Threading\Tasks\AsyncInfoToTaskBridge.CoreCLR.cs" />
|
||||
<Compile Include="System\Threading\WindowsRuntimeSynchronizationContext.cs" />
|
||||
<Compile Include="System\WindowsRuntimeSystemExtensions.CoreCLR.cs" />
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\mincore\Interop.GetRestrictedErrorInfo.cs">
|
||||
<Link>Common\Interop\Windows\mincore\Interop.GetRestrictedErrorInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\System\Runtime\InteropServices\WindowsRuntime\IRestrictedErrorInfo.cs">
|
||||
<Link>Common\System\Runtime\InteropServices\WindowsRuntime\IRestrictedErrorInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\System\Runtime\InteropServices\WindowsRuntime\WindowsRuntimeImportAttribute.cs">
|
||||
<Link>Common\System\Runtime\InteropServices\WindowsRuntime\WindowsRuntimeImportAttribute.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Internal.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
|
||||
namespace System.IO
|
||||
|
@ -10,7 +11,7 @@ namespace System.IO
|
|||
{
|
||||
private void ThrowWithIOExceptionDispatchInfo(Exception e)
|
||||
{
|
||||
WinRtIOHelper.NativeExceptionToIOExceptionInfo(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(_completedOperation.ErrorCode)).Throw();
|
||||
WinRtIOHelper.NativeExceptionToIOExceptionInfo(ExceptionSupport.AttachRestrictedErrorInfo(_completedOperation.ErrorCode)).Throw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to propagate restricted error info generated by an IAsyncInfo onto its resultant exception
|
||||
/// </summary>
|
||||
internal static class RestrictedErrorInfoHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Attach restricted error information to the exception if it may apply to that exception, returning
|
||||
/// back the input value
|
||||
/// </summary>
|
||||
internal static Exception AttachRestrictedErrorInfo(Exception e)
|
||||
{
|
||||
// If there is no exception, then the restricted error info doesn't apply to it
|
||||
if (e != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the restricted error info for this thread and see if it may correlate to the current
|
||||
// exception object. Note that in general the thread's IRestrictedErrorInfo is not meant for
|
||||
// exceptions that are marshaled Windows.Foundation.HResults and instead are intended for
|
||||
// HRESULT ABI return values. However, in many cases async APIs will set the thread's restricted
|
||||
// error info as a convention in order to provide extended debugging information for the ErrorCode
|
||||
// property.
|
||||
IRestrictedErrorInfo restrictedErrorInfo = Interop.mincore.GetRestrictedErrorInfo();
|
||||
if (restrictedErrorInfo != null)
|
||||
{
|
||||
string description;
|
||||
string restrictedDescription;
|
||||
string capabilitySid;
|
||||
int restrictedErrorInfoHResult;
|
||||
restrictedErrorInfo.GetErrorDetails(out description,
|
||||
out restrictedErrorInfoHResult,
|
||||
out restrictedDescription,
|
||||
out capabilitySid);
|
||||
|
||||
// Since this is a special case where by convention there may be a correlation, there is not a
|
||||
// guarantee that the restricted error info does belong to the async error code. In order to
|
||||
// reduce the risk that we associate incorrect information with the exception object, we need
|
||||
// to apply a heuristic where we attempt to match the current exception's HRESULT with the
|
||||
// HRESULT the IRestrictedErrorInfo belongs to. If it is a match we will assume association
|
||||
// for the IAsyncInfo case.
|
||||
if (e.HResult == restrictedErrorInfoHResult)
|
||||
{
|
||||
string errorReference;
|
||||
restrictedErrorInfo.GetReference(out errorReference);
|
||||
|
||||
e.AddExceptionDataForRestrictedErrorInfo(restrictedDescription,
|
||||
errorReference,
|
||||
capabilitySid,
|
||||
restrictedErrorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If we can't get the restricted error info, then proceed as if it isn't associated with this
|
||||
// error.
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Internal.Runtime.InteropServices.WindowsRuntime;
|
||||
using Internal.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
@ -176,7 +177,7 @@ namespace System.Threading.Tasks
|
|||
}
|
||||
else
|
||||
{
|
||||
error = RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(asyncInfo.ErrorCode);
|
||||
error = ExceptionSupport.AttachRestrictedErrorInfo(asyncInfo.ErrorCode);
|
||||
}
|
||||
}
|
||||
else if (asyncStatus == AsyncStatus.Completed && getResultsFunction != null)
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Internal.Runtime.InteropServices.WindowsRuntime;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
|
@ -15,8 +17,6 @@ using System.Threading;
|
|||
using Windows.Foundation;
|
||||
using Windows.UI.Core;
|
||||
|
||||
using System.Diagnostics.Tracing;
|
||||
|
||||
namespace System.Threading
|
||||
{
|
||||
#if FEATURE_APPX
|
||||
|
@ -223,7 +223,7 @@ namespace System.Threading
|
|||
//
|
||||
if (!(ex is ThreadAbortException) && !(ex is AppDomainUnloadedException))
|
||||
{
|
||||
if (!WindowsRuntimeMarshal.ReportUnhandledError(ex))
|
||||
if (!ExceptionSupport.ReportUnhandledError(ex))
|
||||
{
|
||||
var edi = ExceptionDispatchInfo.Capture(ex);
|
||||
ThreadPool.QueueUserWorkItem(o => ((ExceptionDispatchInfo)o).Throw(), edi);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Internal.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
@ -113,7 +114,7 @@ namespace System
|
|||
return Task.CompletedTask;
|
||||
|
||||
case AsyncStatus.Error:
|
||||
return Task.FromException(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
return Task.FromException(ExceptionSupport.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
|
||||
case AsyncStatus.Canceled:
|
||||
return Task.FromCanceled(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
|
||||
|
@ -189,7 +190,7 @@ namespace System
|
|||
return Task.FromResult(source.GetResults());
|
||||
|
||||
case AsyncStatus.Error:
|
||||
return Task.FromException<TResult>(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
return Task.FromException<TResult>(ExceptionSupport.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
|
||||
case AsyncStatus.Canceled:
|
||||
return Task.FromCanceled<TResult>(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
|
||||
|
@ -292,7 +293,7 @@ namespace System
|
|||
return Task.CompletedTask;
|
||||
|
||||
case AsyncStatus.Error:
|
||||
return Task.FromException(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
return Task.FromException(ExceptionSupport.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
|
||||
case AsyncStatus.Canceled:
|
||||
return Task.FromCanceled(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
|
||||
|
@ -401,7 +402,7 @@ namespace System
|
|||
return Task.FromResult(source.GetResults());
|
||||
|
||||
case AsyncStatus.Error:
|
||||
return Task.FromException<TResult>(RestrictedErrorInfoHelper.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
return Task.FromException<TResult>(ExceptionSupport.AttachRestrictedErrorInfo(source.ErrorCode));
|
||||
|
||||
case AsyncStatus.Canceled:
|
||||
return Task.FromCanceled<TResult>(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue