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

support for windows plugins #4

Closed
wants to merge 3 commits into from
Closed

Conversation

tocklime
Copy link
Contributor

@tocklime tocklime commented Jan 4, 2024

This is intended to fix #3.

Here's my first (mostly successful) go at this. I'll add explanatory comments into the changes, but at a high level:

  • generate_bindings.rs now (on windows) also creates qemu_plugin_api.def
  • the (new) build.rs script for qemu-plugin-sys (on windows) makes the appropriate delay link .lib file from the .def. This only works in gnu-style toolchains, not -msvc style.
  • I've dropped in the delay link hook to qemu-plugin. It works without further config on the plugins side.
  • g_free is a problem - windows doesn't expose functions unless asked to, so we don't have an (easy) way of getting access to g_free. For now I've implemented it as a no-op, and so we leak memory whenever it's used.

The tiny example compiles and runs on my windows machine, as does my internal more complex plugin. tracer doesn't compile because it uses memfd, which doesn't work on windows.

Limitations:

  • -gnu only, because I'm using dlltool. there may be a way to get this to work on -msvc, but I've not looked into it.
  • g_free leaks

Add initial support for making windows delay-link library which hopefully
we will be able to link against.

qemu-plugins has win_link_hook which does the runtime link-up to the host
qemu.exe.

the tiny example compiles and runs for me now.

No way to access g_free on windows, so we instead leak memory at the moment.
@tocklime tocklime marked this pull request as draft January 4, 2024 16:32
Comment on lines +17 to +18
[lints.rust]
non_snake_case = "allow"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to stop it complaining about the generated code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, nice!

Comment on lines +13 to +14
//![lints.rust]
//!non_snake_case = "allow"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, to suppress warnings. It seems that this generate-bindings.rs script is intended to run standalone, but it compiles everything under src/ directory anyway. I wonder if there's a way to stop it doing that.

@@ -25,7 +29,7 @@ use tar::Archive;
use xz2::read::XzDecoder;

const QEMU_SRC_URL_BASE: &str = "https://download.qemu.org/";
const QEMU_VERSION: &str = "8.1.3";
const QEMU_VERSION: &str = "8.2.0";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should really be done in a normal upgrade. Probably before this PR.

qemu-plugin-sys/generate-bindings.rs Show resolved Hide resolved
Comment on lines 106 to 113
#[cfg(windows)]
unsafe fn g_free(_mem: *mut c_void){
//TODO: We would really like to call g_free in the qemu binary here
//but we can't, because windows doesn't export symbols unless you explicitly export them
//and g_free isn't so exported.

//For now, we're just going to leak.
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

I'm not sure what we'll be able to do here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. I'm not a windows person but is there an equivalent to dlsym/dlopen to get it since we should have glib2 also loaded before us after all?

@novafacing
Copy link
Owner

Wow, this is awesome, quite a productive holiday season 😉 I'll take a look!

@novafacing
Copy link
Owner

Just merged #5 which includes these commits so I'm going to go ahead and close this one.

@novafacing novafacing closed this Jan 10, 2024
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

Successfully merging this pull request may close these issues.

Windows support for plugins
2 participants