From 885977a21fb1b1f2b6efa9ce1b998fe4d3c92dce Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Fri, 4 Jun 2021 09:30:51 +0200 Subject: [PATCH] replace software_interrupt! macro with generic function (#259) This is a *breaking change*, also add note about safety. --- src/instructions/interrupts.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/instructions/interrupts.rs b/src/instructions/interrupts.rs index f1d171cf8..b9b41a714 100644 --- a/src/instructions/interrupts.rs +++ b/src/instructions/interrupts.rs @@ -149,14 +149,14 @@ pub fn int3() { /// Generate a software interrupt by invoking the `int` instruction. /// -/// This currently needs to be a macro because the `int` argument needs to be an -/// immediate. This macro will be replaced by a generic function when support for -/// const generics is implemented in Rust. +/// ## Safety +/// +/// Invoking an arbitrary interrupt is unsafe. It can cause your system to +/// crash if you invoke a double-fault (#8) or machine-check (#18) exception. +/// It can also cause memory/register corruption depending on the interrupt +/// implementation (if it expects values/pointers to be passed in registers). #[cfg(feature = "inline_asm")] #[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))] -#[macro_export] -macro_rules! software_interrupt { - ($x:expr) => {{ - asm!("int {id}", id = const $x, options(nomem, nostack)); - }}; +pub unsafe fn software_interrupt() { + asm!("int {num}", num = const NUM, options(nomem, nostack)); }