-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add GetLoadLibrary function for PAL & use in TrackErrorCode #15831
Changes from 14 commits
fc70eb1
c6f86e1
e6eb24e
e438dcd
a84e274
e399d06
211f608
5509ae6
356e07e
190e3d0
1cf7432
e84eace
7e36820
d8882d2
1326a11
eab7dc0
448b8db
ef56ee9
db4dcee
1035982
588ede7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -987,8 +987,8 @@ 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 "Unable to load shared library '%1': %2" | ||
IDS_EE_NDIRECT_GETPROCADDRESS "Unable to find an entry point named '%2' in shared library '%1'." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need a windows form of this message too -- that says DLL? |
||
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'." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5721,12 +5721,19 @@ class LoadLibErrorTracker | |
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 @@ class LoadLibErrorTracker | |
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,18 @@ class LoadLibErrorTracker | |
return m_hr; | ||
} | ||
|
||
SString& GetMessage() | ||
{ | ||
return m_message; | ||
} | ||
|
||
void DECLSPEC_NORETURN Throw(SString &libraryNameOrPath) | ||
{ | ||
STANDARD_VM_CONTRACT; | ||
|
||
#ifdef FEATURE_PAL | ||
COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB, libraryNameOrPath.GetUnicode(), GetMessage()); | ||
#else | ||
HRESULT theHRESULT = GetHR(); | ||
if (theHRESULT == HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT)) | ||
{ | ||
|
@@ -5777,6 +5792,7 @@ class LoadLibErrorTracker | |
GetHRMsg(theHRESULT, hrString); | ||
COMPlusThrow(kDllNotFoundException, IDS_EE_NDIRECT_LOADLIB, libraryNameOrPath.GetUnicode(), hrString); | ||
} | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, not worth resetting for, but normally after #else / #elif / #endif you add an inline comment noting what #if or #endif they match with. Eg., line 5785 would end with // APPLE and 5797 with // FEATURE_PAL -- if I understand the convention correctly |
||
|
||
__UNREACHABLE(); | ||
} | ||
|
@@ -5791,8 +5807,17 @@ class LoadLibErrorTracker | |
} | ||
} | ||
|
||
void SetMessage(LPCSTR message) | ||
{ | ||
SString append_string = SString(SString::Utf8, message); | ||
SString newline = SString(SString::Utf8, "\n"); | ||
m_message.Append(newline); | ||
m_message.Append(append_string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just going to jam the strings together isn't it?, you probably want to include \n's. |
||
} | ||
|
||
HRESULT m_hr; | ||
DWORD m_priorityOfLastError; | ||
SString m_message = SString(SString::Utf8, ""); | ||
}; // class LoadLibErrorTracker | ||
|
||
// Local helper function for the LoadLibraryModule function below | ||
|
@@ -5819,7 +5844,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 +5857,7 @@ static HMODULE LocalLoadLibraryHelper( LPCWSTR name, DWORD flags, LoadLibErrorTr | |
|
||
if (hmod == NULL) | ||
{ | ||
pErrorTracker->TrackErrorCode(GetLastError()); | ||
pErrorTracker->TrackErrorCode(); | ||
} | ||
|
||
return hmod; | ||
|
@@ -5852,7 +5877,7 @@ static HMODULE LocalLoadLibraryDirectHelper(LPCWSTR name, DWORD flags, LoadLibEr | |
|
||
if (hmod == NULL) | ||
{ | ||
pErrorTracker->TrackErrorCode(GetLastError()); | ||
pErrorTracker->TrackErrorCode(); | ||
} | ||
|
||
return hmod; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is pretty unusual to use "shared library" name on Windows. If we want to use "shared library" for Unix, Windows version of the error message should keep "DLL".