diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2016-07-09 01:56:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-09 01:56:00 +0200 |
commit | 57b3450f4d232cd53d3b9a0f6566806d73fa4156 (patch) | |
tree | be4700d9f1b3dae8972cfe6ee314a75b6a1553f9 /src/vm/synch.cpp | |
parent | b7d37fe7317381a64aa6331d24e6a9f3d6aab6c5 (diff) | |
download | coreclr-57b3450f4d232cd53d3b9a0f6566806d73fa4156.tar.gz coreclr-57b3450f4d232cd53d3b9a0f6566806d73fa4156.tar.bz2 coreclr-57b3450f4d232cd53d3b9a0f6566806d73fa4156.zip |
Fix exceptions in GC (#6192)
The GC code in general doesn't expect exceptions to be thrown from functions
it calls. However, the event creation functions were in fact throwing, so
in case of OOM, exception would be thrown from various places of the code.
This change creates non-throwing versions of the event creation functions
and replaces all usages of the throwing ones in the GC.
In addition, I've removed blocks with PAL_TRY that were under NO_CATCH_HANDLERS
define and also added Object::SetAppDomainNoThrow, which allowed me to removed
EX_TRY from GCHeap::StressHeap where the Object::SetAppDomain was called before.
Diffstat (limited to 'src/vm/synch.cpp')
-rw-r--r-- | src/vm/synch.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/vm/synch.cpp b/src/vm/synch.cpp index da51c948a8..216dd31587 100644 --- a/src/vm/synch.cpp +++ b/src/vm/synch.cpp @@ -60,6 +60,33 @@ void CLREventBase::CreateAutoEvent (BOOL bInitialState // If TRUE, initial stat } +BOOL CLREventBase::CreateAutoEventNoThrow (BOOL bInitialState // If TRUE, initial state is signalled + ) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + SO_TOLERANT; + // disallow creation of Crst before EE starts + // Can not assert here. ASP.Net uses our Threadpool before EE is started. + PRECONDITION((m_handle == INVALID_HANDLE_VALUE)); + PRECONDITION((!IsOSEvent())); + } + CONTRACTL_END; + + EX_TRY + { + CreateAutoEvent(bInitialState); + } + EX_CATCH + { + } + EX_END_CATCH(SwallowAllExceptions); + + return IsValid(); +} + void CLREventBase::CreateManualEvent (BOOL bInitialState // If TRUE, initial state is signalled ) { @@ -100,6 +127,32 @@ void CLREventBase::CreateManualEvent (BOOL bInitialState // If TRUE, initial st } } +BOOL CLREventBase::CreateManualEventNoThrow (BOOL bInitialState // If TRUE, initial state is signalled + ) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + SO_TOLERANT; + // disallow creation of Crst before EE starts + // Can not assert here. ASP.Net uses our Threadpool before EE is started. + PRECONDITION((m_handle == INVALID_HANDLE_VALUE)); + PRECONDITION((!IsOSEvent())); + } + CONTRACTL_END; + + EX_TRY + { + CreateManualEvent(bInitialState); + } + EX_CATCH + { + } + EX_END_CATCH(SwallowAllExceptions); + + return IsValid(); +} void CLREventBase::CreateMonitorEvent(SIZE_T Cookie) { @@ -340,6 +393,29 @@ void CLREventBase::CreateOSAutoEvent (BOOL bInitialState // If TRUE, initial st m_handle = h; } +BOOL CLREventBase::CreateOSAutoEventNoThrow (BOOL bInitialState // If TRUE, initial state is signalled + ) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + // disallow creation of Crst before EE starts + PRECONDITION((m_handle == INVALID_HANDLE_VALUE)); + } + CONTRACTL_END; + + EX_TRY + { + CreateOSAutoEvent(bInitialState); + } + EX_CATCH + { + } + EX_END_CATCH(SwallowAllExceptions); + + return IsValid(); +} void CLREventBase::CreateOSManualEvent (BOOL bInitialState // If TRUE, initial state is signalled ) @@ -365,6 +441,29 @@ void CLREventBase::CreateOSManualEvent (BOOL bInitialState // If TRUE, initial m_handle = h; } +BOOL CLREventBase::CreateOSManualEventNoThrow (BOOL bInitialState // If TRUE, initial state is signalled + ) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + // disallow creation of Crst before EE starts + PRECONDITION((m_handle == INVALID_HANDLE_VALUE)); + } + CONTRACTL_END; + + EX_TRY + { + CreateOSManualEvent(bInitialState); + } + EX_CATCH + { + } + EX_END_CATCH(SwallowAllExceptions); + + return IsValid(); +} void CLREventBase::CloseEvent() { |