Skip to content

Ability to continue domain unload when an exception is encountered #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions mono/metadata/appdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ ves_icall_System_AppDomain_InternalUnload (gint32 domain_id, MonoError *error)
return;

MonoException *exc = NULL;
mono_domain_try_unload (domain, (MonoObject**)&exc);
mono_domain_try_unload (domain, (MonoObject**)&exc, NULL);
if (exc)
mono_error_set_exception_instance (error, exc);
}
Expand Down Expand Up @@ -2643,7 +2643,7 @@ void
mono_domain_unload (MonoDomain *domain)
{
MonoObject *exc = NULL;
mono_domain_try_unload (domain, &exc);
mono_domain_try_unload (domain, &exc, NULL);
}

static MonoThreadInfoWaitRet
Expand All @@ -2659,9 +2659,12 @@ guarded_wait (MonoThreadHandle *thread_handle, guint32 timeout, gboolean alertab
}

/**
* mono_domain_unload:
* mono_domain_try_unload:
* \param domain The domain to unload
* \param exc Exception information
* \param callback Passes exception information back to caller before domain is unloaded
*
* NOTE: If the callback param is not null the domain unload will continue after executing the callback.
*
* Unloads an appdomain. Follows the process outlined in:
* http://blogs.gotdotnet.com/cbrumme
Expand All @@ -2678,7 +2681,7 @@ guarded_wait (MonoThreadHandle *thread_handle, guint32 timeout, gboolean alertab
* process could end up trying to abort the current thread.
*/
void
mono_domain_try_unload (MonoDomain *domain, MonoObject **exc)
mono_domain_try_unload (MonoDomain *domain, MonoObject **exc, MonoUnityExceptionFunc callback)
{
MonoError error;
MonoThreadHandle *thread_handle;
Expand Down Expand Up @@ -2724,10 +2727,14 @@ mono_domain_try_unload (MonoDomain *domain, MonoObject **exc)
}

if (*exc) {
/* Roll back the state change */
domain->state = MONO_APPDOMAIN_CREATED;
mono_domain_set (caller_domain, FALSE);
return;
if (callback != NULL)
callback (*exc);
else {
/* Roll back the state change */
domain->state = MONO_APPDOMAIN_CREATED;
mono_domain_set (caller_domain, FALSE);
return;
}
}
mono_domain_set (caller_domain, FALSE);

Expand Down
3 changes: 2 additions & 1 deletion mono/metadata/appdomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct _MonoJitInfo MonoJitInfo;

typedef void (*MonoDomainFunc) (MonoDomain *domain, void* user_data);
typedef void (*MonoDomainAssemblyFunc) (MonoAssembly *assembly, void* user_data);
typedef void (*MonoUnityExceptionFunc) (MonoObject* exc);

MONO_API MonoDomain*
mono_init (const char *filename);
Expand Down Expand Up @@ -100,7 +101,7 @@ MONO_API void
mono_domain_unload (MonoDomain *domain);

MONO_API void
mono_domain_try_unload (MonoDomain *domain, MonoObject **exc);
mono_domain_try_unload (MonoDomain *domain, MonoObject **exc, MonoUnityExceptionFunc callback);

MONO_API mono_bool
mono_domain_is_unloading (MonoDomain *domain);
Expand Down
7 changes: 7 additions & 0 deletions mono/metadata/unity-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,13 @@ void mono_unity_domain_install_capture_context_method(MonoDomain* domain, gpoint
domain->capture_context_method = callback;
}


void mono_unity_domain_unload (MonoDomain* domain, MonoUnityExceptionFunc callback)
{
MonoObject *exc = NULL;
mono_domain_try_unload (domain, &exc, callback);
}

//array

int mono_unity_array_get_element_size(MonoArray *arr)
Expand Down
1 change: 1 addition & 0 deletions mono/metadata/unity-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ guint32 mono_unity_method_get_token(MonoMethod *method);
void mono_unity_domain_install_finalize_runtime_invoke(MonoDomain* domain, RuntimeInvokeFunction callback);
void mono_unity_domain_install_capture_context_runtime_invoke(MonoDomain* domain, RuntimeInvokeFunction callback);
void mono_unity_domain_install_capture_context_method(MonoDomain* domain, void* callback);
MONO_API void mono_unity_domain_unload (MonoDomain *domain, MonoUnityExceptionFunc callback);

//array
int mono_unity_array_get_element_size(MonoArray *arr);
Expand Down