| Crates.io | runs_inside_qemu |
| lib.rs | runs_inside_qemu |
| version | 1.2.1 |
| created_at | 2021-07-06 13:02:20.227632+00 |
| updated_at | 2021-11-10 12:16:23.545786+00 |
| description | Small no_std-lib that checks if the binary is running inside a QEMU virtual machine. Only works on x86/x86_64 platforms. |
| homepage | https://github.com/phip1611/runs_inside_qemu |
| repository | https://github.com/phip1611/runs_inside_qemu |
| max_upload_size | |
| id | 419441 |
| size | 17,816 |
runs_inside_qemu is a small no_std-lib that checks if the binary is running inside a
QEMU virtual machine. It doesn't need heap allocations and only works on x86/x86_64 platform.
Under the hood, this is a wrapper around the awesome crate https://crates.io/crates/raw-cpuid.
This crate was build/tested with rustc 1.55.0-nightly. It won't work on stable
as long as inline assembly is not part of stable rust.
use runs_inside_qemu::runs_inside_qemu;
fn main() {
// If we are in QEMU, we use the nice "debugcon"-feature which maps
// the x86 I/O-port `0xe9` to stdout or a file.
if runs_inside_qemu() {
unsafe {
x86::io::outb(0xe9, b'H');
x86::io::outb(0xe9, b'e');
x86::io::outb(0xe9, b'l');
x86::io::outb(0xe9, b'l');
x86::io::outb(0xe9, b'o');
x86::io::outb(0xe9, b'\n');
}
}
}
This doesn't work if you pass -cpu host to QEMU, because in this case the CPU brand string is
not "QEMU Virtual CPU version 2.5+".
This crate needs the nightly toolchain. With Rust 1.56.1 stable, it doesn't build.