+
+ if (thread->pending_exception) {
+ MonoException *exc = thread->pending_exception;
+
+ thread->pending_exception = NULL;
+ return exc;
+ }
+
+ return NULL;
+}
+
+/*
+ * mono_set_pending_exception:
+ *
+ * Set the pending exception of the current thread to EXC. On platforms which
+ * support it, the exception will be thrown when execution returns to managed code.
+ * On other platforms, this function is equivalent to mono_raise_exception ().
+ * Internal calls which report exceptions using this function instead of
+ * raise_exception () might be called by JITted code using a more efficient calling
+ * convention.
+ */
+void
+mono_set_pending_exception (MonoException *exc)
+{
+ MonoThread *thread = mono_thread_current ();
+
+ /* The thread may already be stopping */
+ if (thread == NULL)
+ return;
+
+ if (mono_thread_notify_pending_exc_fn) {
+ MONO_OBJECT_SETREF (thread, pending_exception, exc);
+
+ mono_thread_notify_pending_exc_fn ();
+ } else {
+ /* No way to notify the JIT about the exception, have to throw it now */
+ mono_raise_exception (exc);
+ }