summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2018-02-23 10:40:54 +0100
committerGitHub <noreply@github.com>2018-02-23 10:40:54 +0100
commit1270aa557a1de3e25e8699522ee74e66ce48046a (patch)
treebfed5d61579db71a0cb0869250d44c535ce7e631 /src/pal
parent2ddde33b2b46da116b2b36c2e5db640b5d76901f (diff)
downloadcoreclr-1270aa557a1de3e25e8699522ee74e66ce48046a.tar.gz
coreclr-1270aa557a1de3e25e8699522ee74e66ce48046a.tar.bz2
coreclr-1270aa557a1de3e25e8699522ee74e66ce48046a.zip
Fix preventing memory allocation in signal handler (#16485)
There was a subtle bug. When the hardware exception handler returns back to the signal handler, the exception's CONTEXT record may contain modified registers and so the changes need to be propagated back to the signal context. But the recent change #16384 was restoring the signal context from the originally grabbed context instead of the one that's pointed to by the exception, which is different. I have also added a little optimization - the contextRecord that was added is not needed, since the signalContextRecord can be used as the initial context record for the exception. So we can save the contextRecord and also copying to the signalContextRecord from it.
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/exception/signal.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/pal/src/exception/signal.cpp b/src/pal/src/exception/signal.cpp
index 6748d54f0f..0a3840a479 100644
--- a/src/pal/src/exception/signal.cpp
+++ b/src/pal/src/exception/signal.cpp
@@ -845,7 +845,6 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
{
sigset_t signal_set;
CONTEXT signalContextRecord;
- CONTEXT contextRecord;
EXCEPTION_RECORD exceptionRecord;
native_context_t *ucontext;
@@ -868,7 +867,7 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
// Pre-populate context with data from current frame, because ucontext doesn't have some data (e.g. SS register)
// which is required for restoring context
- RtlCaptureContext(&contextRecord);
+ RtlCaptureContext(&signalContextRecord);
ULONG contextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT;
@@ -879,7 +878,7 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
// Fill context record with required information. from pal.h:
// On non-Win32 platforms, the CONTEXT pointer in the
// PEXCEPTION_POINTERS will contain at least the CONTEXT_CONTROL registers.
- CONTEXTFromNativeContext(ucontext, &contextRecord, contextFlags);
+ CONTEXTFromNativeContext(ucontext, &signalContextRecord, contextFlags);
/* Unmask signal so we can receive it again */
sigemptyset(&signal_set);
@@ -890,17 +889,15 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
ASSERT("pthread_sigmask failed; error number is %d\n", sigmaskRet);
}
- contextRecord.ContextFlags |= CONTEXT_EXCEPTION_ACTIVE;
-
- memcpy_s(&signalContextRecord, sizeof(CONTEXT), &contextRecord, sizeof(CONTEXT));
+ signalContextRecord.ContextFlags |= CONTEXT_EXCEPTION_ACTIVE;
// The exception object takes ownership of the exceptionRecord and contextRecord
- PAL_SEHException exception(&exceptionRecord, &contextRecord, true);
+ PAL_SEHException exception(&exceptionRecord, &signalContextRecord, true);
if (SEHProcessException(&exception))
{
// Exception handling may have modified the context, so update it.
- CONTEXTToNativeContext(&contextRecord, ucontext);
+ CONTEXTToNativeContext(exception.ExceptionPointers.ContextRecord, ucontext);
return true;
}