From 153a5c8256ea3b55f985bfac68f64ddf97800c63 Mon Sep 17 00:00:00 2001 From: Greg Manning Date: Thu, 4 Jan 2024 13:44:40 +0000 Subject: [PATCH 1/3] initial support for making windows plugins 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. --- qemu-plugin-sys/Cargo.toml | 6 + qemu-plugin-sys/build.rs | 35 + qemu-plugin-sys/generate-bindings.rs | 21 +- qemu-plugin-sys/src/bindings.rs | 818 ++++++++++++------------ qemu-plugin-sys/src/qemu_plugin_api.def | 46 ++ qemu-plugin/Cargo.toml | 8 + qemu-plugin/src/lib.rs | 12 + qemu-plugin/src/win_link_hook/mod.rs | 26 + 8 files changed, 578 insertions(+), 394 deletions(-) create mode 100644 qemu-plugin-sys/build.rs create mode 100644 qemu-plugin-sys/src/qemu_plugin_api.def create mode 100644 qemu-plugin/src/win_link_hook/mod.rs diff --git a/qemu-plugin-sys/Cargo.toml b/qemu-plugin-sys/Cargo.toml index bf07893..3a2058a 100644 --- a/qemu-plugin-sys/Cargo.toml +++ b/qemu-plugin-sys/Cargo.toml @@ -10,3 +10,9 @@ publish.workspace = true readme.workspace = true repository.workspace = true version.workspace = true + +[build-dependencies] +anyhow = "1.0.75" + +[lints.rust] +non_snake_case = "allow" \ No newline at end of file diff --git a/qemu-plugin-sys/build.rs b/qemu-plugin-sys/build.rs new file mode 100644 index 0000000..3d88550 --- /dev/null +++ b/qemu-plugin-sys/build.rs @@ -0,0 +1,35 @@ +use std::{path::PathBuf, str::FromStr, env::var}; +use anyhow::{anyhow, Result}; + +fn out_dir() -> Result { + Ok(PathBuf::from( + var("OUT_DIR").map_err(|e| anyhow!("OUT_DIR not set: {e}"))?, + )) +} +fn main() -> Result<()> { + #[cfg(windows)] + { + let out_dir = out_dir()?; + let def_file = PathBuf::from_str("src/qemu_plugin_api.def")?; + let def_file_str = def_file.to_string_lossy(); + let lib_file = out_dir.join("qemu_plugin_api.lib"); + let lib_file_str = lib_file.to_string_lossy(); + let ch = std::process::Command::new("dlltool") + .args([ + "--input-def", + &def_file_str, + "--output-delaylib", + &lib_file_str, + "--dllname", + "qemu.exe", + ]) + .spawn()? + .wait()?; + if !ch.success() { + return Err(anyhow!("dlltool failed")); + } + println!("cargo:rustc-link-search={}", out_dir.display()); + println!("cargo:rustc-link-lib=qemu_plugin_api"); + } + Ok(()) +} diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index bcc53a6..07043a5 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -1,6 +1,8 @@ -#!/usr/bin/env -S cargo +nightly -Z script +#!/usr/bin/env -S cargo +nightly-gnu -Z script //! ```cargo +//! [package] +//! edition = "2021" //! [dependencies] //! anyhow = "*" //! bindgen = "*" @@ -8,6 +10,8 @@ //! reqwest = { version = "*", features = ["blocking"] } //! tar = "*" //! xz2 = "*" +//![lints.rust] +//!non_snake_case = "allow" //! ``` use anyhow::{anyhow, Result}; @@ -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"; fn qemu_src_url() -> String { format!("{}qemu-{}.tar.xz", QEMU_SRC_URL_BASE, QEMU_VERSION) @@ -70,6 +74,14 @@ fn extract_txz(archive: &Path, destination: &Path) -> Result<()> { })?; Ok(()) } +fn generate_windows_delaylink_library(qemu_plugin_symbols: &Path, out_dir: &Path) -> Result<()> { + let def_file = out_dir.join("qemu_plugin_api.def"); + let all_commands = std::fs::read_to_string(qemu_plugin_symbols)?; + let all_commands = all_commands.replace(|x| "{};".contains(x), ""); + std::fs::write(&def_file, format!("EXPORTS\n{all_commands}"))?; + + Ok(()) +} fn generate_bindings(qemu_plugin_header: &Path, destination: &Path) -> Result<()> { let rust_bindings = builder() @@ -139,6 +151,11 @@ fn main() -> Result<()> { )?; } + generate_windows_delaylink_library( + &src_dir.join("plugins").join("qemu-plugins.symbols"), + &out_dir, + )?; + generate_bindings( &src_dir .join("include") diff --git a/qemu-plugin-sys/src/bindings.rs b/qemu-plugin-sys/src/bindings.rs index 0266839..8fed985 100644 --- a/qemu-plugin-sys/src/bindings.rs +++ b/qemu-plugin-sys/src/bindings.rs @@ -1,411 +1,450 @@ /* automatically generated by rust-bindgen 0.69.1 */ -pub const _INTTYPES_H: u32 = 1; -pub const _FEATURES_H: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const __GLIBC_USE_ISOC2X: u32 = 0; -pub const __USE_ISOC11: u32 = 1; -pub const __USE_ISOC99: u32 = 1; -pub const __USE_ISOC95: u32 = 1; -pub const __USE_POSIX_IMPLICITLY: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const __USE_POSIX: u32 = 1; -pub const __USE_POSIX2: u32 = 1; -pub const __USE_POSIX199309: u32 = 1; -pub const __USE_POSIX199506: u32 = 1; -pub const __USE_XOPEN2K: u32 = 1; -pub const __USE_XOPEN2K8: u32 = 1; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __WORDSIZE: u32 = 64; -pub const __WORDSIZE_TIME64_COMPAT32: u32 = 0; -pub const __TIMESIZE: u32 = 64; -pub const __USE_MISC: u32 = 1; -pub const __USE_ATFILE: u32 = 1; -pub const __USE_FORTIFY_LEVEL: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; -pub const __GLIBC_USE_C2X_STRTOL: u32 = 0; -pub const _STDC_PREDEF_H: u32 = 1; -pub const __STDC_IEC_559__: u32 = 1; -pub const __STDC_IEC_60559_BFP__: u32 = 201404; -pub const __STDC_IEC_559_COMPLEX__: u32 = 1; -pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404; -pub const __STDC_ISO_10646__: u32 = 201706; -pub const __GNU_LIBRARY__: u32 = 6; -pub const __GLIBC__: u32 = 2; -pub const __GLIBC_MINOR__: u32 = 38; -pub const _SYS_CDEFS_H: u32 = 1; -pub const __glibc_c99_flexarr_available: u32 = 1; -pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0; -pub const __HAVE_GENERIC_SELECTION: u32 = 1; -pub const _STDINT_H: u32 = 1; -pub const __GLIBC_USE_LIB_EXT2: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; -pub const _BITS_TYPES_H: u32 = 1; -pub const _BITS_TYPESIZES_H: u32 = 1; -pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; -pub const __INO_T_MATCHES_INO64_T: u32 = 1; -pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; -pub const __STATFS_MATCHES_STATFS64: u32 = 1; -pub const __FD_SETSIZE: u32 = 1024; -pub const _BITS_TIME64_H: u32 = 1; -pub const _BITS_WCHAR_H: u32 = 1; -pub const _BITS_STDINT_INTN_H: u32 = 1; -pub const _BITS_STDINT_UINTN_H: u32 = 1; -pub const INT8_MIN: i32 = -128; -pub const INT16_MIN: i32 = -32768; -pub const INT32_MIN: i32 = -2147483648; -pub const INT8_MAX: u32 = 127; -pub const INT16_MAX: u32 = 32767; -pub const INT32_MAX: u32 = 2147483647; -pub const UINT8_MAX: u32 = 255; -pub const UINT16_MAX: u32 = 65535; -pub const UINT32_MAX: u32 = 4294967295; -pub const INT_LEAST8_MIN: i32 = -128; -pub const INT_LEAST16_MIN: i32 = -32768; -pub const INT_LEAST32_MIN: i32 = -2147483648; -pub const INT_LEAST8_MAX: u32 = 127; -pub const INT_LEAST16_MAX: u32 = 32767; -pub const INT_LEAST32_MAX: u32 = 2147483647; -pub const UINT_LEAST8_MAX: u32 = 255; -pub const UINT_LEAST16_MAX: u32 = 65535; -pub const UINT_LEAST32_MAX: u32 = 4294967295; -pub const INT_FAST8_MIN: i32 = -128; -pub const INT_FAST16_MIN: i64 = -9223372036854775808; -pub const INT_FAST32_MIN: i64 = -9223372036854775808; -pub const INT_FAST8_MAX: u32 = 127; -pub const INT_FAST16_MAX: u64 = 9223372036854775807; -pub const INT_FAST32_MAX: u64 = 9223372036854775807; -pub const UINT_FAST8_MAX: u32 = 255; -pub const UINT_FAST16_MAX: i32 = -1; -pub const UINT_FAST32_MAX: i32 = -1; -pub const INTPTR_MIN: i64 = -9223372036854775808; -pub const INTPTR_MAX: u64 = 9223372036854775807; -pub const UINTPTR_MAX: i32 = -1; -pub const PTRDIFF_MIN: i64 = -9223372036854775808; -pub const PTRDIFF_MAX: u64 = 9223372036854775807; -pub const SIG_ATOMIC_MIN: i32 = -2147483648; -pub const SIG_ATOMIC_MAX: u32 = 2147483647; -pub const SIZE_MAX: i32 = -1; +pub const _VCRT_COMPILER_PREPROCESSOR: u32 = 1; +pub const _SAL_VERSION: u32 = 20; +pub const __SAL_H_VERSION: u32 = 180000000; +pub const _USE_DECLSPECS_FOR_SAL: u32 = 0; +pub const _USE_ATTRIBUTES_FOR_SAL: u32 = 0; +pub const _CRT_PACKING: u32 = 8; +pub const _HAS_EXCEPTIONS: u32 = 1; +pub const _STL_LANG: u32 = 0; +pub const _HAS_CXX17: u32 = 0; +pub const _HAS_CXX20: u32 = 0; +pub const _HAS_CXX23: u32 = 0; +pub const _HAS_NODISCARD: u32 = 0; +pub const _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE: u32 = 1; +pub const _CRT_BUILD_DESKTOP_APP: u32 = 1; +pub const _ARGMAX: u32 = 100; +pub const _CRT_INT_MAX: u32 = 2147483647; +pub const _CRT_FUNCTIONS_REQUIRED: u32 = 1; +pub const _CRT_HAS_CXX17: u32 = 0; +pub const _CRT_HAS_C11: u32 = 1; +pub const _CRT_INTERNAL_NONSTDC_NAMES: u32 = 1; +pub const __STDC_SECURE_LIB__: u32 = 200411; +pub const __GOT_SECURE_LIB__: u32 = 200411; +pub const __STDC_WANT_SECURE_LIB__: u32 = 1; +pub const _SECURECRT_FILL_BUFFER_PATTERN: u32 = 254; +pub const _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES: u32 = 0; +pub const _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT: u32 = 0; +pub const _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES: u32 = 1; +pub const _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY: u32 = 0; +pub const _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY: u32 = 0; +pub const WCHAR_MIN: u32 = 0; +pub const WCHAR_MAX: u32 = 65535; pub const WINT_MIN: u32 = 0; -pub const WINT_MAX: u32 = 4294967295; -pub const ____gwchar_t_defined: u32 = 1; -pub const __PRI64_PREFIX: &[u8; 2] = b"l\0"; -pub const __PRIPTR_PREFIX: &[u8; 2] = b"l\0"; -pub const PRId8: &[u8; 2] = b"d\0"; -pub const PRId16: &[u8; 2] = b"d\0"; +pub const WINT_MAX: u32 = 65535; +pub const PRId8: &[u8; 4] = b"hhd\0"; +pub const PRId16: &[u8; 3] = b"hd\0"; pub const PRId32: &[u8; 2] = b"d\0"; -pub const PRId64: &[u8; 3] = b"ld\0"; -pub const PRIdLEAST8: &[u8; 2] = b"d\0"; -pub const PRIdLEAST16: &[u8; 2] = b"d\0"; +pub const PRId64: &[u8; 4] = b"lld\0"; +pub const PRIdLEAST8: &[u8; 4] = b"hhd\0"; +pub const PRIdLEAST16: &[u8; 3] = b"hd\0"; pub const PRIdLEAST32: &[u8; 2] = b"d\0"; -pub const PRIdLEAST64: &[u8; 3] = b"ld\0"; -pub const PRIdFAST8: &[u8; 2] = b"d\0"; -pub const PRIdFAST16: &[u8; 3] = b"ld\0"; -pub const PRIdFAST32: &[u8; 3] = b"ld\0"; -pub const PRIdFAST64: &[u8; 3] = b"ld\0"; -pub const PRIi8: &[u8; 2] = b"i\0"; -pub const PRIi16: &[u8; 2] = b"i\0"; +pub const PRIdLEAST64: &[u8; 4] = b"lld\0"; +pub const PRIdFAST8: &[u8; 4] = b"hhd\0"; +pub const PRIdFAST16: &[u8; 2] = b"d\0"; +pub const PRIdFAST32: &[u8; 2] = b"d\0"; +pub const PRIdFAST64: &[u8; 4] = b"lld\0"; +pub const PRIdMAX: &[u8; 4] = b"lld\0"; +pub const PRIdPTR: &[u8; 4] = b"lld\0"; +pub const PRIi8: &[u8; 4] = b"hhi\0"; +pub const PRIi16: &[u8; 3] = b"hi\0"; pub const PRIi32: &[u8; 2] = b"i\0"; -pub const PRIi64: &[u8; 3] = b"li\0"; -pub const PRIiLEAST8: &[u8; 2] = b"i\0"; -pub const PRIiLEAST16: &[u8; 2] = b"i\0"; +pub const PRIi64: &[u8; 4] = b"lli\0"; +pub const PRIiLEAST8: &[u8; 4] = b"hhi\0"; +pub const PRIiLEAST16: &[u8; 3] = b"hi\0"; pub const PRIiLEAST32: &[u8; 2] = b"i\0"; -pub const PRIiLEAST64: &[u8; 3] = b"li\0"; -pub const PRIiFAST8: &[u8; 2] = b"i\0"; -pub const PRIiFAST16: &[u8; 3] = b"li\0"; -pub const PRIiFAST32: &[u8; 3] = b"li\0"; -pub const PRIiFAST64: &[u8; 3] = b"li\0"; -pub const PRIo8: &[u8; 2] = b"o\0"; -pub const PRIo16: &[u8; 2] = b"o\0"; +pub const PRIiLEAST64: &[u8; 4] = b"lli\0"; +pub const PRIiFAST8: &[u8; 4] = b"hhi\0"; +pub const PRIiFAST16: &[u8; 2] = b"i\0"; +pub const PRIiFAST32: &[u8; 2] = b"i\0"; +pub const PRIiFAST64: &[u8; 4] = b"lli\0"; +pub const PRIiMAX: &[u8; 4] = b"lli\0"; +pub const PRIiPTR: &[u8; 4] = b"lli\0"; +pub const PRIo8: &[u8; 4] = b"hho\0"; +pub const PRIo16: &[u8; 3] = b"ho\0"; pub const PRIo32: &[u8; 2] = b"o\0"; -pub const PRIo64: &[u8; 3] = b"lo\0"; -pub const PRIoLEAST8: &[u8; 2] = b"o\0"; -pub const PRIoLEAST16: &[u8; 2] = b"o\0"; +pub const PRIo64: &[u8; 4] = b"llo\0"; +pub const PRIoLEAST8: &[u8; 4] = b"hho\0"; +pub const PRIoLEAST16: &[u8; 3] = b"ho\0"; pub const PRIoLEAST32: &[u8; 2] = b"o\0"; -pub const PRIoLEAST64: &[u8; 3] = b"lo\0"; -pub const PRIoFAST8: &[u8; 2] = b"o\0"; -pub const PRIoFAST16: &[u8; 3] = b"lo\0"; -pub const PRIoFAST32: &[u8; 3] = b"lo\0"; -pub const PRIoFAST64: &[u8; 3] = b"lo\0"; -pub const PRIu8: &[u8; 2] = b"u\0"; -pub const PRIu16: &[u8; 2] = b"u\0"; +pub const PRIoLEAST64: &[u8; 4] = b"llo\0"; +pub const PRIoFAST8: &[u8; 4] = b"hho\0"; +pub const PRIoFAST16: &[u8; 2] = b"o\0"; +pub const PRIoFAST32: &[u8; 2] = b"o\0"; +pub const PRIoFAST64: &[u8; 4] = b"llo\0"; +pub const PRIoMAX: &[u8; 4] = b"llo\0"; +pub const PRIoPTR: &[u8; 4] = b"llo\0"; +pub const PRIu8: &[u8; 4] = b"hhu\0"; +pub const PRIu16: &[u8; 3] = b"hu\0"; pub const PRIu32: &[u8; 2] = b"u\0"; -pub const PRIu64: &[u8; 3] = b"lu\0"; -pub const PRIuLEAST8: &[u8; 2] = b"u\0"; -pub const PRIuLEAST16: &[u8; 2] = b"u\0"; +pub const PRIu64: &[u8; 4] = b"llu\0"; +pub const PRIuLEAST8: &[u8; 4] = b"hhu\0"; +pub const PRIuLEAST16: &[u8; 3] = b"hu\0"; pub const PRIuLEAST32: &[u8; 2] = b"u\0"; -pub const PRIuLEAST64: &[u8; 3] = b"lu\0"; -pub const PRIuFAST8: &[u8; 2] = b"u\0"; -pub const PRIuFAST16: &[u8; 3] = b"lu\0"; -pub const PRIuFAST32: &[u8; 3] = b"lu\0"; -pub const PRIuFAST64: &[u8; 3] = b"lu\0"; -pub const PRIx8: &[u8; 2] = b"x\0"; -pub const PRIx16: &[u8; 2] = b"x\0"; +pub const PRIuLEAST64: &[u8; 4] = b"llu\0"; +pub const PRIuFAST8: &[u8; 4] = b"hhu\0"; +pub const PRIuFAST16: &[u8; 2] = b"u\0"; +pub const PRIuFAST32: &[u8; 2] = b"u\0"; +pub const PRIuFAST64: &[u8; 4] = b"llu\0"; +pub const PRIuMAX: &[u8; 4] = b"llu\0"; +pub const PRIuPTR: &[u8; 4] = b"llu\0"; +pub const PRIx8: &[u8; 4] = b"hhx\0"; +pub const PRIx16: &[u8; 3] = b"hx\0"; pub const PRIx32: &[u8; 2] = b"x\0"; -pub const PRIx64: &[u8; 3] = b"lx\0"; -pub const PRIxLEAST8: &[u8; 2] = b"x\0"; -pub const PRIxLEAST16: &[u8; 2] = b"x\0"; +pub const PRIx64: &[u8; 4] = b"llx\0"; +pub const PRIxLEAST8: &[u8; 4] = b"hhx\0"; +pub const PRIxLEAST16: &[u8; 3] = b"hx\0"; pub const PRIxLEAST32: &[u8; 2] = b"x\0"; -pub const PRIxLEAST64: &[u8; 3] = b"lx\0"; -pub const PRIxFAST8: &[u8; 2] = b"x\0"; -pub const PRIxFAST16: &[u8; 3] = b"lx\0"; -pub const PRIxFAST32: &[u8; 3] = b"lx\0"; -pub const PRIxFAST64: &[u8; 3] = b"lx\0"; -pub const PRIX8: &[u8; 2] = b"X\0"; -pub const PRIX16: &[u8; 2] = b"X\0"; +pub const PRIxLEAST64: &[u8; 4] = b"llx\0"; +pub const PRIxFAST8: &[u8; 4] = b"hhx\0"; +pub const PRIxFAST16: &[u8; 2] = b"x\0"; +pub const PRIxFAST32: &[u8; 2] = b"x\0"; +pub const PRIxFAST64: &[u8; 4] = b"llx\0"; +pub const PRIxMAX: &[u8; 4] = b"llx\0"; +pub const PRIxPTR: &[u8; 4] = b"llx\0"; +pub const PRIX8: &[u8; 4] = b"hhX\0"; +pub const PRIX16: &[u8; 3] = b"hX\0"; pub const PRIX32: &[u8; 2] = b"X\0"; -pub const PRIX64: &[u8; 3] = b"lX\0"; -pub const PRIXLEAST8: &[u8; 2] = b"X\0"; -pub const PRIXLEAST16: &[u8; 2] = b"X\0"; +pub const PRIX64: &[u8; 4] = b"llX\0"; +pub const PRIXLEAST8: &[u8; 4] = b"hhX\0"; +pub const PRIXLEAST16: &[u8; 3] = b"hX\0"; pub const PRIXLEAST32: &[u8; 2] = b"X\0"; -pub const PRIXLEAST64: &[u8; 3] = b"lX\0"; -pub const PRIXFAST8: &[u8; 2] = b"X\0"; -pub const PRIXFAST16: &[u8; 3] = b"lX\0"; -pub const PRIXFAST32: &[u8; 3] = b"lX\0"; -pub const PRIXFAST64: &[u8; 3] = b"lX\0"; -pub const PRIdMAX: &[u8; 3] = b"ld\0"; -pub const PRIiMAX: &[u8; 3] = b"li\0"; -pub const PRIoMAX: &[u8; 3] = b"lo\0"; -pub const PRIuMAX: &[u8; 3] = b"lu\0"; -pub const PRIxMAX: &[u8; 3] = b"lx\0"; -pub const PRIXMAX: &[u8; 3] = b"lX\0"; -pub const PRIdPTR: &[u8; 3] = b"ld\0"; -pub const PRIiPTR: &[u8; 3] = b"li\0"; -pub const PRIoPTR: &[u8; 3] = b"lo\0"; -pub const PRIuPTR: &[u8; 3] = b"lu\0"; -pub const PRIxPTR: &[u8; 3] = b"lx\0"; -pub const PRIXPTR: &[u8; 3] = b"lX\0"; +pub const PRIXLEAST64: &[u8; 4] = b"llX\0"; +pub const PRIXFAST8: &[u8; 4] = b"hhX\0"; +pub const PRIXFAST16: &[u8; 2] = b"X\0"; +pub const PRIXFAST32: &[u8; 2] = b"X\0"; +pub const PRIXFAST64: &[u8; 4] = b"llX\0"; +pub const PRIXMAX: &[u8; 4] = b"llX\0"; +pub const PRIXPTR: &[u8; 4] = b"llX\0"; pub const SCNd8: &[u8; 4] = b"hhd\0"; pub const SCNd16: &[u8; 3] = b"hd\0"; pub const SCNd32: &[u8; 2] = b"d\0"; -pub const SCNd64: &[u8; 3] = b"ld\0"; +pub const SCNd64: &[u8; 4] = b"lld\0"; pub const SCNdLEAST8: &[u8; 4] = b"hhd\0"; pub const SCNdLEAST16: &[u8; 3] = b"hd\0"; pub const SCNdLEAST32: &[u8; 2] = b"d\0"; -pub const SCNdLEAST64: &[u8; 3] = b"ld\0"; +pub const SCNdLEAST64: &[u8; 4] = b"lld\0"; pub const SCNdFAST8: &[u8; 4] = b"hhd\0"; -pub const SCNdFAST16: &[u8; 3] = b"ld\0"; -pub const SCNdFAST32: &[u8; 3] = b"ld\0"; -pub const SCNdFAST64: &[u8; 3] = b"ld\0"; +pub const SCNdFAST16: &[u8; 2] = b"d\0"; +pub const SCNdFAST32: &[u8; 2] = b"d\0"; +pub const SCNdFAST64: &[u8; 4] = b"lld\0"; +pub const SCNdMAX: &[u8; 4] = b"lld\0"; +pub const SCNdPTR: &[u8; 4] = b"lld\0"; pub const SCNi8: &[u8; 4] = b"hhi\0"; pub const SCNi16: &[u8; 3] = b"hi\0"; pub const SCNi32: &[u8; 2] = b"i\0"; -pub const SCNi64: &[u8; 3] = b"li\0"; +pub const SCNi64: &[u8; 4] = b"lli\0"; pub const SCNiLEAST8: &[u8; 4] = b"hhi\0"; pub const SCNiLEAST16: &[u8; 3] = b"hi\0"; pub const SCNiLEAST32: &[u8; 2] = b"i\0"; -pub const SCNiLEAST64: &[u8; 3] = b"li\0"; +pub const SCNiLEAST64: &[u8; 4] = b"lli\0"; pub const SCNiFAST8: &[u8; 4] = b"hhi\0"; -pub const SCNiFAST16: &[u8; 3] = b"li\0"; -pub const SCNiFAST32: &[u8; 3] = b"li\0"; -pub const SCNiFAST64: &[u8; 3] = b"li\0"; -pub const SCNu8: &[u8; 4] = b"hhu\0"; -pub const SCNu16: &[u8; 3] = b"hu\0"; -pub const SCNu32: &[u8; 2] = b"u\0"; -pub const SCNu64: &[u8; 3] = b"lu\0"; -pub const SCNuLEAST8: &[u8; 4] = b"hhu\0"; -pub const SCNuLEAST16: &[u8; 3] = b"hu\0"; -pub const SCNuLEAST32: &[u8; 2] = b"u\0"; -pub const SCNuLEAST64: &[u8; 3] = b"lu\0"; -pub const SCNuFAST8: &[u8; 4] = b"hhu\0"; -pub const SCNuFAST16: &[u8; 3] = b"lu\0"; -pub const SCNuFAST32: &[u8; 3] = b"lu\0"; -pub const SCNuFAST64: &[u8; 3] = b"lu\0"; +pub const SCNiFAST16: &[u8; 2] = b"i\0"; +pub const SCNiFAST32: &[u8; 2] = b"i\0"; +pub const SCNiFAST64: &[u8; 4] = b"lli\0"; +pub const SCNiMAX: &[u8; 4] = b"lli\0"; +pub const SCNiPTR: &[u8; 4] = b"lli\0"; pub const SCNo8: &[u8; 4] = b"hho\0"; pub const SCNo16: &[u8; 3] = b"ho\0"; pub const SCNo32: &[u8; 2] = b"o\0"; -pub const SCNo64: &[u8; 3] = b"lo\0"; +pub const SCNo64: &[u8; 4] = b"llo\0"; pub const SCNoLEAST8: &[u8; 4] = b"hho\0"; pub const SCNoLEAST16: &[u8; 3] = b"ho\0"; pub const SCNoLEAST32: &[u8; 2] = b"o\0"; -pub const SCNoLEAST64: &[u8; 3] = b"lo\0"; +pub const SCNoLEAST64: &[u8; 4] = b"llo\0"; pub const SCNoFAST8: &[u8; 4] = b"hho\0"; -pub const SCNoFAST16: &[u8; 3] = b"lo\0"; -pub const SCNoFAST32: &[u8; 3] = b"lo\0"; -pub const SCNoFAST64: &[u8; 3] = b"lo\0"; +pub const SCNoFAST16: &[u8; 2] = b"o\0"; +pub const SCNoFAST32: &[u8; 2] = b"o\0"; +pub const SCNoFAST64: &[u8; 4] = b"llo\0"; +pub const SCNoMAX: &[u8; 4] = b"llo\0"; +pub const SCNoPTR: &[u8; 4] = b"llo\0"; +pub const SCNu8: &[u8; 4] = b"hhu\0"; +pub const SCNu16: &[u8; 3] = b"hu\0"; +pub const SCNu32: &[u8; 2] = b"u\0"; +pub const SCNu64: &[u8; 4] = b"llu\0"; +pub const SCNuLEAST8: &[u8; 4] = b"hhu\0"; +pub const SCNuLEAST16: &[u8; 3] = b"hu\0"; +pub const SCNuLEAST32: &[u8; 2] = b"u\0"; +pub const SCNuLEAST64: &[u8; 4] = b"llu\0"; +pub const SCNuFAST8: &[u8; 4] = b"hhu\0"; +pub const SCNuFAST16: &[u8; 2] = b"u\0"; +pub const SCNuFAST32: &[u8; 2] = b"u\0"; +pub const SCNuFAST64: &[u8; 4] = b"llu\0"; +pub const SCNuMAX: &[u8; 4] = b"llu\0"; +pub const SCNuPTR: &[u8; 4] = b"llu\0"; pub const SCNx8: &[u8; 4] = b"hhx\0"; pub const SCNx16: &[u8; 3] = b"hx\0"; pub const SCNx32: &[u8; 2] = b"x\0"; -pub const SCNx64: &[u8; 3] = b"lx\0"; +pub const SCNx64: &[u8; 4] = b"llx\0"; pub const SCNxLEAST8: &[u8; 4] = b"hhx\0"; pub const SCNxLEAST16: &[u8; 3] = b"hx\0"; pub const SCNxLEAST32: &[u8; 2] = b"x\0"; -pub const SCNxLEAST64: &[u8; 3] = b"lx\0"; +pub const SCNxLEAST64: &[u8; 4] = b"llx\0"; pub const SCNxFAST8: &[u8; 4] = b"hhx\0"; -pub const SCNxFAST16: &[u8; 3] = b"lx\0"; -pub const SCNxFAST32: &[u8; 3] = b"lx\0"; -pub const SCNxFAST64: &[u8; 3] = b"lx\0"; -pub const SCNdMAX: &[u8; 3] = b"ld\0"; -pub const SCNiMAX: &[u8; 3] = b"li\0"; -pub const SCNoMAX: &[u8; 3] = b"lo\0"; -pub const SCNuMAX: &[u8; 3] = b"lu\0"; -pub const SCNxMAX: &[u8; 3] = b"lx\0"; -pub const SCNdPTR: &[u8; 3] = b"ld\0"; -pub const SCNiPTR: &[u8; 3] = b"li\0"; -pub const SCNoPTR: &[u8; 3] = b"lo\0"; -pub const SCNuPTR: &[u8; 3] = b"lu\0"; -pub const SCNxPTR: &[u8; 3] = b"lx\0"; +pub const SCNxFAST16: &[u8; 2] = b"x\0"; +pub const SCNxFAST32: &[u8; 2] = b"x\0"; +pub const SCNxFAST64: &[u8; 4] = b"llx\0"; +pub const SCNxMAX: &[u8; 4] = b"llx\0"; +pub const SCNxPTR: &[u8; 4] = b"llx\0"; pub const __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; pub const QEMU_PLUGIN_VERSION: u32 = 1; -#[doc = " Convenience types."] -pub type __u_char = ::std::os::raw::c_uchar; -pub type __u_short = ::std::os::raw::c_ushort; -pub type __u_int = ::std::os::raw::c_uint; -pub type __u_long = ::std::os::raw::c_ulong; -#[doc = " Fixed-size types, underlying types depend on word size and compiler."] -pub type __int8_t = ::std::os::raw::c_schar; -pub type __uint8_t = ::std::os::raw::c_uchar; -pub type __int16_t = ::std::os::raw::c_short; -pub type __uint16_t = ::std::os::raw::c_ushort; -pub type __int32_t = ::std::os::raw::c_int; -pub type __uint32_t = ::std::os::raw::c_uint; -pub type __int64_t = ::std::os::raw::c_long; -pub type __uint64_t = ::std::os::raw::c_ulong; -#[doc = " Smallest types with at least a given width."] -pub type __int_least8_t = __int8_t; -pub type __uint_least8_t = __uint8_t; -pub type __int_least16_t = __int16_t; -pub type __uint_least16_t = __uint16_t; -pub type __int_least32_t = __int32_t; -pub type __uint_least32_t = __uint32_t; -pub type __int_least64_t = __int64_t; -pub type __uint_least64_t = __uint64_t; -pub type __quad_t = ::std::os::raw::c_long; -pub type __u_quad_t = ::std::os::raw::c_ulong; -pub type __intmax_t = ::std::os::raw::c_long; -pub type __uintmax_t = ::std::os::raw::c_ulong; -pub type __dev_t = ::std::os::raw::c_ulong; -pub type __uid_t = ::std::os::raw::c_uint; -pub type __gid_t = ::std::os::raw::c_uint; -pub type __ino_t = ::std::os::raw::c_ulong; -pub type __ino64_t = ::std::os::raw::c_ulong; -pub type __mode_t = ::std::os::raw::c_uint; -pub type __nlink_t = ::std::os::raw::c_uint; -pub type __off_t = ::std::os::raw::c_long; -pub type __off64_t = ::std::os::raw::c_long; -pub type __pid_t = ::std::os::raw::c_int; +pub type va_list = *mut ::std::os::raw::c_char; +extern "C" { + pub fn __va_start(arg1: *mut *mut ::std::os::raw::c_char, ...); +} +pub type __vcrt_bool = bool; +pub type wchar_t = ::std::os::raw::c_ushort; +extern "C" { + pub fn __security_init_cookie(); +} +extern "C" { + pub fn __security_check_cookie(_StackCookie: usize); +} +extern "C" { + pub fn __report_gsfailure(_StackCookie: usize) -> !; +} +extern "C" { + pub static mut __security_cookie: usize; +} +pub type __crt_bool = bool; +extern "C" { + pub fn _invalid_parameter_noinfo(); +} +extern "C" { + pub fn _invalid_parameter_noinfo_noreturn() -> !; +} +extern "C" { + pub fn _invoke_watson( + _Expression: *const wchar_t, + _FunctionName: *const wchar_t, + _FileName: *const wchar_t, + _LineNo: ::std::os::raw::c_uint, + _Reserved: usize, + ) -> !; +} +#[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Basic Types\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] +pub type errno_t = ::std::os::raw::c_int; +pub type wint_t = ::std::os::raw::c_ushort; +pub type wctype_t = ::std::os::raw::c_ushort; +pub type __time32_t = ::std::os::raw::c_long; +pub type __time64_t = ::std::os::raw::c_longlong; +#[repr(C)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub struct __crt_locale_data_public { + pub _locale_pctype: *const ::std::os::raw::c_ushort, + pub _locale_mb_cur_max: ::std::os::raw::c_int, + pub _locale_lc_codepage: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout___crt_locale_data_public() { + const UNINIT: ::std::mem::MaybeUninit<__crt_locale_data_public> = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__crt_locale_data_public>(), + 16usize, + concat!("Size of: ", stringify!(__crt_locale_data_public)) + ); + assert_eq!( + ::std::mem::align_of::<__crt_locale_data_public>(), + 8usize, + concat!("Alignment of ", stringify!(__crt_locale_data_public)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._locale_pctype) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__crt_locale_data_public), + "::", + stringify!(_locale_pctype) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._locale_mb_cur_max) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__crt_locale_data_public), + "::", + stringify!(_locale_mb_cur_max) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._locale_lc_codepage) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(__crt_locale_data_public), + "::", + stringify!(_locale_lc_codepage) + ) + ); +} +impl Default for __crt_locale_data_public { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub struct __crt_locale_pointers { + pub locinfo: *mut __crt_locale_data, + pub mbcinfo: *mut __crt_multibyte_data, +} +#[test] +fn bindgen_test_layout___crt_locale_pointers() { + const UNINIT: ::std::mem::MaybeUninit<__crt_locale_pointers> = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__crt_locale_pointers>(), + 16usize, + concat!("Size of: ", stringify!(__crt_locale_pointers)) + ); + assert_eq!( + ::std::mem::align_of::<__crt_locale_pointers>(), + 8usize, + concat!("Alignment of ", stringify!(__crt_locale_pointers)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).locinfo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__crt_locale_pointers), + "::", + stringify!(locinfo) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).mbcinfo) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__crt_locale_pointers), + "::", + stringify!(mbcinfo) + ) + ); +} +impl Default for __crt_locale_pointers { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type _locale_t = *mut __crt_locale_pointers; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct __fsid_t { - pub __val: [::std::os::raw::c_int; 2usize], +pub struct _Mbstatet { + pub _Wchar: ::std::os::raw::c_ulong, + pub _Byte: ::std::os::raw::c_ushort, + pub _State: ::std::os::raw::c_ushort, } #[test] -fn bindgen_test_layout___fsid_t() { - const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); +fn bindgen_test_layout__Mbstatet() { + const UNINIT: ::std::mem::MaybeUninit<_Mbstatet> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<__fsid_t>(), + ::std::mem::size_of::<_Mbstatet>(), 8usize, - concat!("Size of: ", stringify!(__fsid_t)) + concat!("Size of: ", stringify!(_Mbstatet)) ); assert_eq!( - ::std::mem::align_of::<__fsid_t>(), + ::std::mem::align_of::<_Mbstatet>(), 4usize, - concat!("Alignment of ", stringify!(__fsid_t)) + concat!("Alignment of ", stringify!(_Mbstatet)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr)._Wchar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(__fsid_t), + stringify!(_Mbstatet), + "::", + stringify!(_Wchar) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._Byte) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(_Mbstatet), + "::", + stringify!(_Byte) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._State) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(_Mbstatet), "::", - stringify!(__val) + stringify!(_State) ) ); } -pub type __clock_t = ::std::os::raw::c_long; -pub type __rlim_t = ::std::os::raw::c_ulong; -pub type __rlim64_t = ::std::os::raw::c_ulong; -pub type __id_t = ::std::os::raw::c_uint; -pub type __time_t = ::std::os::raw::c_long; -pub type __useconds_t = ::std::os::raw::c_uint; -pub type __suseconds_t = ::std::os::raw::c_long; -pub type __suseconds64_t = ::std::os::raw::c_long; -pub type __daddr_t = ::std::os::raw::c_int; -pub type __key_t = ::std::os::raw::c_int; -pub type __clockid_t = ::std::os::raw::c_int; -pub type __timer_t = *mut ::std::os::raw::c_void; -pub type __blksize_t = ::std::os::raw::c_int; -pub type __blkcnt_t = ::std::os::raw::c_long; -pub type __blkcnt64_t = ::std::os::raw::c_long; -pub type __fsblkcnt_t = ::std::os::raw::c_ulong; -pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; -pub type __fsword_t = ::std::os::raw::c_long; -pub type __ssize_t = ::std::os::raw::c_long; -pub type __syscall_slong_t = ::std::os::raw::c_long; -pub type __syscall_ulong_t = ::std::os::raw::c_ulong; -#[doc = " These few don't really vary by system, they always correspond\nto one of the other defined types."] -pub type __loff_t = __off64_t; -pub type __caddr_t = *mut ::std::os::raw::c_char; -pub type __intptr_t = ::std::os::raw::c_long; -pub type __socklen_t = ::std::os::raw::c_uint; -#[doc = " C99: An integer type that can be accessed as an atomic entity,\neven in the presence of asynchronous interrupts.\nIt is not currently necessary for this to be machine-specific."] -pub type __sig_atomic_t = ::std::os::raw::c_int; -#[doc = " Signed."] -pub type int_least8_t = __int_least8_t; -pub type int_least16_t = __int_least16_t; -pub type int_least32_t = __int_least32_t; -pub type int_least64_t = __int_least64_t; -#[doc = " Unsigned."] -pub type uint_least8_t = __uint_least8_t; -pub type uint_least16_t = __uint_least16_t; -pub type uint_least32_t = __uint_least32_t; -pub type uint_least64_t = __uint_least64_t; -#[doc = " Signed."] +pub type mbstate_t = _Mbstatet; +pub type time_t = __time64_t; +pub type rsize_t = usize; +pub type int_least8_t = ::std::os::raw::c_schar; +pub type int_least16_t = ::std::os::raw::c_short; +pub type int_least32_t = ::std::os::raw::c_int; +pub type int_least64_t = ::std::os::raw::c_longlong; +pub type uint_least8_t = ::std::os::raw::c_uchar; +pub type uint_least16_t = ::std::os::raw::c_ushort; +pub type uint_least32_t = ::std::os::raw::c_uint; +pub type uint_least64_t = ::std::os::raw::c_ulonglong; pub type int_fast8_t = ::std::os::raw::c_schar; -pub type int_fast16_t = ::std::os::raw::c_long; -pub type int_fast32_t = ::std::os::raw::c_long; -pub type int_fast64_t = ::std::os::raw::c_long; -#[doc = " Unsigned."] +pub type int_fast16_t = ::std::os::raw::c_int; +pub type int_fast32_t = ::std::os::raw::c_int; +pub type int_fast64_t = ::std::os::raw::c_longlong; pub type uint_fast8_t = ::std::os::raw::c_uchar; -pub type uint_fast16_t = ::std::os::raw::c_ulong; -pub type uint_fast32_t = ::std::os::raw::c_ulong; -pub type uint_fast64_t = ::std::os::raw::c_ulong; -#[doc = " Largest integral types."] -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type __gwchar_t = ::std::os::raw::c_uint; -#[doc = " We have to define the `uintmax_t' type using `ldiv_t'."] +pub type uint_fast16_t = ::std::os::raw::c_uint; +pub type uint_fast32_t = ::std::os::raw::c_uint; +pub type uint_fast64_t = ::std::os::raw::c_ulonglong; +pub type intmax_t = ::std::os::raw::c_longlong; +pub type uintmax_t = ::std::os::raw::c_ulonglong; +#[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Types\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct imaxdiv_t { - #[doc = " Quotient."] - pub quot: ::std::os::raw::c_long, - #[doc = " Remainder."] - pub rem: ::std::os::raw::c_long, +pub struct _Lldiv_t { + pub quot: intmax_t, + pub rem: intmax_t, } #[test] -fn bindgen_test_layout_imaxdiv_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); +fn bindgen_test_layout__Lldiv_t() { + const UNINIT: ::std::mem::MaybeUninit<_Lldiv_t> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::<_Lldiv_t>(), 16usize, - concat!("Size of: ", stringify!(imaxdiv_t)) + concat!("Size of: ", stringify!(_Lldiv_t)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::<_Lldiv_t>(), 8usize, - concat!("Alignment of ", stringify!(imaxdiv_t)) + concat!("Alignment of ", stringify!(_Lldiv_t)) ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).quot) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(imaxdiv_t), + stringify!(_Lldiv_t), "::", stringify!(quot) ) @@ -415,97 +454,82 @@ fn bindgen_test_layout_imaxdiv_t() { 8usize, concat!( "Offset of field: ", - stringify!(imaxdiv_t), + stringify!(_Lldiv_t), "::", stringify!(rem) ) ); } +#[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Types\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] +pub type imaxdiv_t = _Lldiv_t; extern "C" { - #[doc = " Compute absolute value of N."] - pub fn imaxabs(__n: intmax_t) -> intmax_t; + #[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Functions\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] + pub fn imaxabs(_Number: intmax_t) -> intmax_t; } extern "C" { - #[doc = " Return the `imaxdiv_t' representation of the value of NUMER over DENOM."] - pub fn imaxdiv(__numer: intmax_t, __denom: intmax_t) -> imaxdiv_t; + pub fn imaxdiv(_Numerator: intmax_t, _Denominator: intmax_t) -> imaxdiv_t; } extern "C" { - #[doc = " Like `strtol' but convert to `intmax_t'."] pub fn strtoimax( - __nptr: *const ::std::os::raw::c_char, - __endptr: *mut *mut ::std::os::raw::c_char, - __base: ::std::os::raw::c_int, + _String: *const ::std::os::raw::c_char, + _EndPtr: *mut *mut ::std::os::raw::c_char, + _Radix: ::std::os::raw::c_int, + ) -> intmax_t; +} +extern "C" { + pub fn _strtoimax_l( + _String: *const ::std::os::raw::c_char, + _EndPtr: *mut *mut ::std::os::raw::c_char, + _Radix: ::std::os::raw::c_int, + _Locale: _locale_t, ) -> intmax_t; } extern "C" { - #[doc = " Like `strtoul' but convert to `uintmax_t'."] pub fn strtoumax( - __nptr: *const ::std::os::raw::c_char, - __endptr: *mut *mut ::std::os::raw::c_char, - __base: ::std::os::raw::c_int, + _String: *const ::std::os::raw::c_char, + _EndPtr: *mut *mut ::std::os::raw::c_char, + _Radix: ::std::os::raw::c_int, + ) -> uintmax_t; +} +extern "C" { + pub fn _strtoumax_l( + _String: *const ::std::os::raw::c_char, + _EndPtr: *mut *mut ::std::os::raw::c_char, + _Radix: ::std::os::raw::c_int, + _Locale: _locale_t, ) -> uintmax_t; } extern "C" { - #[doc = " Like `wcstol' but convert to `intmax_t'."] pub fn wcstoimax( - __nptr: *const __gwchar_t, - __endptr: *mut *mut __gwchar_t, - __base: ::std::os::raw::c_int, + _String: *const wchar_t, + _EndPtr: *mut *mut wchar_t, + _Radix: ::std::os::raw::c_int, + ) -> intmax_t; +} +extern "C" { + pub fn _wcstoimax_l( + _String: *const wchar_t, + _EndPtr: *mut *mut wchar_t, + _Radix: ::std::os::raw::c_int, + _Locale: _locale_t, ) -> intmax_t; } extern "C" { - #[doc = " Like `wcstoul' but convert to `uintmax_t'."] pub fn wcstoumax( - __nptr: *const __gwchar_t, - __endptr: *mut *mut __gwchar_t, - __base: ::std::os::raw::c_int, + _String: *const wchar_t, + _EndPtr: *mut *mut wchar_t, + _Radix: ::std::os::raw::c_int, ) -> uintmax_t; } -pub type wchar_t = ::std::os::raw::c_uint; -#[doc = " Define 'max_align_t' to match the GCC definition."] -#[repr(C)] -#[repr(align(16))] -#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: u128, -} -#[test] -fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); +extern "C" { + pub fn _wcstoumax_l( + _String: *const wchar_t, + _EndPtr: *mut *mut wchar_t, + _Radix: ::std::os::raw::c_int, + _Locale: _locale_t, + ) -> uintmax_t; } +pub type max_align_t = f64; #[doc = " typedef qemu_plugin_id_t - Unique plugin ID"] pub type qemu_plugin_id_t = u64; #[doc = " struct qemu_info_t - system information for plugins\n\n This structure provides for some limited information about the\n system to allow the plugin to make decisions on how to proceed. For\n example it might only be suitable for running on some guest\n architectures or when under full system emulation."] @@ -770,7 +794,7 @@ pub struct qemu_plugin_tb { pub struct qemu_plugin_insn { _unused: [u8; 0], } -#[repr(u32)] +#[repr(i32)] #[doc = " enum qemu_plugin_cb_flags - type of callback\n\n @QEMU_PLUGIN_CB_NO_REGS: callback does not access the CPU's regs\n @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs\n @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs\n\n Note: currently unused, plugins cannot read or change system\n register state."] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum qemu_plugin_cb_flags { @@ -778,7 +802,7 @@ pub enum qemu_plugin_cb_flags { QEMU_PLUGIN_CB_R_REGS = 1, QEMU_PLUGIN_CB_RW_REGS = 2, } -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_R = 1, @@ -804,7 +828,7 @@ extern "C" { userdata: *mut ::std::os::raw::c_void, ); } -#[repr(u32)] +#[repr(i32)] #[doc = " enum qemu_plugin_op - describes an inline op\n\n @QEMU_PLUGIN_INLINE_ADD_U64: add an immediate value uint64_t\n\n Note: currently only a single inline op is supported."] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum qemu_plugin_op { @@ -1033,3 +1057,13 @@ extern "C" { #[doc = " qemu_plugin_entry_code() - returns start address for module\n\n Returns the nominal entry address of the main text segment in\n user-mode. Currently returns 0 for system emulation."] pub fn qemu_plugin_entry_code() -> u64; } +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub struct __crt_locale_data { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub struct __crt_multibyte_data { + pub _address: u8, +} diff --git a/qemu-plugin-sys/src/qemu_plugin_api.def b/qemu-plugin-sys/src/qemu_plugin_api.def new file mode 100644 index 0000000..b13f0ea --- /dev/null +++ b/qemu-plugin-sys/src/qemu_plugin_api.def @@ -0,0 +1,46 @@ +EXPORTS + + qemu_plugin_bool_parse + qemu_plugin_end_code + qemu_plugin_entry_code + qemu_plugin_get_hwaddr + qemu_plugin_hwaddr_device_name + qemu_plugin_hwaddr_is_io + qemu_plugin_hwaddr_phys_addr + qemu_plugin_insn_data + qemu_plugin_insn_disas + qemu_plugin_insn_haddr + qemu_plugin_insn_size + qemu_plugin_insn_symbol + qemu_plugin_insn_vaddr + qemu_plugin_mem_is_big_endian + qemu_plugin_mem_is_sign_extended + qemu_plugin_mem_is_store + qemu_plugin_mem_size_shift + qemu_plugin_n_max_vcpus + qemu_plugin_n_vcpus + qemu_plugin_outs + qemu_plugin_path_to_binary + qemu_plugin_register_atexit_cb + qemu_plugin_register_flush_cb + qemu_plugin_register_vcpu_exit_cb + qemu_plugin_register_vcpu_idle_cb + qemu_plugin_register_vcpu_init_cb + qemu_plugin_register_vcpu_insn_exec_cb + qemu_plugin_register_vcpu_insn_exec_inline + qemu_plugin_register_vcpu_mem_cb + qemu_plugin_register_vcpu_mem_inline + qemu_plugin_register_vcpu_resume_cb + qemu_plugin_register_vcpu_syscall_cb + qemu_plugin_register_vcpu_syscall_ret_cb + qemu_plugin_register_vcpu_tb_exec_cb + qemu_plugin_register_vcpu_tb_exec_inline + qemu_plugin_register_vcpu_tb_trans_cb + qemu_plugin_reset + qemu_plugin_start_code + qemu_plugin_tb_get_insn + qemu_plugin_tb_n_insns + qemu_plugin_tb_vaddr + qemu_plugin_uninstall + qemu_plugin_vcpu_for_each + diff --git a/qemu-plugin/Cargo.toml b/qemu-plugin/Cargo.toml index 90394ad..77c324e 100644 --- a/qemu-plugin/Cargo.toml +++ b/qemu-plugin/Cargo.toml @@ -17,6 +17,14 @@ once_cell = "1.19.0" qemu-plugin-sys = { version = "8.1.3-v3", workspace = true } thiserror = "1.0.51" +[target.'cfg(windows)'.dependencies.windows] +version ="0.52" +features = [ + "Win32_System_WindowsProgramming", + "Win32_System_LibraryLoader", + "Win32_Foundation" +] + [features] # Define external symbols with weak definitions weak = [] diff --git a/qemu-plugin/src/lib.rs b/qemu-plugin/src/lib.rs index b8b576b..77062ca 100644 --- a/qemu-plugin/src/lib.rs +++ b/qemu-plugin/src/lib.rs @@ -95,10 +95,22 @@ pub mod install; pub mod plugin; pub mod sys; +#[cfg(windows)] +mod win_link_hook; + +#[cfg(not(windows))] extern "C" { /// glib g_free is provided by the QEMU program we are being linked into fn g_free(mem: *mut c_void); } +#[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. +} /// The index of a vCPU pub type VCPUIndex = c_uint; diff --git a/qemu-plugin/src/win_link_hook/mod.rs b/qemu-plugin/src/win_link_hook/mod.rs new file mode 100644 index 0000000..a04f928 --- /dev/null +++ b/qemu-plugin/src/win_link_hook/mod.rs @@ -0,0 +1,26 @@ +use windows::Win32::Foundation::HMODULE; +use windows::Win32::System::WindowsProgramming::DELAYLOAD_INFO; +use windows::core::PCSTR; +use windows::Win32::System::LibraryLoader::GetModuleHandleA; + +type FailureHook = unsafe extern "C" fn(dli_notify: u32, pdli: DELAYLOAD_INFO) -> HMODULE; + +#[no_mangle] +pub static __pfnDliFailureHook2 : FailureHook = delaylink_hook; + +extern "C" fn delaylink_hook(dli_notify: u32, pdli: DELAYLOAD_INFO) -> HMODULE { + if dli_notify == 3 { + let name = unsafe { pdli.TargetDllName.to_string() }.unwrap_or_default(); + if name == "qemu.exe" { + match unsafe { GetModuleHandleA(PCSTR::null())} { + Ok(h) => { + return h + } + Err(e) => { + eprintln!("Error loading top level qemu module: {e:?}"); + } + } + } + } + HMODULE::default() +} \ No newline at end of file From 378d0c7c0f16011eb245eace793f6275e6c96402 Mon Sep 17 00:00:00 2001 From: Greg Manning Date: Thu, 4 Jan 2024 16:43:58 +0000 Subject: [PATCH 2/3] hide the windows generation stuff behind cfg(win). --- qemu-plugin-sys/generate-bindings.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 07043a5..2cd4bd6 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -74,6 +74,8 @@ fn extract_txz(archive: &Path, destination: &Path) -> Result<()> { })?; Ok(()) } + +#[cfg(windows)] fn generate_windows_delaylink_library(qemu_plugin_symbols: &Path, out_dir: &Path) -> Result<()> { let def_file = out_dir.join("qemu_plugin_api.def"); let all_commands = std::fs::read_to_string(qemu_plugin_symbols)?; @@ -151,6 +153,7 @@ fn main() -> Result<()> { )?; } + #[cfg(windows)] generate_windows_delaylink_library( &src_dir.join("plugins").join("qemu-plugins.symbols"), &out_dir, From 64dd500c02c0311a7b036f83d66955f2abfb835a Mon Sep 17 00:00:00 2001 From: Greg Manning Date: Mon, 8 Jan 2024 14:45:00 +0000 Subject: [PATCH 3/3] use libc to free things. --- qemu-plugin/Cargo.toml | 1 + qemu-plugin/src/lib.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qemu-plugin/Cargo.toml b/qemu-plugin/Cargo.toml index 77c324e..af6df9a 100644 --- a/qemu-plugin/Cargo.toml +++ b/qemu-plugin/Cargo.toml @@ -16,6 +16,7 @@ anyhow = "1.0.75" once_cell = "1.19.0" qemu-plugin-sys = { version = "8.1.3-v3", workspace = true } thiserror = "1.0.51" +libc = "0.2" [target.'cfg(windows)'.dependencies.windows] version ="0.52" diff --git a/qemu-plugin/src/lib.rs b/qemu-plugin/src/lib.rs index 77062ca..5f92aa3 100644 --- a/qemu-plugin/src/lib.rs +++ b/qemu-plugin/src/lib.rs @@ -104,12 +104,20 @@ extern "C" { fn g_free(mem: *mut c_void); } #[cfg(windows)] -unsafe fn g_free(_mem: *mut c_void){ +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. + //and qemu doesn't export g_free. - //For now, we're just going to leak. + //Instead we'll rely on glib only using stdlib.h's malloc/free and call it directly. + //On glib docs, it says + //> Since GLib 2.46 g_malloc() is hardcoded to always use the system malloc implementation. + //So should be safe to call free ourselves. + unsafe { + if !mem.is_null() { + libc::free(mem); + } + } } /// The index of a vCPU