diff options
Diffstat (limited to 'packaging/0029-Move-exception-allocation-to-PAL_SEHException.patch')
-rw-r--r-- | packaging/0029-Move-exception-allocation-to-PAL_SEHException.patch | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/packaging/0029-Move-exception-allocation-to-PAL_SEHException.patch b/packaging/0029-Move-exception-allocation-to-PAL_SEHException.patch new file mode 100644 index 0000000000..67e9f9e5e4 --- /dev/null +++ b/packaging/0029-Move-exception-allocation-to-PAL_SEHException.patch @@ -0,0 +1,179 @@ +From d7ea540ec5ffa7e44627b61f0cfa480341ec64ec Mon Sep 17 00:00:00 2001 +From: Mikhail Labiuk <m.labiuk@samsung.com> +Date: Tue, 20 Feb 2018 14:26:35 +0300 +Subject: [PATCH 29/47] Move exception allocation to PAL_SEHException + +PAL_SEHException::EnsureExceptionRecordsOnHeap() moves exception record +to heap if needed. + +fix https://github.com/dotnet/coreclr/issues/16338 +--- + src/pal/inc/pal.h | 35 ++++++++++++++++++++++++++++++----- + src/pal/src/exception/seh.cpp | 25 ++----------------------- + src/pal/src/exception/signal.cpp | 6 ++---- + 3 files changed, 34 insertions(+), 32 deletions(-) + +diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h +index e3bfa40..e241219 100644 +--- a/src/pal/inc/pal.h ++++ b/src/pal/inc/pal.h +@@ -3888,8 +3888,6 @@ PAL_BindResources(IN LPCSTR lpDomain); + + #define EXCEPTION_IS_SIGNAL 0x100 + +-#define EXCEPTION_ON_STACK 0x400 +- + #define EXCEPTION_MAXIMUM_PARAMETERS 15 + + // Index in the ExceptionInformation array where we will keep the reference +@@ -5796,6 +5794,11 @@ PAL_FreeExceptionRecords( + IN EXCEPTION_RECORD *exceptionRecord, + IN CONTEXT *contextRecord); + ++VOID ++AllocateExceptionRecords( ++ EXCEPTION_RECORD** exceptionRecord, ++ CONTEXT** contextRecord); ++ + #define EXCEPTION_CONTINUE_SEARCH 0 + #define EXCEPTION_EXECUTE_HANDLER 1 + #define EXCEPTION_CONTINUE_EXECUTION -1 +@@ -5810,14 +5813,14 @@ private: + ExceptionPointers.ExceptionRecord = ex.ExceptionPointers.ExceptionRecord; + ExceptionPointers.ContextRecord = ex.ExceptionPointers.ContextRecord; + TargetFrameSp = ex.TargetFrameSp; ++ RecordsOnStack = ex.RecordsOnStack; + + ex.Clear(); + } + + void FreeRecords() + { +- if (ExceptionPointers.ExceptionRecord != NULL && +- ! (ExceptionPointers.ExceptionRecord->ExceptionFlags | EXCEPTION_ON_STACK) ) ++ if (ExceptionPointers.ExceptionRecord != NULL && !RecordsOnStack ) + { + PAL_FreeExceptionRecords(ExceptionPointers.ExceptionRecord, ExceptionPointers.ContextRecord); + ExceptionPointers.ExceptionRecord = NULL; +@@ -5829,12 +5832,14 @@ public: + EXCEPTION_POINTERS ExceptionPointers; + // Target frame stack pointer set before the 2nd pass. + SIZE_T TargetFrameSp; ++ bool RecordsOnStack; + +- PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord) ++ PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord, bool onStack = false) + { + ExceptionPointers.ExceptionRecord = pExceptionRecord; + ExceptionPointers.ContextRecord = pContextRecord; + TargetFrameSp = NoTargetFrameSp; ++ RecordsOnStack = onStack; + } + + PAL_SEHException() +@@ -5870,6 +5875,26 @@ public: + ExceptionPointers.ExceptionRecord = NULL; + ExceptionPointers.ContextRecord = NULL; + TargetFrameSp = NoTargetFrameSp; ++ RecordsOnStack = false; ++ } ++ ++ void EnsureExceptionRecordsOnHeap() ++ { ++ if( !RecordsOnStack || ExceptionPointers.ExceptionRecord == NULL) ++ { ++ return; ++ } ++ ++ CONTEXT* contextRecordCopy; ++ EXCEPTION_RECORD* exceptionRecordCopy; ++ AllocateExceptionRecords(&exceptionRecordCopy, &contextRecordCopy); ++ ++ *exceptionRecordCopy = *ExceptionPointers.ExceptionRecord; ++ ExceptionPointers.ExceptionRecord = exceptionRecordCopy; ++ *contextRecordCopy = *ExceptionPointers.ContextRecord; ++ ExceptionPointers.ContextRecord = contextRecordCopy; ++ ++ RecordsOnStack = false; + } + + CONTEXT* GetContextRecord() +diff --git a/src/pal/src/exception/seh.cpp b/src/pal/src/exception/seh.cpp +index a7d4ad9..27766f2 100644 +--- a/src/pal/src/exception/seh.cpp ++++ b/src/pal/src/exception/seh.cpp +@@ -232,23 +232,6 @@ void ThrowExceptionHelper(PAL_SEHException* ex) + throw std::move(*ex); + } + +-static PAL_SEHException copyPAL_SEHException(PAL_SEHException* src) +-{ +- CONTEXT* contextRecord = src->GetContextRecord(); +- EXCEPTION_RECORD* exceptionRecord = src->GetExceptionRecord(); +- +- CONTEXT* contextRecordCopy; +- EXCEPTION_RECORD* exceptionRecordCopy; +- AllocateExceptionRecords(&exceptionRecordCopy, &contextRecordCopy); +- +- *exceptionRecordCopy = *exceptionRecord; +- exceptionRecordCopy->ExceptionFlags &= ~EXCEPTION_ON_STACK; +- *contextRecordCopy = *contextRecord; +- return PAL_SEHException(exceptionRecordCopy, contextRecordCopy); +-} +- +- +- + /*++ + Function: + SEHProcessException +@@ -296,10 +279,8 @@ SEHProcessException(PAL_SEHException* exception) + PROCAbort(); + } + } +- +- if(exceptionRecord->ExceptionFlags | EXCEPTION_ON_STACK) +- *exception = copyPAL_SEHException(exception); + ++ exception->EnsureExceptionRecordsOnHeap(); + if (g_hardwareExceptionHandler(exception)) + { + // The exception happened in managed code and the execution should continue. +@@ -312,9 +293,7 @@ SEHProcessException(PAL_SEHException* exception) + + if (CatchHardwareExceptionHolder::IsEnabled()) + { +- if(exceptionRecord->ExceptionFlags | EXCEPTION_ON_STACK) +- *exception = copyPAL_SEHException(exception); +- ++ exception->EnsureExceptionRecordsOnHeap(); + PAL_ThrowExceptionFromContext(exception->GetContextRecord(), exception); + } + } +diff --git a/src/pal/src/exception/signal.cpp b/src/pal/src/exception/signal.cpp +index d42ba38..3b4bec8 100644 +--- a/src/pal/src/exception/signal.cpp ++++ b/src/pal/src/exception/signal.cpp +@@ -808,10 +808,8 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext + ucontext = (native_context_t *)sigcontext; + g_common_signal_handler_context_locvar_offset = (int)((char*)&signalContextRecord - (char*)__builtin_frame_address(0)); + +- //AllocateExceptionRecords(&exceptionRecord, &contextRecord); +- + exceptionRecord.ExceptionCode = CONTEXTGetExceptionCodeForSignal(siginfo, ucontext); +- exceptionRecord.ExceptionFlags = EXCEPTION_IS_SIGNAL | EXCEPTION_ON_STACK; ++ exceptionRecord.ExceptionFlags = EXCEPTION_IS_SIGNAL; + exceptionRecord.ExceptionRecord = NULL; + exceptionRecord.ExceptionAddress = GetNativeContextPC(ucontext); + exceptionRecord.NumberParameters = numParams; +@@ -853,7 +851,7 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext + memcpy_s(&signalContextRecord, sizeof(CONTEXT), &contextRecord, sizeof(CONTEXT)); + + // The exception object takes ownership of the exceptionRecord and contextRecord +- PAL_SEHException exception(&exceptionRecord, &contextRecord); ++ PAL_SEHException exception(&exceptionRecord, &contextRecord, true); + + if (SEHProcessException(&exception)) + { +-- +2.7.4 + |