Skip to content

Commit

Permalink
replace software_interrupt! macro with generic function (#259)
Browse files Browse the repository at this point in the history
This is a *breaking change*, also add note about safety.
  • Loading branch information
Freax13 authored Jun 4, 2021
1 parent 8060f05 commit 885977a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/instructions/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const NUM: u8>() {
asm!("int {num}", num = const NUM, options(nomem, nostack));
}

0 comments on commit 885977a

Please sign in to comment.