From c57ccb0a626d583a92269724b7968a759bfb9d1e Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Mon, 20 Jun 2022 09:48:10 +0900 Subject: [PATCH 1/4] exclude incorrect dlerror message from DllNotFoundException --- src/coreclr/vm/nativelibrary.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index 891ce486352930..e348867fdd2fcb 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -53,6 +53,9 @@ namespace LIMITED_METHOD_CONTRACT; m_hr = E_FAIL; m_priorityOfLastError = 0; +#ifdef TARGET_UNIX + m_messageWritten = false; +#endif } VOID TrackErrorCode() @@ -137,12 +140,27 @@ namespace void SetMessage(LPCSTR message) { +#ifdef TARGET_UNIX + if (m_messageWritten) + { + m_message = SString(SString::Utf8, (LPCSTR)""); + } + else + { + m_message = SString(SString::Utf8, message); + m_messageWritten = true; + } +#else m_message = SString(SString::Utf8, message); +#endif } HRESULT m_hr; DWORD m_priorityOfLastError; SString m_message; +#ifdef TARGET_UNIX + bool m_messageWritten; +#endif }; // class LoadLibErrorTracker // Load the library directly and return the raw system handle From 9344fa1f0a7aa0204addd56ebb330400d3e2736e Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Mon, 20 Jun 2022 16:26:40 +0900 Subject: [PATCH 2/4] Include all error messages --- src/coreclr/vm/nativelibrary.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index e348867fdd2fcb..98e470ffe83100 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -53,9 +53,7 @@ namespace LIMITED_METHOD_CONTRACT; m_hr = E_FAIL; m_priorityOfLastError = 0; -#ifdef TARGET_UNIX - m_messageWritten = false; -#endif + m_message = SString(SString::Utf8, ""); } VOID TrackErrorCode() @@ -141,14 +139,14 @@ namespace void SetMessage(LPCSTR message) { #ifdef TARGET_UNIX - if (m_messageWritten) - { - m_message = SString(SString::Utf8, (LPCSTR)""); - } - else + //Append dlerror() messages of all attempts + SString new_message = SString(SString::Utf8, message); + SString::Iterator i = m_message.Begin(); + + if (!m_message.Find(i, new_message)) { - m_message = SString(SString::Utf8, message); - m_messageWritten = true; + m_message += new_message; + m_message += SString(SString::Utf8, " "); } #else m_message = SString(SString::Utf8, message); @@ -158,9 +156,6 @@ namespace HRESULT m_hr; DWORD m_priorityOfLastError; SString m_message; -#ifdef TARGET_UNIX - bool m_messageWritten; -#endif }; // class LoadLibErrorTracker // Load the library directly and return the raw system handle From 68677265469397170155d3364dafe097c21a4f24 Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Tue, 21 Jun 2022 07:10:18 +0900 Subject: [PATCH 3/4] Apply Feedbacks --- .../InteropServices/NativeLibrary.NativeAot.Unix.cs | 6 +++++- src/coreclr/vm/nativelibrary.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs index 572a7f28294407..bc263d38ee4657 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs @@ -51,7 +51,11 @@ public void Throw(string libraryName) public void TrackErrorMessage(string? message) { - _errorMessage = message; + if (_errorMessage == null) + { + _errorMessage = Environment.NewLine; + } + _errorMessage += " " + message + Environment.NewLine; } } } diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index 98e470ffe83100..e0cf8e7847a480 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -53,7 +53,7 @@ namespace LIMITED_METHOD_CONTRACT; m_hr = E_FAIL; m_priorityOfLastError = 0; - m_message = SString(SString::Utf8, ""); + m_message = SString(SString::Utf8, "\n"); } VOID TrackErrorCode() @@ -139,14 +139,14 @@ namespace void SetMessage(LPCSTR message) { #ifdef TARGET_UNIX - //Append dlerror() messages of all attempts + //Append dlerror() messages SString new_message = SString(SString::Utf8, message); SString::Iterator i = m_message.Begin(); - if (!m_message.Find(i, new_message)) { - m_message += new_message; m_message += SString(SString::Utf8, " "); + m_message += new_message; + m_message += SString(SString::Utf8, "\n"); } #else m_message = SString(SString::Utf8, message); From d24fdf59e96e3012bb000df6009c6953c342a249 Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Tue, 21 Jun 2022 10:45:48 +0900 Subject: [PATCH 4/4] Apply Feedback 2 --- .../Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs | 5 ++++- src/coreclr/vm/nativelibrary.cpp | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs index bc263d38ee4657..b1bb7853cd227f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs @@ -55,7 +55,10 @@ public void TrackErrorMessage(string? message) { _errorMessage = Environment.NewLine; } - _errorMessage += " " + message + Environment.NewLine; + if (!_errorMessage.Contains(message)) + { + _errorMessage += message + Environment.NewLine; + } } } } diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index e0cf8e7847a480..f5873ac0b9bfc0 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -144,7 +144,6 @@ namespace SString::Iterator i = m_message.Begin(); if (!m_message.Find(i, new_message)) { - m_message += SString(SString::Utf8, " "); m_message += new_message; m_message += SString(SString::Utf8, "\n"); }