Skip to content

Commit 885977a

Browse files
authored
replace software_interrupt! macro with generic function (#259)
This is a *breaking change*, also add note about safety.
1 parent 8060f05 commit 885977a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/instructions/interrupts.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ pub fn int3() {
149149

150150
/// Generate a software interrupt by invoking the `int` instruction.
151151
///
152-
/// This currently needs to be a macro because the `int` argument needs to be an
153-
/// immediate. This macro will be replaced by a generic function when support for
154-
/// const generics is implemented in Rust.
152+
/// ## Safety
153+
///
154+
/// Invoking an arbitrary interrupt is unsafe. It can cause your system to
155+
/// crash if you invoke a double-fault (#8) or machine-check (#18) exception.
156+
/// It can also cause memory/register corruption depending on the interrupt
157+
/// implementation (if it expects values/pointers to be passed in registers).
155158
#[cfg(feature = "inline_asm")]
156159
#[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))]
157-
#[macro_export]
158-
macro_rules! software_interrupt {
159-
($x:expr) => {{
160-
asm!("int {id}", id = const $x, options(nomem, nostack));
161-
}};
160+
pub unsafe fn software_interrupt<const NUM: u8>() {
161+
asm!("int {num}", num = const NUM, options(nomem, nostack));
162162
}

0 commit comments

Comments
 (0)