//
// 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
// 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