RFR: 8350869: os::stat doesn't follow symlinks on Windows
Anton Artemov
duke at openjdk.org
Thu May 15 09:58:52 UTC 2025
On Thu, 15 May 2025 08:45:11 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> This PR addresses an issue on Windows, where a class file could not be loaded by a symbolic link.
>>
>> I added a check if a wide path is a symbolic link (soft one) and a method for dereferencing. Both os::stat() and os::open() on Windows now can handle such links.
>>
>> Tested in tiers 1-3. A separate test added.
>
> src/hotspot/os/windows/os_windows.cpp line 4620:
>
>> 4618: const bool result = fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && fd.dwReserved0 == IO_REPARSE_TAG_SYMLINK;
>> 4619: if (0 == ::FindClose(f)) {
>> 4620: errno = ::GetLastError();
>
> I had not noticed this kind of error handling before. It is not obvious that `errno` is able to accept all the values `GetLastError` may report - or perhaps more accurately that anyone checking `errno` would expect to see them.
>
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-170
This mechanism is used throughout the entire os_windows.cpp. For instance,`os::stat()` makes a call to `::GetLastError() `and stores the result in `errno`. Same with `os::open()` In other places, where the error type is known by the programmer, there are explicit assignments to `errno ` of particular error codes. For instance in `os::realpath()`. I just followed the existing pattern.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25233#discussion_r2090788857
More information about the hotspot-runtime-dev
mailing list