Skip to content
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 @@ -12,11 +12,11 @@

<ItemGroup>
<PackageFile Include="$(RuntimeBinDir)ILCompiler.Reflection.ReadyToRun.dll">
<TargetPath>\lib\netstandard2.0\</TargetPath>
<TargetPath>\lib\$(NetCoreAppMinimum)\</TargetPath>
</PackageFile>
<Dependency Include="System.Reflection.Metadata">
<Version>$(SystemReflectionMetadataVersion)</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>$(NetCoreAppMinimum)</TargetFramework>
<Exclude>Build,Analyzers</Exclude>
</Dependency>
</ItemGroup>
Expand Down
126 changes: 63 additions & 63 deletions src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,33 @@ public GcSlotTable() { }
/// <summary>
/// based on <a href="https://github.com/dotnet/runtime/blob/main/src/coreclr/vm/gcinfodecoder.cpp">GcSlotDecoder::DecodeSlotTable</a>
/// </summary>
public GcSlotTable(byte[] image, Machine machine, GcInfoTypes gcInfoTypes, ref int bitOffset)
public GcSlotTable(NativeReader imageReader, Machine machine, GcInfoTypes gcInfoTypes, ref int bitOffset)
{
_machine = machine;

if (NativeReader.ReadBits(image, 1, ref bitOffset) != 0)
if (imageReader.ReadBits(1, ref bitOffset) != 0)
{
NumRegisters = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.NUM_REGISTERS_ENCBASE, ref bitOffset);
NumRegisters = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.NUM_REGISTERS_ENCBASE, ref bitOffset);
}
if (NativeReader.ReadBits(image, 1, ref bitOffset) != 0)
if (imageReader.ReadBits(1, ref bitOffset) != 0)
{
NumStackSlots = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.NUM_STACK_SLOTS_ENCBASE, ref bitOffset);
NumUntracked = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.NUM_UNTRACKED_SLOTS_ENCBASE, ref bitOffset);
NumStackSlots = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.NUM_STACK_SLOTS_ENCBASE, ref bitOffset);
NumUntracked = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.NUM_UNTRACKED_SLOTS_ENCBASE, ref bitOffset);
}
NumSlots = NumRegisters + NumStackSlots + NumUntracked;

GcSlots = new List<GcSlot>();
if (NumRegisters > 0)
{
DecodeRegisters(image, gcInfoTypes, ref bitOffset);
DecodeRegisters(imageReader, gcInfoTypes, ref bitOffset);
}
if (NumStackSlots > 0)
{
DecodeStackSlots(image, machine, gcInfoTypes, NumStackSlots, false, ref bitOffset);
DecodeStackSlots(imageReader, machine, gcInfoTypes, NumStackSlots, false, ref bitOffset);
}
if (NumUntracked > 0)
{
DecodeStackSlots(image, machine, gcInfoTypes, NumUntracked, true, ref bitOffset);
DecodeStackSlots(imageReader, machine, gcInfoTypes, NumUntracked, true, ref bitOffset);
}
}

Expand All @@ -150,50 +150,50 @@ public override string ToString()
return sb.ToString();
}

private void DecodeRegisters(byte[] image, GcInfoTypes gcInfoTypes, ref int bitOffset)
private void DecodeRegisters(NativeReader imageReader, GcInfoTypes gcInfoTypes, ref int bitOffset)
{
// We certainly predecode the first register
uint regNum = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.REGISTER_ENCBASE, ref bitOffset);
GcSlotFlags flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset);
uint regNum = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.REGISTER_ENCBASE, ref bitOffset);
GcSlotFlags flags = (GcSlotFlags)imageReader.ReadBits(2, ref bitOffset);
GcSlots.Add(new GcSlot(GcSlots.Count, (int)regNum, null, flags));

for (int i = 1; i < NumRegisters; i++)
{
if ((uint)flags != 0)
{
regNum = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.REGISTER_ENCBASE, ref bitOffset);
flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset);
regNum = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.REGISTER_ENCBASE, ref bitOffset);
flags = (GcSlotFlags)imageReader.ReadBits(2, ref bitOffset);
}
else
{
uint regDelta = NativeReader.DecodeVarLengthUnsigned(image, gcInfoTypes.REGISTER_DELTA_ENCBASE, ref bitOffset) + 1;
uint regDelta = imageReader.DecodeVarLengthUnsigned(gcInfoTypes.REGISTER_DELTA_ENCBASE, ref bitOffset) + 1;
regNum += regDelta;
}
GcSlots.Add(new GcSlot(GcSlots.Count, (int)regNum, null, flags));
}
}

private void DecodeStackSlots(byte[] image, Machine machine, GcInfoTypes gcInfoTypes, uint nSlots, bool isUntracked, ref int bitOffset)
private void DecodeStackSlots(NativeReader imageReader, Machine machine, GcInfoTypes gcInfoTypes, uint nSlots, bool isUntracked, ref int bitOffset)
{
// We have stack slots left and more room to predecode
GcStackSlotBase spBase = (GcStackSlotBase)NativeReader.ReadBits(image, 2, ref bitOffset);
int normSpOffset = NativeReader.DecodeVarLengthSigned(image, gcInfoTypes.STACK_SLOT_ENCBASE, ref bitOffset);
GcStackSlotBase spBase = (GcStackSlotBase)imageReader.ReadBits(2, ref bitOffset);
int normSpOffset = imageReader.DecodeVarLengthSigned(gcInfoTypes.STACK_SLOT_ENCBASE, ref bitOffset);
int spOffset = gcInfoTypes.DenormalizeStackSlot(normSpOffset);
GcSlotFlags flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset);
GcSlotFlags flags = (GcSlotFlags)imageReader.ReadBits(2, ref bitOffset);
GcSlots.Add(new GcSlot(GcSlots.Count, -1, new GcStackSlot(spOffset, spBase), flags, isUntracked));

for (int i = 1; i < nSlots; i++)
{
spBase = (GcStackSlotBase)NativeReader.ReadBits(image, 2, ref bitOffset);
spBase = (GcStackSlotBase)imageReader.ReadBits(2, ref bitOffset);
if ((uint)flags != 0)
{
normSpOffset = NativeReader.DecodeVarLengthSigned(image, gcInfoTypes.STACK_SLOT_ENCBASE, ref bitOffset);
normSpOffset = imageReader.DecodeVarLengthSigned(gcInfoTypes.STACK_SLOT_ENCBASE, ref bitOffset);
spOffset = gcInfoTypes.DenormalizeStackSlot(normSpOffset);
flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset);
flags = (GcSlotFlags)imageReader.ReadBits(2, ref bitOffset);
}
else
{
int normSpOffsetDelta = NativeReader.DecodeVarLengthSigned(image, gcInfoTypes.STACK_SLOT_DELTA_ENCBASE, ref bitOffset);
int normSpOffsetDelta = imageReader.DecodeVarLengthSigned(gcInfoTypes.STACK_SLOT_DELTA_ENCBASE, ref bitOffset);
normSpOffset += normSpOffsetDelta;
spOffset = gcInfoTypes.DenormalizeStackSlot(normSpOffset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public UnwindCode() { }
/// <summary>
/// Unwind code parsing is based on <a href="https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/unwindamd64.cpp">src\jit\unwindamd64.cpp</a> DumpUnwindInfo
/// </summary>
public UnwindCode(byte[] image, ref int frameOffset, ref int offset)
public UnwindCode(NativeReader imageReader, ref int frameOffset, ref int offset)
{
CodeOffset = NativeReader.ReadByte(image, ref offset);
byte op = NativeReader.ReadByte(image, ref offset);
CodeOffset = imageReader.ReadByte(ref offset);
byte op = imageReader.ReadByte(ref offset);
UnwindOp = (UnwindOpCodes)(op & 15);
OpInfo = (byte)(op >> 4);

Expand All @@ -83,13 +83,13 @@ public UnwindCode(byte[] image, ref int frameOffset, ref int offset)
if (OpInfo == 0)
{
OpInfoStr += "Scaled small";
NextFrameOffset = 8 * NativeReader.ReadUInt16(image, ref offset);
NextFrameOffset = 8 * imageReader.ReadUInt16(ref offset);
}
else if (OpInfo == 1)
{
OpInfoStr += "Unscaled large";
uint nextOffset = NativeReader.ReadUInt16(image, ref offset);
NextFrameOffset = (int)((uint)(NativeReader.ReadUInt16(image, ref offset) << 16) | nextOffset);
uint nextOffset = imageReader.ReadUInt16(ref offset);
NextFrameOffset = (int)((uint)(imageReader.ReadUInt16(ref offset) << 16) | nextOffset);
}
else
{
Expand All @@ -104,43 +104,43 @@ public UnwindCode(byte[] image, ref int frameOffset, ref int offset)
OpInfoStr = $"Unused({OpInfo})";
break;
case UnwindOpCodes.UWOP_SET_FPREG_LARGE:
{
OpInfoStr = $"Unused({OpInfo})";
uint nextOffset = imageReader.ReadUInt16(ref offset);
nextOffset = ((uint)(imageReader.ReadUInt16(ref offset) << 16) | nextOffset);
NextFrameOffset = (int)nextOffset * 16;
if ((NextFrameOffset & 0xF0000000) != 0)
{
OpInfoStr = $"Unused({OpInfo})";
uint nextOffset = NativeReader.ReadUInt16(image, ref offset);
nextOffset = ((uint)(NativeReader.ReadUInt16(image, ref offset) << 16) | nextOffset);
NextFrameOffset = (int)nextOffset * 16;
if ((NextFrameOffset & 0xF0000000) != 0)
{
throw new BadImageFormatException("Warning: Illegal unwindInfo unscaled offset: too large");
}
throw new BadImageFormatException("Warning: Illegal unwindInfo unscaled offset: too large");
}
break;
}
break;
case UnwindOpCodes.UWOP_SAVE_NONVOL:
{
OpInfoStr = $"{(Registers)OpInfo}({OpInfo})";
NextFrameOffset = NativeReader.ReadUInt16(image, ref offset) * 8;
}
break;
{
OpInfoStr = $"{(Registers)OpInfo}({OpInfo})";
NextFrameOffset = imageReader.ReadUInt16(ref offset) * 8;
}
break;
case UnwindOpCodes.UWOP_SAVE_NONVOL_FAR:
{
OpInfoStr = $"{(Registers)OpInfo}({OpInfo})";
uint nextOffset = NativeReader.ReadUInt16(image, ref offset);
NextFrameOffset = (int)((uint)(NativeReader.ReadUInt16(image, ref offset) << 16) | nextOffset);
}
break;
{
OpInfoStr = $"{(Registers)OpInfo}({OpInfo})";
uint nextOffset = imageReader.ReadUInt16(ref offset);
NextFrameOffset = (int)((uint)(imageReader.ReadUInt16(ref offset) << 16) | nextOffset);
}
break;
case UnwindOpCodes.UWOP_SAVE_XMM128:
{
OpInfoStr = $"XMM{OpInfo}({OpInfo})";
NextFrameOffset = (int)NativeReader.ReadUInt16(image, ref offset) * 16;
}
break;
{
OpInfoStr = $"XMM{OpInfo}({OpInfo})";
NextFrameOffset = (int)imageReader.ReadUInt16(ref offset) * 16;
}
break;
case UnwindOpCodes.UWOP_SAVE_XMM128_FAR:
{
OpInfoStr = $"XMM{OpInfo}({OpInfo})";
uint nextOffset = NativeReader.ReadUInt16(image, ref offset);
NextFrameOffset = (int)((uint)(NativeReader.ReadUInt16(image, ref offset) << 16) | nextOffset);
}
break;
{
OpInfoStr = $"XMM{OpInfo}({OpInfo})";
uint nextOffset = imageReader.ReadUInt16(ref offset);
NextFrameOffset = (int)((uint)(imageReader.ReadUInt16(ref offset) << 16) | nextOffset);
}
break;
default:
throw new NotImplementedException(UnwindOp.ToString());
}
Expand Down Expand Up @@ -172,14 +172,14 @@ public UnwindInfo() { }
/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/zap/zapcode.cpp">ZapUnwindData::Save</a>
/// </summary>
public UnwindInfo(byte[] image, int offset)
public UnwindInfo(NativeReader imageReader, int offset)
{
byte versionAndFlags = NativeReader.ReadByte(image, ref offset);
byte versionAndFlags = imageReader.ReadByte(ref offset);
Version = (byte)(versionAndFlags & 7);
Flags = (byte)(versionAndFlags >> 3);
SizeOfProlog = NativeReader.ReadByte(image, ref offset);
CountOfUnwindCodes = NativeReader.ReadByte(image, ref offset);
byte frameRegisterAndOffset = NativeReader.ReadByte(image, ref offset);
SizeOfProlog = imageReader.ReadByte(ref offset);
CountOfUnwindCodes = imageReader.ReadByte(ref offset);
byte frameRegisterAndOffset = imageReader.ReadByte(ref offset);
FrameRegister = (Registers)(frameRegisterAndOffset & 15);
FrameOffset = (byte)(frameRegisterAndOffset >> 4);

Expand All @@ -190,7 +190,7 @@ public UnwindInfo(byte[] image, int offset)
int endOffset = offset + sizeOfUnwindCodes;
while (offset < endOffset)
{
UnwindCode unwindCode = new UnwindCode(image, ref frameOffset, ref offset);
UnwindCode unwindCode = new UnwindCode(imageReader, ref frameOffset, ref offset);
CodeOffsetToUnwindCodeIndex.Add(unwindCode.CodeOffset, UnwindCodes.Count);
UnwindCodes.Add(unwindCode);
}
Expand All @@ -201,7 +201,7 @@ public UnwindInfo(byte[] image, int offset)

// Personality routine RVA must be at 4-aligned address
offset += alignmentPad;
PersonalityRoutineRVA = NativeReader.ReadUInt32(image, ref offset);
PersonalityRoutineRVA = imageReader.ReadUInt32(ref offset);
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public class UnwindInfo : BaseUnwindInfo

public UnwindInfo() { }

public UnwindInfo(byte[] image, int offset)
public UnwindInfo(NativeReader imageReader, int offset)
{
uint startOffset = (uint)offset;

int dw = NativeReader.ReadInt32(image, ref offset);
int dw = imageReader.ReadInt32(ref offset);
CodeWords = ExtractBits(dw, 28, 4);
EpilogCount = ExtractBits(dw, 23, 5);
FBit = ExtractBits(dw, 22, 1);
Expand All @@ -92,7 +92,7 @@ public UnwindInfo(byte[] image, int offset)
{
// We have an extension word specifying a larger number of Code Words or Epilog Counts
// than can be specified in the header word.
dw = NativeReader.ReadInt32(image, ref offset);
dw = imageReader.ReadInt32(ref offset);
ExtendedCodeWords = ExtractBits(dw, 16, 8);
ExtendedEpilogCount = ExtractBits(dw, 0, 16);
}
Expand All @@ -106,7 +106,7 @@ public UnwindInfo(byte[] image, int offset)
{
for (int scope = 0; scope < EpilogCount; scope++)
{
dw = NativeReader.ReadInt32(image, ref offset);
dw = imageReader.ReadInt32(ref offset);
Epilogs[scope] = new Epilog(scope, dw, startOffset);
epilogStartAt[Epilogs[scope].EpilogStartIndex] = true; // an epilog starts at this offset in the unwind codes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public class UnwindInfo : BaseUnwindInfo

public UnwindInfo() { }

public UnwindInfo(byte[] image, int offset)
public UnwindInfo(NativeReader imageReader, int offset)
{
uint startOffset = (uint)offset;

int dw = NativeReader.ReadInt32(image, ref offset);
int dw = imageReader.ReadInt32(ref offset);
CodeWords = ExtractBits(dw, 27, 5);
EpilogCount = ExtractBits(dw, 22, 5);
EBit = ExtractBits(dw, 21, 1);
Expand All @@ -91,7 +91,7 @@ public UnwindInfo(byte[] image, int offset)
{
// We have an extension word specifying a larger number of Code Words or Epilog Counts
// than can be specified in the header word.
dw = NativeReader.ReadInt32(image, ref offset);
dw = imageReader.ReadInt32(ref offset);
ExtendedCodeWords = ExtractBits(dw, 16, 8);
ExtendedEpilogCount = ExtractBits(dw, 0, 16);
}
Expand All @@ -105,7 +105,7 @@ public UnwindInfo(byte[] image, int offset)
{
for (int scope = 0; scope < EpilogCount; scope++)
{
dw = NativeReader.ReadInt32(image, ref offset);
dw = imageReader.ReadInt32(ref offset);
Epilogs[scope] = new Epilog(scope, dw, startOffset);
epilogStartAt[Epilogs[scope].EpilogStartIndex] = true; // an epilog starts at this offset in the unwind codes
}
Expand Down
Loading
Loading