Skip to content

Commit e544ccf

Browse files
author
John Salem
authored
Prevent AV in processinfo2 while suspended (#55379)
1 parent cd4df7d commit e544ccf

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,22 @@ ep_rt_entrypoint_assembly_name_get_utf8 (void)
11691169
{
11701170
STATIC_CONTRACT_NOTHROW;
11711171

1172-
return reinterpret_cast<const ep_char8_t*>(GetAppDomain ()->GetRootAssembly ()->GetSimpleName ());
1172+
AppDomain *app_domain_ref = nullptr;
1173+
Assembly *assembly_ref = nullptr;
1174+
1175+
app_domain_ref = GetAppDomain ();
1176+
if (app_domain_ref != nullptr)
1177+
{
1178+
assembly_ref = app_domain_ref->GetRootAssembly ();
1179+
if (assembly_ref != nullptr)
1180+
{
1181+
return reinterpret_cast<const ep_char8_t*>(assembly_ref->GetSimpleName ());
1182+
}
1183+
}
1184+
1185+
// fallback to the empty string if we can't get assembly info, e.g., if the runtime is
1186+
// suspended before an assembly is loaded.
1187+
return reinterpret_cast<const ep_char8_t*>("");
11731188
}
11741189

11751190
static

src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,42 @@ public static async Task<bool> TEST_ConfigValidation()
388388
return fSuccess;
389389
}
390390

391+
public static async Task<bool> TEST_CanGetProcessInfo2WhileSuspended()
392+
{
393+
bool fSuccess = true;
394+
Task<bool> subprocessTask = Utils.RunSubprocess(
395+
currentAssembly: Assembly.GetExecutingAssembly(),
396+
environment: new Dictionary<string,string>
397+
{
398+
{ Utils.DiagnosticPortSuspend, "1" }
399+
},
400+
duringExecution: (int pid) =>
401+
{
402+
Stream stream = ConnectionHelper.GetStandardTransport(pid);
403+
404+
// 0x04 = ProcessCommandSet, 0x04 = ProcessInfo2
405+
var processInfoMessage = new IpcMessage(0x04, 0x04);
406+
Logger.logger.Log($"Wrote: {processInfoMessage}");
407+
IpcMessage response = IpcClient.SendMessage(stream, processInfoMessage);
408+
Logger.logger.Log($"Received: [{response.Payload.Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]");
409+
ProcessInfo2 processInfo2 = ProcessInfo2.TryParse(response.Payload);
410+
Utils.Assert(String.IsNullOrEmpty(processInfo2.ManagedEntrypointAssemblyName));
411+
412+
// send resume command on this connection
413+
var message = new IpcMessage(0x04,0x01);
414+
Logger.logger.Log($"Sent: {message.ToString()}");
415+
response = IpcClient.SendMessage(ConnectionHelper.GetStandardTransport(pid), message);
416+
Logger.logger.Log($"Received: {response.ToString()}");
417+
418+
return Task.FromResult(true);
419+
}
420+
);
421+
422+
fSuccess &= await subprocessTask;
423+
424+
return fSuccess;
425+
}
426+
391427
public static async Task<int> Main(string[] args)
392428
{
393429
if (args.Length >= 1)

0 commit comments

Comments
 (0)