From bb560e5ab3752bb01f4c63e887dee33c14c68a11 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Fri, 4 Jun 2021 08:43:29 +0200 Subject: [PATCH 1/3] replace software_interrupt! with generic function --- src/instructions/interrupts.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/instructions/interrupts.rs b/src/instructions/interrupts.rs index f1d171cf8..a33a69302 100644 --- a/src/instructions/interrupts.rs +++ b/src/instructions/interrupts.rs @@ -148,15 +148,8 @@ 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. #[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 {id}", id = const X, options(nomem, nostack)); } From fa8be845fbcd5be242726690180412febf0ab7ac Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Fri, 4 Jun 2021 09:20:19 +0200 Subject: [PATCH 2/3] change name for generic parameter --- src/instructions/interrupts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/instructions/interrupts.rs b/src/instructions/interrupts.rs index a33a69302..bc67ee72f 100644 --- a/src/instructions/interrupts.rs +++ b/src/instructions/interrupts.rs @@ -150,6 +150,6 @@ pub fn int3() { /// Generate a software interrupt by invoking the `int` instruction. #[cfg(feature = "inline_asm")] #[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))] -pub unsafe fn software_interrupt() { - asm!("int {id}", id = const X, options(nomem, nostack)); +pub unsafe fn software_interrupt() { + asm!("int {num}", num = const NUM, options(nomem, nostack)); } From f4bc28d19d7ae62391560b1322c703e85b4ba545 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Fri, 4 Jun 2021 09:21:18 +0200 Subject: [PATCH 3/3] add safety comment --- src/instructions/interrupts.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/instructions/interrupts.rs b/src/instructions/interrupts.rs index bc67ee72f..b9b41a714 100644 --- a/src/instructions/interrupts.rs +++ b/src/instructions/interrupts.rs @@ -148,6 +148,13 @@ pub fn int3() { } /// Generate a software interrupt by invoking the `int` instruction. +/// +/// ## 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"))))] pub unsafe fn software_interrupt() {