Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ILCompiler.DependencyAnalysisFramework;
using Internal.Runtime;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler
{
Expand Down Expand Up @@ -339,6 +340,13 @@ public StandaloneGCStaticDescRegionNode StandaloneGCStaticDescRegion(GCStaticDes
return _standaloneGCStaticDescs.GetOrAdd(staticDesc);
}

public BlobNode FieldRvaDataBlob(FieldDesc field)
{
// Use the typical field definition in case this is an instantiated generic type
field = field.GetTypicalFieldDefinition();
return ReadOnlyDataBlob(NameMangler.GetMangledFieldName(field), ((EcmaField)field).GetFieldRvaData(), Target.PointerSize);
}

public class UtcDictionaryLayoutProvider : DictionaryLayoutProvider
{
public override DictionaryLayoutNode GetLayout(TypeSystemEntity methodOrType)
Expand Down
5 changes: 2 additions & 3 deletions src/ILCompiler.Compiler/src/Compiler/UtcNameMangler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,9 @@ public override string GetMangledStringName(string literal)
return mangledName;
}

public string GetMangledDataBlobName(byte[] blob)
public string GetMangledDataBlobName(FieldDesc field)
{
var hash = _sha256.ComputeHash(blob);
return "__Data_" + BitConverter.ToString(hash).Replace("-", "");
return "__Data_" + ComputeMangledFieldName(field);
}

public string GetImportedTlsIndexPrefix()
Expand Down
51 changes: 32 additions & 19 deletions src/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

using Internal.Runtime;

// Disable: Filter expression is a constant. We know. We just can't do an unfiltered catch.
#pragma warning disable 7095

namespace System.Runtime
{
public enum RhFailFastReason
Expand Down Expand Up @@ -180,7 +183,7 @@ internal static void FailFastViaClasslib(RhFailFastReason reason, object unhandl
// Invoke the classlib fail fast function.
CalliIntrinsics.CallVoid(pFailFastFunction, reason, unhandledException, IntPtr.Zero, IntPtr.Zero);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand Down Expand Up @@ -226,7 +229,7 @@ private static void OnFirstChanceExceptionViaClassLib(object exception)
{
CalliIntrinsics.CallVoid(pOnFirstChanceFunction, exception);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand Down Expand Up @@ -258,7 +261,7 @@ internal static unsafe void UnhandledExceptionFailFastViaClasslib(
{
CalliIntrinsics.CallVoid(pFailFastFunction, reason, unhandledException, exInfo._pExContext->IP, (IntPtr)pContext);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand Down Expand Up @@ -288,7 +291,7 @@ private static void AppendExceptionStackFrameViaClasslib(object exception, IntPt
{
CalliIntrinsics.CallVoid(pAppendStackFrame, exception, IP, flags);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand All @@ -315,7 +318,7 @@ internal static Exception GetClasslibException(ExceptionIDs id, IntPtr address)
{
e = CalliIntrinsics.Call<Exception>(pGetRuntimeExceptionFunction, id);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand Down Expand Up @@ -351,7 +354,7 @@ internal static Exception GetClasslibExceptionFromEEType(ExceptionIDs id, IntPtr
{
e = CalliIntrinsics.Call<Exception>(pGetRuntimeExceptionFunction, id);
}
catch
catch when (true)
{
// disallow all exceptions leaking out of callbacks
}
Expand Down Expand Up @@ -873,28 +876,38 @@ private static bool FindFirstPassHandler(object exception, uint idxStart,
return false;
}

#if DEBUG && !INPLACE_RUNTIME
private static EEType* s_pLowLevelObjectType;

private static bool ShouldTypedClauseCatchThisException(object exception, EEType* pClauseType)
private static void AssertNotRuntimeObject(EEType* pClauseType)
{
if (TypeCast.IsInstanceOfClass(exception, pClauseType) != null)
return true;
//
// The C# try { } catch { } clause expands into a typed catch of System.Object.
// Since runtime has its own definition of System.Object, try { } catch { } might not do what
// was intended (catch all exceptions).
//
// This assertion is making sure we don't use try { } catch { } within the runtime.
// The runtime codebase should either use try { } catch (Exception) { } for exception types
// from the runtime or a try { } catch when (true) { } to catch all exceptions.
//

if (s_pLowLevelObjectType == null)
{
// TODO: Avoid allocating here as that may fail
// Allocating might fail, but since this is just a debug assert, it's probably fine.
s_pLowLevelObjectType = new System.Object().EEType;
}

// This allows the typical try { } catch { }--which expands to a typed catch of System.Object--to work on
// all objects when the clause is in the low level runtime code. This special case is needed because
// objects from foreign type systems are sometimes throw back up at runtime code and this is the only way
// to catch them outside of having a filter with no type check in it, which isn't currently possible to
// write in C#. See https://github.com/dotnet/roslyn/issues/4388
if (pClauseType->IsEquivalentTo(s_pLowLevelObjectType))
return true;
Debug.Assert(!pClauseType->IsEquivalentTo(s_pLowLevelObjectType));
}
#endif // DEBUG && !INPLACE_RUNTIME

return false;

private static bool ShouldTypedClauseCatchThisException(object exception, EEType* pClauseType)
{
#if DEBUG && !INPLACE_RUNTIME
AssertNotRuntimeObject(pClauseType);
#endif

return TypeCast.IsInstanceOfClass(exception, pClauseType) != null;
}

private static void InvokeSecondPass(ref ExInfo exInfo, uint idxStart)
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime.Base/src/System/Runtime/ThunkPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static unsafe ThunksHeap CreateThunksHeap(IntPtr commonStubAddress)
if (newHeap._nextAvailableThunkPtr != IntPtr.Zero)
return newHeap;
}
catch { }
catch (Exception) { }

return null;
}
Expand All @@ -156,7 +156,7 @@ private unsafe bool ExpandHeap()
{
newBlockInfo = new AllocatedBlock();
}
catch
catch (Exception)
{
return false;
}
Expand Down