-
Notifications
You must be signed in to change notification settings - Fork 76
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
Using GR plugins without setting PATH on Windows #489
Comments
We might want to use a UTF-16 version. julia> using GR
julia> kernel32 = :kernel32
:kernel32
julia> all([@ccall kernel32.SetDllDirectoryW(push!(transcode(UInt16, d),0x0000)::Ptr{UInt16})::Bool for d in GR.GRPreferences.GR_jll.LIBPATH_list])
true
julia> x = 0:2π/360:2π; y = sin.(x);
julia> plot(x,y) # No errors
|
Actually SetDllDirectoryW may only keep the last directory added. Perhaps we need https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-adddlldirectory |
julia> using GR
julia> kernel32 = :kernel32
julia> [@ccall kernel32.AddDllDirectory(push!(transcode(UInt16, d),0x0000)::Ptr{UInt16})::Ptr{Nothing} for d in reverse(GR.GRPreferences.GR_jll.LIBPATH_list)]
35-element Vector{Ptr{Nothing}}:
Ptr{Nothing} @0x00000001cf47b0d0
Ptr{Nothing} @0x00000001cf47b4e0
Ptr{Nothing} @0x00000001cf47b680
Ptr{Nothing} @0x00000001cf47cd40
Ptr{Nothing} @0x00000001cf47a4a0
Ptr{Nothing} @0x00000001cf47cad0
Ptr{Nothing} @0x00000001cf47a3d0
Ptr{Nothing} @0x00000001cf47c930
Ptr{Nothing} @0x00000001cf47a300
Ptr{Nothing} @0x00000001cf47cba0
⋮
Ptr{Nothing} @0x00000001cf47a7e0
Ptr{Nothing} @0x00000001cf47b270
Ptr{Nothing} @0x00000001cf47c790
Ptr{Nothing} @0x00000001cf47ce10
Ptr{Nothing} @0x00000001cf47a8b0
Ptr{Nothing} @0x00000001cf47b340
Ptr{Nothing} @0x00000001cf474710
Ptr{Nothing} @0x00000001cf47b8f0
Ptr{Nothing} @0x00000001cf47cfb0
Ptr{Nothing} @0x00000001cf47b9c0
julia> @ccall kernel32.SetDefaultDllDirectories(0x00000400::UInt32)::Bool
true
julia> x = 0:2π/360:2π; y = sin.(x);
julia> plot(x,y) |
@mkitti : This plugin is only used by us, e.g. when we develop a new GKS output driver. In normal GR operation, this method is never used. The plugins are called directly here. So, by using a workstation type 301 (or "plugin"), programmers can then develop and test a new output driver (built as a shared object) without having to completely rebuild the GKS each time. |
301 leads to
That calls Which leads to the code I pointed to earlier, right? |
Similarly, 382 leads to https://github.com/sciapp/gr/blob/9aa4f55f75101b76ba8e4406b78601e410642cc6/lib/gks/gks.c#L272
https://github.com/sciapp/gr/blob/9aa4f55f75101b76ba8e4406b78601e410642cc6/lib/gks/plugin.c#L239 That in turn dynamically loads |
That's right, yes. Which means, that |
Thanks for working on a clean fix @mkitti, and the corresponding analysis: this is the right way to proceed. I had seen https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications before, but without a windows machine, and having never user windows, it was difficult to work on this issue.
To me unless the |
I try to implement the |
It seems to me, that we don't need any
In any case, I will use the |
What is |
Also, my suggestion is to use |
To be specific, my suggestion is that we replace Line 38 in da5cfd3
with kernel32 = :kernel32
@ccall kernel32.SetDefaultDllDirectories(0x00000400::UInt32)::Bool
[@ccall kernel32.AddDllDirectory(push!(transcode(UInt16, d),0x0000)::Ptr{UInt16})::Ptr{Nothing} for d in GRPreferences.GR_jll.LIBPATH_list] I think it might make sense to also do
Currently, when using GR_jll, the
|
We implemented the use of |
Currently, we set
ENV["PATH"]
on Windows since we need to communicate the DLL search path to GR so that it can dynamically load plugins.GR.jl/src/funcptrs.jl
Line 38 in 8b18b19
The normal Windows search order is specified in the documentation with
PATH
being sixth in the priority list.https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications
If SafeDllSearchMode is disabled, the search order is as follows:
The directory from which the application loaded.
As @giordano pointed out, this "looks like a bad idea".
The GR plugin loading code is located here:
https://github.com/sciapp/gr/blob/9aa4f55f75101b76ba8e4406b78601e410642cc6/lib/gks/plugin.c#L46-L55
Noticeably, this uses
SetDllDirectory
which maps to eitherSetDllDirectoryA
orSetDllDirectoryW
based on the value of the environment variableGRDIR
.Setting
GRDIR
works for a single directory. The following works in VSCode after commenting out line 38 of funcptrs.jl above.If we did not set
GRDIR
, this error occurs:GKS: svgplugin.dll: can't load library, error 126 (0x7e)
.While setting
GRDIR
for a single directory works, there may be many directories to include in the DLL search path:One strategy then would be for us to call
SetDllDirectoryA
directly. This works in VSCode:We could of course do this for all directories in
LIBPATH_list
. This also works in VSCode.cc:@t-bltg
The text was updated successfully, but these errors were encountered: