3 Commits

Author SHA1 Message Date
f6ec7480ff library_loader_names: run with Wine's native wsock32, and check the copy is the fixture
Under Wine, loading a wsock32.dll by path gives Wine's builtin wsock32, not the
fixture copy, so the same-base checks failed (Tauwni, Wine 11 on macOS, #2525).
CTest now runs the test with WINEDLLOVERRIDES=wsock32=n,b, which Windows ignores
and scripts/run_wine_tests.py keeps, and the test checks by path that the module
it loaded is its own copy, saying why when it is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 22:36:30 -06:00
450c5e52b3 library_loader: ask Windows for a host module's name on every GetProcAddress
Dropping the HMODULE -> name entry in free_library() after FreeLibrary
left a window (timbot103's review on #2525): between FreeLibrary and the
erase, another thread can load a different DLL at the freed base and
call GetProcAddress, which then found the old name and served the old
module's shims. Holding loader_mutex across FreeLibrary would invite a
lock-order inversion with the loader lock.

So there is no cache any more: host_module_name() calls
GetModuleFileNameW each time, which always answers for the module mapped
at that base now, and free_library() is a plain FreeLibrary again.

library_loader_names_test gains the window itself: the host's
FreeLibrary is called directly, so the shim never sees the unload, and
the plain copy loaded at the same base must not be served the shim. It
fails with the cache-and-erase version and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:07:50 -06:00
d1b7d10c76 library_loader: no ".dll" for an empty name; FreeLibrary drops the cached name
Two bugs from kevincommits' finding in #1608 (item 2):

- module_name() and module_name_w() stripped the directory and then
  added ".dll" when no '.' was left, so "" and a path ending in a slash
  came out as ".dll". That passed every `dll.empty()` guard and went to
  the bundled loader's lookups as a module name. Both now return an
  empty name there.
- host_module_name() caches HMODULE -> module name for GetProcAddress on
  host modules, and free_library() never removed the entry. A DLL loaded
  later at the same base was then served the freed module's shims.
  free_library() now erases the entry when FreeLibrary succeeds; a module
  that is still loaded is looked up again on the next call.

New test library_loader_names: a fake bundled loader records the names
it is asked for, and a fixture DLL with no relocations at a fixed base is
loaded as wsock32.dll (a shimmed host module), freed, and loaded again
under a plain name at the same base. Both checks fail on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:40:30 -06:00