[jni] Refresh current domain after attaching thread to runtime when registering types. #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change triggered by https://bugzilla.xamarin.com/show_bug.cgi?id=44448
It's possible for the register call to be called on a thread that hasn't been registered with Mono yet. As such, the
mono_domain_get
call will return NULL untilmono_jit_thread_attach
is invoked where domain information for the current thread becomes correct.This is an issue because it means we invoke
monodroid_runtime_invoke
passing NULL as a bogus domain argument. This caused a crash withmono_domain_set
as it doesn't support being passed a NULL domain.This commit solves the problem by re-requesting the current domain after the
mono_jit_thread_attach
call. If the thread had been registered beforehand, this will essentially be a no-op as it should return the same domain again. If it hadn't, attaching the thread will have set the current domain to be the root appdomain which will be returned bymono_domain_get
making our current domain variable now valid.