Function runs_inside_qemu::runs_inside_qemu[][src]

pub fn runs_inside_qemu() -> bool
Expand description

Returns if the code is running inside a QEMU virtual machine. Only works on x86/x86_64 platform.

Doesn’t panic and in case something strange happens, it returns false in favor of a Result, because these errors are absolutely unlikely.

Example Usage


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');
        }
    }
}