Skip to content

Windows: Using SetDefaultDllDirectories prevents Julia from loading DLLs #47820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mkitti opened this issue Dec 7, 2022 · 1 comment
Open
Labels
system:windows Affects only Windows

Comments

@mkitti
Copy link
Contributor

mkitti commented Dec 7, 2022

Using SetDefaultDllDirectories irreversibly prevents Julia from loading shared libraries.

Julia's jl_dlopen is implemented via LoadLibraryExW(wfilename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH).
https://github.com/JuliaLang/julia/blob/63830a6f2050e61b7b2aca78e2462487fd3f59d0/src/dlload.c

I suggest that we consider switching to LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_DEFAULT_DIRS when available, and we consider adding a fallback mechanism when using LOAD_WITH_ALTERED_SEARCH_PATH fails to load a library.

See https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw

Minimum example:

julia> @ccall "kernel32".SetDefaultDllDirectories(0x1000::UInt32)::UInt8 # 0x1000 LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
0x01

julia> using Random

julia> MersenneTwister(1234)
ERROR: could not load library "libdSFMT"
The parameter is incorrect.
Stacktrace:
 [1] dsfmt_init_by_array
   @ C:\Users\kittisopikulm\.julia\juliaup\julia-1.8.3+0.x64\share\julia\stdlib\v1.8\Random\src\DSFMT.jl:69 [inlined]
 [2] seed!(r::MersenneTwister, seed::Vector{UInt32})
   @ Random C:\Users\kittisopikulm\.julia\juliaup\julia-1.8.3+0.x64\share\julia\stdlib\v1.8\Random\src\RNGs.jl:313
 [3] seed!
   @ C:\Users\kittisopikulm\.julia\juliaup\julia-1.8.3+0.x64\share\julia\stdlib\v1.8\Random\src\RNGs.jl:321 [inlined]
 [4] MersenneTwister(seed::Int64)
   @ Random C:\Users\kittisopikulm\.julia\juliaup\julia-1.8.3+0.x64\share\julia\stdlib\v1.8\Random\src\RNGs.jl:113
 [5] top-level scope
   @ REPL[11]:1
@mkitti
Copy link
Contributor Author

mkitti commented Dec 7, 2022

Also see #47775 for a partial fix for when SetDefaultDllDirectories is used and disrupts DLL loading with LOAD_WITH_ALTERED_SEARCH_PATH

@brenhinkeller brenhinkeller added the system:windows Affects only Windows label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:windows Affects only Windows
Projects
None yet
Development

No branches or pull requests

2 participants