Remove .dll from Interop.Libraries.HostPolicy for consistency with other runtime...
authorElinor Fung <elfung@microsoft.com>
Tue, 4 Oct 2022 21:09:50 +0000 (14:09 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Oct 2022 21:09:50 +0000 (14:09 -0700)
src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs
src/native/corehost/hostmisc/pal.h
src/native/corehost/hostmisc/utils.h
src/native/corehost/hostpolicy/hostpolicy_context.cpp
src/native/corehost/test/nativehost/nativehost.cpp

index bf53b27..bc10bf0 100644 (file)
@@ -44,7 +44,7 @@ internal static partial class Interop
         internal const string CompressionNative = "System.IO.Compression.Native";
         internal const string GlobalizationNative = "System.Globalization.Native";
         internal const string MsQuic = "msquic.dll";
-        internal const string HostPolicy = "hostpolicy.dll";
+        internal const string HostPolicy = "hostpolicy";
         internal const string Ucrtbase = "ucrtbase.dll";
         internal const string Xolehlp = "xolehlp.dll";
     }
index 547f344..2fc4a50 100644 (file)
 //
 // We cannot maintain the same (compat) invariant for linux and thus, we will fallback to using lowest RID-Platform.
 #if defined(TARGET_WINDOWS)
-#define LIB_PREFIX
-#define MAKE_LIBNAME(NAME) (_X(NAME) _X(".dll"))
+#define LIB_PREFIX ""
+#define LIB_FILE_EXT ".dll"
 #define FALLBACK_HOST_RID _X("win10")
 #elif defined(TARGET_OSX)
-#define LIB_PREFIX _X("lib")
-#define MAKE_LIBNAME(NAME) (LIB_PREFIX _X(NAME) _X(".dylib"))
+#define LIB_PREFIX "lib"
+#define LIB_FILE_EXT ".dylib"
 #define FALLBACK_HOST_RID _X("osx.10.12")
 #else
-#define LIB_PREFIX _X("lib")
-#define MAKE_LIBNAME(NAME) (LIB_PREFIX _X(NAME) _X(".so"))
+#define LIB_PREFIX "lib"
+#define LIB_FILE_EXT ".so"
 #if defined(TARGET_FREEBSD)
 #define FALLBACK_HOST_RID _X("freebsd")
 #elif defined(TARGET_ILLUMOS)
 #endif
 #endif
 
-#define LIBCORECLR_FILENAME (LIB_PREFIX _X("coreclr"))
-#define LIBCORECLR_NAME MAKE_LIBNAME("coreclr")
+#define _STRINGIFY(s) _X(s)
 
-#define CORELIB_NAME _X("System.Private.CoreLib.dll")
-
-#define LIBHOSTPOLICY_FILENAME (LIB_PREFIX _X("hostpolicy"))
-#define LIBHOSTPOLICY_NAME MAKE_LIBNAME("hostpolicy")
+#define LIB_NAME(NAME) LIB_PREFIX NAME
+#define LIB_FILE_NAME(NAME) LIB_PREFIX NAME LIB_FILE_EXT
+#define LIB_FILE_NAME_X(NAME) _STRINGIFY(LIB_FILE_NAME(NAME))
 
-#define LIBFXR_NAME MAKE_LIBNAME("hostfxr")
+#define CORELIB_NAME _X("System.Private.CoreLib.dll")
+#define LIBCORECLR_NAME LIB_FILE_NAME_X("coreclr")
+#define LIBFXR_NAME LIB_FILE_NAME_X("hostfxr")
+#define LIBHOSTPOLICY_NAME LIB_FILE_NAME_X("hostpolicy")
 
 #if !defined(PATH_MAX) && !defined(_WIN32)
 #define PATH_MAX    4096
index 97d4976..1bef3e2 100644 (file)
@@ -8,7 +8,6 @@
 #include "trace.h"
 #include <type_traits>
 
-#define _STRINGIFY(s) _X(s)
 #if defined(_WIN32)
 #define DOTNET_CORE_INSTALL_PREREQUISITES_URL _X("https://go.microsoft.com/fwlink/?linkid=798306")
 #elif defined(TARGET_OSX)
index 8d64883..89a1392 100644 (file)
@@ -53,56 +53,50 @@ namespace
 
     // pinvoke_override:
     // Check if given function belongs to one of statically linked libraries and return a pointer if found.
-    const void* STDMETHODCALLTYPE pinvoke_override(const char* libraryName, const char* entrypointName)
+    const void* STDMETHODCALLTYPE pinvoke_override(const char* library_name, const char* entry_point_name)
     {
-#if defined(_WIN32)
-        const char* hostPolicyLib = "hostpolicy.dll";
-
-        if (strcmp(libraryName, "System.IO.Compression.Native") == 0)
+        // This function is only called with the library name specified for a p/invoke, not any variations.
+        // It must handle exact matches to the names specified. See Interop.Libraries.cs for each platform.
+#if !defined(_WIN32)
+        if (strcmp(library_name, LIB_NAME("System.Net.Security.Native")) == 0)
         {
-            return CompressionResolveDllImport(entrypointName);
+            return SecurityResolveDllImport(entry_point_name);
         }
-#else
-        const char* hostPolicyLib = "libhostpolicy";
 
-        if (strcmp(libraryName, "libSystem.IO.Compression.Native") == 0)
+        if (strcmp(library_name, LIB_NAME("System.Native")) == 0)
         {
-            return CompressionResolveDllImport(entrypointName);
+            return SystemResolveDllImport(entry_point_name);
         }
 
-        if (strcmp(libraryName, "libSystem.Net.Security.Native") == 0)
+        if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.OpenSsl")) == 0)
         {
-            return SecurityResolveDllImport(entrypointName);
+            return CryptoResolveDllImport(entry_point_name);
         }
+#endif
 
-        if (strcmp(libraryName, "libSystem.Native") == 0)
+        if (strcmp(library_name, LIB_NAME("System.IO.Compression.Native")) == 0)
         {
-            return SystemResolveDllImport(entrypointName);
+            return CompressionResolveDllImport(entry_point_name);
         }
 
-        if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.OpenSsl") == 0)
-        {
-            return CryptoResolveDllImport(entrypointName);
-        }
-#endif
         // there are two PInvokes in the hostpolicy itself, redirect them here.
-        if (strcmp(libraryName, hostPolicyLib) == 0)
+        if (strcmp(library_name, LIB_NAME("hostpolicy")) == 0)
         {
-            if (strcmp(entrypointName, "corehost_resolve_component_dependencies") == 0)
+            if (strcmp(entry_point_name, "corehost_resolve_component_dependencies") == 0)
             {
                 return (void*)corehost_resolve_component_dependencies;
             }
 
-            if (strcmp(entrypointName, "corehost_set_error_writer") == 0)
+            if (strcmp(entry_point_name, "corehost_set_error_writer") == 0)
             {
                 return (void*)corehost_set_error_writer;
             }
         }
 
 #if defined(TARGET_OSX)
-        if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.Apple") == 0)
+        if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.Apple")) == 0)
         {
-            return CryptoAppleResolveDllImport(entrypointName);
+            return CryptoAppleResolveDllImport(entry_point_name);
         }
 #endif
 
index 1017dfb..0d74bf8 100644 (file)
@@ -72,7 +72,7 @@ int main(const int argc, const pal::char_t *argv[])
             }
 
             nethost_path = get_directory(nethost_path);
-            nethost_path.append(MAKE_LIBNAME("nethost"));
+            nethost_path.append(LIB_FILE_NAME_X("nethost"));
 
             pal::dll_t nethost;
             if (!pal::load_library(&nethost_path, &nethost))