Skip to content
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

suggestions to tidy up the windows linking code. #9

Closed
tocklime opened this issue Jan 19, 2024 · 2 comments
Closed

suggestions to tidy up the windows linking code. #9

tocklime opened this issue Jan 19, 2024 · 2 comments

Comments

@tocklime
Copy link
Contributor

tocklime commented Jan 19, 2024

if name.starts_with("qemu") {

Note that the "qemu.exe" here is not the name of the calling executable, but rather the name of the delay-linked DLL that is created in

let ch = Command::new("dlltool")
.args([
"--input-def",
&def_file_str,
"--output-delaylib",
&lib_file_str,
"--dllname",
"qemu.exe",
])
.spawn()?
.wait()?;
. I used qemu.exe because there was some chatter on the qemu-devel mailing list about moving (eventually) to a single-executable based approach, at which point much of this machinery would be unnecessary.

qemu-system-arm.exe loads plugin.dll, then plugin.dll loads qemu.exe. The win_link_hook module intercepts the failure to load qemu.exe, and returns a reference to the top-level executable (regardless of how it is named).

So, a few comments:

  • There is an unfinished safety justification on line 46:
    // nul-byte dependent `strcpy`. In this instance, it is safe because
    let name = unsafe { pdli.TargetDllName.to_string() }.unwrap_or_default();
  • Because you're hooking failure rather than notification now, if there happens to be a "qemu.exe" on the DLL load path, then the plugin will load that instead of getting a reference to the calling binary. It's a weird situation, and I'm not sure which behaviour is preferable.
  • as above, the check on line 51 is OK as is, but also it was fine before, too. Now, if the plugin happens to also link to other qemu* DLLs and they fail to load, then we will reroute to the calling executable. This might surprise the user.
  • unfinished comment on line 43.
@novafacing
Copy link
Owner

Understood, thanks for explaining that! In that case I'll revert the check back to explicitly qemu.exe, although maybe we can call it something like qemu-delay-link.exe or something if there's no reason to only have it named qemu.exe. I think that would repair the behavior to be how you intended it as well as remove some confusion (at least for me, a windows noob).

@novafacing
Copy link
Owner

I think this is resolved by #12, we can revisit later if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants