Refactor internal System.AppDomain out of CoreLib (dotnet/coreclr#21460)
authorJan Kotas <jkotas@microsoft.com>
Mon, 10 Dec 2018 21:34:03 +0000 (13:34 -0800)
committerGitHub <noreply@github.com>
Mon, 10 Dec 2018 21:34:03 +0000 (13:34 -0800)
Fixes dotnet/coreclr#21028

Commit migrated from https://github.com/dotnet/coreclr/commit/64f76abbde7f3b7a91bbdbe66c9beebc63bb8f0c

31 files changed:
src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx
src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs
src/coreclr/src/System.Private.CoreLib/src/System/AppContext.cs
src/coreclr/src/System.Private.CoreLib/src/System/AppDomain.cs [deleted file]
src/coreclr/src/System.Private.CoreLib/src/System/AppDomainUnloadedException.cs [deleted file]
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskExceptionHolder.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.cs
src/coreclr/src/vm/appdomain.cpp
src/coreclr/src/vm/appdomain.hpp
src/coreclr/src/vm/clrprivtypecachewinrt.cpp
src/coreclr/src/vm/comdelegate.cpp
src/coreclr/src/vm/comsynchronizable.cpp
src/coreclr/src/vm/comsynchronizable.h
src/coreclr/src/vm/crossgencompile.cpp
src/coreclr/src/vm/ecalllist.h
src/coreclr/src/vm/excep.cpp
src/coreclr/src/vm/exceptionhandling.cpp
src/coreclr/src/vm/marshalnative.cpp
src/coreclr/src/vm/marshalnative.h
src/coreclr/src/vm/metasig.h
src/coreclr/src/vm/mscorlib.h
src/coreclr/src/vm/object.h
src/coreclr/src/vm/rexcep.h
src/coreclr/src/vm/threads.cpp
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs
src/libraries/System.Private.CoreLib/src/System/HResults.cs

index ca6171e..192720b 100644 (file)
   <data name="Arg_AmbiguousMatchException" xml:space="preserve">
     <value>Ambiguous match found.</value>
   </data>
-  <data name="Arg_AppDomainUnloadedException" xml:space="preserve">
-    <value>Attempted to access an unloaded AppDomain.</value>
-  </data>
   <data name="Arg_ApplicationException" xml:space="preserve">
     <value>Error in the application.</value>
   </data>
   <data name="ReflectionTypeLoad_LoadFailed" xml:space="preserve">
     <value>Unable to load one or more of the requested types.</value>
   </data>
-  <data name="Remoting_AppDomainUnloaded_ThreadUnwound" xml:space="preserve">
-    <value>The application domain in which the thread was running has been unloaded.</value>
-  </data>
   <data name="ResourceReaderIsClosed" xml:space="preserve">
     <value>ResourceReader is closed.</value>
   </data>
index a4c9bec..17fa5d7 100644 (file)
     <Compile Include="$(BclSourcesRoot)\Microsoft\Win32\Win32Native.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Activator.cs" />
     <Compile Include="$(BclSourcesRoot)\System\AppContext.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\AppDomain.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\AppDomainUnloadedException.cs" />
     <Compile Include="$(BclSourcesRoot)\System\ArgIterator.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Array.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Attribute.cs" />
index c6fc981..dd808b3 100644 (file)
@@ -249,7 +249,10 @@ namespace Microsoft.Win32
         [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode)]
         internal static extern unsafe bool FreeEnvironmentStrings(char* pStrings);
 
-        [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
+        [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto)]
+        internal static extern int GetCurrentThreadId();
+
+        [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto)]
         internal static extern uint GetCurrentProcessId();
 
         [DllImport(Interop.Libraries.Ole32)]
index 0f3ee35..d1a3a98 100644 (file)
@@ -6,6 +6,8 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
+using System.Runtime.ExceptionServices;
+using System.Runtime.Loader;
 using System.Runtime.Versioning;
 using System.Threading;
 
@@ -13,16 +15,9 @@ namespace System
 {
     public static class AppContext
     {
-        private static Dictionary<string, object> s_dataStore = new Dictionary<string, object>();
+        private static readonly Dictionary<string, object> s_dataStore = new Dictionary<string, object>();
         private static Dictionary<string, bool> s_switches;
 
-        static AppContext()
-        {
-            // Unloading event must happen before ProcessExit event
-            AppDomain.CurrentDomain.ProcessExit += OnUnloading;
-            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
-        }
-
         internal static unsafe void Setup(char** pNames, char** pValues, int count)
         {
             for (int i = 0; i < count; i++)
@@ -83,50 +78,17 @@ namespace System
             }
         }
 
-        public static event UnhandledExceptionEventHandler UnhandledException
-        {
-            add
-            {
-                AppDomain.CurrentDomain.UnhandledException += value;
-            }
+        public static event UnhandledExceptionEventHandler UnhandledException;
 
-            remove
-            {
-                AppDomain.CurrentDomain.UnhandledException -= value;
-            }
-        }
-
-        public static event System.EventHandler<System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs> FirstChanceException
-        {
-            add
-            {
-                AppDomain.CurrentDomain.FirstChanceException += value;
-            }
-            remove
-            {
-                AppDomain.CurrentDomain.FirstChanceException -= value;
-            }
-        }
+        public static event System.EventHandler<FirstChanceExceptionEventArgs> FirstChanceException;
 
         public static event System.EventHandler ProcessExit;
-        internal static event System.EventHandler Unloading;
 
-        private static void OnProcessExit(object sender, EventArgs e)
+        private static void OnProcessExit()
         {
-            var processExit = ProcessExit;
-            if (processExit != null)
-            {
-                processExit(null, EventArgs.Empty);
-            }
-        }
+            AssemblyLoadContext.OnProcessExit();
 
-        private static void OnUnloading(object sender, EventArgs e)
-        {
-            var unloading = Unloading;
-            if (unloading != null)
-            {
-                unloading(null, EventArgs.Empty);
-            }
+            ProcessExit?.Invoke(null /* AppDomain */, EventArgs.Empty);
         }
 
         /// <summary>
@@ -177,7 +139,7 @@ namespace System
             if (s_switches == null)
             {
                 // Compatibility switches are rarely used. Initialize the Dictionary lazily
-                Interlocked.CompareExchange(ref s_switches, new Dictionary<string, bool>(), null); 
+                Interlocked.CompareExchange(ref s_switches, new Dictionary<string, bool>(), null);
             }
 
             lock (s_switches)
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/AppDomain.cs b/src/coreclr/src/System.Private.CoreLib/src/System/AppDomain.cs
deleted file mode 100644 (file)
index 78ef0fc..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.Contracts;
-using System.IO;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading;
-
-namespace System
-{
-    /// <summary>
-    /// Domains represent an application within the runtime. Objects cannot be
-    /// shared between domains and each domain can be configured independently.
-    /// </summary>
-    internal sealed class AppDomain
-    {
-        // Domain security information
-        // These fields initialized from the other side only. (NOTE: order
-        // of these fields cannot be changed without changing the layout in
-        // the EE- AppDomainBaseObject in this case)
-
-        public event AssemblyLoadEventHandler AssemblyLoad;
-
-        private ResolveEventHandler _TypeResolve;
-
-        public event ResolveEventHandler TypeResolve
-        {
-            add
-            {
-                lock (this)
-                {
-                    _TypeResolve += value;
-                }
-            }
-
-            remove
-            {
-                lock (this)
-                {
-                    _TypeResolve -= value;
-                }
-            }
-        }
-
-        private ResolveEventHandler _ResourceResolve;
-
-        public event ResolveEventHandler ResourceResolve
-        {
-            add
-            {
-                lock (this)
-                {
-                    _ResourceResolve += value;
-                }
-            }
-
-            remove
-            {
-                lock (this)
-                {
-                    _ResourceResolve -= value;
-                }
-            }
-        }
-
-        private ResolveEventHandler _AssemblyResolve;
-
-        public event ResolveEventHandler AssemblyResolve
-        {
-            add
-            {
-                lock (this)
-                {
-                    _AssemblyResolve += value;
-                }
-            }
-
-            remove
-            {
-                lock (this)
-                {
-                    _AssemblyResolve -= value;
-                }
-            }
-        }
-
-        private EventHandler _processExit;
-
-        private EventHandler _domainUnload;
-
-        private UnhandledExceptionEventHandler _unhandledException;
-
-        // Delegate that will hold references to FirstChance exception notifications
-        private EventHandler<FirstChanceExceptionEventArgs> _firstChanceException;
-
-        private IntPtr _pDomain;                      // this is an unmanaged pointer (AppDomain * m_pDomain)` used from the VM.
-
-        public static AppDomain CurrentDomain => Thread.GetDomain();
-
-        [Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread.  http://go.microsoft.com/fwlink/?linkid=14202", false)]
-        [DllImport(Interop.Libraries.Kernel32)]
-        public static extern int GetCurrentThreadId();
-
-        private AppDomain()
-        {
-            Debug.Fail("Object cannot be created through this constructor.");
-        }
-
-        // support reliability for certain event handlers, if the target
-        // methods also participate in this discipline.  If caller passes
-        // an existing MulticastDelegate, then we could use a MDA to indicate
-        // that reliability is not guaranteed.  But if it is a single cast
-        // scenario, we can make it work.
-
-        public event EventHandler ProcessExit
-        {
-            add
-            {
-                if (value != null)
-                {
-                    RuntimeHelpers.PrepareContractedDelegate(value);
-                    lock (this)
-                        _processExit += value;
-                }
-            }
-            remove
-            {
-                lock (this)
-                    _processExit -= value;
-            }
-        }
-
-        public event EventHandler DomainUnload
-        {
-            add
-            {
-                if (value != null)
-                {
-                    RuntimeHelpers.PrepareContractedDelegate(value);
-                    lock (this)
-                        _domainUnload += value;
-                }
-            }
-            remove
-            {
-                lock (this)
-                    _domainUnload -= value;
-            }
-        }
-
-        public event UnhandledExceptionEventHandler UnhandledException
-        {
-            add
-            {
-                if (value != null)
-                {
-                    RuntimeHelpers.PrepareContractedDelegate(value);
-                    lock (this)
-                        _unhandledException += value;
-                }
-            }
-            remove
-            {
-                lock (this)
-                    _unhandledException -= value;
-            }
-        }
-
-        // This is the event managed code can wireup against to be notified
-        // about first chance exceptions.
-        //
-        // To register/unregister the callback, the code must be SecurityCritical.
-        public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException
-        {
-            add
-            {
-                if (value != null)
-                {
-                    RuntimeHelpers.PrepareContractedDelegate(value);
-                    lock (this)
-                        _firstChanceException += value;
-                }
-            }
-            remove
-            {
-                lock (this)
-                    _firstChanceException -= value;
-            }
-        }
-
-        // This method is called by the VM.
-        private void OnAssemblyLoadEvent(RuntimeAssembly LoadedAssembly)
-        {
-            AssemblyLoad?.Invoke(this, new AssemblyLoadEventArgs(LoadedAssembly));
-        }
-
-        // This method is called by the VM.
-        private RuntimeAssembly OnResourceResolveEvent(RuntimeAssembly assembly, string resourceName)
-        {
-            return InvokeResolveEvent(_ResourceResolve, assembly, resourceName);
-        }
-
-        // This method is called by the VM
-        private RuntimeAssembly OnTypeResolveEvent(RuntimeAssembly assembly, string typeName)
-        {
-            return InvokeResolveEvent(_TypeResolve, assembly, typeName);
-        }
-
-        // This method is called by the VM.
-        private RuntimeAssembly OnAssemblyResolveEvent(RuntimeAssembly assembly, string assemblyFullName)
-        {
-            return InvokeResolveEvent(_AssemblyResolve, assembly, assemblyFullName);
-        }
-
-        private RuntimeAssembly InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, string name)
-        {
-            if (eventHandler == null)
-                return null;
-
-            var args = new ResolveEventArgs(name, assembly);
-
-            foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
-            {
-                Assembly asm = handler(this, args);
-                RuntimeAssembly ret = GetRuntimeAssembly(asm);
-                if (ret != null)
-                    return ret;
-            }
-
-            return null;
-        }
-
-#if FEATURE_COMINTEROP
-        // Called by VM - code:CLRPrivTypeCacheWinRT::RaiseDesignerNamespaceResolveEvent
-        private string[] OnDesignerNamespaceResolveEvent(string namespaceName)
-        {
-            return System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMetadata.OnDesignerNamespaceResolveEvent(this, namespaceName);
-        }
-#endif // FEATURE_COMINTEROP
-
-        private static RuntimeAssembly GetRuntimeAssembly(Assembly asm)
-        {
-            return
-                asm == null ? null :
-                asm is RuntimeAssembly rtAssembly ? rtAssembly :
-                asm is AssemblyBuilder ab ? ab.InternalAssembly :
-                null;
-        }
-
-        internal int GetId() => 1;
-    }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/AppDomainUnloadedException.cs b/src/coreclr/src/System.Private.CoreLib/src/System/AppDomainUnloadedException.cs
deleted file mode 100644 (file)
index 597a39c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*=============================================================================
-**
-** 
-**
-** Purpose: Exception class for attempt to access an unloaded AppDomain
-**
-**
-=============================================================================*/
-
-
-using System.Runtime.Serialization;
-
-namespace System
-{
-    [Serializable]
-    [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    internal class AppDomainUnloadedException : SystemException
-    {
-        public AppDomainUnloadedException()
-            : base(SR.Arg_AppDomainUnloadedException)
-        {
-            HResult = HResults.COR_E_APPDOMAINUNLOADED;
-        }
-
-        protected AppDomainUnloadedException(SerializationInfo info, StreamingContext context) : base(info, context)
-        {
-        }
-    }
-}
-
index d5e2878..b36266f 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     {
         private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve;
 
-        internal static string[] OnDesignerNamespaceResolveEvent(AppDomain appDomain, string namespaceName)
+        internal static string[] OnDesignerNamespaceResolve(string namespaceName)
         {
             EventHandler<DesignerNamespaceResolveEventArgs> eventHandler = DesignerNamespaceResolve;
             if (eventHandler != null)
@@ -28,7 +28,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 {
                     DesignerNamespaceResolveEventArgs eventArgs = new DesignerNamespaceResolveEventArgs(namespaceName);
 
-                    handler(appDomain, eventArgs);
+                    handler(null /* AppDomain */, eventArgs);
 
                     Collection<string> assemblyFilesCollection = eventArgs.ResolvedAssemblyFiles;
                     if (assemblyFilesCollection.Count > 0)
index e003ce2..7ec6cf4 100644 (file)
@@ -2,18 +2,12 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-
-using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Reflection;
 using System.IO;
-using System.Runtime.Versioning;
+using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
-using System.Security;
-using System.Threading;
-
 
 namespace System.Runtime.Loader
 {
@@ -47,12 +41,6 @@ namespace System.Runtime.Loader
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
         internal static extern void InternalStartProfile(string profile, IntPtr ptrNativeAssemblyLoadContext);
 
-        static AssemblyLoadContext()
-        {
-            // We register the cleanup of all AssemblyLoadContext that have not been finalized in the AppContext.Unloading
-            AppContext.Unloading += OnAppContextUnloading;
-        }
-
         protected AssemblyLoadContext() : this(false, false)
         {
         }
@@ -503,12 +491,7 @@ namespace System.Runtime.Loader
             InternalStartProfile(profile, m_pNativeAssemblyLoadContext);
         }
 
-        private void OnAppContextUnloading()
-        {
-            InitiateUnload();
-        }
-
-        private static void OnAppContextUnloading(object sender, EventArgs e)
+        internal static void OnProcessExit()
         {
             lock (ContextsToUnload)
             {
@@ -519,7 +502,7 @@ namespace System.Runtime.Loader
                     if (alcAlive.Value.TryGetTarget(out alc))
                     {
                         // Should we use a try/catch?
-                        alc.OnAppContextUnloading();
+                        alc.InitiateUnload();
                     }
                 }
                 ContextsToUnload.Clear();
@@ -541,32 +524,67 @@ namespace System.Runtime.Loader
         private static readonly object s_initLock = new object();
 
         // Occurs when an Assembly is loaded
-        public static event AssemblyLoadEventHandler AssemblyLoad
+        public static event AssemblyLoadEventHandler AssemblyLoad;
+
+        // Occurs when resolution of type fails
+        public static event ResolveEventHandler TypeResolve;
+
+        // Occurs when resolution of resource fails
+        public static event ResolveEventHandler ResourceResolve;
+
+        // Occurs when resolution of assembly fails
+        // This event is fired after resolve events of AssemblyLoadContext fails
+        public static event ResolveEventHandler AssemblyResolve;
+
+        // This method is called by the VM.
+        private static void OnAssemblyLoad(RuntimeAssembly assembly)
         {
-            add { AppDomain.CurrentDomain.AssemblyLoad += value; }
-            remove { AppDomain.CurrentDomain.AssemblyLoad -= value; }
+            AssemblyLoad?.Invoke(null /* AppDomain */, new AssemblyLoadEventArgs(assembly));
         }
 
-        // Occurs when resolution of type fails
-        public static event ResolveEventHandler TypeResolve
+        // This method is called by the VM.
+        private static RuntimeAssembly OnResourceResolve(RuntimeAssembly assembly, string resourceName)
         {
-            add { AppDomain.CurrentDomain.TypeResolve += value; }
-            remove { AppDomain.CurrentDomain.TypeResolve -= value; }
+            return InvokeResolveEvent(ResourceResolve, assembly, resourceName);
         }
 
-        // Occurs when resolution of resource fails
-        public static event ResolveEventHandler ResourceResolve
+        // This method is called by the VM
+        private static RuntimeAssembly OnTypeResolve(RuntimeAssembly assembly, string typeName)
         {
-            add { AppDomain.CurrentDomain.ResourceResolve += value; }
-            remove { AppDomain.CurrentDomain.ResourceResolve -= value; }
+            return InvokeResolveEvent(TypeResolve, assembly, typeName);
         }
 
-        // Occurs when resolution of assembly fails
-        // This event is fired after resolve events of AssemblyLoadContext fails
-        public static event ResolveEventHandler AssemblyResolve
+        // This method is called by the VM.
+        private static RuntimeAssembly OnAssemblyResolve(RuntimeAssembly assembly, string assemblyFullName)
+        {
+            return InvokeResolveEvent(AssemblyResolve, assembly, assemblyFullName);
+        }
+
+        private static RuntimeAssembly InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, string name)
+        {
+            if (eventHandler == null)
+                return null;
+
+            var args = new ResolveEventArgs(name, assembly);
+
+            foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
+            {
+                Assembly asm = handler(null /* AppDomain */, args);
+                RuntimeAssembly ret = GetRuntimeAssembly(asm);
+                if (ret != null)
+                    return ret;
+            }
+
+            return null;
+        }
+
+        private static RuntimeAssembly GetRuntimeAssembly(Assembly asm)
         {
-            add { AppDomain.CurrentDomain.AssemblyResolve += value; }
-            remove { AppDomain.CurrentDomain.AssemblyResolve -= value; }
+            return
+                asm == null ? null :
+                asm is RuntimeAssembly rtAssembly ? rtAssembly :
+                asm is System.Reflection.Emit.AssemblyBuilder ab ? ab.InternalAssembly :
+                null;
         }
 
         private enum InternalState
index 504ecce..da5ba85 100644 (file)
@@ -836,7 +836,7 @@ namespace System.Threading.Tasks
             // If unhandled error reporting APIs are available use those, otherwise since this 
             // would have executed on the thread pool otherwise, let it propagate there.
 
-            if (!(exc is ThreadAbortException || exc is AppDomainUnloadedException))
+            if (!(exc is ThreadAbortException))
             {
 #if FEATURE_COMINTEROP
                 if (!WindowsRuntimeMarshal.ReportUnhandledError(exc))
index 3046bd9..5f2ce58 100644 (file)
@@ -248,7 +248,7 @@ namespace System.Threading.Tasks
             for (int i = 0; i < exceptions.Count; i++)
             {
                 var t = exceptions[i].SourceException.GetType();
-                if (t != typeof(ThreadAbortException) && t != typeof(AppDomainUnloadedException))
+                if (t != typeof(ThreadAbortException))
                 {
                     MarkAsUnhandled();
                     break;
index 2c345c8..11d68a7 100644 (file)
@@ -466,33 +466,12 @@ namespace System.Threading
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
         private static extern void nativeInitCultureAccessors();
 
-        /*======================================================================
-        ** Returns the current domain in which current thread is running.
-        ======================================================================*/
-
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        private static extern AppDomain GetDomainInternal();
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        private static extern AppDomain GetFastDomainInternal();
-
-        internal static AppDomain GetDomain()
-        {
-
-            AppDomain ad;
-            ad = GetFastDomainInternal();
-            if (ad == null)
-                ad = GetDomainInternal();
-
-            return ad;
-        }
-
-
         /*
          *  This returns a unique id to identify an appdomain.
          */
         internal static int GetDomainID()
         {
-            return GetDomain().GetId();
+            return 1;
         }
 
 
index 8b03bc2..3e850f1 100644 (file)
@@ -3003,8 +3003,7 @@ bool SystemDomain::IsReflectionInvocationMethod(MethodDesc* pMeth)
         CLASS__LAZY_INITIALIZER,
         CLASS__DYNAMICMETHOD,
         CLASS__DELEGATE,
-        CLASS__MULTICAST_DELEGATE,
-        CLASS__APP_DOMAIN
+        CLASS__MULTICAST_DELEGATE
     };
 
     static const BinderClassID genericReflectionInvocationTypes[] = {
@@ -3029,8 +3028,6 @@ bool SystemDomain::IsReflectionInvocationMethod(MethodDesc* pMeth)
             genericReflectionInvocationTypeDefs[i] = MscorlibBinder::GetClass(genericReflectionInvocationTypes[i])->GetCl();
         }
 
-        MscorlibBinder::GetClass(CLASS__APP_DOMAIN);
-
         VolatileStore(&fInited, true);
     }
 
@@ -3596,8 +3593,6 @@ AppDomain::AppDomain()
 
     m_handleStore = NULL;
 
-    m_ExposedObject = NULL;
-
  #ifdef _DEBUG
     m_pThreadTrackInfoList = NULL;
     m_TrackSpinLock = 0;
@@ -3823,8 +3818,6 @@ void AppDomain::Init()
     SetStage(STAGE_READYFORMANAGEDCODE);
 
 #ifndef CROSSGEN_COMPILE
-    m_ExposedObject = CreateHandle(NULL);
-
     COUNTER_ONLY(GetPerfCounters().m_Loading.cAppDomains++);
 
 #ifdef FEATURE_TIERED_COMPILATION
@@ -4013,48 +4006,6 @@ void AppDomain::CloseDomain()
         Stop();
 }
 
-/*********************************************************************/
-
-struct GetExposedObject_Args
-{
-    AppDomain *pDomain;
-    OBJECTREF *ref;
-};
-
-OBJECTREF AppDomain::GetExposedObject()
-{
-    CONTRACTL
-    {
-        MODE_COOPERATIVE;
-        THROWS;
-        GC_TRIGGERS;
-        INJECT_FAULT(COMPlusThrowOM(););
-    }
-    CONTRACTL_END;
-
-    OBJECTREF ref = GetRawExposedObject();
-    if (ref == NULL)
-    {
-        APPDOMAINREF obj = NULL;
-
-        MethodTable *pMT = MscorlibBinder::GetClass(CLASS__APP_DOMAIN);
-
-        // Create the module object
-        obj = (APPDOMAINREF) AllocateObject(pMT);
-        obj->SetDomain(this);
-
-        if (!StoreFirstObjectInHandle(m_ExposedObject, (OBJECTREF) obj))
-        {
-            obj = (APPDOMAINREF) GetRawExposedObject();
-            _ASSERTE(obj);
-        }
-
-        return (OBJECTREF) obj;
-    }
-
-    return ref;
-}
-
 #endif // !CROSSGEN_COMPILE
 
 #ifdef FEATURE_COMINTEROP
@@ -5039,10 +4990,6 @@ DomainFile *AppDomain::LoadDomainFile(FileLoadLock *pLock, FileLoadLevel targetL
     }
     CONTRACT_END;
 
-
-    if(!CanLoadCode())
-        COMPlusThrow(kAppDomainUnloadedException);
-
     // Thread stress
     APIThreadStress::SyncThreadStress();
 
@@ -6522,36 +6469,37 @@ void AppDomain::RaiseLoadingAssemblyEvent(DomainAssembly *pAssembly)
     }
     CONTRACTL_END;
 
+    if (pAssembly->GetFile()->IsSystem())
+    {
+        return;
+    }
+
     GCX_COOP();
     FAULT_NOT_FATAL();
     OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
 
     EX_TRY
     {
-        struct _gc {
-            APPDOMAINREF AppDomainRef;
-            OBJECTREF    orThis;
-        } gc;
-        ZeroMemory(&gc, sizeof(gc));
+        if (MscorlibBinder::GetField(FIELD__ASSEMBLYLOADCONTEXT__ASSEMBLY_LOAD)->GetStaticOBJECTREF() != NULL)
+        {
+            struct _gc {
+                OBJECTREF    orThis;
+            } gc;
+            ZeroMemory(&gc, sizeof(gc));
 
-        if ((gc.AppDomainRef = (APPDOMAINREF) GetRawExposedObject()) != NULL) {
-            if (gc.AppDomainRef->m_pAssemblyEventHandler != NULL)
-            {
-                ARG_SLOT args[2];
-                GCPROTECT_BEGIN(gc);
+            ARG_SLOT args[1];
+            GCPROTECT_BEGIN(gc);
 
-                gc.orThis = pAssembly->GetExposedAssemblyObject();
+            gc.orThis = pAssembly->GetExposedAssemblyObject();
 
-                MethodDescCallSite  onAssemblyLoad(METHOD__APP_DOMAIN__ON_ASSEMBLY_LOAD, &gc.orThis);
+            MethodDescCallSite onAssemblyLoad(METHOD__ASSEMBLYLOADCONTEXT__ON_ASSEMBLY_LOAD);
 
-                // GetExposedAssemblyObject may cause a gc, so call this before filling args[0]
-                args[1] = ObjToArgSlot(gc.orThis);
-                args[0] = ObjToArgSlot(gc.AppDomainRef);
+            // GetExposedAssemblyObject may cause a gc, so call this before filling args[0]
+            args[0] = ObjToArgSlot(gc.orThis);
 
-                onAssemblyLoad.Call(args);
+            onAssemblyLoad.Call(args);
 
-                GCPROTECT_END();
-            }
+            GCPROTECT_END();
         }
     }
     EX_CATCH
@@ -6560,97 +6508,26 @@ void AppDomain::RaiseLoadingAssemblyEvent(DomainAssembly *pAssembly)
     EX_END_CATCH(SwallowAllExceptions);
 }
 
-
 BOOL AppDomain::OnUnhandledException(OBJECTREF *pThrowable, BOOL isTerminating/*=TRUE*/) 
 {
     STATIC_CONTRACT_NOTHROW;
     STATIC_CONTRACT_GC_TRIGGERS;
     STATIC_CONTRACT_MODE_ANY;
 
-    BOOL retVal= FALSE;
+    BOOL retVal = FALSE;
 
     GCX_COOP();
 
-    // The Everett behavior was to send the unhandled exception event only to the Default
-    // AppDomain (since that's the only place that exceptions actually went unhandled).
-    //
-    // During Whidbey development, we broadcast the event to all AppDomains in the process.
-    //
-    // But the official shipping Whidbey behavior is that the unhandled exception event is
-    // sent to the Default AppDomain and to whatever AppDomain the exception went unhandled
-    // in.  To achieve this, we declare the exception to be unhandled *BEFORE* we marshal
-    // it back to the Default AppDomain at the base of the Finalizer, threadpool and managed
-    // threads.
-    //
-    // The rationale for sending the event to the Default AppDomain as well as the one the
-    // exception went unhandled in is:
-    //
-    // 1)  This is compatible with the pre-Whidbey behavior, where only the Default AppDomain
-    //     received the notification.
-    //
-    // 2)  This is convenient for hosts, which don't want to bother injecting listeners into
-    //     every single AppDomain.
-
-    AppDomain *pAppDomain = GetAppDomain();
-    OBJECTREF orSender = 0;
-
-    GCPROTECT_BEGIN(orSender);
-
-    orSender = pAppDomain->GetRawExposedObject();
-
-    retVal = pAppDomain->RaiseUnhandledExceptionEventNoThrow(&orSender, pThrowable, isTerminating);
-
-    GCPROTECT_END();
-
-    return retVal;
-}
-
-
-// Move outside of the AppDomain iteration, to avoid issues with the GC Frames being outside
-// the domain transition.  This is a chronic issue that causes us to report roots for an AppDomain
-// after we have left it.  This causes problems with AppDomain unloading that we only find
-// with stress coverage..
-void AppDomain::RaiseOneExitProcessEvent()
-{
-    CONTRACTL
+    EX_TRY
     {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_COOPERATIVE;
+        retVal = GetAppDomain()->RaiseUnhandledExceptionEvent(pThrowable, isTerminating);
     }
-    CONTRACTL_END;
-
-    struct _gc
-    {
-        APPDOMAINREF Domain;
-        OBJECTREF    Delegate;
-    } gc;
-    ZeroMemory(&gc, sizeof(gc));
-
-    GCPROTECT_BEGIN(gc);
-    gc.Domain = (APPDOMAINREF) SystemDomain::GetCurrentDomain()->GetRawExposedObject();
-    if (gc.Domain != NULL)
+    EX_CATCH
     {
-        gc.Delegate = gc.Domain->m_pProcessExitEventHandler;
-        if (gc.Delegate != NULL)
-            DistributeEvent(&gc.Delegate, (OBJECTREF *) &gc.Domain);
     }
-    GCPROTECT_END();
-}
-
-// Local wrapper used in AppDomain::RaiseExitProcessEvent,
-// introduced solely to avoid stack overflow because of _alloca in the loop.
-// It's just factored out body of the loop, but it has to be a member method of AppDomain,
-// because it calls private RaiseOneExitProcessEvent
-/*static*/ void AppDomain::RaiseOneExitProcessEvent_Wrapper(AppDomainIterator* pi)
-{
-    STATIC_CONTRACT_MODE_COOPERATIVE;
-    STATIC_CONTRACT_THROWS;
-    STATIC_CONTRACT_GC_TRIGGERS;
+    EX_END_CATCH(SwallowAllExceptions)  // Swallow any errors.
 
-    ENTER_DOMAIN_PTR(pi->GetDomain(), ADV_ITERATOR)
-    AppDomain::RaiseOneExitProcessEvent();
-    END_DOMAIN_TRANSITION;
+    return retVal;
 }
 
 static LONG s_ProcessedExitProcessEventCount = 0;
@@ -6675,58 +6552,12 @@ void AppDomain::RaiseExitProcessEvent()
 
     _ASSERTE (GetThread()->PreemptiveGCDisabled());
 
-    _ASSERTE (GetThread()->GetDomain()->IsDefaultDomain());
-
-    AppDomainIterator i(TRUE);
-    while (i.Next())
-    {
-        RaiseOneExitProcessEvent_Wrapper(&i);
-        FastInterlockIncrement(&s_ProcessedExitProcessEventCount);
-    }
-}
-
-
-BOOL
-AppDomain::RaiseUnhandledExceptionEventNoThrow(OBJECTREF *pSender, OBJECTREF *pThrowable, BOOL isTerminating)
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_TRIGGERS;
-        MODE_COOPERATIVE;
-    }
-    CONTRACTL_END;
-    BOOL bRetVal=FALSE;
-
-    EX_TRY
-    {
-        bRetVal = RaiseUnhandledExceptionEvent(pSender, pThrowable, isTerminating);
-    }
-    EX_CATCH
-    {
-    }
-    EX_END_CATCH(SwallowAllExceptions)  // Swallow any errors.
-    return bRetVal;
-
+    MethodDescCallSite onProcessExit(METHOD__APPCONTEXT__ON_PROCESS_EXIT);
+    onProcessExit.Call(NULL);
 }
 
 BOOL
-AppDomain::HasUnhandledExceptionEventHandler()
-{
-    CONTRACTL
-    {
-        MODE_COOPERATIVE;
-        GC_NOTRIGGER; //essential
-        NOTHROW;
-    }
-    CONTRACTL_END;
-    if (GetRawExposedObject()==NULL)
-        return FALSE;
-    return (((APPDOMAINREF)GetRawExposedObject())->m_pUnhandledExceptionEventHandler!=NULL);
-}
-
-BOOL
-AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pSender, OBJECTREF *pThrowable, BOOL isTerminating)
+AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pThrowable, BOOL isTerminating)
 {
     CONTRACTL
     {
@@ -6737,34 +6568,28 @@ AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pSender, OBJECTREF *pThrowabl
     }
     CONTRACTL_END;
 
-    if (!HasUnhandledExceptionEventHandler())
-        return FALSE;
-
-    BOOL result = FALSE;
-
     _ASSERTE(pThrowable != NULL && IsProtectedByGCFrame(pThrowable));
-    _ASSERTE(pSender    != NULL && IsProtectedByGCFrame(pSender));
 
     _ASSERTE(this == GetThread()->GetDomain());
 
+    OBJECTREF orDelegate = MscorlibBinder::GetField(FIELD__APPCONTEXT__UNHANDLED_EXCEPTION)->GetStaticOBJECTREF();
+    if (orDelegate == NULL)
+        return FALSE;
 
-    OBJECTREF orDelegate = NULL;
-
-    GCPROTECT_BEGIN(orDelegate);
-
-    APPDOMAINREF orAD = (APPDOMAINREF) GetAppDomain()->GetRawExposedObject();
+    struct _gc {
+        OBJECTREF Delegate;
+        OBJECTREF Sender;
+    } gc;
+    ZeroMemory(&gc, sizeof(gc));
 
-    if (orAD != NULL)
+    GCPROTECT_BEGIN(gc);
+    gc.Delegate = orDelegate;
+    if (orDelegate != NULL)
     {
-        orDelegate = orAD->m_pUnhandledExceptionEventHandler;
-        if (orDelegate != NULL)
-        {
-            result = TRUE;
-            DistributeUnhandledExceptionReliably(&orDelegate, pSender, pThrowable, isTerminating);
-        }
+        DistributeUnhandledExceptionReliably(&gc.Delegate, &gc.Sender, pThrowable, isTerminating);
     }
     GCPROTECT_END();
-    return result;
+    return TRUE;
 }
 
 #endif // CROSSGEN_COMPILE
@@ -7686,48 +7511,43 @@ DomainAssembly* AppDomain::RaiseTypeResolveEventThrowing(DomainAssembly* pAssemb
 
     OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
 
-
     DomainAssembly* pResolvedAssembly = NULL;
     _ASSERTE(strcmp(szName, g_AppDomainClassName));
 
     GCX_COOP();
 
     struct _gc {
-        OBJECTREF AppDomainRef;
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
     ZeroMemory(&gc, sizeof(gc));
 
     GCPROTECT_BEGIN(gc);
-    if ((gc.AppDomainRef = GetRawExposedObject()) != NULL)
-    {
-        if (pAssembly != NULL)
-            gc.AssemblyRef = pAssembly->GetExposedAssemblyObject();
 
-        MethodDescCallSite onTypeResolve(METHOD__APP_DOMAIN__ON_TYPE_RESOLVE, &gc.AppDomainRef);
+    if (pAssembly != NULL)
+        gc.AssemblyRef = pAssembly->GetExposedAssemblyObject();
 
-        gc.str = StringObject::NewString(szName);
-        ARG_SLOT args[3] =
-        {
-            ObjToArgSlot(gc.AppDomainRef),
-            ObjToArgSlot(gc.AssemblyRef),
-            ObjToArgSlot(gc.str)
-        };
-        ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onTypeResolve.Call_RetOBJECTREF(args);
+    MethodDescCallSite onTypeResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_TYPE_RESOLVE);
 
-        if (ResultingAssemblyRef != NULL)
-        {
-            pResolvedAssembly = ResultingAssemblyRef->GetDomainAssembly();
+    gc.str = StringObject::NewString(szName);
+    ARG_SLOT args[2] =
+    {
+        ObjToArgSlot(gc.AssemblyRef),
+        ObjToArgSlot(gc.str)
+    };
+    ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onTypeResolve.Call_RetOBJECTREF(args);
 
-            if (pResultingAssemblyRef)
-                *pResultingAssemblyRef = ResultingAssemblyRef;
-            else
+    if (ResultingAssemblyRef != NULL)
+    {
+        pResolvedAssembly = ResultingAssemblyRef->GetDomainAssembly();
+
+        if (pResultingAssemblyRef)
+            *pResultingAssemblyRef = ResultingAssemblyRef;
+        else
+        {
+            if (pResolvedAssembly->IsCollectible())
             {
-                if (pResolvedAssembly->IsCollectible())
-                {
-                    COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleBoundNonCollectible"));
-                }
+                COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleBoundNonCollectible"));
             }
         }
     }
@@ -7754,34 +7574,30 @@ Assembly* AppDomain::RaiseResourceResolveEvent(DomainAssembly* pAssembly, LPCSTR
     GCX_COOP();
 
     struct _gc {
-        OBJECTREF AppDomainRef;
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
     ZeroMemory(&gc, sizeof(gc));
 
     GCPROTECT_BEGIN(gc);
-    if ((gc.AppDomainRef = GetRawExposedObject()) != NULL)
-    {
-        if (pAssembly != NULL)
-            gc.AssemblyRef=pAssembly->GetExposedAssemblyObject();
 
-        MethodDescCallSite onResourceResolve(METHOD__APP_DOMAIN__ON_RESOURCE_RESOLVE, &gc.AppDomainRef);
-        gc.str = StringObject::NewString(szName);
-        ARG_SLOT args[3] =
-        {
-            ObjToArgSlot(gc.AppDomainRef),
-            ObjToArgSlot(gc.AssemblyRef),
-            ObjToArgSlot(gc.str)
-        };
-        ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onResourceResolve.Call_RetOBJECTREF(args);
-        if (ResultingAssemblyRef != NULL)
+    if (pAssembly != NULL)
+        gc.AssemblyRef=pAssembly->GetExposedAssemblyObject();
+
+    MethodDescCallSite onResourceResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_RESOURCE_RESOLVE);
+    gc.str = StringObject::NewString(szName);
+    ARG_SLOT args[2] =
+    {
+        ObjToArgSlot(gc.AssemblyRef),
+        ObjToArgSlot(gc.str)
+    };
+    ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onResourceResolve.Call_RetOBJECTREF(args);
+    if (ResultingAssemblyRef != NULL)
+    {
+        pResolvedAssembly = ResultingAssemblyRef->GetAssembly();
+        if (pResolvedAssembly->IsCollectible())
         {
-            pResolvedAssembly = ResultingAssemblyRef->GetAssembly();
-            if (pResolvedAssembly->IsCollectible())
-            {
-                COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleAssemblyResolve"));
-            }
+            COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleAssemblyResolve"));
         }
     }
     GCPROTECT_END();
@@ -7819,25 +7635,22 @@ AppDomain::RaiseAssemblyResolveEvent(
     Assembly* pAssembly = NULL;
 
     struct _gc {
-        OBJECTREF AppDomainRef;
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
     ZeroMemory(&gc, sizeof(gc));
 
     GCPROTECT_BEGIN(gc);
-    if ((gc.AppDomainRef = GetRawExposedObject()) != NULL)
     {
         if (pSpec->GetParentAssembly() != NULL)
         {
             gc.AssemblyRef=pSpec->GetParentAssembly()->GetExposedAssemblyObject();
         }
 
-        MethodDescCallSite onAssemblyResolve(METHOD__APP_DOMAIN__ON_ASSEMBLY_RESOLVE, &gc.AppDomainRef);
+        MethodDescCallSite onAssemblyResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_ASSEMBLY_RESOLVE);
 
         gc.str = StringObject::NewString(ssName);
-        ARG_SLOT args[3] = {
-            ObjToArgSlot(gc.AppDomainRef),
+        ARG_SLOT args[2] = {
             ObjToArgSlot(gc.AssemblyRef),
             ObjToArgSlot(gc.str)
         };
index 06941f9..0aeab8f 100644 (file)
@@ -1856,25 +1856,8 @@ public:
     virtual BOOL IsAppDomain() { LIMITED_METHOD_DAC_CONTRACT; return TRUE; }
     virtual PTR_AppDomain AsAppDomain() { LIMITED_METHOD_CONTRACT; return dac_cast<PTR_AppDomain>(this); }
 
-    OBJECTREF GetExposedObject();
-    OBJECTREF GetRawExposedObject() {
-        CONTRACTL
-        {
-            NOTHROW;
-            GC_NOTRIGGER;
-            SO_TOLERANT;
-            MODE_COOPERATIVE;
-        }
-        CONTRACTL_END;
-        if (m_ExposedObject) {
-            return ObjectFromHandle(m_ExposedObject);
-        }
-        else {
-            return NULL;
-        }
-    }
-
-    OBJECTHANDLE GetRawExposedObjectHandleForDebugger() { LIMITED_METHOD_DAC_CONTRACT; return m_ExposedObject; }
+    OBJECTREF GetRawExposedObject() { LIMITED_METHOD_CONTRACT; return NULL; }
+    OBJECTHANDLE GetRawExposedObjectHandleForDebugger() { LIMITED_METHOD_DAC_CONTRACT; return NULL; }
 
 #ifdef FEATURE_COMINTEROP
     MethodTable *GetRedirectedType(WinMDAdapter::RedirectedTypeIndex index);
@@ -2610,12 +2593,6 @@ public:
         return m_dwThreadEnterCount==1 || m_dwThreadsStillInAppDomain ==1;
     }
 
-    BOOL CanLoadCode()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return m_Stage >= STAGE_READYFORMANAGEDCODE;
-    }
-
     static void RefTakerAcquire(AppDomain* pDomain)
     {
         WRAPPER_NO_CONTRACT;
@@ -2891,8 +2868,6 @@ public:
 #endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING
 
 private:
-    static void RaiseOneExitProcessEvent_Wrapper(AppDomainIterator* pi);
-    static void RaiseOneExitProcessEvent();
     size_t EstimateSize();
     EEClassFactoryInfoHashTable* SetupClassFactHash();
 #ifdef FEATURE_COMINTEROP
@@ -2919,21 +2894,7 @@ private:
     friend class DomainAssembly;
 
 private:
-
-    BOOL RaiseUnhandledExceptionEvent(OBJECTREF *pSender, OBJECTREF *pThrowable, BOOL isTerminating);
-    BOOL HasUnhandledExceptionEventHandler();
-    BOOL RaiseUnhandledExceptionEventNoThrow(OBJECTREF *pSender, OBJECTREF *pThrowable, BOOL isTerminating);
-    
-    struct RaiseUnhandled_Args
-    {
-        AppDomain *pExceptionDomain;
-        AppDomain *pTargetDomain;
-        OBJECTREF *pSender;
-        OBJECTREF *pThrowable;
-        BOOL isTerminating;
-        BOOL *pResult;
-    };
-
+    BOOL RaiseUnhandledExceptionEvent(OBJECTREF *pThrowable, BOOL isTerminating);
 
     enum Stage {
         STAGE_CREATING,
@@ -3037,8 +2998,6 @@ private:
     // by one. For it to hit zero an explicit close must have happened.
     LONG        m_cRef;                    // Ref count.
 
-    OBJECTHANDLE    m_ExposedObject;
-
     // Hash table that maps a clsid to a type
     PtrHashMap          m_clsidHash;
 
index 3125392..799cb23 100644 (file)
@@ -173,43 +173,36 @@ CLRPrivTypeCacheWinRT::RaiseDesignerNamespaceResolveEvent(
     CLRPrivBinderUtil::WStringListHolder * pFileNameList)
 {
     STANDARD_VM_CONTRACT;
-    
+
     _ASSERTE(pFileNameList != nullptr);
-    
-    AppDomain * pAppDomain = AppDomain::GetCurrentDomain();
-    
+
     GCX_COOP();
     
     struct _gc {
-        OBJECTREF AppDomainRef;
         STRINGREF str;
     } gc;
     ZeroMemory(&gc, sizeof(gc));
     
     GCPROTECT_BEGIN(gc);
-    if ((gc.AppDomainRef = pAppDomain->GetRawExposedObject()) != NULL)
+    MethodDescCallSite onNamespaceResolve(METHOD__WINDOWSRUNTIMEMETATADA__ON_DESIGNER_NAMESPACE_RESOLVE);
+    gc.str = StringObject::NewString(wszNamespace);
+    ARG_SLOT args[1] =
     {
-        MethodDescCallSite onNamespaceResolve(METHOD__APP_DOMAIN__ON_DESIGNER_NAMESPACE_RESOLVE, &gc.AppDomainRef);
-        gc.str = StringObject::NewString(wszNamespace);
-        ARG_SLOT args[2] =
-        {
-            ObjToArgSlot(gc.AppDomainRef),
-            ObjToArgSlot(gc.str)
-        };
-        PTRARRAYREF ResultingFileNameArrayRef = (PTRARRAYREF) onNamespaceResolve.Call_RetOBJECTREF(args);
-        if (ResultingFileNameArrayRef != NULL)
+        ObjToArgSlot(gc.str)
+    };
+    PTRARRAYREF ResultingFileNameArrayRef = (PTRARRAYREF) onNamespaceResolve.Call_RetOBJECTREF(args);
+    if (ResultingFileNameArrayRef != NULL)
+    {
+        for (DWORD i = 0; i < ResultingFileNameArrayRef->GetNumComponents(); i++)
         {
-            for (DWORD i = 0; i < ResultingFileNameArrayRef->GetNumComponents(); i++)
-            {
-                STRINGREF ResultingFileNameRef = (STRINGREF) ResultingFileNameArrayRef->GetAt(i);
-                _ASSERTE(ResultingFileNameRef != NULL); // Verified in the managed code OnDesignerNamespaceResolveEvent
+            STRINGREF ResultingFileNameRef = (STRINGREF) ResultingFileNameArrayRef->GetAt(i);
+            _ASSERTE(ResultingFileNameRef != NULL); // Verified in the managed code OnDesignerNamespaceResolveEvent
                 
-                SString sFileName;
-                ResultingFileNameRef->GetSString(sFileName);
-                _ASSERTE(!sFileName.IsEmpty()); // Verified in the managed code OnDesignerNamespaceResolveEvent
+            SString sFileName;
+            ResultingFileNameRef->GetSString(sFileName);
+            _ASSERTE(!sFileName.IsEmpty()); // Verified in the managed code OnDesignerNamespaceResolveEvent
                 
-                pFileNameList->InsertTail(sFileName.GetUnicode());
-            }
+            pFileNameList->InsertTail(sFileName.GetUnicode());
         }
     }
     GCPROTECT_END();
index 24c1213..8ceab3e 100644 (file)
@@ -3581,103 +3581,6 @@ static void InvokeUnhandledSwallowing(OBJECTREF *pDelegate,
     EX_END_CATCH(SwallowAllExceptions)
 }
 
-
-// Helper to dispatch a single event notification.
-static void InvokeNotify(OBJECTREF *pDelegate, OBJECTREF *pDomain)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_COOPERATIVE;
-    }
-    CONTRACTL_END;
-
-    _ASSERTE(pDelegate  != NULL && IsProtectedByGCFrame(pDelegate));
-    _ASSERTE(pDomain    != NULL && IsProtectedByGCFrame(pDomain));
-
-    STRESS_LOG2(LF_GC, LL_INFO1000, "Distributing reliable event: MethodPtr=%p MethodPtrAux=%p\n",
-        DELEGATEREF(*pDelegate)->GetMethodPtr(),
-        DELEGATEREF(*pDelegate)->GetMethodPtrAux());
-
-    // All reliable events should be delivered on finalizer thread
-    _ASSERTE(IsFinalizerThread());
-
-    INDEBUG(Thread* pThread = GetThread());
-
-    // This is an early check for condition that we assert in Thread::InternalReset called from DoOneFinalization later.
-    _ASSERTE(!pThread->HasCriticalRegion());
-    _ASSERTE(!pThread->HasThreadAffinity());
-
-    PREPARE_NONVIRTUAL_CALLSITE_USING_CODE(DELEGATEREF(*pDelegate)->GetMethodPtr());
-
-    DECLARE_ARGHOLDER_ARRAY(args, 3);
-
-    args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(DELEGATEREF(*pDelegate)->GetTarget());
-    args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(*pDomain);
-    args[ARGNUM_2] = NULL;
-
-    CALL_MANAGED_METHOD_NORET(args);
-
-    // This is an early check for condition that we assert in Thread::InternalReset called from DoOneFinalization later.
-    _ASSERTE(!pThread->HasCriticalRegion());
-    _ASSERTE(!pThread->HasThreadAffinity());
-}
-
-
-void DistributeEvent(OBJECTREF *pDelegate, OBJECTREF *pDomain)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_COOPERATIVE;
-    }
-    CONTRACTL_END;
-
-    _ASSERTE(pDelegate  != NULL && IsProtectedByGCFrame(pDelegate));
-    _ASSERTE(pDomain    != NULL && IsProtectedByGCFrame(pDomain));
-
-    Thread *pThread = GetThread();
-
-    struct _gc
-    {
-        PTRARRAYREF Array;
-        OBJECTREF   InnerDelegate;
-    } gc;
-    ZeroMemory(&gc, sizeof(gc));
-
-    GCPROTECT_BEGIN(gc);
-
-    gc.Array = (PTRARRAYREF) ((DELEGATEREF)(*pDelegate))->GetInvocationList();
-    if (gc.Array == NULL || !gc.Array->GetMethodTable()->IsArray())
-    {
-        InvokeNotify(pDelegate, pDomain);
-    }
-    else
-    {
-        // The _invocationCount could be less than the array size, if we are sharing
-        // immutable arrays cleverly.
-        INT_PTR invocationCount = ((DELEGATEREF)(*pDelegate))->GetInvocationCount();
-            
-        _ASSERTE(FitsInU4(invocationCount));
-        DWORD cnt = static_cast<DWORD>(invocationCount);
-
-        _ASSERTE(cnt <= gc.Array->GetNumComponents());
-
-        for (DWORD i=0; i<cnt; i++)
-        {
-            gc.InnerDelegate = gc.Array->m_Array[i];
-            InvokeNotify(&gc.InnerDelegate, pDomain);
-            if (pThread->IsAbortRequested())
-            {
-                pThread->UnmarkThreadForAbort(Thread::TAR_Thread);
-            }
-        }
-    }
-    GCPROTECT_END();
-}
-
 // The unhandled exception event is a little easier to distribute, because
 // we simply swallow any failures and proceed to the next event sink.
 void DistributeUnhandledExceptionReliably(OBJECTREF *pDelegate,
index e7ed1f0..e99837c 100644 (file)
@@ -1464,74 +1464,6 @@ FCIMPL1(void, ThreadNative::DisableComObjectEagerCleanup, ThreadBaseObject* pThi
 FCIMPLEND
 #endif //FEATURE_COMINTEROP
 
-
-FCIMPL0(Object*, ThreadNative::GetDomain)
-{
-    FCALL_CONTRACT;
-
-    APPDOMAINREF refRetVal = NULL;
-
-    Thread* thread = GetThread();
-
-    if ((thread) && (thread->GetDomain()))
-    {
-        HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
-        refRetVal = (APPDOMAINREF) thread->GetDomain()->GetExposedObject();
-        HELPER_METHOD_FRAME_END();
-    }
-
-    return OBJECTREFToObject(refRetVal);
-}
-FCIMPLEND
-
-#if defined(_TARGET_X86_) && defined(_MSC_VER)
-__declspec(naked) LPVOID __fastcall ThreadNative::FastGetDomain()
-{
-    STATIC_CONTRACT_MODE_COOPERATIVE;
-    STATIC_CONTRACT_GC_NOTRIGGER;
-    STATIC_CONTRACT_NOTHROW;
-    STATIC_CONTRACT_SO_TOLERANT;
-
-    __asm {
-        call GetAppDomain
-        test eax, eax
-        je done
-        mov eax, dword ptr [eax]AppDomain.m_ExposedObject
-        test eax, eax
-        je done
-        mov eax, dword ptr [eax]
-done:
-        ret
-    }
-}
-#else // _TARGET_X86_ && _MSC_VER
-LPVOID F_CALL_CONV ThreadNative::FastGetDomain()
-{
-    CONTRACTL
-    {
-        GC_NOTRIGGER;
-        NOTHROW;
-        MODE_COOPERATIVE;
-        SO_TOLERANT;
-    }
-    CONTRACTL_END;
-
-    AppDomain *pDomain;
-    OBJECTHANDLE ExposedObject;
-
-    pDomain = GetAppDomain();
-    if (!pDomain) {
-        return NULL;
-    }
-    ExposedObject = pDomain->m_ExposedObject;
-    if (ExposedObject) {
-        return *(LPVOID *)ExposedObject;
-    }
-    return NULL;
-}
-#endif // _TARGET_X86_ && _MSC_VER
-
-
 //
 // nativeGetSafeCulture is used when the culture get requested from the thread object. 
 // we have to check the culture in the FCALL because in FCALL the thread cannot be 
index 79c0bee..a770fba 100644 (file)
@@ -61,9 +61,6 @@ public:
         ApartmentUnknown = 2
     };
 
-    static LPVOID F_CALL_CONV FastGetCurrentThread();
-    static LPVOID F_CALL_CONV FastGetDomain();
-
     static void StartInner(ThreadBaseObject* pThisUNSAFE);
 
     static FCDECL1(void, Abort, ThreadBaseObject* pThis);
@@ -87,7 +84,6 @@ public:
     static FCDECL3(INT32,   SetApartmentState, ThreadBaseObject* pThisUNSAFE, INT32 iState, CLR_BOOL fireMDAOnMismatch);
     static FCDECL1(void,    StartupSetApartmentState, ThreadBaseObject* pThis);
 #endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
-    static FCDECL0(Object*, GetDomain);
     static void QCALLTYPE nativeInitCultureAccessors();
 
     static
index 4f7d532..1380c1f 100644 (file)
@@ -276,11 +276,6 @@ void CrawlFrame::GetExactGenericInstantiations(Instantiation *pClassInst, Instan
     UNREACHABLE();
 }
 
-OBJECTREF AppDomain::GetExposedObject()
-{
-    UNREACHABLE();
-}
-
 BOOL Object::SupportsInterface(OBJECTREF pObj, MethodTable* pInterfaceMT)
 {
     UNREACHABLE();
index 2db7b70..492bd95 100644 (file)
@@ -682,8 +682,6 @@ FCFuncStart(gThreadFuncs)
     FCFuncElement("SleepInternal", ThreadNative::Sleep)
 #define Sleep(a) Dont_Use_Sleep(a)
     FCFuncElement("SetStart", ThreadNative::SetStart)
-    FCFuncElement("GetDomainInternal", ThreadNative::GetDomain)
-    FCFuncElement("GetFastDomainInternal", ThreadNative::FastGetDomain)
     QCFuncElement("InformThreadNameChange", ThreadNative::InformThreadNameChange)
     FCFuncElement("SpinWaitInternal", ThreadNative::SpinWait)
     QCFuncElement("YieldInternal", ThreadNative::YieldThread)
index cbb6be4..75e962c 100644 (file)
@@ -4486,8 +4486,7 @@ bool ExceptionIsAlwaysSwallowed(EXCEPTION_POINTERS *pExceptionInfo)
                 throwable = pThread->LastThrownObject();
             }
             //@todo: could throwable be NULL here?
-            isSwallowed = IsExceptionOfType(kThreadAbortException, &throwable) ||
-                          IsExceptionOfType(kAppDomainUnloadedException, &throwable);
+            isSwallowed = IsExceptionOfType(kThreadAbortException, &throwable);
         }
     }
 
@@ -5624,12 +5623,6 @@ DefaultCatchHandler(PEXCEPTION_POINTERS pExceptionPointers,
                     dump = FALSE;
                     INDEBUG(suppressSelectiveBreak=TRUE);
                 }
-                else if (isThreadBaseFilter && IsExceptionOfType(kAppDomainUnloadedException, &throwable))
-                {
-                    // AppdomainUnloadedException is also a special case.
-                    dump = FALSE;
-                    INDEBUG(suppressSelectiveBreak=TRUE);
-                }
 
                 // Finally, should we print the message?
                 if (dump)
@@ -12234,30 +12227,18 @@ BOOL ExceptionNotifications::CanDeliverNotificationToCurrentAppDomain(ExceptionN
 {
     CONTRACTL
     {
-        NOTHROW;
-        GC_NOTRIGGER;
+        THROWS;
+        GC_TRIGGERS;
         MODE_COOPERATIVE;
-        SO_TOLERANT;
         PRECONDITION(GetThread() != NULL);
         PRECONDITION(notificationType  != UnhandledExceptionHandler);
     }
     CONTRACTL_END;
 
-    Thread *pCurThread = GetThread();
-
-    // Get the current AppDomain
-    OBJECTREF oCurAppDomain = pCurThread->GetDomain()->GetRawExposedObject();
-    if (oCurAppDomain == NULL)
-    {
-        // Managed object for the current domain does not exist. Hence, no one
-        // can wireup to exception notifications, let alone receive them.
-        return FALSE;
-    }
-
     // Do we have handler(s) of the specific type wired up?
     if (notificationType == FirstChanceExceptionHandler)
     {
-        return (((APPDOMAINREF)oCurAppDomain)->GetFirstChanceExceptionNotificationHandler() != NULL);
+        return MscorlibBinder::GetField(FIELD__APPCONTEXT__FIRST_CHANCE_EXCEPTION)->GetStaticOBJECTREF() != NULL;
     }
     else
     {
@@ -12372,12 +12353,11 @@ void ExceptionNotifications::DeliverNotificationInternal(ExceptionNotificationHa
     // Save the reference to the current AppDomain. If the user code has
     // wired upto this event, then the managed AppDomain object will exist.
     gc.oCurAppDomain = pCurDomain->GetRawExposedObject();
-    _ASSERTE(gc.oCurAppDomain);
 
     // Get the reference to the delegate based upon the type of notification
     if (notificationType == FirstChanceExceptionHandler)
     {
-        gc.oNotificationDelegate = ((APPDOMAINREF)gc.oCurAppDomain)->GetFirstChanceExceptionNotificationHandler();
+        gc.oNotificationDelegate = MscorlibBinder::GetField(FIELD__APPCONTEXT__FIRST_CHANCE_EXCEPTION)->GetStaticOBJECTREF();
     }
     else
     {
index f78f9c3..869084c 100644 (file)
@@ -6119,8 +6119,8 @@ void ExceptionTracker::StackRange::CombineWith(StackFrame sfCurrent, StackRange*
         // the frame where the nesting first occurs and that will ensure that the stack range of the new
         // nested exception is extended to contain the scan range of the previous tracker's scan.  However,
         // if the exception dispatch calls a C++ handler (e.g. a finally) and then that handler tries to 
-        // reverse-pinvoke into the runtime, AND we trigger an exception (e.g. ThreadAboard, 
-        // AppDomainUnloaded) before we reach another managed frame (which would have the CLR personality
+        // reverse-pinvoke into the runtime, AND we trigger an exception (e.g. ThreadAbort) 
+        // before we reach another managed frame (which would have the CLR personality
         // routine associated with it), the first callback to ProcessCLRException for this new exception
         // will occur on a frame that has never been seen before by the current tracker.
         //
index cacc09a..7614ddd 100644 (file)
@@ -2451,111 +2451,6 @@ void QCALLTYPE MarshalNative::GetInspectableIIDs(
     END_QCALL;
 }
 
-
-void QCALLTYPE MarshalNative::GetCachedWinRTTypes(
-                        QCall::ObjectHandleOnStack hadObj,
-                        int * pEpoch,
-                        QCall::ObjectHandleOnStack retArrayMT)
-{
-    CONTRACTL
-    {
-        QCALL_CHECK;
-        PRECONDITION(CheckPointer(*hadObj.m_ppObject, NULL_OK));
-    }
-    CONTRACTL_END;
-
-    BEGIN_QCALL;
-
-    AppDomain * pDomain = GetAppDomain();
-
-    {
-        GCX_COOP();
-
-        // set return to failure value
-        retArrayMT.Set(NULL);
-
-        OBJECTREF orDomain = NULL;
-        GCPROTECT_BEGIN(orDomain);
-
-        orDomain = ObjectToOBJECTREF(*hadObj.m_ppObject);
-
-        // Validation: hadObj represents a non-NULL System.AppDomain instance
-        if(orDomain != NULL)
-        {
-            MethodTable* pMT = orDomain->GetMethodTable();
-            PREFIX_ASSUME(pMT != NULL);
-            if (!pMT->CanCastToClass(MscorlibBinder::GetClass(CLASS__APP_DOMAIN)))
-                // TODO: find better resource string
-                COMPlusThrow(kArgumentException, IDS_EE_ADUNLOAD_DEFAULT);
-
-            pDomain = ((AppDomainBaseObject*)(OBJECTREFToObject(orDomain)))->GetDomain();
-        }
-        GCPROTECT_END();
-    }
-
-    if (pDomain != NULL)
-    {
-        SArray<PTR_MethodTable> types;
-        SArray<GUID> guids;
-        UINT e = *(UINT*)pEpoch;
-        pDomain->GetCachedWinRTTypes(&types, &guids, e, (UINT*)pEpoch);
-
-        retArrayMT.SetIntPtrArray((void**)(&types[0]), types.GetCount());
-    }
-
-    END_QCALL;
-}
-
-void QCALLTYPE MarshalNative::GetCachedWinRTTypeByIID(
-                        QCall::ObjectHandleOnStack hadObj,
-                        GUID guid,
-                        void * * ppMT)
-{
-    CONTRACTL
-    {
-        QCALL_CHECK;
-        PRECONDITION(CheckPointer(*hadObj.m_ppObject, NULL_OK));
-    }
-    CONTRACTL_END;
-
-    BEGIN_QCALL;
-
-    AppDomain * pDomain = GetAppDomain();
-
-    {
-        GCX_COOP();
-
-        // set return to failure value
-        *ppMT = NULL;
-
-        OBJECTREF orDomain = NULL;
-        GCPROTECT_BEGIN(orDomain);
-
-        orDomain = ObjectToOBJECTREF(*hadObj.m_ppObject);
-
-        // Validation: hadObj represents a non-NULL System.AppDomain instance
-        if(orDomain != NULL)
-        {
-            MethodTable* pMT = orDomain->GetMethodTable();
-            PREFIX_ASSUME(pMT != NULL);
-            if (!pMT->CanCastToClass(MscorlibBinder::GetClass(CLASS__APP_DOMAIN)))
-                // TODO: find better resource string
-                COMPlusThrow(kArgumentException, IDS_EE_ADUNLOAD_DEFAULT);
-
-            pDomain = ((AppDomainBaseObject*)(OBJECTREFToObject(orDomain)))->GetDomain();
-        }
-        GCPROTECT_END();
-    }
-
-    if (pDomain != NULL)
-    {
-        *ppMT = pDomain->LookupTypeByGuid(guid);;
-    }
-
-
-    END_QCALL;
-}
-
 //====================================================================
 // Helper function used in the COM slot to method info mapping.
 //====================================================================  
index 9b6aa2c..ddc8351 100644 (file)
@@ -240,8 +240,6 @@ public:
     static FCDECL2(void, InitializeManagedWinRTFactoryObject, Object *unsafe_pThis, ReflectClassBaseObject *unsafe_pType);
     static FCDECL1(Object *, GetNativeActivationFactory, ReflectClassBaseObject *unsafe_pType);
     static void QCALLTYPE GetInspectableIIDs(QCall::ObjectHandleOnStack hobj, QCall::ObjectHandleOnStack retArrayGuids);
-    static void QCALLTYPE GetCachedWinRTTypes(QCall::ObjectHandleOnStack hadObj, int * epoch, QCall::ObjectHandleOnStack retArrayMT);
-    static void QCALLTYPE GetCachedWinRTTypeByIID(QCall::ObjectHandleOnStack hadObj, GUID iid, void * * ppMT);
 
 private:
     static int GetComSlotInfo(MethodTable *pMT, MethodTable **ppDefItfMT);
index ea0fb6f..0897afc 100644 (file)
@@ -437,7 +437,6 @@ DEFINE_METASIG(IM(Int_Int_Int_Int_RetVoid, i i i i, v))
 DEFINE_METASIG_T(IM(Obj_EventArgs_RetVoid, j C(EVENT_ARGS), v))
 DEFINE_METASIG_T(IM(Obj_UnhandledExceptionEventArgs_RetVoid, j C(UNHANDLED_EVENTARGS), v))
 
-DEFINE_METASIG_T(IM(Assembly_RetVoid, C(ASSEMBLY), v))
 DEFINE_METASIG_T(IM(Assembly_RetBool, C(ASSEMBLY), F))
 DEFINE_METASIG_T(IM(AssemblyBase_RetBool, C(ASSEMBLYBASE), F))
 DEFINE_METASIG_T(IM(Exception_RetVoid, C(EXCEPTION), v))
@@ -474,9 +473,8 @@ DEFINE_METASIG(IM(Int_VoidPtr_RetVoid, i P(v), v))
 DEFINE_METASIG(IM(VoidPtr_RetVoid, P(v), v))
 
 DEFINE_METASIG_T(IM(Str_RetModule, s, C(MODULE)))
-DEFINE_METASIG_T(IM(Assembly_Str_RetAssembly, C(ASSEMBLY) s, C(ASSEMBLY)))
+DEFINE_METASIG_T(SM(Assembly_Str_RetAssembly, C(ASSEMBLY) s, C(ASSEMBLY)))
 DEFINE_METASIG_T(SM(Str_Bool_RetAssembly, s F, C(ASSEMBLY)))
-DEFINE_METASIG_T(IM(Str_Str_Str_Assembly_Assembly_RetVoid, s s s C(ASSEMBLY) C(ASSEMBLY), v))
 DEFINE_METASIG(IM(Str_Str_Obj_RetVoid, s s j, v))
 DEFINE_METASIG(IM(Str_Str_Str_Obj_RetVoid, s s s j, v))
 DEFINE_METASIG(IM(Str_Str_Str_Obj_Bool_RetVoid, s s s j F, v))
@@ -540,19 +538,9 @@ DEFINE_METASIG_T(SM(LicenseInteropHelper_AllocateAndValidateLicense, g(RT_TYPE_H
 DEFINE_METASIG_T(SM(LicenseInteropHelper_RequestLicKey, g(RT_TYPE_HANDLE) r(I), i))
 DEFINE_METASIG_T(IM(LicenseInteropHelper_GetLicInfo, g(RT_TYPE_HANDLE) r(i) r(i), v))
 
-// App Domain related defines
-DEFINE_METASIG(IM(Bool_Str_Str_ArrStr_ArrStr_RetVoid, F s s a(s) a(s), v))
-DEFINE_METASIG_T(SM(Str_RetAppDomain, s, C(APP_DOMAIN)))
-DEFINE_METASIG(SM(Str_ArrStr_ArrStr_RetVoid, s a(s) a(s), v))
-#ifdef FEATURE_COMINTEROP
-// System.AppDomain.OnReflectionOnlyNamespaceResolveEvent
-DEFINE_METASIG_T(IM(Assembly_Str_RetArrAssembly, C(ASSEMBLY) s, a(C(ASSEMBLY))))
-// System.AppDomain.OnDesignerNamespaceResolveEvent
-DEFINE_METASIG(IM(Str_RetArrStr, s, a(s)))
-#endif //FEATURE_COMINTEROP
-
-// Object Clone 
-DEFINE_METASIG(SM(Obj_OutStr_OutStr_OutArrStr_OutArrObj_RetObj, j r(s) r(s) r(a(s)) r(a(j)), j))
+DEFINE_METASIG_T(SM(Assembly_RetVoid, C(ASSEMBLY), v))
+DEFINE_METASIG_T(SM(Assembly_Str_RetArrAssembly, C(ASSEMBLY) s, a(C(ASSEMBLY))))
+DEFINE_METASIG(SM(Str_RetArrStr, s, a(s)))
 
 // Execution Context
 DEFINE_METASIG_T(SM(SyncCtx_ArrIntPtr_Bool_Int_RetInt, C(SYNCHRONIZATION_CONTEXT) a(I) F i, i))
index 6128711..f257ecd 100644 (file)
@@ -67,27 +67,10 @@ DEFINE_FIELD(ACCESS_VIOLATION_EXCEPTION, TARGET,            _target)
 DEFINE_FIELD(ACCESS_VIOLATION_EXCEPTION, ACCESSTYPE,        _accessType)
 
 DEFINE_CLASS(APPCONTEXT,            System,                 AppContext)
-DEFINE_METHOD(APPCONTEXT,   SETUP,  Setup,    SM_PtrPtrChar_PtrPtrChar_Int_RetVoid)
-
-DEFINE_CLASS_U(System,                 AppDomain,      AppDomainBaseObject)
-DEFINE_FIELD_U(AssemblyLoad,               AppDomainBaseObject, m_pAssemblyEventHandler)
-DEFINE_FIELD_U(_TypeResolve,               AppDomainBaseObject, m_pTypeEventHandler)
-DEFINE_FIELD_U(_ResourceResolve,           AppDomainBaseObject, m_pResourceEventHandler)
-DEFINE_FIELD_U(_AssemblyResolve,           AppDomainBaseObject, m_pAsmResolveEventHandler)
-DEFINE_FIELD_U(_processExit,               AppDomainBaseObject, m_pProcessExitEventHandler)
-DEFINE_FIELD_U(_domainUnload,              AppDomainBaseObject, m_pDomainUnloadEventHandler)
-DEFINE_FIELD_U(_unhandledException,        AppDomainBaseObject, m_pUnhandledExceptionEventHandler)
-DEFINE_FIELD_U(_firstChanceException,      AppDomainBaseObject, m_pFirstChanceExceptionHandler)
-DEFINE_FIELD_U(_pDomain,                   AppDomainBaseObject, m_pDomain)
-
-DEFINE_CLASS(APP_DOMAIN,            System,                 AppDomain)
-DEFINE_METHOD(APP_DOMAIN,           ON_ASSEMBLY_LOAD,       OnAssemblyLoadEvent,        IM_Assembly_RetVoid)
-DEFINE_METHOD(APP_DOMAIN,           ON_RESOURCE_RESOLVE,    OnResourceResolveEvent,     IM_Assembly_Str_RetAssembly)
-DEFINE_METHOD(APP_DOMAIN,           ON_TYPE_RESOLVE,        OnTypeResolveEvent,         IM_Assembly_Str_RetAssembly)
-DEFINE_METHOD(APP_DOMAIN,           ON_ASSEMBLY_RESOLVE,    OnAssemblyResolveEvent,     IM_Assembly_Str_RetAssembly)
-#ifdef FEATURE_COMINTEROP
-DEFINE_METHOD(APP_DOMAIN,           ON_DESIGNER_NAMESPACE_RESOLVE, OnDesignerNamespaceResolveEvent, IM_Str_RetArrStr)
-#endif //FEATURE_COMINTEROP
+DEFINE_METHOD(APPCONTEXT,   SETUP,              Setup,          SM_PtrPtrChar_PtrPtrChar_Int_RetVoid)
+DEFINE_METHOD(APPCONTEXT,   ON_PROCESS_EXIT,    OnProcessExit,  SM_RetVoid)
+DEFINE_FIELD(APPCONTEXT, UNHANDLED_EXCEPTION,           UnhandledException)
+DEFINE_FIELD(APPCONTEXT, FIRST_CHANCE_EXCEPTION,        FirstChanceException)
 
 DEFINE_CLASS(ARG_ITERATOR,          System,                 ArgIterator)
 DEFINE_CLASS_U(System,              ArgIterator,            VARARGS)  // Includes a SigPointer.
@@ -881,10 +864,20 @@ DEFINE_METHOD(UNHANDLED_EVENTARGS,  CTOR,                   .ctor,
 DEFINE_CLASS(FIRSTCHANCE_EVENTARGS,   ExceptionServices,      FirstChanceExceptionEventArgs)
 DEFINE_METHOD(FIRSTCHANCE_EVENTARGS,  CTOR,                   .ctor,                      IM_Exception_RetVoid)
 
-DEFINE_CLASS(ASSEMBLYLOADCONTEXT,  Loader,                AssemblyLoadContext)    
+DEFINE_CLASS(ASSEMBLYLOADCONTEXT,  Loader,                AssemblyLoadContext)
 DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  RESOLVE,          Resolve,                      SM_IntPtr_AssemblyName_RetAssemblyBase)
 DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  RESOLVEUNMANAGEDDLL,          ResolveUnmanagedDll,                      SM_Str_IntPtr_RetIntPtr)
 DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  RESOLVEUSINGEVENT,          ResolveUsingResolvingEvent,                      SM_IntPtr_AssemblyName_RetAssemblyBase)
+DEFINE_FIELD(ASSEMBLYLOADCONTEXT,   ASSEMBLY_LOAD,          AssemblyLoad)
+DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  ON_ASSEMBLY_LOAD,       OnAssemblyLoad, SM_Assembly_RetVoid)
+DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  ON_RESOURCE_RESOLVE,    OnResourceResolve, SM_Assembly_Str_RetAssembly)
+DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  ON_TYPE_RESOLVE,        OnTypeResolve, SM_Assembly_Str_RetAssembly)
+DEFINE_METHOD(ASSEMBLYLOADCONTEXT,  ON_ASSEMBLY_RESOLVE,    OnAssemblyResolve, SM_Assembly_Str_RetAssembly)
+
+#ifdef FEATURE_COMINTEROP
+DEFINE_CLASS(WINDOWSRUNTIMEMETATADA, WinRT, WindowsRuntimeMetadata) 
+DEFINE_METHOD(WINDOWSRUNTIMEMETATADA,  ON_DESIGNER_NAMESPACE_RESOLVE, OnDesignerNamespaceResolve, SM_Str_RetArrStr)
+#endif //FEATURE_COMINTEROP
 
 DEFINE_CLASS(LAZY,              System,     Lazy`1)
 
index a6c020e..aeebc3b 100644 (file)
@@ -51,8 +51,6 @@ void ErectWriteBarrierForMT(MethodTable **dst, MethodTable *ref);
  *  |       |
  *  |       +-  PtrArray   - Array of OBJECTREFs, different than base arrays because of pObjectClass
  *  |              
- *  +-- code:AppDomainBaseObject - The base object for the class AppDomain
- *  |              
  *  +-- code:AssemblyBaseObject - The base object for the class Assembly
  *
  *
@@ -1562,56 +1560,6 @@ class MarshalByRefObjectBaseObject : public Object
 {
 };
 
-// AppDomainBaseObject 
-// This class is the base class for application domains
-//  
-class AppDomainBaseObject : public MarshalByRefObjectBaseObject
-{
-    friend class AppDomain;
-    friend class MscorlibBinder;
-
-  protected:
-    // READ ME:
-    // Modifying the order or fields of this object may require other changes to the
-    //  classlib class definition of this object.
-    OBJECTREF    m_pAssemblyEventHandler; // Delegate for 'loading assembly' event
-    OBJECTREF    m_pTypeEventHandler;     // Delegate for 'resolve type' event
-    OBJECTREF    m_pResourceEventHandler; // Delegate for 'resolve resource' event
-    OBJECTREF    m_pAsmResolveEventHandler; // Delegate for 'resolve assembly' event
-    OBJECTREF    m_pProcessExitEventHandler; // Delegate for 'process exit' event.  Only used in Default appdomain.
-    OBJECTREF    m_pDomainUnloadEventHandler; // Delegate for 'about to unload domain' event
-    OBJECTREF    m_pUnhandledExceptionEventHandler; // Delegate for 'unhandled exception' event
-
-    OBJECTREF    m_pFirstChanceExceptionHandler; // Delegate for 'FirstChance Exception' event
-
-    AppDomain*   m_pDomain;            // Pointer to the BaseDomain Structure
-
-  protected:
-    AppDomainBaseObject() { LIMITED_METHOD_CONTRACT; }
-   ~AppDomainBaseObject() { LIMITED_METHOD_CONTRACT; }
-   
-  public:
-
-    void SetDomain(AppDomain* p) 
-    {
-        LIMITED_METHOD_CONTRACT;
-        m_pDomain = p;
-    }
-    AppDomain* GetDomain() 
-    {
-        LIMITED_METHOD_CONTRACT;
-        return m_pDomain;
-    }
-
-    // Returns the reference to the delegate of the first chance exception notification handler
-    OBJECTREF GetFirstChanceExceptionNotificationHandler()
-    {
-        LIMITED_METHOD_CONTRACT;
-
-        return m_pFirstChanceExceptionHandler;
-    }
-};
-
 // AssemblyBaseObject 
 // This class is the base class for assemblies
 //  
@@ -1800,7 +1748,6 @@ typedef PTR_ReflectClassBaseObject REFLECTCLASSBASEREF;
 typedef PTR_ReflectMethodObject REFLECTMETHODREF;
 typedef PTR_ReflectFieldObject REFLECTFIELDREF;
 typedef PTR_ThreadBaseObject THREADBASEREF;
-typedef PTR_AppDomainBaseObject APPDOMAINREF;
 typedef PTR_AssemblyBaseObject ASSEMBLYREF;
 typedef PTR_AssemblyNameBaseObject ASSEMBLYNAMEREF;
 
index 9113783..29f40cf 100644 (file)
 
 DEFINE_EXCEPTION(g_ReflectionNS,       AmbiguousMatchException,        false,  COR_E_AMBIGUOUSMATCH)
 DEFINE_EXCEPTION(g_SystemNS,           ApplicationException,           false,  COR_E_APPLICATION)
-DEFINE_EXCEPTION(g_SystemNS,           AppDomainUnloadedException,     false,  COR_E_APPDOMAINUNLOADED)
 DEFINE_EXCEPTION(g_SystemNS,           ArithmeticException,            false,  COR_E_ARITHMETIC)
 
 DEFINE_EXCEPTION(g_SystemNS,           ArgumentException,              false,
index 8bfdfb7..ffb5eb1 100644 (file)
@@ -8080,8 +8080,7 @@ static void ManagedThreadBase_DispatchMiddle(ManagedThreadCallState *pCallState)
         // behavior (swallowing all unhandled exception), then swallow all unhandled exception.
         //
         if (SwallowUnhandledExceptions() ||
-            IsExceptionOfType(kThreadAbortException, pException) ||
-            IsExceptionOfType(kAppDomainUnloadedException, pException))
+            IsExceptionOfType(kThreadAbortException, pException))
         {
             // Do nothing to swallow the exception
         }
index 9eed287..f7e3230 100644 (file)
@@ -456,15 +456,13 @@ namespace System.Diagnostics.Tracing
         {
             get
             {
-#pragma warning disable 612, 618
-                int threadID = AppDomain.GetCurrentThreadId();
+                int threadID = Win32Native.GetCurrentThreadId();
 
                 // Managed thread IDs are more aggressively re-used than native thread IDs,
                 // so we'll use the latter...
                 return new Guid(unchecked((uint)threadID),
                                 unchecked((ushort)s_currentPid), unchecked((ushort)(s_currentPid >> 16)),
                                 0x94, 0x1b, 0x87, 0xd5, 0xa6, 0x5c, 0x36, 0x64);
-#pragma warning restore 612, 618
             }
         }
 #endif // !ES_BUILD_STANDALONE
index 6f2eb9b..bd89f32 100644 (file)
@@ -344,19 +344,6 @@ namespace System.Security.Permissions
 }
 #endif
 
-#if ES_BUILD_PN
-namespace System
-{
-    internal static class AppDomain
-    {
-        public static int GetCurrentThreadId()
-        {
-            return Internal.Runtime.Augments.RuntimeThread.CurrentThread.ManagedThreadId;
-        }
-    }    
-}
-#endif
-
 #if ES_BUILD_STANDALONE
 namespace Microsoft.Win32
 {
@@ -366,7 +353,10 @@ namespace Microsoft.Win32
     [SuppressUnmanagedCodeSecurityAttribute()]
     internal static class Win32Native
     {
-        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        public static extern int GetCurrentThreadId();
+
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
         internal static extern uint GetCurrentProcessId();
     }
 }
index a3d87ac..fadda45 100644 (file)
@@ -29,7 +29,6 @@ namespace System
         internal const int S_FALSE = unchecked((int)0x1);
         internal const int COR_E_ABANDONEDMUTEX = unchecked((int)0x8013152D);
         internal const int COR_E_AMBIGUOUSMATCH = unchecked((int)0x8000211D);
-        internal const int COR_E_APPDOMAINUNLOADED = unchecked((int)0x80131014);
         internal const int COR_E_APPLICATION = unchecked((int)0x80131600);
         internal const int COR_E_ARGUMENT = unchecked((int)0x80070057);
         internal const int COR_E_ARGUMENTOUTOFRANGE = unchecked((int)0x80131502);