Skip to content

Commit

Permalink
Do not access unloading domains in debugger (#34013)
Browse files Browse the repository at this point in the history
There was a race where a domain was being unloaded while debugger would access it. A domain was only removed from the 'appdomains_list' as a very last step. The domain was already invalid to access at this point (locks freed for example).

Worse, images would be unloaded if only referenced by that domain. All places the debugger iterates domains hold the loader lock. The loader lock is acquired by the domain unloading process, so as long as a domain is not unloading when we access it inside of the loader lock we are safe.

<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->

Co-authored-by: UnityAlex <UnityAlex@users.noreply.github.com>
  • Loading branch information
monojenkins and UnityAlex authored Mar 25, 2020
1 parent 2b2dedc commit dcbee66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mono/mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,9 @@ send_types_for_domain (MonoDomain *domain, void *user_data)
MonoDomain* old_domain;
AgentDomainInfo *info = NULL;

if (mono_domain_is_unloading (domain))
return;

info = get_agent_domain_info (domain);
g_assert (info);

Expand All @@ -4379,6 +4382,9 @@ send_assemblies_for_domain (MonoDomain *domain, void *user_data)
GSList *tmp;
MonoDomain* old_domain;

if (mono_domain_is_unloading (domain))
return;

old_domain = mono_domain_get ();

mono_domain_set_fast (domain, TRUE);
Expand Down Expand Up @@ -6864,6 +6870,10 @@ get_types (gpointer key, gpointer value, gpointer user_data)
MonoType *t;
GSList *tmp;
MonoDomain *domain = (MonoDomain*)key;

if (mono_domain_is_unloading (domain))
return;

MonoAssemblyLoadContext *alc = mono_domain_default_alc (domain);
GetTypesArgs *ud = (GetTypesArgs*)user_data;

Expand Down Expand Up @@ -6903,6 +6913,9 @@ get_types_for_source_file (gpointer key, gpointer value, gpointer user_data)
GetTypesForSourceFileArgs *ud = (GetTypesForSourceFileArgs*)user_data;
MonoDomain *domain = (MonoDomain*)key;

if (mono_domain_is_unloading (domain))
return;

AgentDomainInfo *info = (AgentDomainInfo *)domain_jit_info (domain)->agent_info;

/* Update 'source_file_to_class' cache */
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/debugger-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ collect_domain_bp (gpointer key, gpointer value, gpointer user_data)
CollectDomainData *ud = (CollectDomainData*)user_data;
MonoMethod *m;

if (mono_domain_is_unloading (domain))
return;

mono_domain_lock (domain);
g_hash_table_iter_init (&iter, domain_jit_info (domain)->seq_points);
while (g_hash_table_iter_next (&iter, (void**)&m, (void**)&seq_points)) {
Expand Down

0 comments on commit dcbee66

Please sign in to comment.