RFR: 8364816: GetLastError() in os_windows.cpp should not store value to errno [v2]
Joel Sikström
jsikstro at openjdk.org
Wed Aug 27 08:45:43 UTC 2025
On Wed, 27 Aug 2025 07:33:47 GMT, Anton Artemov <duke at openjdk.org> wrote:
>> src/hotspot/os/windows/os_windows.cpp line 4700:
>>
>>> 4698: if (hFile == INVALID_HANDLE_VALUE) {
>>> 4699: DWORD errcode = ::GetLastError();
>>> 4700: log_debug(os)("get_path_to_target() failed to CreateFileW: GetLastError->%lu.", errcode);
>>
>> The callers of `get_path_to_target` expects errno to be set, which it isn't anymore. We should probably set errno in this case and update the comments.
>>
>> See: https://github.com/openjdk/jdk/blob/master/src/hotspot/os/windows/os_windows.cpp#L4804-L4813 and https://github.com/openjdk/jdk/blob/master/src/hotspot/os/windows/os_windows.cpp#L5018-L5027
>
> Thanks for spotting. Actually, this comment, as well as the code around it, is mine as well. When writing it, I was storing results of `GetLastError()` in `errno`, which as we know is wrong and is addressed in this PR.
>
> The callers of `get_path_to_target()` do not expect any value in `errno` actually. The only thing they do when failing (this is where the `errno` value would be potentially useful) is that freeing some char array and returning -1. The error, which caused it, has been already reported. The comment is misleading. I fixed it.
I think we still need to set errno in the failure path in https://github.com/toxaart/jdk/blob/JDK-8364816-get-last-error/src/hotspot/os/windows/os_windows.cpp#L4804-L4811.
Right next to the Windows specific code that you removed in this PR, we are checking the errno result, which is unset if we exit from the path calling `get_path_to_target()`. See https://github.com/toxaart/jdk/blob/JDK-8364816-get-last-error/src/hotspot/share/cds/aotClassLocation.cpp#L234-L246.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26901#discussion_r2303285732
More information about the hotspot-runtime-dev
mailing list