Bring back DefaultDllImportSearchPathsAttribute (dotnet/coreclr#10786)
authorYi Zhang (CLR) <yizhang82@users.noreply.github.com>
Fri, 7 Apr 2017 14:29:10 +0000 (07:29 -0700)
committerJan Kotas <jkotas@microsoft.com>
Fri, 7 Apr 2017 14:29:10 +0000 (07:29 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/6f0bd8d2b7d956cda9c0d80315ca9a853d2a4680

src/coreclr/src/vm/dllimport.cpp
src/coreclr/src/vm/dllimport.h

index c0a73e8..3abe9cb 100644 (file)
@@ -5888,68 +5888,13 @@ static HMODULE LocalLoadLibraryDirectHelper(LPCWSTR name, DWORD flags, LoadLibEr
 #endif // !FEATURE_PAL
 }
 
-
-#if !defined(FEATURE_CORESYSTEM)
-
-#define NATIVE_DLL(d) L#d, L#d W(".dll")
-
-const LPCWSTR wellKnownModules[] =
-{
-    NATIVE_DLL(advapi32),
-    NATIVE_DLL(gdi32),
-    NATIVE_DLL(gdiplus),
-    NATIVE_DLL(kernel32),
-    NATIVE_DLL(mscoree),
-    NATIVE_DLL(ole32),
-    NATIVE_DLL(shfolder),
-    NATIVE_DLL(user32),
-    NATIVE_DLL(version)
-};
-
-BOOL CompareLibNames (UPTR val1, UPTR val2)
-{
-    CONTRACTL {
-        MODE_ANY;
-        NOTHROW;
-        GC_NOTRIGGER;
-    }
-    CONTRACTL_END;
-
-    LPCWSTR wszStr1 = (LPCWSTR)(val1 << 1);
-    LPCWSTR wszStr2 = (LPCWSTR)val2;
-
-    if (SString::_wcsicmp(wszStr1, wszStr2) == 0)
-        return TRUE;
-
-    return FALSE;
-}
-
-PtrHashMap * NDirect::s_pWellKnownNativeModules  = NULL;
+#if !defined(FEATURE_PAL)
 bool         NDirect::s_fSecureLoadLibrarySupported = false;
-
-HINSTANCE NDirect::CheckForWellKnownModules(LPCWSTR wszLibName, LoadLibErrorTracker *pErrorTracker)
-{
-    STANDARD_VM_CONTRACT;
-
-    ModuleHandleHolder hMod;
-    ULONG hash = HashiString(wszLibName);
-    LPCWSTR     wszName = NULL;
-    wszName = (LPCWSTR) s_pWellKnownNativeModules->LookupValue((UPTR) hash, (LPVOID)wszLibName);
-
-    if (wszName != (LPCWSTR)INVALIDENTRY)
-    {
-        hMod = LocalLoadLibraryHelper(wszLibName, 0, pErrorTracker);
-    }
-
-    return hMod.Extract();
-}
-
-#endif  // !FEATURE_CORESYSTEM
+#endif
 
 #define TOLOWER(a) (((a) >= W('A') && (a) <= W('Z')) ? (W('a') + (a - W('A'))) : (a))
 #define TOHEX(a)   ((a)>=10 ? W('a')+(a)-10 : W('0')+(a))
 
-
 // static
 HMODULE NDirect::LoadLibraryFromPath(LPCWSTR libraryPath)
 {
@@ -6155,10 +6100,6 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke
        return hmod.Extract();
     }
 
-#if !defined(FEATURE_CORESYSTEM)
-    hmod = CheckForWellKnownModules(wszLibName, pErrorTracker);
-#endif
-
 #ifdef FEATURE_PAL
     // In the PAL version of CoreCLR, the CLR module itself exports the functionality
     // that the Windows version obtains from kernel32 and friends.  In order to avoid
@@ -6432,6 +6373,17 @@ VOID NDirect::NDirectLink(NDirectMethodDesc *pMD)
     }
     CONTRACTL_END;
 
+#if !defined(FEATURE_PAL)
+    // Check if the OS supports the new secure LoadLibraryEx flags introduced in KB2533623
+    HMODULE hMod = CLRGetModuleHandle(WINDOWS_KERNEL32_DLLNAME_W);
+    _ASSERTE(hMod != NULL);
+
+    if (GetProcAddress(hMod, "AddDllDirectory") != NULL)
+    {
+        // The AddDllDirectory export was added in KB2533623 together with the new flag support
+        s_fSecureLoadLibrarySupported = true;
+    }
+#endif // !FEATURE_PAL
 }
 
 
index c9d1fbf..1dfb442 100644 (file)
@@ -131,10 +131,7 @@ private:
 
     static HMODULE LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pDomain, const wchar_t* wszLibName);
 
-#if !defined(FEATURE_CORESYSTEM)
-    static HINSTANCE    CheckForWellKnownModules(LPCWSTR wszLibName, LoadLibErrorTracker *pErrorTracker);
-    static PtrHashMap   *s_pWellKnownNativeModules;
-
+#if !defined(FEATURE_PAL)
     // Indicates if the OS supports the new secure LoadLibraryEx flags introduced in KB2533623
     static bool         s_fSecureLoadLibrarySupported;
 
@@ -144,7 +141,7 @@ public:
         LIMITED_METHOD_CONTRACT;
         return s_fSecureLoadLibrarySupported;
     }
-#endif // !FEATURE_CORESYSTEM
+#endif // !FEATURE_PAL
 };
 
 //----------------------------------------------------------------