Skip to content

Commit 5fd7ed8

Browse files
committed
Skip 0 and -1 addresses.
1 parent 5a3cff2 commit 5fd7ed8

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/BenchmarkDotNet/Disassemblers/ClrMdV2Disassembler.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ namespace BenchmarkDotNet.Disassemblers
1414
// This Disassembler uses ClrMd v2x. Please keep it in sync with ClrMdV1Disassembler (if possible).
1515
internal abstract class ClrMdV2Disassembler
1616
{
17-
// Translating an address to a method can cause AV and a process crash (https://github.com/dotnet/BenchmarkDotNet/issues/2070).
18-
// It was partially fixed in https://github.com/dotnet/runtime/pull/79846,
19-
// fully fixed in https://github.com/dotnet/runtime/pull/90797.
20-
protected static readonly bool IsVulnerableToAvInDac = !RuntimeInformation.IsWindows() && Environment.Version < new Version(8, 0);
21-
2217
internal DisassemblyResult AttachAndDisassemble(Settings settings)
2318
{
2419
using (var dataTarget = DataTarget.AttachToProcess(
@@ -247,11 +242,15 @@ protected static bool TryReadNativeCodeAddresses(ClrRuntime runtime, ClrMethod m
247242

248243
protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD, State state, bool isIndirectCallOrJump, int depth, ClrMethod currentMethod)
249244
{
250-
var runtime = state.Runtime;
245+
// 0 or -1 (ulong.MaxValue) addresses are invalid, and will crash the runtime in older runtimes. https://github.com/dotnet/runtime/pull/90794
246+
if (address == 0 || address == ulong.MaxValue)
247+
return;
251248

252249
if (state.AddressToNameMapping.ContainsKey(address))
253250
return;
254251

252+
var runtime = state.Runtime;
253+
255254
var jitHelperFunctionName = runtime.GetJitHelperFunctionName(address);
256255
if (!string.IsNullOrEmpty(jitHelperFunctionName))
257256
{
@@ -276,7 +275,7 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
276275

277276
if (method is null)
278277
{
279-
if (isAddressPrecodeMD || !IsVulnerableToAvInDac)
278+
if (isAddressPrecodeMD)
280279
{
281280
var methodDescriptor = runtime.GetMethodByHandle(address);
282281
if (!(methodDescriptor is null))
@@ -293,14 +292,11 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
293292
}
294293
}
295294

296-
if (!IsVulnerableToAvInDac)
295+
var methodTableName = runtime.DacLibrary.SOSDacInterface.GetMethodTableName(address);
296+
if (!string.IsNullOrEmpty(methodTableName))
297297
{
298-
var methodTableName = runtime.DacLibrary.SOSDacInterface.GetMethodTableName(address);
299-
if (!string.IsNullOrEmpty(methodTableName))
300-
{
301-
state.AddressToNameMapping.Add(address, $"MT_{methodTableName}");
302-
return;
303-
}
298+
state.AddressToNameMapping.Add(address, $"MT_{methodTableName}");
299+
return;
304300
}
305301
return;
306302
}

src/BenchmarkDotNet/Disassemblers/IntelDisassembler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
8484

8585
if (address > ushort.MaxValue)
8686
{
87-
if (!IsVulnerableToAvInDac || IsCallOrJump(instruction))
88-
{
89-
TryTranslateAddressToName(address, isPrestubMD, state, isIndirect, depth, currentMethod);
90-
}
87+
TryTranslateAddressToName(address, isPrestubMD, state, isIndirect, depth, currentMethod);
9188
}
9289
}
9390

0 commit comments

Comments
 (0)