summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Godbe <wigodbe@microsoft.com>2018-01-25 10:23:01 -0800
committerGitHub <noreply@github.com>2018-01-25 10:23:01 -0800
commite5a17bac5f0fd0b0137be7c8cf23391adc59958f (patch)
treea7ec970bb54af2ffdbe407e07e6369333781507d
parent8dfd31f3297203578a9915676805cfaeb64da813 (diff)
downloadcoreclr-e5a17bac5f0fd0b0137be7c8cf23391adc59958f.tar.gz
coreclr-e5a17bac5f0fd0b0137be7c8cf23391adc59958f.tar.bz2
coreclr-e5a17bac5f0fd0b0137be7c8cf23391adc59958f.zip
Add GetLoadLibrary function for PAL & use in TrackErrorCode (#15831)
* Add GetLoadLibrary function for PAL & use in TrackErrorCode * Finish changes to dllimport.cpp * Fix unix build errors * fix windows issues * Address feedback * Fix return type * Address feedback * Fix return type * Fix usage of LPCWSTR * Use shared library string * Append message strings * Fix append * Append newline * Fix spelling * Modify error messages * Resolve conflicts * Add mac message & stop appending all exceptions * Fix another error message * Fix NoName Error * Add newline to .h file
-rw-r--r--src/dlls/mscorrc/mscorrc.rc12
-rw-r--r--src/dlls/mscorrc/resource.h7
-rw-r--r--src/pal/inc/pal.h5
-rw-r--r--src/pal/src/loader/module.cpp38
-rw-r--r--src/pal/src/loader/modulename.cpp2
-rw-r--r--src/vm/dllimport.cpp45
6 files changed, 86 insertions, 23 deletions
diff --git a/src/dlls/mscorrc/mscorrc.rc b/src/dlls/mscorrc/mscorrc.rc
index 1f2423b69c..fb6dcd60a5 100644
--- a/src/dlls/mscorrc/mscorrc.rc
+++ b/src/dlls/mscorrc/mscorrc.rc
@@ -987,8 +987,11 @@ BEGIN
IDS_EE_NDIRECT_BADNATL_CALLCONV "Invalid PInvoke or UnmanagedFunctionPointer calling convention."
IDS_EE_NDIRECT_BADNATL_VARARGS_CALLCONV "Invalid PInvoke calling convention. Vararg functions must use the cdecl calling convention."
IDS_EE_NDIRECT_BADNATL_THISCALL "Invalid PInvoke calling convention. Thiscall requires that the first parameter is present and can be enregistered."
- IDS_EE_NDIRECT_LOADLIB "Unable to load DLL '%1': %2"
- IDS_EE_NDIRECT_GETPROCADDRESS "Unable to find an entry point named '%2' in DLL '%1'."
+ IDS_EE_NDIRECT_LOADLIB_WIN "Unable to load DLL '%1' or one of its dependencies: %2"
+ IDS_EE_NDIRECT_LOADLIB_LINUX "Unable to load shared library '%1' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: %2"
+ IDS_EE_NDIRECT_LOADLIB_MAC "Unable to load shared library '%1' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: %2"
+ IDS_EE_NDIRECT_GETPROCADDRESS_WIN "Unable to find an entry point named '%2' in DLL '%1'."
+ IDS_EE_NDIRECT_GETPROCADDRESS_UNIX "Unable to find an entry point named '%2' in shared library '%1'."
IDS_EE_NDIRECT_GETPROCADDRESS_NONAME "A library name must be specified in a DllImport attribute applied to non-IJW methods."
IDS_EE_CLASS_CONSTRAINTS_VIOLATION "GenericArguments[%1], '%2', on '%3' violates the constraint of type parameter '%4'."
IDS_EE_METHOD_CONSTRAINTS_VIOLATION "Method %1.%2: type argument '%3' violates the constraint of type parameter '%4'."
@@ -1223,9 +1226,8 @@ BEGIN
IDS_CLASSLOAD_NOTINTERFACE "Could not load type '%1' from assembly '%2' because it attempts to implement a class as an interface."
IDS_CLASSLOAD_VALUEINSTANCEFIELD "Could not load the value type '%1' from assembly '%2' because it has an instance field of itself."
- IDS_CLASSLOAD_BYREFLIKE_STATICFIELD "A value type containing a ByRef-like instance field cannot be used as the type for a static field."
- IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD "A value type containing a ByRef-like instance field cannot be used as the type for a class instance field."
- IDS_CLASSLOAD_NOTBYREFLIKE "A value type containing a ByRef-like instance field must be ByRef-like type."
+ IDS_CLASSLOAD_BYREFLIKE_STATICFIELD "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a static field."
+ IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a class instance field."
IDS_CLASSLOAD_BAD_NAME "Type name '%1' from assembly '%2' is invalid."
IDS_CLASSLOAD_RANK_TOOLARGE "'%1' from assembly '%2' has too many dimensions."
diff --git a/src/dlls/mscorrc/resource.h b/src/dlls/mscorrc/resource.h
index 45ddd2ec82..0fbbf1ce1a 100644
--- a/src/dlls/mscorrc/resource.h
+++ b/src/dlls/mscorrc/resource.h
@@ -95,8 +95,8 @@
#define IDS_EE_NDIRECT_UNSUPPORTED_SIG 0x1708
#define IDS_EE_EXCEPTION_FROM_HRESULT 0x1709
#define IDS_EE_NDIRECT_BADNATL 0x170a
-#define IDS_EE_NDIRECT_LOADLIB 0x170b
-#define IDS_EE_NDIRECT_GETPROCADDRESS 0x170c
+#define IDS_EE_NDIRECT_LOADLIB_WIN 0x170b
+#define IDS_EE_NDIRECT_GETPROCADDRESS_WIN 0x170c
#define IDS_EE_COM_UNSUPPORTED_SIG 0x170d
#define IDS_EE_NOSYNCHRONIZED 0x170f
#define IDS_EE_NDIRECT_BADNATL_THISCALL 0x1710
@@ -894,3 +894,6 @@
#define IDS_CLASSLOAD_BYREFLIKE_STATICFIELD 0x263b
#define IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD 0x263c
#define IDS_CLASSLOAD_NOTBYREFLIKE 0x263d
+#define IDS_EE_NDIRECT_LOADLIB_LINUX 0x263e
+#define IDS_EE_NDIRECT_LOADLIB_MAC 0x263f
+#define IDS_EE_NDIRECT_GETPROCADDRESS_UNIX 0x2640
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index aff205d7dd..75a68956a1 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -2719,6 +2719,11 @@ LPCVOID
PAL_GetSymbolModuleBase(void *symbol);
PALIMPORT
+LPCSTR
+PALAPI
+PAL_GetLoadLibraryError();
+
+PALIMPORT
LPVOID
PALAPI
PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(
diff --git a/src/pal/src/loader/module.cpp b/src/pal/src/loader/module.cpp
index 9e8f2ac302..f73adfa56a 100644
--- a/src/pal/src/loader/module.cpp
+++ b/src/pal/src/loader/module.cpp
@@ -367,8 +367,8 @@ GetProcAddress(
}
else
{
- TRACE("Symbol %s not found in module %p (named %S), dlerror message is \"%s\"\n",
- lpProcName, module, MODNAME(module), dlerror());
+ TRACE("Symbol %s not found in module %p (named %S)\n",
+ lpProcName, module, MODNAME(module));
SetLastError(ERROR_PROC_NOT_FOUND);
}
done:
@@ -840,6 +840,33 @@ PAL_GetSymbolModuleBase(void *symbol)
return retval;
}
+/*++
+ PAL_GetLoadLibraryError
+
+ Wrapper for dlerror() to be used by PAL functions
+
+Return value:
+
+A LPCSTR containing the output of dlerror()
+
+--*/
+PALIMPORT
+LPCSTR
+PALAPI
+PAL_GetLoadLibraryError()
+{
+
+ PERF_ENTRY(PAL_GetLoadLibraryError);
+ ENTRY("PAL_GetLoadLibraryError");
+
+ LPCSTR last_error = dlerror();
+
+ LOGEXIT("PAL_GetLoadLibraryError returns %p\n", last_error);
+ PERF_EXIT(PAL_GetLoadLibraryError);
+ return last_error;
+}
+
+
/* Internal PAL functions *****************************************************/
/*++
@@ -870,7 +897,7 @@ BOOL LOADInitializeModules()
exe_module.dl_handle = dlopen(nullptr, RTLD_LAZY);
if (exe_module.dl_handle == nullptr)
{
- ERROR("Executable module will be broken : dlopen(nullptr) failed dlerror message is \"%s\" \n", dlerror());
+ ERROR("Executable module will be broken : dlopen(nullptr) failed\n");
return FALSE;
}
exe_module.lib_name = nullptr;
@@ -1107,7 +1134,7 @@ static BOOL LOADFreeLibrary(MODSTRUCT *module, BOOL fCallDllMain)
if (module->dl_handle && 0 != dlclose(module->dl_handle))
{
/* report dlclose() failure, but proceed anyway. */
- WARN("dlclose() call failed! error message is \"%s\"\n", dlerror());
+ WARN("dlclose() call failed!\n");
}
/* release all memory */
@@ -1376,7 +1403,6 @@ static void *LOADLoadLibraryDirect(LPCSTR libraryNameOrPath)
void *dl_handle = dlopen(libraryNameOrPath, RTLD_LAZY);
if (dl_handle == nullptr)
{
- WARN("dlopen() failed; dlerror says '%s'\n", dlerror());
SetLastError(ERROR_MOD_NOT_FOUND);
}
else
@@ -1696,7 +1722,7 @@ MODSTRUCT *LOADGetPalLibrary()
Dl_info info;
if (dladdr((PVOID)&LOADGetPalLibrary, &info) == 0)
{
- ERROR("LOADGetPalLibrary: dladdr() failed. dlerror message is \"%s\"\n", dlerror());
+ ERROR("LOADGetPalLibrary: dladdr() failed.\n");
goto exit;
}
// Stash a copy of the CoreCLR installation path in a global variable.
diff --git a/src/pal/src/loader/modulename.cpp b/src/pal/src/loader/modulename.cpp
index 87c1b026c2..e6a371f582 100644
--- a/src/pal/src/loader/modulename.cpp
+++ b/src/pal/src/loader/modulename.cpp
@@ -60,7 +60,7 @@ const char *PAL_dladdr(LPVOID ProcAddress)
Dl_info dl_info;
if (!dladdr(ProcAddress, &dl_info))
{
- WARN("dladdr() call failed! dlerror says '%s'\n", dlerror());
+ WARN("dladdr() call failed!\n");
/* If we get an error, return NULL */
return (NULL);
}
diff --git a/src/vm/dllimport.cpp b/src/vm/dllimport.cpp
index e7857e412d..b06de143db 100644
--- a/src/vm/dllimport.cpp
+++ b/src/vm/dllimport.cpp
@@ -5721,12 +5721,19 @@ public:
m_priorityOfLastError = 0;
}
- VOID TrackErrorCode(DWORD dwLastError)
+ VOID TrackErrorCode()
{
LIMITED_METHOD_CONTRACT;
DWORD priority;
+#ifdef FEATURE_PAL
+
+ SetMessage(PAL_GetLoadLibraryError());
+#else
+
+ DWORD dwLastError = GetLastError();
+
switch (dwLastError)
{
case ERROR_FILE_NOT_FOUND:
@@ -5747,8 +5754,8 @@ public:
priority = const_priorityCouldNotLoad;
break;
}
-
UpdateHR(priority, HRESULT_FROM_WIN32(dwLastError));
+#endif
}
// Sets the error code to HRESULT as could not load DLL
@@ -5762,10 +5769,20 @@ public:
return m_hr;
}
+ SString& GetMessage()
+ {
+ return m_message;
+ }
+
void DECLSPEC_NORETURN Throw(SString &libraryNameOrPath)
{
STANDARD_VM_CONTRACT;
+#if defined(__APPLE__)
+ COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB_MAC, libraryNameOrPath.GetUnicode(), GetMessage());
+#elif defined(FEATURE_PAL)
+ COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB_LINUX, libraryNameOrPath.GetUnicode(), GetMessage());
+#else // __APPLE__
HRESULT theHRESULT = GetHR();
if (theHRESULT == HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT))
{
@@ -5775,8 +5792,9 @@ public:
{
SString hrString;
GetHRMsg(theHRESULT, hrString);
- COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB, libraryNameOrPath.GetUnicode(), hrString);
+ COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB_WIN, libraryNameOrPath.GetUnicode(), hrString);
}
+#endif // FEATURE_PAL
__UNREACHABLE();
}
@@ -5791,8 +5809,14 @@ private:
}
}
+ void SetMessage(LPCSTR message)
+ {
+ m_message = SString(SString::Utf8, message);
+ }
+
HRESULT m_hr;
DWORD m_priorityOfLastError;
+ SString m_message;
}; // class LoadLibErrorTracker
// Local helper function for the LoadLibraryModule function below
@@ -5819,7 +5843,7 @@ static HMODULE LocalLoadLibraryHelper( LPCWSTR name, DWORD flags, LoadLibErrorTr
DWORD dwLastError = GetLastError();
if (dwLastError != ERROR_INVALID_PARAMETER)
{
- pErrorTracker->TrackErrorCode(dwLastError);
+ pErrorTracker->TrackErrorCode();
return hmod;
}
}
@@ -5832,7 +5856,7 @@ static HMODULE LocalLoadLibraryHelper( LPCWSTR name, DWORD flags, LoadLibErrorTr
if (hmod == NULL)
{
- pErrorTracker->TrackErrorCode(GetLastError());
+ pErrorTracker->TrackErrorCode();
}
return hmod;
@@ -5852,7 +5876,7 @@ static HMODULE LocalLoadLibraryDirectHelper(LPCWSTR name, DWORD flags, LoadLibEr
if (hmod == NULL)
{
- pErrorTracker->TrackErrorCode(GetLastError());
+ pErrorTracker->TrackErrorCode();
}
return hmod;
@@ -6298,7 +6322,7 @@ VOID NDirect::NDirectLink(NDirectMethodDesc *pMD)
{
if (pMD->GetLibName() == NULL)
COMPlusThrow(kEntryPointNotFoundException, IDS_EE_NDIRECT_GETPROCADDRESS_NONAME);
-
+
StackSString ssLibName(SString::Utf8, pMD->GetLibName());
if (!hmod)
@@ -6312,8 +6336,11 @@ VOID NDirect::NDirectLink(NDirectMethodDesc *pMD)
wszEPName[0] = W('?');
wszEPName[1] = W('\0');
}
-
- COMPlusThrow(kEntryPointNotFoundException, IDS_EE_NDIRECT_GETPROCADDRESS, ssLibName.GetUnicode(), wszEPName);
+#ifdef FEATURE_PAL
+ COMPlusThrow(kEntryPointNotFoundException, IDS_EE_NDIRECT_GETPROCADDRESS_UNIX, ssLibName.GetUnicode(), wszEPName);
+#else
+ COMPlusThrow(kEntryPointNotFoundException, IDS_EE_NDIRECT_GETPROCADDRESS_WIN, ssLibName.GetUnicode(), wszEPName);
+#endif
}
}