RFR: 8364816: GetLastError() in os_windows.cpp should not store value to errno [v6]

Joel Sikström jsikstro at openjdk.org
Mon Sep 1 09:51:31 UTC 2025


On Fri, 29 Aug 2025 08:50:05 GMT, Anton Artemov <duke at openjdk.org> wrote:

>> Hi, please consider the following changes:
>> 
>> In `os_windows.cpp` in a few places results returned by `GetLastError()` are stored to `errno`. However, `errno` has no relation to `GetLastError()`, and their ranges are not the same.
>> 
>> Results of `GetLastError()` should be stored into variables of type `DWORD`.
>> 
>> The removed section in `src/hotspot/share/cds/aotClassLocation.cpp` was relying on values returned by `GetLastError()` and stored to `errno` in `os::stat()`. Though the logic was correct, these values should not be stored to `errno`. The functionality is preserved by storing a **valid** value `ENOENT` to `errno` in `os::stat()`. 
>> 
>> Tested in tiers 1 - 3.
>
> Anton Artemov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8364816: Addressed reviewer's comment.

src/hotspot/os/windows/os_windows.cpp line 4822:

> 4820:     if (errcode == ERROR_FILE_NOT_FOUND || errcode == ERROR_PATH_NOT_FOUND) {
> 4821:       errno = ENOENT;
> 4822:     }

To maintain the old behavior, we should set errno to 0 to avoid reading an old value of a previous error stored in errno, which could change the behavior or either succeeding or crashing in aotClassLocation.cpp.

Suggestion:

    } else {
      _set_errno(0);
    }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26901#discussion_r2313451830


More information about the hotspot-runtime-dev mailing list