From 153a5c8256ea3b55f985bfac68f64ddf97800c63 Mon Sep 17 00:00:00 2001 From: Greg Manning Date: Thu, 4 Jan 2024 13:44:40 +0000 Subject: [PATCH 01/33] 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 02/33] 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 5d0e901801e31bd466a02b825a0ced9fffc76f08 Mon Sep 17 00:00:00 2001 From: novafacing Date: Thu, 4 Jan 2024 16:17:58 -0800 Subject: [PATCH 03/33] Format, add docstrings, move weak to more descriptive module --- qemu-plugin-sys/build.rs | 5 +-- qemu-plugin-sys/generate-bindings.rs | 35 ++++++++----------- qemu-plugin/Cargo.toml | 6 ++-- qemu-plugin/src/lib.rs | 15 ++++---- .../src/{weak.rs => unix_weak_link/mod.rs} | 3 ++ qemu-plugin/src/win_link_hook/mod.rs | 18 +++++----- qemu/build.rs | 22 ++++-------- 7 files changed, 48 insertions(+), 56 deletions(-) rename qemu-plugin/src/{weak.rs => unix_weak_link/mod.rs} (98%) diff --git a/qemu-plugin-sys/build.rs b/qemu-plugin-sys/build.rs index 3d88550..edbd9d1 100644 --- a/qemu-plugin-sys/build.rs +++ b/qemu-plugin-sys/build.rs @@ -1,11 +1,12 @@ -use std::{path::PathBuf, str::FromStr, env::var}; use anyhow::{anyhow, Result}; +use std::{env::var, path::PathBuf, process::Command, str::FromStr}; fn out_dir() -> Result { Ok(PathBuf::from( var("OUT_DIR").map_err(|e| anyhow!("OUT_DIR not set: {e}"))?, )) } + fn main() -> Result<()> { #[cfg(windows)] { @@ -14,7 +15,7 @@ fn main() -> Result<()> { 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") + let ch = Command::new("dlltool") .args([ "--input-def", &def_file_str, diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 2cd4bd6..0fe80bf 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -22,14 +22,14 @@ use bindgen::{ use cargo_metadata::MetadataCommand; use reqwest::blocking::get; use std::{ - fs::{File, OpenOptions, create_dir_all}, + fs::{create_dir_all, read_to_string, write, File, OpenOptions}, path::Path, }; use tar::Archive; use xz2::read::XzDecoder; const QEMU_SRC_URL_BASE: &str = "https://download.qemu.org/"; -const QEMU_VERSION: &str = "8.2.0"; +const QEMU_VERSION: &str = "8.1.3"; fn qemu_src_url() -> String { format!("{}qemu-{}.tar.xz", QEMU_SRC_URL_BASE, QEMU_VERSION) @@ -78,9 +78,9 @@ fn extract_txz(archive: &Path, destination: &Path) -> Result<()> { #[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)?; + let all_commands = 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}"))?; + write(&def_file, format!("EXPORTS\n{all_commands}"))?; Ok(()) } @@ -115,15 +115,17 @@ fn generate_bindings(qemu_plugin_header: &Path, destination: &Path) -> Result<() } fn main() -> Result<()> { - let metadata = MetadataCommand::new() - .no_deps() - .exec()?; + let metadata = MetadataCommand::new().no_deps().exec()?; - let package = metadata.packages.iter() + let package = metadata + .packages + .iter() .find(|p| p.name == "qemu-plugin-sys") .ok_or_else(|| anyhow!("Failed to find package"))?; - let out_dir = package.manifest_path.parent() + let out_dir = package + .manifest_path + .parent() .ok_or_else(|| anyhow!("Failed to get manifest path"))? .join("src") .into_std_path_buf(); @@ -140,17 +142,11 @@ fn main() -> Result<()> { let src_dir = tmp_dir.join(format!("qemu-{}", QEMU_VERSION)); if !src_archive.exists() { - download( - &qemu_src_url(), - &src_archive, - )?; + download(&qemu_src_url(), &src_archive)?; } if !src_dir.exists() { - extract_txz( - &src_archive, - &src_dir, - )?; + extract_txz(&src_archive, &src_dir)?; } #[cfg(windows)] @@ -160,10 +156,7 @@ fn main() -> Result<()> { )?; generate_bindings( - &src_dir - .join("include") - .join("qemu") - .join("qemu-plugin.h"), + &src_dir.join("include").join("qemu").join("qemu-plugin.h"), &out_dir.join("bindings.rs"), )?; diff --git a/qemu-plugin/Cargo.toml b/qemu-plugin/Cargo.toml index 77c324e..0b64607 100644 --- a/qemu-plugin/Cargo.toml +++ b/qemu-plugin/Cargo.toml @@ -18,13 +18,13 @@ qemu-plugin-sys = { version = "8.1.3-v3", workspace = true } thiserror = "1.0.51" [target.'cfg(windows)'.dependencies.windows] -version ="0.52" +version = "0.52" features = [ "Win32_System_WindowsProgramming", "Win32_System_LibraryLoader", - "Win32_Foundation" + "Win32_Foundation", ] [features] # Define external symbols with weak definitions -weak = [] +unix-weak-link = [] diff --git a/qemu-plugin/src/lib.rs b/qemu-plugin/src/lib.rs index 77062ca..f659181 100644 --- a/qemu-plugin/src/lib.rs +++ b/qemu-plugin/src/lib.rs @@ -71,10 +71,13 @@ //! ``` #![deny(missing_docs)] -#![cfg_attr(feature = "weak", feature(linkage))] +#![cfg_attr(all(unix, feature = "unix-weak-link"), feature(linkage))] -#[cfg(feature = "weak")] -mod weak; +#[cfg(all(unix, feature = "unix-weak-link"))] +mod unix_weak_link; + +#[cfg(windows)] +mod win_link_hook; use crate::error::{Error, Result}; use qemu_plugin_sys::{ @@ -95,16 +98,14 @@ 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){ +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. diff --git a/qemu-plugin/src/weak.rs b/qemu-plugin/src/unix_weak_link/mod.rs similarity index 98% rename from qemu-plugin/src/weak.rs rename to qemu-plugin/src/unix_weak_link/mod.rs index a3bdd29..a40a2ff 100644 --- a/qemu-plugin/src/weak.rs +++ b/qemu-plugin/src/unix_weak_link/mod.rs @@ -1,3 +1,6 @@ +//! Weak linkage for unix hosts allowing this library to be built as an rlib, leaving QEMU +//! symbols unresolved + use std::ptr::{null, null_mut}; use qemu_plugin_sys::*; diff --git a/qemu-plugin/src/win_link_hook/mod.rs b/qemu-plugin/src/win_link_hook/mod.rs index a04f928..65d6582 100644 --- a/qemu-plugin/src/win_link_hook/mod.rs +++ b/qemu-plugin/src/win_link_hook/mod.rs @@ -1,26 +1,28 @@ -use windows::Win32::Foundation::HMODULE; -use windows::Win32::System::WindowsProgramming::DELAYLOAD_INFO; +//! Hook for linking against exported QEMU symbols at runtime + use windows::core::PCSTR; +use windows::Win32::Foundation::HMODULE; use windows::Win32::System::LibraryLoader::GetModuleHandleA; +use windows::Win32::System::WindowsProgramming::DELAYLOAD_INFO; type FailureHook = unsafe extern "C" fn(dli_notify: u32, pdli: DELAYLOAD_INFO) -> HMODULE; #[no_mangle] -pub static __pfnDliFailureHook2 : FailureHook = delaylink_hook; +/// Callback invoked by Windows loader to complete linking against QEMU symbols +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 - } + 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 +} diff --git a/qemu/build.rs b/qemu/build.rs index d6f1b8c..5caa5f7 100644 --- a/qemu/build.rs +++ b/qemu/build.rs @@ -1,9 +1,12 @@ +//! Build script for QEMU binaries. Configures QEMU by converting crate features to configure +//! arguments, then builds it into the crate OUT_DIR. + use anyhow::{anyhow, Error, Result}; use command_ext::CommandExtCheck; use reqwest::blocking::get; use std::{ env::var, - fs::{File, OpenOptions, create_dir_all}, + fs::{create_dir_all, File, OpenOptions}, path::{Path, PathBuf}, process::Command, }; @@ -898,28 +901,17 @@ fn main() -> Result<()> { let build_dir = out_dir.join("qemu-build"); let install_dir = out_dir.join("qemu"); - if !src_archive.exists() { - download( - &qemu_src_url(), - &src_archive, - )?; + download(&qemu_src_url(), &src_archive)?; } if !src_dir.exists() { - extract_txz( - &src_archive, - &src_dir, - )?; + extract_txz(&src_archive, &src_dir)?; } if !build_dir.exists() { create_dir_all(&build_dir)?; - configure( - &build_dir, - &src_dir, - &install_dir, - )?; + configure(&build_dir, &src_dir, &install_dir)?; make(&build_dir)?; } From 51f2cd63a2e45c36e81d299e1a880161421f408b Mon Sep 17 00:00:00 2001 From: novafacing Date: Thu, 4 Jan 2024 16:19:23 -0800 Subject: [PATCH 04/33] Use new weak feature name in examples --- qemu-plugin/Cargo.toml | 2 +- qemu-plugin/examples/tracer/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-plugin/Cargo.toml b/qemu-plugin/Cargo.toml index 0b64607..75d603c 100644 --- a/qemu-plugin/Cargo.toml +++ b/qemu-plugin/Cargo.toml @@ -26,5 +26,5 @@ features = [ ] [features] -# Define external symbols with weak definitions +# Define external symbols with weak definition unix-weak-link = [] diff --git a/qemu-plugin/examples/tracer/Cargo.toml b/qemu-plugin/examples/tracer/Cargo.toml index 9da2592..94d467f 100644 --- a/qemu-plugin/examples/tracer/Cargo.toml +++ b/qemu-plugin/examples/tracer/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib", "lib"] [dependencies] qemu = { workspace = true, features = ["plugins", "debug-info"] } -qemu-plugin = { workspace = true, features = ["weak"] } +qemu-plugin = { workspace = true, features = ["unix-weak-link"] } anyhow = "1.0.75" ffi = "0.1.0" ctor = "0.2.6" From a0fcc99d29a7e6aac6026504684c98649e33e84a Mon Sep 17 00:00:00 2001 From: novafacing Date: Thu, 4 Jan 2024 16:19:51 -0800 Subject: [PATCH 05/33] Fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4027b58..a86c1ce 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ QEMU for Rust, and Rust for QEMU! This repository provides several QEMU-related crates: -* [qemu](https://github.com/novaafcing/qemu-rs/tree/main/qemu): QEMU binary installer +* [qemu](https://github.com/novafacing/qemu-rs/tree/main/qemu): QEMU binary installer * [qemu-plugin-sys](https://github.com/novafacing/qemu-rs/tree/main/qemu-plugin-sys): Low level bindings to the QEMU plugin API * [qemu-plugin](https://github.com/novafacing/qemu-rs/tree/main/qemu-plugin): High level bindings to the QEMU plugin API From 849183ff3c47fc13107ad83730f07e1e5615a2e1 Mon Sep 17 00:00:00 2001 From: novafacing Date: Thu, 4 Jan 2024 16:21:09 -0800 Subject: [PATCH 06/33] Fix unused import, update bindings --- qemu-plugin-sys/generate-bindings.rs | 4 +- qemu-plugin-sys/src/bindings.rs | 818 +++++++++++++-------------- 2 files changed, 395 insertions(+), 427 deletions(-) diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 0fe80bf..6f93751 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -21,8 +21,10 @@ use bindgen::{ }; use cargo_metadata::MetadataCommand; use reqwest::blocking::get; +#[cfg(windows)] +use std::fs::{read_to_string, write}; use std::{ - fs::{create_dir_all, read_to_string, write, File, OpenOptions}, + fs::{create_dir_all, File, OpenOptions}, path::Path, }; use tar::Archive; diff --git a/qemu-plugin-sys/src/bindings.rs b/qemu-plugin-sys/src/bindings.rs index 8fed985..0266839 100644 --- a/qemu-plugin-sys/src/bindings.rs +++ b/qemu-plugin-sys/src/bindings.rs @@ -1,450 +1,411 @@ /* automatically generated by rust-bindgen 0.69.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 _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 WINT_MIN: u32 = 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 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 PRId32: &[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 PRId64: &[u8; 3] = b"ld\0"; +pub const PRIdLEAST8: &[u8; 2] = b"d\0"; +pub const PRIdLEAST16: &[u8; 2] = b"d\0"; pub const PRIdLEAST32: &[u8; 2] = b"d\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 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 PRIi32: &[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 PRIi64: &[u8; 3] = b"li\0"; +pub const PRIiLEAST8: &[u8; 2] = b"i\0"; +pub const PRIiLEAST16: &[u8; 2] = b"i\0"; pub const PRIiLEAST32: &[u8; 2] = b"i\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 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 PRIo32: &[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 PRIo64: &[u8; 3] = b"lo\0"; +pub const PRIoLEAST8: &[u8; 2] = b"o\0"; +pub const PRIoLEAST16: &[u8; 2] = b"o\0"; pub const PRIoLEAST32: &[u8; 2] = b"o\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 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 PRIu32: &[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 PRIu64: &[u8; 3] = b"lu\0"; +pub const PRIuLEAST8: &[u8; 2] = b"u\0"; +pub const PRIuLEAST16: &[u8; 2] = b"u\0"; pub const PRIuLEAST32: &[u8; 2] = b"u\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 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 PRIx32: &[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 PRIx64: &[u8; 3] = b"lx\0"; +pub const PRIxLEAST8: &[u8; 2] = b"x\0"; +pub const PRIxLEAST16: &[u8; 2] = b"x\0"; pub const PRIxLEAST32: &[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 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 PRIX32: &[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 PRIX64: &[u8; 3] = b"lX\0"; +pub const PRIXLEAST8: &[u8; 2] = b"X\0"; +pub const PRIXLEAST16: &[u8; 2] = b"X\0"; pub const PRIXLEAST32: &[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 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 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; 4] = b"lld\0"; +pub const SCNd64: &[u8; 3] = b"ld\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; 4] = b"lld\0"; +pub const SCNdLEAST64: &[u8; 3] = b"ld\0"; pub const SCNdFAST8: &[u8; 4] = b"hhd\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 SCNdFAST16: &[u8; 3] = b"ld\0"; +pub const SCNdFAST32: &[u8; 3] = b"ld\0"; +pub const SCNdFAST64: &[u8; 3] = b"ld\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; 4] = b"lli\0"; +pub const SCNi64: &[u8; 3] = b"li\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; 4] = b"lli\0"; +pub const SCNiLEAST64: &[u8; 3] = b"li\0"; pub const SCNiFAST8: &[u8; 4] = b"hhi\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; 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; 4] = b"llo\0"; -pub const SCNoFAST8: &[u8; 4] = b"hho\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 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; 4] = b"llu\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; 4] = b"llu\0"; +pub const SCNuLEAST64: &[u8; 3] = b"lu\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 SCNuFAST16: &[u8; 3] = b"lu\0"; +pub const SCNuFAST32: &[u8; 3] = b"lu\0"; +pub const SCNuFAST64: &[u8; 3] = b"lu\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 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 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 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; 4] = b"llx\0"; +pub const SCNx64: &[u8; 3] = b"lx\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; 4] = b"llx\0"; +pub const SCNxLEAST64: &[u8; 3] = b"lx\0"; pub const SCNxFAST8: &[u8; 4] = b"hhx\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 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 __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; pub const QEMU_PLUGIN_VERSION: u32 = 1; -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; +#[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; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct _Mbstatet { - pub _Wchar: ::std::os::raw::c_ulong, - pub _Byte: ::std::os::raw::c_ushort, - pub _State: ::std::os::raw::c_ushort, +pub struct __fsid_t { + pub __val: [::std::os::raw::c_int; 2usize], } #[test] -fn bindgen_test_layout__Mbstatet() { - const UNINIT: ::std::mem::MaybeUninit<_Mbstatet> = ::std::mem::MaybeUninit::uninit(); +fn bindgen_test_layout___fsid_t() { + const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_Mbstatet>(), + ::std::mem::size_of::<__fsid_t>(), 8usize, - concat!("Size of: ", stringify!(_Mbstatet)) + concat!("Size of: ", stringify!(__fsid_t)) ); assert_eq!( - ::std::mem::align_of::<_Mbstatet>(), + ::std::mem::align_of::<__fsid_t>(), 4usize, - concat!("Alignment of ", stringify!(_Mbstatet)) + concat!("Alignment of ", stringify!(__fsid_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._Wchar) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - 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!(__fsid_t), "::", - stringify!(_State) + stringify!(__val) ) ); } -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 __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 int_fast8_t = ::std::os::raw::c_schar; -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 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 uint_fast8_t = ::std::os::raw::c_uchar; -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-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] +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'."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct _Lldiv_t { - pub quot: intmax_t, - pub rem: intmax_t, +pub struct imaxdiv_t { + #[doc = " Quotient."] + pub quot: ::std::os::raw::c_long, + #[doc = " Remainder."] + pub rem: ::std::os::raw::c_long, } #[test] -fn bindgen_test_layout__Lldiv_t() { - const UNINIT: ::std::mem::MaybeUninit<_Lldiv_t> = ::std::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_imaxdiv_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_Lldiv_t>(), + ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(_Lldiv_t)) + concat!("Size of: ", stringify!(imaxdiv_t)) ); assert_eq!( - ::std::mem::align_of::<_Lldiv_t>(), + ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(_Lldiv_t)) + concat!("Alignment of ", stringify!(imaxdiv_t)) ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).quot) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(_Lldiv_t), + stringify!(imaxdiv_t), "::", stringify!(quot) ) @@ -454,82 +415,97 @@ fn bindgen_test_layout__Lldiv_t() { 8usize, concat!( "Offset of field: ", - stringify!(_Lldiv_t), + stringify!(imaxdiv_t), "::", stringify!(rem) ) ); } -#[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Types\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] -pub type imaxdiv_t = _Lldiv_t; extern "C" { - #[doc = "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n Functions\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"] - pub fn imaxabs(_Number: intmax_t) -> intmax_t; + #[doc = " Compute absolute value of N."] + pub fn imaxabs(__n: intmax_t) -> intmax_t; } extern "C" { - pub fn imaxdiv(_Numerator: intmax_t, _Denominator: intmax_t) -> imaxdiv_t; + #[doc = " Return the `imaxdiv_t' representation of the value of NUMER over DENOM."] + pub fn imaxdiv(__numer: intmax_t, __denom: intmax_t) -> imaxdiv_t; } extern "C" { + #[doc = " Like `strtol' but convert to `intmax_t'."] pub fn strtoimax( - _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, + __nptr: *const ::std::os::raw::c_char, + __endptr: *mut *mut ::std::os::raw::c_char, + __base: ::std::os::raw::c_int, ) -> intmax_t; } extern "C" { + #[doc = " Like `strtoul' but convert to `uintmax_t'."] pub fn strtoumax( - _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, + __nptr: *const ::std::os::raw::c_char, + __endptr: *mut *mut ::std::os::raw::c_char, + __base: ::std::os::raw::c_int, ) -> uintmax_t; } extern "C" { + #[doc = " Like `wcstol' but convert to `intmax_t'."] pub fn wcstoimax( - _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, + __nptr: *const __gwchar_t, + __endptr: *mut *mut __gwchar_t, + __base: ::std::os::raw::c_int, ) -> intmax_t; } extern "C" { + #[doc = " Like `wcstoul' but convert to `uintmax_t'."] pub fn wcstoumax( - _String: *const wchar_t, - _EndPtr: *mut *mut wchar_t, - _Radix: ::std::os::raw::c_int, + __nptr: *const __gwchar_t, + __endptr: *mut *mut __gwchar_t, + __base: ::std::os::raw::c_int, ) -> uintmax_t; } -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 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) + ) + ); } -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."] @@ -794,7 +770,7 @@ pub struct qemu_plugin_tb { pub struct qemu_plugin_insn { _unused: [u8; 0], } -#[repr(i32)] +#[repr(u32)] #[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 { @@ -802,7 +778,7 @@ pub enum qemu_plugin_cb_flags { QEMU_PLUGIN_CB_R_REGS = 1, QEMU_PLUGIN_CB_RW_REGS = 2, } -#[repr(i32)] +#[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_R = 1, @@ -828,7 +804,7 @@ extern "C" { userdata: *mut ::std::os::raw::c_void, ); } -#[repr(i32)] +#[repr(u32)] #[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 { @@ -1057,13 +1033,3 @@ 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, -} From 69b2509097feb84f7414fc0e1e0a382387188396 Mon Sep 17 00:00:00 2001 From: novafacing Date: Thu, 4 Jan 2024 16:34:07 -0800 Subject: [PATCH 07/33] Add blocklist for bindings to reduce unused definitions --- qemu-plugin-sys/build.rs | 6 +- qemu-plugin-sys/generate-bindings.rs | 348 ++++++++++++++++++ qemu-plugin-sys/src/bindings.rs | 505 --------------------------- 3 files changed, 353 insertions(+), 506 deletions(-) diff --git a/qemu-plugin-sys/build.rs b/qemu-plugin-sys/build.rs index edbd9d1..36e8b6f 100644 --- a/qemu-plugin-sys/build.rs +++ b/qemu-plugin-sys/build.rs @@ -1,6 +1,10 @@ -use anyhow::{anyhow, Result}; +#[cfg(windows)] +use anyhow::anyhow; +use anyhow::Result; +#[cfg(windows)] use std::{env::var, path::PathBuf, process::Command, str::FromStr}; +#[cfg(windows)] fn out_dir() -> Result { Ok(PathBuf::from( var("OUT_DIR").map_err(|e| anyhow!("OUT_DIR not set: {e}"))?, diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 6f93751..0ba2607 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -108,8 +108,356 @@ fn generate_bindings(qemu_plugin_header: &Path, destination: &Path) -> Result<() .derive_partialeq(true) .generate_comments(true) .header(qemu_plugin_header.to_str().unwrap()) + // Blocklist because we will define these items .blocklist_function("qemu_plugin_install") .blocklist_item("qemu_plugin_version") + // Blocklist because these types are not necessary + .blocklist_item("_INTTYPES_H") + .blocklist_item("_FEATURES_H") + .blocklist_item("_DEFAULT_SOURCE") + .blocklist_item("__GLIBC_USE_ISOC2X") + .blocklist_item("__USE_ISOC11") + .blocklist_item("__USE_ISOC99") + .blocklist_item("__USE_ISOC95") + .blocklist_item("__USE_POSIX_IMPLICITLY") + .blocklist_item("_POSIX_SOURCE") + .blocklist_item("_POSIX_C_SOURCE") + .blocklist_item("__USE_POSIX") + .blocklist_item("__USE_POSIX2") + .blocklist_item("__USE_POSIX199309") + .blocklist_item("__USE_POSIX199506") + .blocklist_item("__USE_XOPEN2K") + .blocklist_item("__USE_XOPEN2K8") + .blocklist_item("_ATFILE_SOURCE") + .blocklist_item("__WORDSIZE") + .blocklist_item("__WORDSIZE_TIME64_COMPAT32") + .blocklist_item("__TIMESIZE") + .blocklist_item("__USE_MISC") + .blocklist_item("__USE_ATFILE") + .blocklist_item("__USE_FORTIFY_LEVEL") + .blocklist_item("__GLIBC_USE_DEPRECATED_GETS") + .blocklist_item("__GLIBC_USE_DEPRECATED_SCANF") + .blocklist_item("__GLIBC_USE_C2X_STRTOL") + .blocklist_item("_STDC_PREDEF_H") + .blocklist_item("__STDC_IEC_559__") + .blocklist_item("__STDC_IEC_60559_BFP__") + .blocklist_item("__STDC_IEC_559_COMPLEX__") + .blocklist_item("__STDC_IEC_60559_COMPLEX__") + .blocklist_item("__STDC_ISO_10646__") + .blocklist_item("__GNU_LIBRARY__") + .blocklist_item("__GLIBC__") + .blocklist_item("__GLIBC_MINOR__") + .blocklist_item("_SYS_CDEFS_H") + .blocklist_item("__glibc_c99_flexarr_available") + .blocklist_item("__LDOUBLE_REDIRECTS_TO_FLOAT128_ABI") + .blocklist_item("__HAVE_GENERIC_SELECTION") + .blocklist_item("_STDINT_H") + .blocklist_item("__GLIBC_USE_LIB_EXT2") + .blocklist_item("__GLIBC_USE_IEC_60559_BFP_EXT") + .blocklist_item("__GLIBC_USE_IEC_60559_BFP_EXT_C2X") + .blocklist_item("__GLIBC_USE_IEC_60559_EXT") + .blocklist_item("__GLIBC_USE_IEC_60559_FUNCS_EXT") + .blocklist_item("__GLIBC_USE_IEC_60559_FUNCS_EXT_C2X") + .blocklist_item("__GLIBC_USE_IEC_60559_TYPES_EXT") + .blocklist_item("_BITS_TYPES_H") + .blocklist_item("_BITS_TYPESIZES_H") + .blocklist_item("__OFF_T_MATCHES_OFF64_T") + .blocklist_item("__INO_T_MATCHES_INO64_T") + .blocklist_item("__RLIM_T_MATCHES_RLIM64_T") + .blocklist_item("__STATFS_MATCHES_STATFS64") + .blocklist_item("__FD_SETSIZE") + .blocklist_item("_BITS_TIME64_H") + .blocklist_item("_BITS_WCHAR_H") + .blocklist_item("_BITS_STDINT_INTN_H") + .blocklist_item("_BITS_STDINT_UINTN_H") + .blocklist_item("INT8_MIN") + .blocklist_item("INT16_MIN") + .blocklist_item("INT32_MIN") + .blocklist_item("INT8_MAX") + .blocklist_item("INT16_MAX") + .blocklist_item("INT32_MAX") + .blocklist_item("UINT8_MAX") + .blocklist_item("UINT16_MAX") + .blocklist_item("UINT32_MAX") + .blocklist_item("INT_LEAST8_MIN") + .blocklist_item("INT_LEAST16_MIN") + .blocklist_item("INT_LEAST32_MIN") + .blocklist_item("INT_LEAST8_MAX") + .blocklist_item("INT_LEAST16_MAX") + .blocklist_item("INT_LEAST32_MAX") + .blocklist_item("UINT_LEAST8_MAX") + .blocklist_item("UINT_LEAST16_MAX") + .blocklist_item("UINT_LEAST32_MAX") + .blocklist_item("INT_FAST8_MIN") + .blocklist_item("INT_FAST16_MIN") + .blocklist_item("INT_FAST32_MIN") + .blocklist_item("INT_FAST8_MAX") + .blocklist_item("INT_FAST16_MAX") + .blocklist_item("INT_FAST32_MAX") + .blocklist_item("UINT_FAST8_MAX") + .blocklist_item("UINT_FAST16_MAX") + .blocklist_item("UINT_FAST32_MAX") + .blocklist_item("INTPTR_MIN") + .blocklist_item("INTPTR_MAX") + .blocklist_item("UINTPTR_MAX") + .blocklist_item("PTRDIFF_MIN") + .blocklist_item("PTRDIFF_MAX") + .blocklist_item("SIG_ATOMIC_MIN") + .blocklist_item("SIG_ATOMIC_MAX") + .blocklist_item("SIZE_MAX") + .blocklist_item("WINT_MIN") + .blocklist_item("WINT_MAX") + .blocklist_item("____gwchar_t_defined") + .blocklist_item("__PRI64_PREFIX") + .blocklist_item("__PRIPTR_PREFIX") + .blocklist_item("PRId8") + .blocklist_item("PRId16") + .blocklist_item("PRId32") + .blocklist_item("PRId64") + .blocklist_item("PRIdLEAST8") + .blocklist_item("PRIdLEAST16") + .blocklist_item("PRIdLEAST32") + .blocklist_item("PRIdLEAST64") + .blocklist_item("PRIdFAST8") + .blocklist_item("PRIdFAST16") + .blocklist_item("PRIdFAST32") + .blocklist_item("PRIdFAST64") + .blocklist_item("PRIi8") + .blocklist_item("PRIi16") + .blocklist_item("PRIi32") + .blocklist_item("PRIi64") + .blocklist_item("PRIiLEAST8") + .blocklist_item("PRIiLEAST16") + .blocklist_item("PRIiLEAST32") + .blocklist_item("PRIiLEAST64") + .blocklist_item("PRIiFAST8") + .blocklist_item("PRIiFAST16") + .blocklist_item("PRIiFAST32") + .blocklist_item("PRIiFAST64") + .blocklist_item("PRIo8") + .blocklist_item("PRIo16") + .blocklist_item("PRIo32") + .blocklist_item("PRIo64") + .blocklist_item("PRIoLEAST8") + .blocklist_item("PRIoLEAST16") + .blocklist_item("PRIoLEAST32") + .blocklist_item("PRIoLEAST64") + .blocklist_item("PRIoFAST8") + .blocklist_item("PRIoFAST16") + .blocklist_item("PRIoFAST32") + .blocklist_item("PRIoFAST64") + .blocklist_item("PRIu8") + .blocklist_item("PRIu16") + .blocklist_item("PRIu32") + .blocklist_item("PRIu64") + .blocklist_item("PRIuLEAST8") + .blocklist_item("PRIuLEAST16") + .blocklist_item("PRIuLEAST32") + .blocklist_item("PRIuLEAST64") + .blocklist_item("PRIuFAST8") + .blocklist_item("PRIuFAST16") + .blocklist_item("PRIuFAST32") + .blocklist_item("PRIuFAST64") + .blocklist_item("PRIx8") + .blocklist_item("PRIx16") + .blocklist_item("PRIx32") + .blocklist_item("PRIx64") + .blocklist_item("PRIxLEAST8") + .blocklist_item("PRIxLEAST16") + .blocklist_item("PRIxLEAST32") + .blocklist_item("PRIxLEAST64") + .blocklist_item("PRIxFAST8") + .blocklist_item("PRIxFAST16") + .blocklist_item("PRIxFAST32") + .blocklist_item("PRIxFAST64") + .blocklist_item("PRIX8") + .blocklist_item("PRIX16") + .blocklist_item("PRIX32") + .blocklist_item("PRIX64") + .blocklist_item("PRIXLEAST8") + .blocklist_item("PRIXLEAST16") + .blocklist_item("PRIXLEAST32") + .blocklist_item("PRIXLEAST64") + .blocklist_item("PRIXFAST8") + .blocklist_item("PRIXFAST16") + .blocklist_item("PRIXFAST32") + .blocklist_item("PRIXFAST64") + .blocklist_item("PRIdMAX") + .blocklist_item("PRIiMAX") + .blocklist_item("PRIoMAX") + .blocklist_item("PRIuMAX") + .blocklist_item("PRIxMAX") + .blocklist_item("PRIXMAX") + .blocklist_item("PRIdPTR") + .blocklist_item("PRIiPTR") + .blocklist_item("PRIoPTR") + .blocklist_item("PRIuPTR") + .blocklist_item("PRIxPTR") + .blocklist_item("PRIXPTR") + .blocklist_item("SCNd8") + .blocklist_item("SCNd16") + .blocklist_item("SCNd32") + .blocklist_item("SCNd64") + .blocklist_item("SCNdLEAST8") + .blocklist_item("SCNdLEAST16") + .blocklist_item("SCNdLEAST32") + .blocklist_item("SCNdLEAST64") + .blocklist_item("SCNdFAST8") + .blocklist_item("SCNdFAST16") + .blocklist_item("SCNdFAST32") + .blocklist_item("SCNdFAST64") + .blocklist_item("SCNi8") + .blocklist_item("SCNi16") + .blocklist_item("SCNi32") + .blocklist_item("SCNi64") + .blocklist_item("SCNiLEAST8") + .blocklist_item("SCNiLEAST16") + .blocklist_item("SCNiLEAST32") + .blocklist_item("SCNiLEAST64") + .blocklist_item("SCNiFAST8") + .blocklist_item("SCNiFAST16") + .blocklist_item("SCNiFAST32") + .blocklist_item("SCNiFAST64") + .blocklist_item("SCNu8") + .blocklist_item("SCNu16") + .blocklist_item("SCNu32") + .blocklist_item("SCNu64") + .blocklist_item("SCNuLEAST8") + .blocklist_item("SCNuLEAST16") + .blocklist_item("SCNuLEAST32") + .blocklist_item("SCNuLEAST64") + .blocklist_item("SCNuFAST8") + .blocklist_item("SCNuFAST16") + .blocklist_item("SCNuFAST32") + .blocklist_item("SCNuFAST64") + .blocklist_item("SCNo8") + .blocklist_item("SCNo16") + .blocklist_item("SCNo32") + .blocklist_item("SCNo64") + .blocklist_item("SCNoLEAST8") + .blocklist_item("SCNoLEAST16") + .blocklist_item("SCNoLEAST32") + .blocklist_item("SCNoLEAST64") + .blocklist_item("SCNoFAST8") + .blocklist_item("SCNoFAST16") + .blocklist_item("SCNoFAST32") + .blocklist_item("SCNoFAST64") + .blocklist_item("SCNx8") + .blocklist_item("SCNx16") + .blocklist_item("SCNx32") + .blocklist_item("SCNx64") + .blocklist_item("SCNxLEAST8") + .blocklist_item("SCNxLEAST16") + .blocklist_item("SCNxLEAST32") + .blocklist_item("SCNxLEAST64") + .blocklist_item("SCNxFAST8") + .blocklist_item("SCNxFAST16") + .blocklist_item("SCNxFAST32") + .blocklist_item("SCNxFAST64") + .blocklist_item("SCNdMAX") + .blocklist_item("SCNiMAX") + .blocklist_item("SCNoMAX") + .blocklist_item("SCNuMAX") + .blocklist_item("SCNxMAX") + .blocklist_item("SCNdPTR") + .blocklist_item("SCNiPTR") + .blocklist_item("SCNoPTR") + .blocklist_item("SCNuPTR") + .blocklist_item("SCNxPTR") + .blocklist_item("__bool_true_false_are_defined") + .blocklist_item("true_") + .blocklist_item("false_") + .blocklist_item("__u_char") + .blocklist_item("__u_short") + .blocklist_item("__u_int") + .blocklist_item("__u_long") + .blocklist_item("__int8_t") + .blocklist_item("__uint8_t") + .blocklist_item("__int16_t") + .blocklist_item("__uint16_t") + .blocklist_item("__int32_t") + .blocklist_item("__uint32_t") + .blocklist_item("__int64_t") + .blocklist_item("__uint64_t") + .blocklist_item("__int_least8_t") + .blocklist_item("__uint_least8_t") + .blocklist_item("__int_least16_t") + .blocklist_item("__uint_least16_t") + .blocklist_item("__int_least32_t") + .blocklist_item("__uint_least32_t") + .blocklist_item("__int_least64_t") + .blocklist_item("__uint_least64_t") + .blocklist_item("__quad_t") + .blocklist_item("__u_quad_t") + .blocklist_item("__intmax_t") + .blocklist_item("__uintmax_t") + .blocklist_item("__dev_t") + .blocklist_item("__uid_t") + .blocklist_item("__gid_t") + .blocklist_item("__ino_t") + .blocklist_item("__ino64_t") + .blocklist_item("__mode_t") + .blocklist_item("__nlink_t") + .blocklist_item("__off_t") + .blocklist_item("__off64_t") + .blocklist_item("__pid_t") + .blocklist_item("__fsid_t") + .blocklist_item("__clock_t") + .blocklist_item("__rlim_t") + .blocklist_item("__rlim64_t") + .blocklist_item("__id_t") + .blocklist_item("__time_t") + .blocklist_item("__useconds_t") + .blocklist_item("__suseconds_t") + .blocklist_item("__suseconds64_t") + .blocklist_item("__daddr_t") + .blocklist_item("__key_t") + .blocklist_item("__clockid_t") + .blocklist_item("__timer_t") + .blocklist_item("__blksize_t") + .blocklist_item("__blkcnt_t") + .blocklist_item("__blkcnt64_t") + .blocklist_item("__fsblkcnt_t") + .blocklist_item("__fsblkcnt64_t") + .blocklist_item("__fsfilcnt_t") + .blocklist_item("__fsfilcnt64_t") + .blocklist_item("__fsword_t") + .blocklist_item("__ssize_t") + .blocklist_item("__syscall_slong_t") + .blocklist_item("__syscall_ulong_t") + .blocklist_item("__loff_t") + .blocklist_item("__caddr_t") + .blocklist_item("__intptr_t") + .blocklist_item("__socklen_t") + .blocklist_item("__sig_atomic_t") + .blocklist_item("int_least8_t") + .blocklist_item("int_least16_t") + .blocklist_item("int_least32_t") + .blocklist_item("int_least64_t") + .blocklist_item("uint_least8_t") + .blocklist_item("uint_least16_t") + .blocklist_item("uint_least32_t") + .blocklist_item("uint_least64_t") + .blocklist_item("int_fast8_t") + .blocklist_item("int_fast16_t") + .blocklist_item("int_fast32_t") + .blocklist_item("int_fast64_t") + .blocklist_item("uint_fast8_t") + .blocklist_item("uint_fast16_t") + .blocklist_item("uint_fast32_t") + .blocklist_item("uint_fast64_t") + .blocklist_item("intmax_t") + .blocklist_item("uintmax_t") + .blocklist_item("__gwchar_t") + .blocklist_item("imaxdiv_t") + .blocklist_item("imaxabs") + .blocklist_item("imaxdiv") + .blocklist_item("strtoimax") + .blocklist_item("strtoumax") + .blocklist_item("wcstoimax") + .blocklist_item("wcstoumax") + .blocklist_item("max_align_t") + .blocklist_item("wchar_t") .generate()?; rust_bindings.write_to_file(destination)?; diff --git a/qemu-plugin-sys/src/bindings.rs b/qemu-plugin-sys/src/bindings.rs index 0266839..139b51e 100644 --- a/qemu-plugin-sys/src/bindings.rs +++ b/qemu-plugin-sys/src/bindings.rs @@ -1,511 +1,6 @@ /* 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 __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; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct __fsid_t { - pub __val: [::std::os::raw::c_int; 2usize], -} -#[test] -fn bindgen_test_layout___fsid_t() { - const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<__fsid_t>(), - 8usize, - concat!("Size of: ", stringify!(__fsid_t)) - ); - assert_eq!( - ::std::mem::align_of::<__fsid_t>(), - 4usize, - concat!("Alignment of ", stringify!(__fsid_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__fsid_t), - "::", - stringify!(__val) - ) - ); -} -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 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 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'."] -#[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, -} -#[test] -fn bindgen_test_layout_imaxdiv_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(imaxdiv_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(imaxdiv_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).quot) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(imaxdiv_t), - "::", - stringify!(quot) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rem) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(imaxdiv_t), - "::", - stringify!(rem) - ) - ); -} -extern "C" { - #[doc = " Compute absolute value of N."] - pub fn imaxabs(__n: 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; -} -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, - ) -> 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, - ) -> 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, - ) -> 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, - ) -> 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) - ) - ); -} #[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."] From 32622cfacd23eaae11d309875bf94dccecf9eff1 Mon Sep 17 00:00:00 2001 From: novafacing Date: Sat, 6 Jan 2024 21:27:47 -0800 Subject: [PATCH 08/33] Update workflow with all dependencies --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6816735..553fd16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,9 +27,11 @@ jobs: remove-docker-images: 'true' - name: Install QEMU Build Dependencies run: | - sudo apt-get -y install git libglib2.0-dev libfdt-dev \ - libpixman-1-dev zlib1g-dev ninja-build + sudo apt-get -y update && \ + sudo apt-get -y install bison flex git curl libglib2.0-dev libfdt-dev \ + libpixman-1-dev zlib1g-dev ninja-build build-essential python3 python3-pip python3-venv && \ + python3 -m pip install sphinx sphinx_rtd_theme - uses: dtolnay/rust-toolchain@nightly - uses: actions/checkout@v3 - name: Build - run: cargo build -vv -p tracer + run: cargo run -r --bin tracer -- -a /bin/ls -- -lah From 7a1b54c5ccf71f9b1c721c1440788d8e9ce251c1 Mon Sep 17 00:00:00 2001 From: novafacing Date: Sat, 6 Jan 2024 21:28:17 -0800 Subject: [PATCH 09/33] Disable space freeing --- .github/workflows/ci.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 553fd16..a5cbcd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,17 @@ jobs: runs-on: ubuntu-latest steps: - - name: Free build space - uses: easimon/maximize-build-space@master - with: - root-reserve-mb: 2048 - temp-reserve-mb: 256 - swap-size-mb: 1024 - remove-dotnet: 'true' - remove-android: 'true' - remove-haskell: 'true' - remove-codeql: 'true' - remove-docker-images: 'true' + # - name: Free build space + # uses: easimon/maximize-build-space@master + # with: + # root-reserve-mb: 2048 + # temp-reserve-mb: 256 + # swap-size-mb: 1024 + # remove-dotnet: 'true' + # remove-android: 'true' + # remove-haskell: 'true' + # remove-codeql: 'true' + # remove-docker-images: 'true' - name: Install QEMU Build Dependencies run: | sudo apt-get -y update && \ From 1c82542fe40d329ab6cc07239713ae9bc165741e Mon Sep 17 00:00:00 2001 From: novafacing Date: Sat, 6 Jan 2024 22:03:56 -0800 Subject: [PATCH 10/33] Re-enable space shaving --- .github/workflows/ci.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5cbcd0..553fd16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,17 @@ jobs: runs-on: ubuntu-latest steps: - # - name: Free build space - # uses: easimon/maximize-build-space@master - # with: - # root-reserve-mb: 2048 - # temp-reserve-mb: 256 - # swap-size-mb: 1024 - # remove-dotnet: 'true' - # remove-android: 'true' - # remove-haskell: 'true' - # remove-codeql: 'true' - # remove-docker-images: 'true' + - name: Free build space + uses: easimon/maximize-build-space@master + with: + root-reserve-mb: 2048 + temp-reserve-mb: 256 + swap-size-mb: 1024 + remove-dotnet: 'true' + remove-android: 'true' + remove-haskell: 'true' + remove-codeql: 'true' + remove-docker-images: 'true' - name: Install QEMU Build Dependencies run: | sudo apt-get -y update && \ From d1439273920337aa662325d9a4bc414fb3c3fd36 Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 09:25:26 -0800 Subject: [PATCH 11/33] Enable g_free on Windows --- .github/workflows/ci.yml | 19 +++++++++---------- qemu-plugin/Cargo.toml | 3 +++ qemu-plugin/src/lib.rs | 13 +++++++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 553fd16..3c58568 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,24 +12,23 @@ env: jobs: build: runs-on: ubuntu-latest - steps: - name: Free build space uses: easimon/maximize-build-space@master with: - root-reserve-mb: 2048 - temp-reserve-mb: 256 - swap-size-mb: 1024 - remove-dotnet: 'true' - remove-android: 'true' - remove-haskell: 'true' - remove-codeql: 'true' - remove-docker-images: 'true' + root-reserve-mb: 2048 + temp-reserve-mb: 256 + swap-size-mb: 1024 + remove-dotnet: "true" + remove-android: "true" + remove-haskell: "true" + remove-codeql: "true" + remove-docker-images: "true" - name: Install QEMU Build Dependencies run: | sudo apt-get -y update && \ sudo apt-get -y install bison flex git curl libglib2.0-dev libfdt-dev \ - libpixman-1-dev zlib1g-dev ninja-build build-essential python3 python3-pip python3-venv && \ + libpixman-1-dev zlib1g-dev ninja-build build-essential python3 python3-pip python3-venv && \ python3 -m pip install sphinx sphinx_rtd_theme - uses: dtolnay/rust-toolchain@nightly - uses: actions/checkout@v3 diff --git a/qemu-plugin/Cargo.toml b/qemu-plugin/Cargo.toml index 75d603c..b0c0c52 100644 --- a/qemu-plugin/Cargo.toml +++ b/qemu-plugin/Cargo.toml @@ -25,6 +25,9 @@ features = [ "Win32_Foundation", ] +[target.'cfg(windows)'.dependencies.libc] +version = "0.2.152" + [features] # Define external symbols with weak definition unix-weak-link = [] diff --git a/qemu-plugin/src/lib.rs b/qemu-plugin/src/lib.rs index f659181..f38ea3a 100644 --- a/qemu-plugin/src/lib.rs +++ b/qemu-plugin/src/lib.rs @@ -80,6 +80,8 @@ mod unix_weak_link; mod win_link_hook; use crate::error::{Error, Result}; +#[cfg(windows)] +use libc::free; use qemu_plugin_sys::{ qemu_plugin_cb_flags, qemu_plugin_hwaddr, qemu_plugin_id_t, qemu_plugin_insn, qemu_plugin_mem_rw, qemu_plugin_meminfo_t, qemu_plugin_simple_cb_t, qemu_plugin_tb, @@ -109,8 +111,15 @@ 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. + + // NOTE: glib 2.46 g_malloc always uses system malloc implementation: + // https://docs.gtk.org/glib/func.mem_is_system_malloc.html + // So it is safe to call libc free to free a `g_malloc`-ed object + unsafe { + if !mem.is_null() { + free(mem) + } + } } /// The index of a vCPU From fa780c2c72eec0819c6ed8182b4ea90fbe7432c0 Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 09:55:47 -0800 Subject: [PATCH 12/33] Test in container --- .dockerignore | 10 ++++++++++ .github/workflows/ci.yml | 12 +++--------- Dockerfile | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..767dae2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c58568..318e776 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ env: jobs: build: + name: Build And Test runs-on: ubuntu-latest steps: - name: Free build space @@ -24,13 +25,6 @@ jobs: remove-haskell: "true" remove-codeql: "true" remove-docker-images: "true" - - name: Install QEMU Build Dependencies + - name: Build Test Container run: | - sudo apt-get -y update && \ - sudo apt-get -y install bison flex git curl libglib2.0-dev libfdt-dev \ - libpixman-1-dev zlib1g-dev ninja-build build-essential python3 python3-pip python3-venv && \ - python3 -m pip install sphinx sphinx_rtd_theme - - uses: dtolnay/rust-toolchain@nightly - - uses: actions/checkout@v3 - - name: Build - run: cargo run -r --bin tracer -- -a /bin/ls -- -lah + docker build -t qemu-rs-test . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e1d7e29 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:22.04 + +ENV PATH="${PATH}:/root/.cargo/bin" + +RUN apt-get -y update && \ + apt-get -y install bison flex git curl libglib2.0-dev libfdt-dev \ + libpixman-1-dev zlib1g-dev ninja-build build-essential python3 python3-pip python3-venv && \ + python3 -m pip install sphinx sphinx_rtd_theme && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly + +COPY . /qemu-rs + +WORKDIR /qemu-rs + +RUN cargo run -r --bin tracer -- -a /bin/ls -- -lah + From b30a5f7b855be1c58361b789b5187733684c86d0 Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 09:57:06 -0800 Subject: [PATCH 13/33] Checkout before build --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 318e776..6275232 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: remove-haskell: "true" remove-codeql: "true" remove-docker-images: "true" + - uses: actions/checkout@v4 - name: Build Test Container run: | docker build -t qemu-rs-test . From cf1f1a1f9513d09460dd336199b702b4c6d4bfcc Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 09:58:31 -0800 Subject: [PATCH 14/33] Dont strip space for docker building --- .github/workflows/ci.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6275232..80f5f89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,6 @@ jobs: name: Build And Test runs-on: ubuntu-latest steps: - - name: Free build space - uses: easimon/maximize-build-space@master - with: - root-reserve-mb: 2048 - temp-reserve-mb: 256 - swap-size-mb: 1024 - remove-dotnet: "true" - remove-android: "true" - remove-haskell: "true" - remove-codeql: "true" - remove-docker-images: "true" - uses: actions/checkout@v4 - name: Build Test Container run: | From d9bdab514a58eb232ed2407b733b35320f44bbde Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 14:05:29 -0800 Subject: [PATCH 15/33] Fix build then run to avoid missing libtracer.so --- .github/workflows/ci.yml | 2 +- Dockerfile | 3 ++- qemu-plugin-sys/generate-bindings.rs | 27 +++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80f5f89..96e0dad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,4 +17,4 @@ jobs: - uses: actions/checkout@v4 - name: Build Test Container run: | - docker build -t qemu-rs-test . + docker build -t qemu-rs-test . | tee /tmp/qemu-rs-test.log || { cat /tmp/qemu-rs-test.log; exit 1 } diff --git a/Dockerfile b/Dockerfile index e1d7e29..75eaa00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,6 @@ COPY . /qemu-rs WORKDIR /qemu-rs -RUN cargo run -r --bin tracer -- -a /bin/ls -- -lah +RUN cargo build -r && \ + cargo run -r --bin tracer -- -a /bin/ls -- -lah diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 0ba2607..8adc35f 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -1,18 +1,17 @@ #!/usr/bin/env -S cargo +nightly-gnu -Z script - -//! ```cargo -//! [package] -//! edition = "2021" -//! [dependencies] -//! anyhow = "*" -//! bindgen = "*" -//! cargo_metadata = "*" -//! reqwest = { version = "*", features = ["blocking"] } -//! tar = "*" -//! xz2 = "*" -//![lints.rust] -//!non_snake_case = "allow" -//! ``` +``` +[package] +edition = "2021" +[dependencies] +anyhow = "*" +bindgen = "*" +cargo_metadata = "*" +reqwest = { version = "*", features = ["blocking"] } +tar = "*" +xz2 = "*" +[lints.rust] +non_snake_case = "allow" +``` use anyhow::{anyhow, Result}; use bindgen::{ From 1f459a128f9202d1033dc0b238d76d51550ea592 Mon Sep 17 00:00:00 2001 From: novafacing Date: Mon, 8 Jan 2024 14:19:27 -0800 Subject: [PATCH 16/33] Escape braces --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96e0dad..e842b43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,4 +17,4 @@ jobs: - uses: actions/checkout@v4 - name: Build Test Container run: | - docker build -t qemu-rs-test . | tee /tmp/qemu-rs-test.log || { cat /tmp/qemu-rs-test.log; exit 1 } + docker build -t qemu-rs-test . | tee /tmp/qemu-rs-test.log || \{ cat /tmp/qemu-rs-test.log; exit 1 \} From ed0b33562dcbfb978c753bd918c5d461f553e2c4 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 00:19:51 -0800 Subject: [PATCH 17/33] Dont build qemu in workflow --- .github/workflows/ci.yml | 18 +- Cargo.toml | 6 +- README.md | 18 +- .../examples => plugins}/tiny/Cargo.toml | 0 .../examples => plugins}/tiny/src/lib.rs | 0 plugins/tracer/Cargo.toml | 35 +++ .../Cargo.toml => plugins/tracer/Cargo.toml~ | 6 +- .../tracer/src/bin/tracer.rs | 86 ++++++- plugins/tracer/src/bin/tracer.rs~ | 240 ++++++++++++++++++ .../examples => plugins}/tracer/src/lib.rs | 0 .../tracer/tests/.ninja_log | 0 .../tracer/tests/build.ninja | 0 .../tracer/tests/test-aarch64 | Bin .../examples => plugins}/tracer/tests/test.c | 0 qemu-plugin-sys/generate-bindings.rs | 24 +- 15 files changed, 409 insertions(+), 24 deletions(-) rename {qemu-plugin/examples => plugins}/tiny/Cargo.toml (100%) rename {qemu-plugin/examples => plugins}/tiny/src/lib.rs (100%) create mode 100644 plugins/tracer/Cargo.toml rename qemu-plugin/examples/tracer/Cargo.toml => plugins/tracer/Cargo.toml~ (72%) rename {qemu-plugin/examples => plugins}/tracer/src/bin/tracer.rs (75%) create mode 100644 plugins/tracer/src/bin/tracer.rs~ rename {qemu-plugin/examples => plugins}/tracer/src/lib.rs (100%) rename {qemu-plugin/examples => plugins}/tracer/tests/.ninja_log (100%) rename {qemu-plugin/examples => plugins}/tracer/tests/build.ninja (100%) rename {qemu-plugin/examples => plugins}/tracer/tests/test-aarch64 (100%) rename {qemu-plugin/examples => plugins}/tracer/tests/test.c (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e842b43..6baf123 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,21 @@ env: CARGO_TERM_COLOR: always jobs: - build: - name: Build And Test + test_examples: runs-on: ubuntu-latest + container: ubuntu:22.04 steps: + - name: Install QEMU User + run: | + apt-get -y update && \ + apt-get -y install qemu-user + - uses: dtolnay/rust-toolchain@nightly - uses: actions/checkout@v4 - - name: Build Test Container + - name: Test QEMU Install + run: | + qemu-x86_64 --help + - name: Build run: | - docker build -t qemu-rs-test . | tee /tmp/qemu-rs-test.log || \{ cat /tmp/qemu-rs-test.log; exit 1 \} + cd plugins/tracer + cargo build -r + cargo run -r --bin tracer -- -a /bin/ls -- -lah diff --git a/Cargo.toml b/Cargo.toml index f9921b4..aa92bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,11 @@ resolver = "2" members = [ "qemu", "qemu-plugin", - "qemu-plugin/examples/tiny", - "qemu-plugin/examples/tracer", + "qemu-plugin-sys", + "plugins/tiny", + "plugins/tracer", ] +default-members = ["qemu-plugin", "qemu-plugin-sys"] [workspace.dependencies] qemu-plugin-sys = { version = "8.1.3-v3", path = "qemu-plugin-sys" } diff --git a/README.md b/README.md index a86c1ce..d3570b0 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,20 @@ and instructions) of a program like: ```sh cargo run -r --bin tracer -- -a /bin/ls -- -lah -``` \ No newline at end of file +``` + +## Installing QEMU + +This repository also provides a crate (`qemu`) which builds QEMU from source and +installs Rust wrappers for QEMU as binaries. + +You can install QEMU with (add any additional features you need, e.g. `plugins`): + +```sh +cargo install qemu@8.1.3-v3 --features=binaries +``` + +On some systems, particularly BTRFS systems, `/tmp` may not be large enough for the +temporary build directory (QEMU is quite large to build). In this case, create a +directory on your root filesystem (e.g. `$HOME/.cargo/tmp`) and set +`CARGO_TARGET_DIR=$HOME/.cargo/tmp` when running the install command. \ No newline at end of file diff --git a/qemu-plugin/examples/tiny/Cargo.toml b/plugins/tiny/Cargo.toml similarity index 100% rename from qemu-plugin/examples/tiny/Cargo.toml rename to plugins/tiny/Cargo.toml diff --git a/qemu-plugin/examples/tiny/src/lib.rs b/plugins/tiny/src/lib.rs similarity index 100% rename from qemu-plugin/examples/tiny/src/lib.rs rename to plugins/tiny/src/lib.rs diff --git a/plugins/tracer/Cargo.toml b/plugins/tracer/Cargo.toml new file mode 100644 index 0000000..1f6e44c --- /dev/null +++ b/plugins/tracer/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "tracer" +version = "0.1.0" +edition = "2021" + +[lib] +name = "tracer" +crate-type = ["cdylib", "lib"] + +[dependencies] +anyhow = "1.0.75" +ctor = "0.2.6" +qemu-plugin = { workspace = true, features = ["unix-weak-link"] } +serde = { version = "1.0.193", features = ["derive"] } +serde_cbor = "0.11.2" +tokio = { version = "1.35.0", features = ["full"] } +typed-builder = "0.18.0" +yaxpeax-x86 = "1.2.2" + +# Dependencies only used by this crate's `tracer` binary. We do not use dev-dependencies +# because they cannot be optional. +clap = { version = "4.4.11", features = ["derive", "string"] } +# Enable the `qemu` feature to build and install QEMU with the `qemu` crate instead +# of trying to use the system QEMU. +qemu = { workspace = true, features = [ + "plugins", + "debug-info", +], optional = true } +memfd-exec = { version = "0.2.1", optional = true } +rand = "0.8.5" +serde_json = "1.0.108" + +[features] +qemu = ["dep:memfd-exec", "dep:qemu"] +default = [] diff --git a/qemu-plugin/examples/tracer/Cargo.toml b/plugins/tracer/Cargo.toml~ similarity index 72% rename from qemu-plugin/examples/tracer/Cargo.toml rename to plugins/tracer/Cargo.toml~ index 94d467f..8551f8e 100644 --- a/qemu-plugin/examples/tracer/Cargo.toml +++ b/plugins/tracer/Cargo.toml~ @@ -8,7 +8,6 @@ name = "tracer" crate-type = ["cdylib", "lib"] [dependencies] -qemu = { workspace = true, features = ["plugins", "debug-info"] } qemu-plugin = { workspace = true, features = ["unix-weak-link"] } anyhow = "1.0.75" ffi = "0.1.0" @@ -22,3 +21,8 @@ serde = { version = "1.0.193", features = ["derive"] } memfd-exec = "0.2.1" serde_json = "1.0.108" yaxpeax-x86 = "1.2.2" + +# Enable the `qemu` feature to build and install QEMU with the `qemu` crate instead +# of trying to use the system QEMU. +qemu = { workspace = true, features = ["plugins", "debug-info"], optional = true } + diff --git a/qemu-plugin/examples/tracer/src/bin/tracer.rs b/plugins/tracer/src/bin/tracer.rs similarity index 75% rename from qemu-plugin/examples/tracer/src/bin/tracer.rs rename to plugins/tracer/src/bin/tracer.rs index a59be68..6f15509 100644 --- a/qemu-plugin/examples/tracer/src/bin/tracer.rs +++ b/plugins/tracer/src/bin/tracer.rs @@ -1,10 +1,14 @@ use anyhow::{anyhow, Error, Result}; use clap::Parser; +#[cfg(feature = "memfd-exec")] use memfd_exec::{MemFdExecutable, Stdio}; +#[cfg(feature = "qemu")] use qemu::QEMU_X86_64_LINUX_USER; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use serde_cbor::Deserializer; use serde_json::to_string; +#[cfg(not(feature = "qemu"))] +use std::process::{Command, Stdio}; use std::{ fs::OpenOptions, io::{stdout, BufRead, BufReader, Write}, @@ -21,7 +25,7 @@ use tracer::Event; #[cfg(debug_assertions)] const PLUGIN: &[u8] = include_bytes!(concat!( env!("CARGO_MANIFEST_DIR"), - "/../../../target/debug/libtracer.so" + "/../../target/debug/libtracer.so" )); #[cfg(not(debug_assertions))] @@ -105,6 +109,7 @@ impl Args { } } +#[cfg(feature = "qemu")] async fn run(input: Option>, args: Vec) -> Result<()> { let mut exe = MemFdExecutable::new("qemu", QEMU_X86_64_LINUX_USER) .args(args) @@ -179,6 +184,81 @@ async fn run(input: Option>, args: Vec) -> Result<()> { Ok(()) } +#[cfg(not(feature = "qemu"))] +async fn run(input: Option>, args: Vec) -> Result<()> { + let mut exe = Command::new("qemu-x86_64") + .args(args) + .stdin(if input.is_some() { + Stdio::piped() + } else { + Stdio::inherit() + }) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn()?; + + if let Some(input) = input { + let mut stdin = exe.stdin.take().ok_or_else(|| anyhow!("No stdin"))?; + spawn_blocking(move || stdin.write_all(&input)); + } + + let stdout = exe.stdout.take().ok_or_else(|| anyhow!("No stdout"))?; + + let out_reader = spawn_blocking(move || { + let mut line = String::new(); + let mut out_reader = BufReader::new(stdout); + + loop { + line.clear(); + + if let 0 = out_reader.read_line(&mut line)? { + break; + } + + let line = line.trim(); + + if !line.is_empty() { + println!("{line}"); + } + } + + Ok::<(), Error>(()) + }); + + let stderr = exe.stderr.take().ok_or_else(|| anyhow!("No stderr"))?; + + let err_reader = spawn_blocking(move || { + let mut line = String::new(); + let mut err_reader = BufReader::new(stderr); + + loop { + line.clear(); + + if let 0 = err_reader.read_line(&mut line)? { + break; + } + + let line = line.trim(); + + if !line.is_empty() { + eprintln!("{line}"); + } + } + + Ok::<(), Error>(()) + }); + + let waiter = spawn_blocking(move || exe.wait()); + + let (out_res, err_res, waiter_res) = join!(out_reader, err_reader, waiter); + + out_res??; + err_res??; + waiter_res??; + + Ok(()) +} + fn listen

(listen_sock: UnixListener, outfile: Option

) -> Result<()> where P: AsRef, @@ -193,8 +273,8 @@ where let it = Deserializer::from_reader(&mut stream).into_iter::(); for event in it { - outfile_stream.write(to_string(&event?)?.as_bytes())?; - outfile_stream.write(b"\n")?; + outfile_stream.write_all(to_string(&event?)?.as_bytes())?; + outfile_stream.write_all(b"\n")?; } Ok(()) diff --git a/plugins/tracer/src/bin/tracer.rs~ b/plugins/tracer/src/bin/tracer.rs~ new file mode 100644 index 0000000..ead681e --- /dev/null +++ b/plugins/tracer/src/bin/tracer.rs~ @@ -0,0 +1,240 @@ +use anyhow::{anyhow, Error, Result}; +use clap::Parser; +use memfd_exec::{MemFdExecutable, Stdio}; +#[cfg(feature = "qemu")] +use qemu::QEMU_X86_64_LINUX_USER; +use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use serde_cbor::Deserializer; +use serde_json::to_string; +use std::{ + fs::OpenOptions, + io::{stdout, BufRead, BufReader, Write}, + os::unix::net::UnixListener, + path::{Path, PathBuf}, +}; +use tokio::{ + fs::{read, remove_file, write}, + join, main, spawn, + task::spawn_blocking, +}; +use tracer::Event; + +#[cfg(debug_assertions)] +const PLUGIN: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../target/debug/libtracer.so" +)); + +#[cfg(not(debug_assertions))] +const PLUGIN: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../target/release/libtracer.so" +)); + +fn tmp(prefix: &str, suffix: &str) -> PathBuf { + PathBuf::from(format!( + "{}{}{}", + prefix, + thread_rng() + .sample_iter(&Alphanumeric) + .take(8) + .map(char::from) + .collect::(), + suffix + )) +} + +#[derive(Parser, Debug, Clone)] +/// Run QEMU with a plugin that logs events. To pass arguments to QEMU, use the QEMU environment +/// variables. +struct Args { + #[clap(short = 'i', long)] + /// Whether instructions should be logged + pub log_insns: bool, + #[clap(short = 'm', long)] + /// Whether memory accesses should be logged + pub log_mem: bool, + #[clap(short = 's', long)] + /// Whether syscalls should be logged + pub log_syscalls: bool, + #[clap(short = 'a', long)] + /// Whether all events should be logged + pub log_all: bool, + #[clap(short = 'I', long)] + /// An input file to use as the program's stdin, otherwise the driver's stdin is used + pub input_file: Option, + #[clap(short = 'O', long)] + /// An output file to write the trace to, otherwise stdout is used + pub output_file: Option, + /// The program to run + #[clap()] + pub program: PathBuf, + /// The arguments to the program + #[clap(num_args = 1.., last = true)] + pub args: Vec, +} + +impl Args { + fn to_plugin_args(&self) -> String { + format!( + "log_insns={},log_mem={},log_syscalls={}", + self.log_insns | self.log_all, + self.log_mem | self.log_all, + self.log_syscalls | self.log_all + ) + } + + fn to_qemu_args(&self, socket_path: &Path, plugin_path: &Path) -> Result> { + let mut qemu_args = vec![ + "-plugin".to_string(), + format!( + "{},{},socket_path={}", + plugin_path.display(), + self.to_plugin_args(), + socket_path.display() + ), + "--".to_string(), + self.program + .to_str() + .ok_or_else(|| anyhow!("Failed to convert program path to string"))? + .to_string(), + ]; + + qemu_args.extend(self.args.clone()); + + Ok(qemu_args) + } +} + +async fn run(input: Option>, args: Vec) -> Result<()> { + let mut exe = MemFdExecutable::new("qemu", QEMU_X86_64_LINUX_USER) + .args(args) + .stdin(if input.is_some() { + Stdio::piped() + } else { + Stdio::inherit() + }) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn()?; + + if let Some(input) = input { + let mut stdin = exe.stdin.take().ok_or_else(|| anyhow!("No stdin"))?; + spawn_blocking(move || stdin.write_all(&input)); + } + + let stdout = exe.stdout.take().ok_or_else(|| anyhow!("No stdout"))?; + + let out_reader = spawn_blocking(move || { + let mut line = String::new(); + let mut out_reader = BufReader::new(stdout); + + loop { + line.clear(); + + if let 0 = out_reader.read_line(&mut line)? { + break; + } + + let line = line.trim(); + + if !line.is_empty() { + println!("{line}"); + } + } + + Ok::<(), Error>(()) + }); + + let stderr = exe.stderr.take().ok_or_else(|| anyhow!("No stderr"))?; + + let err_reader = spawn_blocking(move || { + let mut line = String::new(); + let mut err_reader = BufReader::new(stderr); + + loop { + line.clear(); + + if let 0 = err_reader.read_line(&mut line)? { + break; + } + + let line = line.trim(); + + if !line.is_empty() { + eprintln!("{line}"); + } + } + + Ok::<(), Error>(()) + }); + + let waiter = spawn_blocking(move || exe.wait()); + + let (out_res, err_res, waiter_res) = join!(out_reader, err_reader, waiter); + + out_res??; + err_res??; + waiter_res??; + + Ok(()) +} + +fn listen

(listen_sock: UnixListener, outfile: Option

) -> Result<()> +where + P: AsRef, +{ + let mut outfile_stream = if let Some(outfile) = outfile.as_ref() { + Box::new(OpenOptions::new().create(true).append(true).open(outfile)?) as Box + } else { + Box::new(stdout()) as Box + }; + + let (mut stream, _) = listen_sock.accept()?; + let it = Deserializer::from_reader(&mut stream).into_iter::(); + + for event in it { + outfile_stream.write(to_string(&event?)?.as_bytes())?; + outfile_stream.write(b"\n")?; + } + + Ok(()) +} + +#[main] +async fn main() -> Result<()> { + let args = Args::parse(); + + let socket_path = tmp("/tmp/qemu-", ".sock"); + let plugin_path = tmp("/tmp/qemu-", ".so"); + + write(&plugin_path, PLUGIN).await?; + + let input = if let Some(input_file) = args.input_file.as_ref() { + let Ok(input_file) = input_file.canonicalize() else { + return Err(anyhow!("Failed to canonicalize input file")); + }; + + Some(read(input_file).await?) + } else { + None + }; + + let listen_sock = UnixListener::bind(&socket_path)?; + + let qemu_args = args.to_qemu_args(&socket_path, &plugin_path)?; + let qemu_task = spawn(async move { run(input, qemu_args).await }); + + let socket_task = spawn_blocking(move || listen(listen_sock, args.output_file.as_ref())); + + let (qemu_res, socket_res) = join!(qemu_task, socket_task); + + remove_file(&plugin_path).await?; + remove_file(&socket_path).await?; + + qemu_res??; + + socket_res??; + + Ok(()) +} diff --git a/qemu-plugin/examples/tracer/src/lib.rs b/plugins/tracer/src/lib.rs similarity index 100% rename from qemu-plugin/examples/tracer/src/lib.rs rename to plugins/tracer/src/lib.rs diff --git a/qemu-plugin/examples/tracer/tests/.ninja_log b/plugins/tracer/tests/.ninja_log similarity index 100% rename from qemu-plugin/examples/tracer/tests/.ninja_log rename to plugins/tracer/tests/.ninja_log diff --git a/qemu-plugin/examples/tracer/tests/build.ninja b/plugins/tracer/tests/build.ninja similarity index 100% rename from qemu-plugin/examples/tracer/tests/build.ninja rename to plugins/tracer/tests/build.ninja diff --git a/qemu-plugin/examples/tracer/tests/test-aarch64 b/plugins/tracer/tests/test-aarch64 similarity index 100% rename from qemu-plugin/examples/tracer/tests/test-aarch64 rename to plugins/tracer/tests/test-aarch64 diff --git a/qemu-plugin/examples/tracer/tests/test.c b/plugins/tracer/tests/test.c similarity index 100% rename from qemu-plugin/examples/tracer/tests/test.c rename to plugins/tracer/tests/test.c diff --git a/qemu-plugin-sys/generate-bindings.rs b/qemu-plugin-sys/generate-bindings.rs index 8adc35f..8be0987 100755 --- a/qemu-plugin-sys/generate-bindings.rs +++ b/qemu-plugin-sys/generate-bindings.rs @@ -1,17 +1,15 @@ #!/usr/bin/env -S cargo +nightly-gnu -Z script -``` -[package] -edition = "2021" -[dependencies] -anyhow = "*" -bindgen = "*" -cargo_metadata = "*" -reqwest = { version = "*", features = ["blocking"] } -tar = "*" -xz2 = "*" -[lints.rust] -non_snake_case = "allow" -``` +## [package] +## edition = "2021" +## [dependencies] +## anyhow = "*" +## bindgen = "*" +## cargo_metadata = "*" +## reqwest = { version = "*", features = ["blocking"] } +## tar = "*" +## xz2 = "*" +## [lints.rust] +## non_snake_case = "allow" use anyhow::{anyhow, Result}; use bindgen::{ From 46bfd9dcebadc4f1391ff09aa973f9a25448a500 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 00:23:22 -0800 Subject: [PATCH 18/33] Add dependencies --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6baf123..a8bd4cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Install QEMU User run: | apt-get -y update && \ - apt-get -y install qemu-user + apt-get -y install git curl qemu-user - uses: dtolnay/rust-toolchain@nightly - uses: actions/checkout@v4 - name: Test QEMU Install From 1df37f9a8e20a34f8a939a5d28ee25a8fc91bdb7 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 10:03:51 -0800 Subject: [PATCH 19/33] Add linker dep --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8bd4cc..4916d23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Install QEMU User run: | apt-get -y update && \ - apt-get -y install git curl qemu-user + apt-get -y install git curl qemu-user build-essential - uses: dtolnay/rust-toolchain@nightly - uses: actions/checkout@v4 - name: Test QEMU Install From 66a63cf257eb33be8dfa00e61f2d7655b1285fd1 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 13:24:57 -0800 Subject: [PATCH 20/33] Add ignores and seed img generation --- .github/.gitignore | 1 + .github/rsrc/.gitignore | 1 + .github/rsrc/seed.img | Bin 0 -> 374784 bytes .github/workflows/ci.yml | 59 +++++++++++++++++++++- .gitignore | 3 ++ plugins/tracer/src/bin/tracer.rs | 2 +- scripts/ci.sh | 84 +++++++++++++++++++++++++++++++ scripts/mk-cloudinit.sh | 20 ++++++++ 8 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/rsrc/.gitignore create mode 100644 .github/rsrc/seed.img create mode 100755 scripts/ci.sh create mode 100755 scripts/mk-cloudinit.sh diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..cd3d225 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +logs \ No newline at end of file diff --git a/.github/rsrc/.gitignore b/.github/rsrc/.gitignore new file mode 100644 index 0000000..ad30bfe --- /dev/null +++ b/.github/rsrc/.gitignore @@ -0,0 +1 @@ +*.yml \ No newline at end of file diff --git a/.github/rsrc/seed.img b/.github/rsrc/seed.img new file mode 100644 index 0000000000000000000000000000000000000000..d9719b636299bccb6dc348f0443849d776ac1907 GIT binary patch literal 374784 zcmeI*OK%&;0RZ4x2Sr`A4T_*hi@>fYLJK4ZNu(?&k%}H@Y9*~BKES11DMew>mXZk7 zBQRwcO&@?yZT~}#`47GIx8#_M(Vx)Hl9Yv5cHDy$Iq0_ncV>t4{C2_Nk`N~Z8vz0Y z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5Fn5>S8BC-7B-6Z=2m?1c7JbY za6EYN^Cy!397iU>N$S}!3n8l>;p){eHGX>Pr>EK8tfJH5+BoG}xLQT7hWtl2eiFi$ zSE_+T8kT8CQ#qyxcDPc`G)1d86Oy#dn(T#`@CI z&6v+_cQ)H=D~*l(B=NnO`C4r;-k$B|jb7Pl&)uFao9o3!x+>R3d8((YJnzNkO7DZB zANzTu^{o$mzBa#5tJjw5H|K9IykDz*c_yLu%ofh%$ilbYZ4JIs0^`>-djhY3z?I4T zA2vb}+F>(nh4|dR`(ZEagh4n?kLTr>jOAqh|J7XnjiVdS-(R2qe|}oxttvVlu8&i$ zzi9q{Zcm=qJ82gquom)k)fAx&owRR-MyOKaBqfHWu$ca8;ci$Dt0`AZ`yyRyd5UkR zM?b|{DYY4TDb`5GofM1Vos{x!3hSwcrEoLF@-Ul9bkY^tPHn8Dyj3m#%c#yT)0xTq zOu{qMf6e^=N=?15L}yN4<-`bFvcP{%=Ko9Xhvo?oAV7cs0RjXF5FkK+0D+4W$VT6> zXBXFinh6jfK!5-N0t5&UAV7csflC({-T7Y&J^;A%Gob?n2oNAZfB*pk1PBlyK;Ys8 zveEz8x&6O5VKoyVK!5-N0t5&UAV7csfy);d-T7bl{r}~k2|XY{fB*pk1PBlyK!5-N z0v9Ln_cOn-|L5!nKmJ+m^f&g)?)S5Q{X6t}-^(6%w|lR4?>8apq|kuAJrR(&HJ zgx%4?0W(jR5LkH0T=+(K7>23TgK%2L86!Y|009C7&PO2cJ;|o}e@l1QMfYx6o~_>K zujjGXX?_rU#Y(lTTf3k4n(K{rig$aRey7>ls3LcYmAs7QX1Ckv_2X(<;H}#!i>=Yh zZ*j8pTbZ{S?S9cLyBm3<%wx0D?l+qKxKfnO*xkIfQIzX>Z&bMK=FMWYXg2yqrya}A zX0Msg##rX5)u$O#lc~DZB9$rHsS|18x!!iX)7jW;Al0@@!;_O?#$lK^m3fu+uNDhKe|8Iuhplg{xVsc_d7pM z10XZ5AXTZup1 zJ*n%X!TxY}l>G67qlcdkm*ek-4|k4!KS~;Yvb(>(9Ov%s9nRew3_tPK PathBuf { diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100755 index 0000000..96de2b0 --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +#Run workflows locally using act + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +WORKFLOW_FILE="${SCRIPT_DIR}/../.github/workflows/ci.yml" +SECRETS_FILE="${SCRIPT_DIR}/../.secrets" + +if [ ! -f "${SECRETS_FILE}" ]; then + echo "No file '${SECRETS_FILE}' found. Please create one. It must have the following keys: + GITHUB_TOKEN" \ + "You can find your GitHub token with 'gh auth token'" + exit 1 +fi + +if ! command -v act &>/dev/null; then + echo "act must be installed! Install at https://github.com/nektos/act" + exit 1 +fi + +if ! command -v unbuffer &>/dev/null; then + echo "unbuffer must be installed! Install 'expect' from your package manager" + exit 1 +fi + +populate_env_file() { + ENV_FILE="${1}" + echo "Attempting automatic configuration of proxy with ENV_FILE=${ENV_FILE}" + + if [ -z "${HTTP_PROXY}" ] && [ -f ~/.docker/config.json ]; then + HTTP_PROXY=$(grep httpProxy ~/.docker/config.json | awk -F'\"[:space:]*:[:space:]*' '{split($2,a,"\""); print a[2]}') + echo "Exported docker config HTTP_PROXY=${HTTP_PROXY}" + elif [ -n "${HTTP_PROXY}" ]; then + echo "Exported docker config HTTP_PROXY=${HTTP_PROXY}" + fi + echo "HTTP_PROXY=${HTTP_PROXY}" >>"${ENV_FILE}" + echo "proxy=${HTTP_PROXY}" >>"${ENV_FILE}" + + if [ -z "${HTTPS_PROXY}" ] && [ -f ~/.docker/config.json ]; then + HTTPS_PROXY=$(grep httpsProxy ~/.docker/config.json | awk -F'\"[:space:]*:[:space:]*' '{split($2,a,"\""); print a[2]}') + echo "Exported docker config HTTPS_PROXY=${HTTPS_PROXY}" + elif [ -n "${HTTPS_PROXY}" ]; then + echo "Exported docker config HTTPS_PROXY=${HTTPS_PROXY}" + fi + echo "HTTPS_PROXY=${HTTPS_PROXY}" >>"${ENV_FILE}" + + if [ -z "${http_proxy}" ] && [ -f ~/.docker/config.json ]; then + http_proxy=$(grep httpProxy ~/.docker/config.json | awk -F'\"[:space:]*:[:space:]*' '{split($2,a,"\""); print a[2]}') + echo "Exported docker config http_proxy=${http_proxy}" + elif [ -n "${http_proxy}" ]; then + echo "Exported docker config http_proxy=${http_proxy}" + fi + echo "http_proxy=${http_proxy}" >>"${ENV_FILE}" + + if [ -z "${https_proxy}" ] && [ -f ~/.docker/config.json ]; then + https_proxy=$(grep httpsProxy ~/.docker/config.json | awk -F'\"[:space:]*:[:space:]*' '{split($2,a,"\""); print a[2]}') + echo "Exported docker config https_proxy=${https_proxy}" + elif [ -n "${https_proxy}" ]; then + echo "Exported docker config https_proxy=${https_proxy}" + fi + echo "https_proxy=${https_proxy}" >>"${ENV_FILE}" + + if [ -z "${NO_PROXY}" ] && [ -f ~/.docker/config.json ]; then + NO_PROXY=$(grep noProxy ~/.docker/config.json | awk -F'\"[:space:]*:[:space:]*' '{split($2,a,"\""); print a[2]}') + echo "Exported docker config NO_PROXY=${NO_PROXY}" + elif [ -n "${NO_PROXY}" ]; then + echo "Exported docker config NO_PROXY=${NO_PROXY}" + fi + echo "NO_PROXY=${NO_PROXY}" >>"${ENV_FILE}" + + cat "${ENV_FILE}" +} + +ENV_FILE=$(mktemp) +ARTIFACT_DIR=$(mktemp -d) +populate_env_file "${ENV_FILE}" +mkdir -p "${SCRIPT_DIR}/../.github/logs/" +unbuffer act -W "${WORKFLOW_FILE}" --env-file="${ENV_FILE}" --secret-file="${SECRETS_FILE}" \ + --artifact-server-path "${ARTIFACT_DIR}" \ + "$@" | tee "${SCRIPT_DIR}/../.github/logs/$(date '+%F-%T').log" +rm "${ENV_FILE}" diff --git a/scripts/mk-cloudinit.sh b/scripts/mk-cloudinit.sh new file mode 100755 index 0000000..bc64315 --- /dev/null +++ b/scripts/mk-cloudinit.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +# sudo -E dnf install -y cloud-utils + +mkdir -p .github/rsrc/ +# password is "password" +# mkpasswd --method=SHA-512 --rounds=4096 +PASSWD="$6$rounds=4096$EhaOFVl.Hr626Zg2$mIqOEWTXg0U4cfIDDsYYLtqNMoCLRMVQfX4iZnlQTt.dnBoXetHdMzyGdY2MVOWGV18UowbFNSJowTHmBDb4z1" +cat < .github/rsrc/user-data.yml +users: + - name: user + passwd: ${PASSWD} + lock_passwd: false + groups: [sudo] + shell: /bin/bash +EOF + +cloud-localds .github/rsrc/seed.img .github/rsrc/user-data.yml \ No newline at end of file From bb8c68316bb34ebbe649bc4baf4ab2c3fa25d6cc Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 13:29:29 -0800 Subject: [PATCH 21/33] Add config line to cloud init --- .github/rsrc/seed.img | Bin 374784 -> 374784 bytes .github/workflows/ci.yml | 5 +++-- scripts/mk-cloudinit.sh | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/rsrc/seed.img b/.github/rsrc/seed.img index d9719b636299bccb6dc348f0443849d776ac1907..06ae5a34426abd0afd25d65091f03c6a8e895e40 100644 GIT binary patch delta 280 zcmZqpAlC3fY=cF!h^3*4fx!bK10xdyLjy}gV .github/rsrc/user-data.yml +#cloud-config users: - name: user passwd: ${PASSWD} From 576aead1d211073d11d1ec003277ec8999a7ab1b Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 19:01:38 -0800 Subject: [PATCH 22/33] Add working cloud-init config --- .github/rsrc/id_rsa | 38 ++++++++++++++++++++++++++++++++++++++ .github/rsrc/id_rsa.pub | 1 + .github/rsrc/seed.img | Bin 374784 -> 374784 bytes .github/workflows/ci.yml | 19 ++++++++++++++----- qemu-plugin/src/lib.rs | 4 ++-- scripts/mk-cloudinit.sh | 22 +++++++++++++++------- 6 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 .github/rsrc/id_rsa create mode 100644 .github/rsrc/id_rsa.pub diff --git a/.github/rsrc/id_rsa b/.github/rsrc/id_rsa new file mode 100644 index 0000000..5f13cfc --- /dev/null +++ b/.github/rsrc/id_rsa @@ -0,0 +1,38 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn +NhAAAAAwEAAQAAAYEA2bW01Jm9ujWY0VoDuL3D4XmQ09D1Tkyg98MQoXNg7nZ6IJP2F8PW +N4OHRwrd6/flcDj5c8YfgkwqCryu8f/qq+nlgaQ8dskJIUnaLa3YtVax2KrQu/2zHH6StI +abiQYKM+6L0OPZxwrbX+uSfs/QEAF0KCxcXVDjvXjpvOla+MWunm9B+s11yj+qesSc+MWp +gZKvZYH8FmIIy+P77cnnjDgXx51vHHdO8rI4uLuoNpaMQjqbtpGP3pFYbqAId1lrQSBzVJ +4ybrhZw/+pfzhoXrHDCd4lTd6fihj0IHQkPmuxgd09EZONfsiDGX7iUoTrRvGt9WjCVClz +vjPgCIy/0hpUG4/+1GAtX4V3rN84gT1e+qThFL8GimiPzUXL1abT5YQiWCbN/eJ90kd/Tj +fhsAhD1xOOK8TlHi/28COF+czhSektncm0Wrng5wWYpZkJG7yX4GE5MKWikgCXB4SvCW81 +0+Ievgk1g7nL2c8oynYixG2JfE4q3gcFmOf9UwixAAAFiE9S/jRPUv40AAAAB3NzaC1yc2 +EAAAGBANm1tNSZvbo1mNFaA7i9w+F5kNPQ9U5MoPfDEKFzYO52eiCT9hfD1jeDh0cK3ev3 +5XA4+XPGH4JMKgq8rvH/6qvp5YGkPHbJCSFJ2i2t2LVWsdiq0Lv9sxx+krSGm4kGCjPui9 +Dj2ccK21/rkn7P0BABdCgsXF1Q47146bzpWvjFrp5vQfrNdco/qnrEnPjFqYGSr2WB/BZi +CMvj++3J54w4F8edbxx3TvKyOLi7qDaWjEI6m7aRj96RWG6gCHdZa0Egc1SeMm64WcP/qX +84aF6xwwneJU3en4oY9CB0JD5rsYHdPRGTjX7Igxl+4lKE60bxrfVowlQpc74z4AiMv9Ia +VBuP/tRgLV+Fd6zfOIE9Xvqk4RS/Bopoj81Fy9Wm0+WEIlgmzf3ifdJHf0434bAIQ9cTji +vE5R4v9vAjhfnM4UnpLZ3JtFq54OcFmKWZCRu8l+BhOTClopIAlweErwlvNdPiHr4JNYO5 +y9nPKMp2IsRtiXxOKt4HBZjn/VMIsQAAAAMBAAEAAAGAB2nBl1zoDgRz0HqcvnRXPHjsyJ +qglLbFIySdLwswR3RpMI1rO3hNlbi0wTN2dqnLciqde17JXUDhzFlsCVVcELgjWoqMrMSI +Cx4yN7yYAMY7wm+AEauoBvoMHamo94WpMKcgc4ejp2x4J3QsegUSXg4nnfPTPhHyXEX3Cw +nE4UxNZ6uNCwjGmFE6SUmDOREVdlIX5vhh7KLwTt2Dqz9VEyQokqFqqnTpTzgoeGla5ydx +jZKEcXczx3nKYaNxQFue/ElJw9KabSAZ3v3T9rzw0z3rP7n0Bvn/xs7+i2cKJhJIkQtPUa +Z1r/GMrE+yp3BMYw5vcqKx+OOvNPkoIiRSzuyJ3qJK4okibtDCkYfPk/FxuCX/7nVlL/Ak +n3CaVWWWGTGOyohW6+MxJ/z16gqgXNy8gwKRnsIEUtpc7RoGIO8MT5fVrMOhlwmJHnPnEm +2/185hraTHLrb8V6suTwCvbzB65e3TSQaJXyMqOyYSdOXM3fmpZrSmHw7y8DqJ74lhAAAA +wDIxqOfvRc7j736AKgp2qDhJftc/mb8osZsbPgApCbVLZmI9Zvy1PFDEcNfDunU06Mue+2 +yaWhaeQ180UAqJ4E3vgE1OkBMae+bPyk/v5HeGmZfxvcFhxP87/zMxqARxVLy2ECDS2NR5 +A/G5bL4VJatmFJiAa5N137X5FDlctvy5h+ZEhMJdy/LYCJld5mM7EMoa3AKErkSnhdI+mH +v9x34mWSzeB198qGb7QMqvhGLu7ZEVqRAIaAZ5HhkIx8oO0QAAAMEA97+ZMXEbNQFTyFMO +GuT42A3wU0RJmKqRD3wQDeW5Ua/RF+WeaMxAWRZG5Pj8X0p4WAsupJEfU4FZFsQhmu0Kzr +vvTEHmFBmupnYdwmQSDk4SkJLrXNQSpkFoxTdSDZ3/P+WgDAdC1pU1/ClAXS7gQZhWLzCo +IGDIFkUEvcUCxh0Jf8YszFWWb3WZ7lOBFdQCyS6SmvQtyq+M8ghi0Ce+btU3TvpFPRKa0p +LT9vw3LMhjeYidBrzZu/gvWWuhJb3hAAAAwQDg9fyPweE++XeHXtyzqDZIRRw5O/fsEGow +cgSDfII2zJhiPOzO55HuguS92uak7oLsoFx5+Ulw9jdFu+spn2W2+iAaSlg9CTQVSt/Z/W +gyN48rYziYtoC0eKcKNdXoMX+ovAdwRA7LfGVc3MKm1jX+tlJ6lcWT5ZAodGdDX+mzMJfA +8U6K4Z/lgId5D/xZjNMm5n+dZ7rnLcQoUsa7nnrJ6wob4nDDEYDIGx4FvDIyyEupRmesmt +2S9f5i0kz7hNEAAAAQZmVkb3JhQGxvY2FsaG9zdAECAw== +-----END OPENSSH PRIVATE KEY----- diff --git a/.github/rsrc/id_rsa.pub b/.github/rsrc/id_rsa.pub new file mode 100644 index 0000000..b742645 --- /dev/null +++ b/.github/rsrc/id_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDZtbTUmb26NZjRWgO4vcPheZDT0PVOTKD3wxChc2Dudnogk/YXw9Y3g4dHCt3r9+VwOPlzxh+CTCoKvK7x/+qr6eWBpDx2yQkhSdotrdi1VrHYqtC7/bMcfpK0hpuJBgoz7ovQ49nHCttf65J+z9AQAXQoLFxdUOO9eOm86Vr4xa6eb0H6zXXKP6p6xJz4xamBkq9lgfwWYgjL4/vtyeeMOBfHnW8cd07ysji4u6g2loxCOpu2kY/ekVhuoAh3WWtBIHNUnjJuuFnD/6l/OGhescMJ3iVN3p+KGPQgdCQ+a7GB3T0Rk41+yIMZfuJShOtG8a31aMJUKXO+M+AIjL/SGlQbj/7UYC1fhXes3ziBPV76pOEUvwaKaI/NRcvVptPlhCJYJs394n3SR39ON+GwCEPXE44rxOUeL/bwI4X5zOFJ6S2dybRaueDnBZilmQkbvJfgYTkwpaKSAJcHhK8JbzXT4h6+CTWDucvZzyjKdiLEbYl8TireBwWY5/1TCLE= fedora@localhost diff --git a/.github/rsrc/seed.img b/.github/rsrc/seed.img index 06ae5a34426abd0afd25d65091f03c6a8e895e40..6f41b8e7d459fddf1f0974d5ab06f3b0ab58f356 100644 GIT binary patch delta 1334 zcma)6-D=}T6i!&WrF&7@g=TwGqFvI`A{@z*EK4a_YRQfrNw#cDwq;W&`WZ{IWJ%GV zWl`1(>0P0e<^_7!+lGCKK1TK~mw|nNR{kkVn}v2@=9_cQH|Lxgedy)g!OOdY-^t4Z z3dis&ir!!-MxbSsE^i!H!sTc0ZFaA`%Rk=#AFLmLlOH^WKEL|(hWWU_oA38Ocnep~ z4YrB?dh<2>*8MkW@5SEX-ew#=-Qv^j@vDcgrFZk8Ef0G0V7+M?uC>T3p$)Md0g6lK1SFEZBBv3g>7zUd%iWkHW|lQ3FrjE6Kl zT!>va&n%dgS)Wh&YKFiUAqhrIP|vVs&#@%Kk3+*Q55v~@B4(?I*4C#1k6J;(F{Yna z{j^8WE3ZfxPss`g=XBAZ(({G0%ovCw4a7M`4nrbSNuZ%EGFKG7O9o`d<%Ms~I2W{Q zP8XxGITHvZjh6tlMP}OaMwD)#)nzoZiG(yU*UwlnNHAxN0B2|=e$B#1qnJ5wbq3yQ z#wE#_S4T(}5t|l>^frgv!ww$6e6!m#4YmiX)h2_>Xx|~q@bbJpnI@cMiE)!s@v_?H z2D~D|ZMb$m6A-EC_OuyN9gNxX)KWl%=Qh(FR>?qY4AOl@eC zRoC*P_!;#4`F(jIY7$$1Xy?HA&H>A4Bez0r3lA#wcM3h(%JKf;9eM5>Q1Soycii2H zSGU##@;)K5-dTMs_Fc`IAe??#EMGw#v0Ia*QT?Q_ws!%sjzo#!gD`q@z5nOx`lGx5 Im_HGJ0dwo9YybcN delta 487 zcmZqpAlC3fY=c>|n6Z(ip^1UP10w??69Yp7OGB{0WS?ePRxoRGUh@fdB2;xR4`Jq& z<(n+=z)28DKd52kL{O8n9~gmU7d)`mMhL?cG1M{0Gk}4-B7|0iXrIjXFc`af1&BI@ zRS(Ad nxHKg{7A#hrk(!fZrJ$dbnWvwWSe(JNk@0{1Mu86m@O5(l&UuXG diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a301831..b906f10 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: - name: Build and Test Tiny run: | cd plugins/tiny - cargo build -r || exit 0 cargo build -r qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah cd ../.. @@ -49,7 +48,7 @@ jobs: # QEMU 8.1.0 QEMU_URL: "https://qemu.weilnetz.de/w64/2023/qemu-w64-setup-20230822.exe" RUSTUP_URL: "https://win.rustup.rs/x86_64" - UBUNTU_CLOUDIMG_URL: "https://cloud-images.ubuntu.com/releases/22.04/release-20231211/ubuntu-22.04-server-cloudimg-amd64.img" + FEDORA_CLOUDIMG_URL: "https://download.fedoraproject.org/pub/fedora/linux/releases/39/Cloud/x86_64/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2" steps: - uses: msys2/setup-msys2@v2 @@ -75,12 +74,22 @@ jobs: - name: Download Ubuntu Cloud Image run: | $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri ${{ env.UBUNTU_CLOUDIMG_URL }} -OutFile ubuntu.img + Invoke-WebRequest -Uri ${{ env.FEDORA_CLOUDIMG_URL }} -OutFile Fedora-Cloud-Base-39-1.5.x86_64.qcow2 - name: Build and Test Tiny + shell: msys2 {0} run: | cd plugins/tiny - cargo build -r || exit 0 cargo build -r cd ../.. - qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -drive if=virtio,format=qcow2,file=ubuntu.img -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/libtiny.so + $job = Start-Job -ScriptBlock { qemu-system-x86_64 -machine type=q35 -m 2G -nographic -serial stdio -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img } + Start-Sleep -Seconds 45.0 + $jobEvent = Register-ObjectEvent $job StateChanged -Action { + $jobEvent | Unregister-Event + Write-Host "Unregistered and succeeded!" + Set-Content -Path success "" + } + ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now + Start-Sleep -Seconds 15.0 + $status = Test-Path -Path success + exit $status diff --git a/qemu-plugin/src/lib.rs b/qemu-plugin/src/lib.rs index f38ea3a..1f2b8e5 100644 --- a/qemu-plugin/src/lib.rs +++ b/qemu-plugin/src/lib.rs @@ -107,11 +107,11 @@ extern "C" { } #[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. - + // NOTE: glib 2.46 g_malloc always uses system malloc implementation: // https://docs.gtk.org/glib/func.mem_is_system_malloc.html // So it is safe to call libc free to free a `g_malloc`-ed object diff --git a/scripts/mk-cloudinit.sh b/scripts/mk-cloudinit.sh index f12fec2..48ebc65 100755 --- a/scripts/mk-cloudinit.sh +++ b/scripts/mk-cloudinit.sh @@ -5,17 +5,25 @@ set -e # sudo -E dnf install -y cloud-utils mkdir -p .github/rsrc/ +rm .github/rsrc/id_* || true +if [ ! -f .github/rsrc/id_rsa ]; then + ssh-keygen -C fedora@localhost -t rsa -q -f .github/rsrc/id_rsa -N "" +fi + +KEY="$(cat .github/rsrc/id_rsa.pub)" # password is "password" # mkpasswd --method=SHA-512 --rounds=4096 -PASSWD="$6$rounds=4096$EhaOFVl.Hr626Zg2$mIqOEWTXg0U4cfIDDsYYLtqNMoCLRMVQfX4iZnlQTt.dnBoXetHdMzyGdY2MVOWGV18UowbFNSJowTHmBDb4z1" +PASSWORD='$6$rounds=4096$At.ZMrhUfvsFwTiG$VJ8aQCC3nr8SpUL99OHcWsR6BvlVur5qvKQHni8n5v1HxB0E3.2eLX0tbxq8nHv.JJb2cU5mXr8bAgogCd5Ke1' cat < .github/rsrc/user-data.yml #cloud-config -users: - - name: user - passwd: ${PASSWD} - lock_passwd: false - groups: [sudo] - shell: /bin/bash +bootcmd: + - useradd -m -p ${PASSWORD} -s /bin/bash fedora + - mkdir -p /home/fedora/.ssh + - echo "${KEY}" >> /home/fedora/.ssh/authorized_keys + - chown -R fedora:fedora /home/fedora/.ssh + - chmod 700 /home/fedora/.ssh + - chmod 600 /home/fedora/.ssh/authorized_keys + - echo "fedora ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers EOF cloud-localds .github/rsrc/seed.img .github/rsrc/user-data.yml \ No newline at end of file From 8709fe09ec0b75720cb39a54c0d5c1d80405711e Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 19:06:08 -0800 Subject: [PATCH 23/33] Use powershell --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b906f10..d5b83ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,9 +41,6 @@ jobs: test_plugins_windows: name: Build and Test Plugins (Windows) runs-on: windows-latest - defaults: - run: - shell: msys2 {0} env: # QEMU 8.1.0 QEMU_URL: "https://qemu.weilnetz.de/w64/2023/qemu-w64-setup-20230822.exe" @@ -77,12 +74,12 @@ jobs: Invoke-WebRequest -Uri ${{ env.FEDORA_CLOUDIMG_URL }} -OutFile Fedora-Cloud-Base-39-1.5.x86_64.qcow2 - name: Build and Test Tiny - shell: msys2 {0} run: | + $env:Path += ";C:\msys64\ucrt64\bin;C:\msys64\usr\bin;" cd plugins/tiny cargo build -r cd ../.. - $job = Start-Job -ScriptBlock { qemu-system-x86_64 -machine type=q35 -m 2G -nographic -serial stdio -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img } + $job = Start-Job -ScriptBlock { C:\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -serial stdio -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img } Start-Sleep -Seconds 45.0 $jobEvent = Register-ObjectEvent $job StateChanged -Action { $jobEvent | Unregister-Event From bd63c72bf62dc699ca5a2f379db938da87c8222b Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 19:17:43 -0800 Subject: [PATCH 24/33] Add system syscall trace plugin --- Cargo.toml | 1 + plugins/tiny-system/Cargo.toml | 13 ++++++++++ plugins/tiny-system/src/lib.rs | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 plugins/tiny-system/Cargo.toml create mode 100644 plugins/tiny-system/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index aa92bc1..c89807b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "qemu-plugin", "qemu-plugin-sys", "plugins/tiny", + "plugins/tiny-system", "plugins/tracer", ] default-members = ["qemu-plugin", "qemu-plugin-sys"] diff --git a/plugins/tiny-system/Cargo.toml b/plugins/tiny-system/Cargo.toml new file mode 100644 index 0000000..47d3942 --- /dev/null +++ b/plugins/tiny-system/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "tiny-system" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +qemu-plugin.workspace = true +anyhow = "1.0.75" +ffi = "0.1.0" +ctor = "0.2.6" diff --git a/plugins/tiny-system/src/lib.rs b/plugins/tiny-system/src/lib.rs new file mode 100644 index 0000000..ff2b88d --- /dev/null +++ b/plugins/tiny-system/src/lib.rs @@ -0,0 +1,43 @@ +use anyhow::{anyhow, Result}; +use ctor::ctor; +use qemu_plugin::{ + plugin::{HasCallbacks, Plugin, Register, PLUGIN}, + PluginId, +}; +use std::sync::Mutex; + +struct TinyTrace {} + +impl Plugin for TinyTrace {} +impl Register for TinyTrace {} + +impl HasCallbacks for TinyTrace { + fn on_syscall( + &mut self, + id: PluginId, + vcpu_index: qemu_plugin::VCPUIndex, + num: i64, + a1: u64, + a2: u64, + a3: u64, + a4: u64, + a5: u64, + a6: u64, + a7: u64, + a8: u64, + ) -> Result<(), anyhow::Error> { + println!( + "on_syscall: id: {:?}, vcpu_index: {:?}, num: {:?}, a1: {:?}, a2: {:?}, a3: {:?}, a4: {:?}, a5: {:?}, a6: {:?}, a7: {:?}, a8: {:?}", + id, vcpu_index, num, a1, a2, a3, a4, a5, a6, a7, a8 + ); + Ok(()) + } +} + +#[ctor] +fn init() { + PLUGIN + .set(Mutex::new(Box::new(TinyTrace {}))) + .map_err(|_| anyhow!("Failed to set plugin")) + .expect("Failed to set plugin"); +} From 19e486cd256316a61184f19656cce13e62612a55 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 19:47:42 -0800 Subject: [PATCH 25/33] Use Start-Process instead of Start-Job --- .github/workflows/ci.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5b83ef..746ce4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,17 +76,9 @@ jobs: - name: Build and Test Tiny run: | $env:Path += ";C:\msys64\ucrt64\bin;C:\msys64\usr\bin;" - cd plugins/tiny + cd plugins/tiny-system cargo build -r cd ../.. - $job = Start-Job -ScriptBlock { C:\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -serial stdio -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img } - Start-Sleep -Seconds 45.0 - $jobEvent = Register-ObjectEvent $job StateChanged -Action { - $jobEvent | Unregister-Event - Write-Host "Unregistered and succeeded!" - Set-Content -Path success "" - } + Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + Start-Sleep -Seconds 60.0 ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now - Start-Sleep -Seconds 15.0 - $status = Test-Path -Path success - exit $status From d58ed8461523b6e2104ec24ffba47b9d19ca47b9 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 19:56:43 -0800 Subject: [PATCH 26/33] Locating qemu --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 746ce4f..65da99a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,8 @@ jobs: run: | pacman -Syu --noconfirm pacman -Sy mingw-w64-ucrt-x86_64-qemu --noconfirm + qemu-system-x86_64.exe --version + which qemu-system-x86_64 - uses: actions/checkout@v4 @@ -75,7 +77,6 @@ jobs: - name: Build and Test Tiny run: | - $env:Path += ";C:\msys64\ucrt64\bin;C:\msys64\usr\bin;" cd plugins/tiny-system cargo build -r cd ../.. From ece4c6fcbfe2cb08c6a3aae60bd30a323dca0a06 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 20:31:19 -0800 Subject: [PATCH 27/33] Use custom msys path --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65da99a..1698da8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,7 @@ jobs: msystem: UCRT64 update: true install: git mingw-w64-ucrt-x86_64-gcc + location: C:\msys-custom - name: Download and Install Rust run: | @@ -65,8 +66,7 @@ jobs: run: | pacman -Syu --noconfirm pacman -Sy mingw-w64-ucrt-x86_64-qemu --noconfirm - qemu-system-x86_64.exe --version - which qemu-system-x86_64 + C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe --version - uses: actions/checkout@v4 @@ -80,6 +80,6 @@ jobs: cd plugins/tiny-system cargo build -r cd ../.. - Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" Start-Sleep -Seconds 60.0 ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now From 28d40aecb09eeff240e19f3895f178ab0117f6fc Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 20:44:47 -0800 Subject: [PATCH 28/33] Test in powershell --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1698da8..eddaffe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,9 @@ jobs: run: | pacman -Syu --noconfirm pacman -Sy mingw-w64-ucrt-x86_64-qemu --noconfirm + + - name: Test QEMU + run: | C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe --version - uses: actions/checkout@v4 From 01ae201b7af54748d6556afb071b04a12fe323b8 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 20:59:30 -0800 Subject: [PATCH 29/33] Fix path to cloud img --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eddaffe..f0d978e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,16 +73,17 @@ jobs: - uses: actions/checkout@v4 - - name: Download Ubuntu Cloud Image + - name: Download Cloud Image run: | $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri ${{ env.FEDORA_CLOUDIMG_URL }} -OutFile Fedora-Cloud-Base-39-1.5.x86_64.qcow2 + ls - name: Build and Test Tiny run: | cd plugins/tiny-system cargo build -r cd ../.. - Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=../Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" Start-Sleep -Seconds 60.0 ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now From e688b977edaad6e77198fb0f6f319fd6caf05c2a Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 21:00:34 -0800 Subject: [PATCH 30/33] Wait for process to exit --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0d978e..07d3ff6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,7 @@ jobs: cd plugins/tiny-system cargo build -r cd ../.. - Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + $process = Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" Start-Sleep -Seconds 60.0 ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now + Wait-Process -Id $process.id From 917500b52c506094b0e96948b652c4568865e061 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 21:21:01 -0800 Subject: [PATCH 31/33] Wait with sleep and increase time before shutdown --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07d3ff6..42e6482 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,8 @@ jobs: cd plugins/tiny-system cargo build -r cd ../.. - $process = Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" - Start-Sleep -Seconds 60.0 + Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + Start-Sleep -Seconds 240.0 ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now - Wait-Process -Id $process.id + # Wait for shutdown + Start-Sleep -Seconds 30.0 From fab7ac571b131253e2635f3743e89d7052fe60e5 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 22:27:24 -0800 Subject: [PATCH 32/33] Add debug messages --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42e6482..f16b4bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,10 @@ jobs: cargo build -r cd ../.. Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" - Start-Sleep -Seconds 240.0 + echo "Sleeping 180.0 seconds until booted (boot process took 118s first time)" + Start-Sleep -Seconds 180.0 + echo "Sending shutdown command to VM" ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now # Wait for shutdown + echo "Waiting 30.0 seconds for shutdown" Start-Sleep -Seconds 30.0 From 30d0d7b7192c99ee9c1ad2f6a90539008da4b727 Mon Sep 17 00:00:00 2001 From: novafacing Date: Tue, 9 Jan 2024 23:11:22 -0800 Subject: [PATCH 33/33] Switch system example to actually do things in system mode, remove SSHing and just stop process --- .github/workflows/ci.yml | 11 ++++---- plugins/tiny-system/src/lib.rs | 47 ++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f16b4bb..fbe1ad9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,11 +84,10 @@ jobs: cd plugins/tiny-system cargo build -r cd ../.. - Start-Process PowerShell.exe -NoNewWindow -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" + $process = Start-Process PowerShell.exe -NoNewWindow -RedirectStandardOutput out.txt -RedirectStandardError err.txt -PassThru -ArgumentList "-Command", "C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe -machine type=q35 -m 2G -nographic -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=virtio,format=qcow2,file=Fedora-Cloud-Base-39-1.5.x86_64.qcow2 -drive if=virtio,format=raw,file=.github/rsrc/seed.img -plugin target/release/tiny_system.dll" echo "Sleeping 180.0 seconds until booted (boot process took 118s first time)" Start-Sleep -Seconds 180.0 - echo "Sending shutdown command to VM" - ssh -p 2222 -i .github/rsrc/id_rsa fedora@localhost sudo shutdown now - # Wait for shutdown - echo "Waiting 30.0 seconds for shutdown" - Start-Sleep -Seconds 30.0 + echo "Stopping process" + Stop-Process -Id $process.id + cat out.txt + cat err.txt diff --git a/plugins/tiny-system/src/lib.rs b/plugins/tiny-system/src/lib.rs index ff2b88d..22b85d1 100644 --- a/plugins/tiny-system/src/lib.rs +++ b/plugins/tiny-system/src/lib.rs @@ -12,24 +12,39 @@ impl Plugin for TinyTrace {} impl Register for TinyTrace {} impl HasCallbacks for TinyTrace { - fn on_syscall( + fn on_vcpu_init( &mut self, id: PluginId, - vcpu_index: qemu_plugin::VCPUIndex, - num: i64, - a1: u64, - a2: u64, - a3: u64, - a4: u64, - a5: u64, - a6: u64, - a7: u64, - a8: u64, - ) -> Result<(), anyhow::Error> { - println!( - "on_syscall: id: {:?}, vcpu_index: {:?}, num: {:?}, a1: {:?}, a2: {:?}, a3: {:?}, a4: {:?}, a5: {:?}, a6: {:?}, a7: {:?}, a8: {:?}", - id, vcpu_index, num, a1, a2, a3, a4, a5, a6, a7, a8 - ); + vcpu_id: qemu_plugin::VCPUIndex, + ) -> std::prelude::v1::Result<(), anyhow::Error> { + println!("on_vcpu_init: id: {:?}, vcpu_id: {:?}", id, vcpu_id); + Ok(()) + } + + fn on_vcpu_idle( + &mut self, + id: PluginId, + vcpu_id: qemu_plugin::VCPUIndex, + ) -> std::prelude::v1::Result<(), anyhow::Error> { + println!("on_vcpu_idle: id: {:?}, vcpu_id: {:?}", id, vcpu_id); + Ok(()) + } + + fn on_vcpu_exit( + &mut self, + id: PluginId, + vcpu_id: qemu_plugin::VCPUIndex, + ) -> std::prelude::v1::Result<(), anyhow::Error> { + println!("on_vcpu_exit: id: {:?}, vcpu_id: {:?}", id, vcpu_id); + Ok(()) + } + + fn on_vcpu_resume( + &mut self, + id: PluginId, + vcpu_id: qemu_plugin::VCPUIndex, + ) -> std::prelude::v1::Result<(), anyhow::Error> { + println!("on_vcpu_resume: id: {:?}, vcpu_id: {:?}", id, vcpu_id); Ok(()) } }