Skip to content

Commit 84407e7

Browse files
author
Chris Pick
committed
Add notes on using crate from Linux userspace
It took me a little research to figure out how to use this crate from x86/x86_64 Linux userspace. Add some notes to help people in the future.
1 parent c882e1f commit 84407e7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Add the special ISA debug exit device by passing the flags:
5858
-device isa-debug-exit,iobase=0xf4,iosize=0x04
5959
```
6060

61-
When instantiating the handle, `iobase` must be given as the first parameter.
61+
When instantiating the handle with `qemu_exit::X86::new()`, `iobase` must be given as the first
62+
parameter.
6263

6364
The second parameter must be an `EXIT_SUCCESS` code of your choice that is an odd number, aka
6465
bit number zero must be `1`. This is needed because in QEMU, the provided code is internally
@@ -69,6 +70,18 @@ possible to let QEMU invoke `exit(0)`.
6970
let qemu_exit_handle = qemu_exit::X86::new(io_base, custom_exit_success);
7071
```
7172

73+
#### x86/x86_64 Linux
74+
75+
To use this mechanism from Linux userspace, the kernel must be compiled with
76+
`CONFIG_X86_IOPL_IOPERM=y` (which is the default) and the process must start with root privileges
77+
(or `CAP_SYS_RAWIO`) and call: [`ioperm(2)`](https://man7.org/linux/man-pages/man2/ioperm.2.html):
78+
```rust
79+
nix::errno::Errno::result(unsafe { libc::ioperm( 0xf4, 4, 1 )}).expect("ioperm failed");
80+
```
81+
82+
Privileges/capabilities can then be dropped. Normal users can subsequently call
83+
`qemu_exit_handle.exit*()`.
84+
7285
## Literature
7386

7487
- [Semihosting for AArch32 and AArch64](https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst)

0 commit comments

Comments
 (0)