Skip to content

Commit 29b55db

Browse files
authored
Merge pull request #159 from Washi1337/feature/upgrade-asmresolver
Upgrade to AsmResolver 6.0.0-rc.1
2 parents ba8e549 + c437fb2 commit 29b55db

File tree

71 files changed

+390
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+390
-366
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageLicense>https://github.com/Washi1337/Echo/LICENSE.md</PackageLicense>
77
<RepositoryUrl>https://github.com/Washi1337/Echo</RepositoryUrl>
88
<RepositoryType>git</RepositoryType>
9-
<LangVersion>12</LangVersion>
9+
<LangVersion>14</LangVersion>
1010
<Nullable>enable</Nullable>
1111
<VersionPrefix>1.0.0</VersionPrefix>
1212
<VersionSuffix>alpha.1</VersionSuffix>

src/Platforms/Echo.Platforms.AsmResolver/Echo.Platforms.AsmResolver.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.4" />
25+
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-rc.1" />
2626
<PackageReference Include="Nullable" Version="1.3.1">
2727
<PrivateAssets>all</PrivateAssets>
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Platforms/Echo.Platforms.AsmResolver/Emulation/CilVirtualMachine.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public class CilVirtualMachine
3535
/// </summary>
3636
/// <param name="contextModule">The main module to base the context on.</param>
3737
/// <param name="is32Bit">Indicates whether the virtual machine runs in 32-bit mode or 64-bit mode.</param>
38-
public CilVirtualMachine(ModuleDefinition contextModule, bool is32Bit)
38+
public CilVirtualMachine(RuntimeContext runtimeContext, bool is32Bit)
3939
{
4040
Memory = new VirtualMemory(is32Bit ? uint.MaxValue : long.MaxValue);
4141
Loader = new PELoader(Memory);
4242

43-
ValueFactory = new ValueFactory(contextModule, is32Bit);
43+
ValueFactory = new ValueFactory(runtimeContext, is32Bit);
4444
HostObjects = new ObjectMapMemory<object, HostObject>(0x1000_0000, o => new HostObject(o, this));
4545
ObjectMarshaller = new ObjectMarshaller(this);
4646

@@ -114,11 +114,8 @@ public ValueFactory ValueFactory
114114
get;
115115
}
116116

117-
/// <summary>
118-
/// Gets the main module the emulator is executing instructions for.
119-
/// </summary>
120-
public ModuleDefinition ContextModule => ValueFactory.ContextModule;
121-
117+
public RuntimeContext RuntimeContext => ValueFactory.RuntimeContext;
118+
122119
/// <summary>
123120
/// Gets the service that is responsible for mapping executable files in memory.
124121
/// </summary>

src/Platforms/Echo.Platforms.AsmResolver/Emulation/CliMarshaller.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ private TypeSignature GetElementType(TypeSignature type)
3131
case ElementType.ValueType:
3232
if (!_resolvedTypes.TryGetValue(type, out var definition))
3333
{
34-
definition = type.Resolve();
35-
if (definition is not null)
34+
if (type.TryResolve(_valueFactory.RuntimeContext, out definition))
3635
_resolvedTypes.Add(type, definition);
3736
}
3837

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/Arrays/LdElemHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ protected override CilDispatchResult DispatchInternal(CilExecutionContext contex
9393

9494
private static TypeSignature GetElementType(CilExecutionContext context, CilInstruction instruction)
9595
{
96-
var factory = context.Machine.ValueFactory.ContextModule.CorLibTypeFactory;
96+
var factory = context.Machine.ValueFactory.CorLibTypeFactory;
9797
return instruction.OpCode.Code switch
9898
{
99-
CilCode.Ldelem => ((ITypeDefOrRef) instruction.Operand!).ToTypeSignature(),
99+
CilCode.Ldelem => ((ITypeDefOrRef) instruction.Operand!).ToTypeSignature(context.Machine.RuntimeContext),
100100
CilCode.Ldelem_I => factory.IntPtr,
101101
CilCode.Ldelem_I1 => factory.SByte,
102102
CilCode.Ldelem_I2 => factory.Int16,

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/Arrays/LdElemaHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ protected override CilDispatchResult DispatchInternal(CilExecutionContext contex
2020
var genericContext = GenericContext.FromMethod(context.CurrentFrame.Method);
2121

2222
// Determine parameters.
23-
var elementType = ((ITypeDefOrRef) instruction.Operand!).ToTypeSignature().InstantiateGenericTypes(genericContext);
23+
var elementType = ((ITypeDefOrRef) instruction.Operand!)
24+
.ToTypeSignature(context.RuntimeContext)
25+
.InstantiateGenericTypes(genericContext);
26+
2427
var arrayIndex = stack.Pop();
2528
var arrayAddress = stack.Pop();
2629
var result = factory.RentNativeInteger(false);

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/Arrays/NewArrHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using AsmResolver.DotNet;
22
using AsmResolver.DotNet.Signatures;
33
using AsmResolver.PE.DotNet.Cil;
4-
using Echo.Memory;
54
using Echo.Platforms.AsmResolver.Emulation.Stack;
65

76
namespace Echo.Platforms.AsmResolver.Emulation.Dispatch.Arrays
@@ -19,8 +18,10 @@ protected override CilDispatchResult DispatchInternal(CilExecutionContext contex
1918
var factory = context.Machine.ValueFactory;
2019
var genericContext = GenericContext.FromMethod(context.CurrentFrame.Method);
2120

22-
var elementType = ((ITypeDefOrRef)instruction.Operand!).ToTypeSignature().InstantiateGenericTypes(genericContext);
2321
var elementCount = stack.Pop();
22+
var elementType = ((ITypeDefOrRef)instruction.Operand!)
23+
.ToTypeSignature(context.RuntimeContext)
24+
.InstantiateGenericTypes(genericContext);
2425

2526
try
2627
{

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/Arrays/StElemHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ protected override CilDispatchResult DispatchInternal(CilExecutionContext contex
8989

9090
private static TypeSignature GetElementType(CilExecutionContext context, CilInstruction instruction)
9191
{
92-
var factory = context.Machine.ValueFactory.ContextModule.CorLibTypeFactory;
92+
var factory = context.Machine.ValueFactory.CorLibTypeFactory;
9393
return instruction.OpCode.Code switch
9494
{
95-
CilCode.Stelem => ((ITypeDefOrRef) instruction.Operand!).ToTypeSignature(),
95+
CilCode.Stelem => ((ITypeDefOrRef) instruction.Operand!).ToTypeSignature(context.RuntimeContext),
9696
CilCode.Stelem_I => factory.IntPtr,
9797
CilCode.Stelem_I1 => factory.SByte,
9898
CilCode.Stelem_I2 => factory.Int16,

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/CilExecutionContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Threading;
2+
using AsmResolver.DotNet;
23
using Echo.Platforms.AsmResolver.Emulation.Stack;
34

45
namespace Echo.Platforms.AsmResolver.Emulation.Dispatch
@@ -44,5 +45,7 @@ public CancellationToken CancellationToken
4445
{
4546
get;
4647
}
48+
49+
public RuntimeContext RuntimeContext => Machine.RuntimeContext;
4750
}
4851
}

src/Platforms/Echo.Platforms.AsmResolver/Emulation/Dispatch/ControlFlow/RetHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CilDispatchResult Dispatch(CilExecutionContext context, CilInstruction in
3535
if (index != -1 && body.Instructions[index].OpCode.Code == CilCode.Newobj)
3636
{
3737
var resultingType = calleeFrame.Method.DeclaringType!
38-
.ToTypeSignature()
38+
.ToTypeSignature(context.RuntimeContext)
3939
.InstantiateGenericTypes(genericContext);
4040

4141
var slot = CreateResultingStackSlot(

0 commit comments

Comments
 (0)