diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsProcessPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsProcessPropertiesSupport.java index d4bce3010fd7..7e67e701a33c 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsProcessPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsProcessPropertiesSupport.java @@ -46,16 +46,14 @@ import com.oracle.svm.core.windows.headers.Process; import com.oracle.svm.core.windows.headers.WinBase; import com.oracle.svm.core.windows.headers.WinBase.HANDLE; +import com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer; @AutomaticallyRegisteredImageSingleton(ProcessPropertiesSupport.class) public class WindowsProcessPropertiesSupport extends BaseProcessPropertiesSupport { @Override public String getExecutableName() { - CCharPointer path = UnsafeStackValue.get(WinBase.MAX_PATH, CCharPointer.class); - WinBase.HMODULE hModule = LibLoaderAPI.GetModuleHandleA(WordFactory.nullPointer()); - int result = LibLoaderAPI.GetModuleFileNameA(hModule, path, WinBase.MAX_PATH); - return result == 0 ? null : CTypeConversion.toJavaString(path); + return getModulePath(LibLoaderAPI.GetModuleHandleA(WordFactory.nullPointer())); } @Override @@ -122,10 +120,16 @@ public String getObjectFile(PointerBase symbolAddress) { (CCharPointer) symbolAddress, module) == 0) { return null; } + return getModulePath(module.read()); + } - CCharPointer path = UnsafeStackValue.get(WinBase.MAX_PATH, CCharPointer.class); - int result = LibLoaderAPI.GetModuleFileNameA(module.read(), path, WinBase.MAX_PATH); - return result == 0 ? null : CTypeConversion.toJavaString(path); + private static String getModulePath(WinBase.HMODULE module) { + WCharPointer path = UnsafeStackValue.get(WinBase.MAX_PATH, WCharPointer.class); + int length = LibLoaderAPI.GetModuleFileNameW(module, path, WinBase.MAX_PATH); + if (length == 0 || length == WinBase.MAX_PATH) { + return null; + } + return WindowsSystemPropertiesSupport.toJavaString(path, length); } @Override diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java index e2596d7849bc..353855263cba 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSystemPropertiesSupport.java @@ -182,7 +182,7 @@ protected String javaLibraryPathValue() { return libraryPath.toString(); } - private static String toJavaString(WCharPointer wcString, int length) { + static String toJavaString(WCharPointer wcString, int length) { return asCharBuffer(wcString, length).toString(); } diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/LibLoaderAPI.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/LibLoaderAPI.java index 077ce9bf3049..1c8aea2d8090 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/LibLoaderAPI.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/LibLoaderAPI.java @@ -32,9 +32,9 @@ import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer; import com.oracle.svm.core.windows.headers.WinBase.HMODULE; import com.oracle.svm.core.windows.headers.WinBase.HMODULEPointer; +import com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer; // Checkstyle: stop @@ -48,10 +48,6 @@ public class LibLoaderAPI { @CFunction(transition = NO_TRANSITION) public static native int FreeLibrary(HMODULE hLibModule); - /** Retrieves the fully qualified path of the file that contains the specified module. */ - @CFunction(transition = NO_TRANSITION) - public static native int GetModuleFileNameA(HMODULE hModule, CCharPointer lpFilename, int nSize); - /** Retrieves the fully qualified path of the file that contains the specified module. */ @CFunction(transition = NO_TRANSITION) public static native int GetModuleFileNameW(HMODULE hModule, WCharPointer lpFilename, int nSize);