Skip to content

Commit 4286a67

Browse files
Copilotjkotas
andcommitted
Add context argument to crash dump functions
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
1 parent c23a584 commit 4286a67

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

src/coreclr/nativeaot/Runtime/unix/HardwareExceptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void SIGSEGVHandler(int code, siginfo_t *siginfo, void *context)
559559
RestoreSignalHandler(code, &g_previousSIGSEGV);
560560
}
561561

562-
PalCreateCrashDumpIfEnabled(code, siginfo);
562+
PalCreateCrashDumpIfEnabled(code, siginfo, context);
563563
}
564564

565565
// Handler for the SIGFPE signal
@@ -581,7 +581,7 @@ void SIGFPEHandler(int code, siginfo_t *siginfo, void *context)
581581
RestoreSignalHandler(code, &g_previousSIGFPE);
582582
}
583583

584-
PalCreateCrashDumpIfEnabled(code, siginfo);
584+
PalCreateCrashDumpIfEnabled(code, siginfo, context);
585585
}
586586

587587
// Initialize hardware exception handling

src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,18 @@ CreateCrashDump(
355355
Parameters:
356356
signal - POSIX signal number or 0
357357
siginfo - signal info or nullptr
358+
context - signal context or nullptr
358359
exceptionRecord - address of exception record or nullptr
359360
360361
(no return value)
361362
--*/
362363
void
363-
PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* exceptionRecord)
364+
PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, void* exceptionRecord)
364365
{
366+
// Store context in a volatile variable to prevent optimization
367+
volatile void* volatileContext = context;
368+
(void)volatileContext;
369+
365370
#if !defined(HOST_MACCATALYST) && !defined(HOST_IOS) && !defined(HOST_TVOS)
366371
// If enabled, launch the create minidump utility and wait until it completes
367372
if (g_argvCreateDump[0] != nullptr)
@@ -454,13 +459,13 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* exceptionRecor
454459
void
455460
PalCreateCrashDumpIfEnabled()
456461
{
457-
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, nullptr);
462+
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, nullptr, nullptr);
458463
}
459464

460465
void
461466
PalCreateCrashDumpIfEnabled(void* pExceptionRecord)
462467
{
463-
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, pExceptionRecord);
468+
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, nullptr, pExceptionRecord);
464469
}
465470

466471
/*++

src/coreclr/nativeaot/Runtime/unix/PalCreateDump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
extern bool PalCreateDumpInitialize();
99
extern void PalCreateCrashDumpIfEnabled();
10-
extern void PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo = nullptr, void* exceptionRecord = nullptr);
10+
extern void PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo = nullptr, void* context = nullptr, void* exceptionRecord = nullptr);
1111
extern void PalCreateCrashDumpIfEnabled(void* pExceptionRecord);

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static void invoke_previous_action(struct sigaction* action, int code, siginfo_t
433433
// Shutdown and create the core dump before we restore the signal to the default handler.
434434
PROCNotifyProcessShutdown(IsRunningOnAlternateStack(context));
435435

436-
PROCCreateCrashDumpIfEnabled(code, siginfo, true);
436+
PROCCreateCrashDumpIfEnabled(code, siginfo, context, true);
437437

438438
// Restore the original and restart h/w exception.
439439
restore_signal(code, action);
@@ -462,7 +462,7 @@ static void invoke_previous_action(struct sigaction* action, int code, siginfo_t
462462

463463
PROCNotifyProcessShutdown(IsRunningOnAlternateStack(context));
464464

465-
PROCCreateCrashDumpIfEnabled(code, siginfo, true);
465+
PROCCreateCrashDumpIfEnabled(code, siginfo, context, true);
466466
}
467467

468468
/*++
@@ -851,7 +851,7 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context)
851851
DWORD val = 0;
852852
if (enableDumpOnSigTerm.IsSet() && enableDumpOnSigTerm.TryAsInteger(10, val) && val == 1)
853853
{
854-
PROCCreateCrashDumpIfEnabled(code, siginfo, false);
854+
PROCCreateCrashDumpIfEnabled(code, siginfo, context, false);
855855
}
856856
}
857857

src/coreclr/pal/src/include/pal/process.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ VOID PROCNotifyProcessShutdown(bool isExecutingOnAltStack = false);
182182
Parameters:
183183
signal - POSIX signal number
184184
siginfo - POSIX signal info or nullptr
185+
context - signal context or nullptr
185186
serialize - allow only one thread to generate core dump
186187
187188
(no return value)
188189
--*/
189-
VOID PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, bool serialize);
190+
VOID PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, bool serialize);
190191

191192
#ifdef __cplusplus
192193
}

src/coreclr/pal/src/thread/process.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,23 +2716,32 @@ PAL_GenerateCoreDump(
27162716
Parameters:
27172717
signal - POSIX signal number
27182718
siginfo - POSIX signal info or nullptr
2719+
context - signal context or nullptr
27192720
serialize - allow only one thread to generate core dump
27202721
27212722
(no return value)
27222723
--*/
27232724
#ifdef HOST_ANDROID
27242725
#include <minipal/log.h>
27252726
VOID
2726-
PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, bool serialize)
2727+
PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, bool serialize)
27272728
{
2729+
// Store context in a volatile variable to prevent optimization
2730+
volatile void* volatileContext = context;
2731+
(void)volatileContext;
2732+
27282733
// TODO: Dump all managed threads callstacks into logcat and/or file?
27292734
// TODO: Dump stress log into logcat and/or file when enabled?
27302735
minipal_log_write_fatal("Aborting process.\n");
27312736
}
27322737
#else
27332738
VOID
2734-
PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, bool serialize)
2739+
PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, bool serialize)
27352740
{
2741+
// Store context in a volatile variable to prevent optimization
2742+
volatile void* volatileContext = context;
2743+
(void)volatileContext;
2744+
27362745
// If enabled, launch the create minidump utility and wait until it completes
27372746
if (!g_argvCreateDump.empty())
27382747
{
@@ -2821,7 +2830,7 @@ PROCAbort(int signal, siginfo_t* siginfo)
28212830
// Do any shutdown cleanup before aborting or creating a core dump
28222831
PROCNotifyProcessShutdown();
28232832

2824-
PROCCreateCrashDumpIfEnabled(signal, siginfo, true);
2833+
PROCCreateCrashDumpIfEnabled(signal, siginfo, nullptr, true);
28252834

28262835
// Restore all signals; the SIGABORT handler to prevent recursion and
28272836
// the others to prevent multiple core dumps from being generated.

0 commit comments

Comments
 (0)