@@ -190,7 +190,11 @@ HRESULT JitInstance::StartUp(char* PathToJit,
190190 {
191191 mc = firstContext;
192192 jitHost = new JitHost (*this );
193- pnjitStartup (jitHost);
193+ if (!callJitStartup (jitHost))
194+ {
195+ LogError (" jitStartup failed" );
196+ return -1 ;
197+ }
194198 }
195199
196200 pJitInstance = pngetJit ();
@@ -256,7 +260,11 @@ bool JitInstance::reLoad(MethodContext* firstContext)
256260 {
257261 mc = firstContext;
258262 jitHost = new JitHost (*this );
259- pnjitStartup (jitHost);
263+ if (!callJitStartup (jitHost))
264+ {
265+ LogError (" jitStartup failed" );
266+ return false ;
267+ }
260268 }
261269
262270 pJitInstance = pngetJit ();
@@ -465,17 +473,56 @@ void JitInstance::freeLongLivedArray(void* array)
465473 HeapFree (ourHeap, 0 , array);
466474}
467475
476+ // Helper for calling pnjitStartup. Needed to allow SEH here.
477+ bool JitInstance::callJitStartup (ICorJitHost* jithost)
478+ {
479+ // Calling into the collection, which could fail, especially
480+ // for altjits. So protect the call.
481+
482+ struct Param : FilterSuperPMIExceptionsParam_CaptureException
483+ {
484+ JitInstance* pThis;
485+ ICorJitHost* jithost;
486+ bool result;
487+ } param;
488+ param.pThis = this ;
489+ param.jithost = jithost;
490+ param.result = false ;
491+
492+ PAL_TRY (Param*, pParam, ¶m)
493+ {
494+ pParam->pThis ->pnjitStartup (pParam->jithost );
495+ pParam->result = true ;
496+ }
497+ PAL_EXCEPT_FILTER (FilterSuperPMIExceptions_CaptureExceptionAndStop)
498+ {
499+ SpmiException e (¶m.exceptionPointers );
500+
501+ LogError (" failed to call jitStartup." );
502+ e.ShowAndDeleteMessage ();
503+ }
504+ PAL_ENDTRY
505+
506+ return param.result ;
507+ }
508+
468509// Reset JitConfig, that stores Enviroment variables.
469510bool JitInstance::resetConfig (MethodContext* firstContext)
470511{
471- if (pnjitStartup != nullptr )
512+ if (pnjitStartup == nullptr )
513+ {
514+ return false ;
515+ }
516+
517+ mc = firstContext;
518+ ICorJitHost* newHost = new JitHost (*this );
519+
520+ if (!callJitStartup (newHost))
472521 {
473- mc = firstContext;
474- ICorJitHost* newHost = new JitHost (*this );
475- pnjitStartup (newHost);
476- delete static_cast <JitHost*>(jitHost);
477- jitHost = newHost;
478- return true ;
522+ return false ;
479523 }
480- return false ;
481- }
524+
525+ delete static_cast <JitHost*>(jitHost);
526+ jitHost = newHost;
527+ return true ;
528+ }
0 commit comments