Skip to content

Commit

Permalink
Merge pull request #16 from novafacing/add-v9.0.0-api
Browse files Browse the repository at this point in the history
Update to 9.0.0, add plugin version 2 and 3, update tracer and tiny examples with register output.
  • Loading branch information
novafacing authored Jun 3, 2024
2 parents 7b6088c + fa36f97 commit 7c481e8
Show file tree
Hide file tree
Showing 32 changed files with 2,799 additions and 554 deletions.
227 changes: 215 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,218 @@ env:
CARGO_TERM_COLOR: always

jobs:
test_plugins_linux:
name: Build and Test Plugins (Linux)
test_plugins_linux_v1:
name: Build and Test Plugins API v1 (Linux)
runs-on: ubuntu-latest
container: ubuntu:22.04
container: ubuntu:24.04
env:
# Hash of v1
QEMU_COMMIT_HASH: fb691b8cbabf5bde7d25a7f720d5ec7d5b1341e1
steps:
- name: Install QEMU User
- name: Set up Sources List
run: |
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y build-dep qemu
# Clone without history
- name: Clone QEMU
run: |
git clone https://github.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"
- name: Build QEMU
run: |
cd qemu-upstream
./configure --enable-plugins
cd build
make -j$(nproc)
make install
cd ../..
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
run: |
qemu-x86_64 --help
- name: Build and Test Tracer
run: |
apt-get -y update && \
apt-get -y install git curl qemu-user build-essential
cd plugins/tracer
cargo build -r --features=plugin-api-v1 --no-default-features || exit 0
cargo build -r --features=plugin-api-v1 --no-default-features
cargo run --features=plugin-api-v1 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..
- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r --features=plugin-api-v1 --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..
test_plugins_linux_v2:
name: Build and Test Plugins API v2 (Linux)
runs-on: ubuntu-latest
container: ubuntu:24.04
env:
# Hash of v2
QEMU_COMMIT_HASH: fba3b490a26cb278dfa183d7fcc375746e312980
steps:
- name: Set up Sources List
run: |
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y build-dep qemu
# Clone without history
- name: Clone QEMU
run: |
git clone https://github.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"
- name: Build QEMU
run: |
cd qemu-upstream
./configure --enable-plugins
cd build
make -j$(nproc)
make install
cd ../..
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
run: |
qemu-x86_64 --help
- name: Build and Test Tracer
run: |
cd plugins/tracer
cargo build -r --features=plugin-api-v2 --no-default-features || exit 0
cargo build -r --features=plugin-api-v2 --no-default-features
cargo run --features=plugin-api-v2 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..
- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r --features=plugin-api-v2 --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..
test_plugins_linux_v3:
name: Build and Test Plugins API V3 (Linux)
runs-on: ubuntu-latest
container: ubuntu:24.04
env:
# Hash of v3
QEMU_COMMIT_HASH: 7de77d37880d7267a491cb32a1b2232017d1e545
steps:
- name: Set up Sources List
run: |
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y build-dep qemu
# Clone without history
- name: Clone QEMU
run: |
git clone https://github.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"
- name: Build QEMU
run: |
cd qemu-upstream
./configure --enable-plugins
cd build
make -j$(nproc)
make install
cd ../..
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
Expand All @@ -27,22 +230,22 @@ jobs:
- name: Build and Test Tracer
run: |
cd plugins/tracer
cargo build -r || exit 0
cargo build -r
cargo run -r --bin tracer -- -a /bin/ls -- -lah
cargo build -r --features=plugin-api-v3 --no-default-features || exit 0
cargo build -r --features=plugin-api-v3 --no-default-features
cargo run --features=plugin-api-v3 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..
- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r
cargo build -r --features=plugin-api-v3 --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..
test_plugins_windows:
name: Build and Test Plugins (Windows)
runs-on: windows-latest
env:
# QEMU 8.2.0
# QEMU 9.0.0
# NOTE: This installer does not work headless
# QEMU_URL: "https://qemu.weilnetz.de/w64/2023/qemu-w64-setup-20231224.exe"
RUSTUP_URL: "https://win.rustup.rs/x86_64"
Expand Down Expand Up @@ -83,7 +286,7 @@ jobs:
- name: Build and Test Tiny
run: |
cd plugins/tiny-system
cargo build -r
cargo build -r --features=plugin-api-v3 --no-default-features
cd ../..
$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)"
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.buildScripts.enable": false
"rust-analyzer.cargo.buildScripts.enable": false,
}
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-2.0-only"
publish = true
readme = "README.md"
repository = "https://github.com/novafacing/qemu-rs"
version = "8.2.2-v0"
version = "9.0.0-v0"

[workspace]
resolver = "2"
Expand All @@ -23,6 +23,6 @@ members = [
default-members = ["qemu-plugin", "qemu-plugin-sys"]

[workspace.dependencies]
qemu-plugin-sys = { version = "8.2.2-v0", path = "qemu-plugin-sys" }
qemu-plugin = { version = "8.2.2-v0", path = "qemu-plugin" }
qemu = { version = "8.2.2-v0", path = "qemu" }
qemu-plugin-sys = { version = "9.0.0-v0", path = "qemu-plugin-sys", default-features = false }
qemu-plugin = { version = "9.0.0-v0", path = "qemu-plugin", default-features = false }
qemu = { version = "9.0.0-v0", path = "qemu" }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ 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.2.2-v0 --features=binaries
cargo install qemu@9.0.0-v0 --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.
`CARGO_TARGET_DIR=$HOME/.cargo/tmp` when running the install command.
10 changes: 9 additions & 1 deletion plugins/tiny-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
qemu-plugin.workspace = true
qemu-plugin = { workspace = true, features = [
"unix-weak-link",
], default-features = false }
anyhow = "1.0.75"
ffi = "0.1.0"
ctor = "0.2.6"

[features]
default = ["plugin-api-v2"]
plugin-api-v1 = ["qemu-plugin/plugin-api-v1"]
plugin-api-v2 = ["qemu-plugin/plugin-api-v2"]
plugin-api-v3 = ["qemu-plugin/plugin-api-v3"]
10 changes: 9 additions & 1 deletion plugins/tiny/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
qemu-plugin.workspace = true
qemu-plugin = { workspace = true, features = [
"unix-weak-link",
], default-features = false }
anyhow = "1.0.75"
ffi = "0.1.0"
ctor = "0.2.6"

[features]
default = ["plugin-api-v2"]
plugin-api-v1 = ["qemu-plugin/plugin-api-v1"]
plugin-api-v2 = ["qemu-plugin/plugin-api-v2"]
plugin-api-v3 = ["qemu-plugin/plugin-api-v3"]
28 changes: 25 additions & 3 deletions plugins/tiny/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,53 @@ use qemu_plugin::{
plugin::{HasCallbacks, Plugin, Register, PLUGIN},
PluginId, TranslationBlock,
};
#[cfg(any(feature = "plugin-api-v2", feature = "plugin-api-v3"))]
use qemu_plugin::{qemu_plugin_get_registers, RegisterDescriptor, VCPUIndex};
use std::sync::Mutex;

struct TinyTrace {}
#[derive(Default)]
struct TinyTrace {
#[cfg(any(feature = "plugin-api-v2", feature = "plugin-api-v3"))]
registers: Vec<RegisterDescriptor<'static>>,
}

impl Plugin for TinyTrace {}
impl Register for TinyTrace {}

impl HasCallbacks for TinyTrace {
#[cfg(any(feature = "plugin-api-v2", feature = "plugin-api-v3"))]
fn on_vcpu_init(&mut self, _id: PluginId, _vcpu_id: VCPUIndex) -> Result<()> {
self.registers = qemu_plugin_get_registers()?;
Ok(())
}
fn on_translation_block_translate(
&mut self,
_id: PluginId,
tb: TranslationBlock,
) -> Result<()> {
#[cfg(any(feature = "plugin-api-v2", feature = "plugin-api-v3"))]
let registers = self.registers.clone();

tb.instructions().try_for_each(|insn| {
println!("{:08x}: {}", insn.vaddr(), insn.disas()?);

#[cfg(any(feature = "plugin-api-v2", feature = "plugin-api-v3"))]
{
for register in &registers {
let value = register.read()?;
println!(" {}: {:?}", register.name, value);
}
}

Ok(())
})
}
}


#[ctor]
fn init() {
PLUGIN
.set(Mutex::new(Box::new(TinyTrace {})))
.set(Mutex::new(Box::new(TinyTrace::default())))
.map_err(|_| anyhow!("Failed to set plugin"))
.expect("Failed to set plugin");
}
Loading

0 comments on commit 7c481e8

Please sign in to comment.