Skip to content

Commit

Permalink
aarch64-dit: have set_dit_enabled return previous state (#1109)
Browse files Browse the repository at this point in the history
This is more inlining-friendly
  • Loading branch information
tarcieri authored Sep 6, 2024
1 parent 8bdc7cb commit aa12a34
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions aarch64-dit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ impl Dit {
#[must_use]
pub fn enable(&self) -> Guard<'_> {
let was_enabled = if self.is_supported() {
let was_enabled = unsafe { get_dit_enabled() };
unsafe { set_dit_enabled() };
was_enabled
unsafe { set_dit_enabled() }
} else {
false
};
Expand Down Expand Up @@ -102,9 +100,13 @@ unsafe fn get_dit_enabled() -> bool {
}

/// Enable DIT for the current thread.
///
/// Returns the previous DIT state prior to enabling DIT.
#[target_feature(enable = "dit")]
unsafe fn set_dit_enabled() {
unsafe fn set_dit_enabled() -> bool {
let was_enabled = get_dit_enabled();
asm!("msr DIT, #1", options(nomem, nostack, preserves_flags));
was_enabled
}

/// Restore DIT state depending on the enabled bit.
Expand Down Expand Up @@ -153,7 +155,8 @@ mod tests {
let dit_enabled = unsafe { get_dit_enabled() };
assert!(!dit_enabled);

unsafe { set_dit_enabled() };
let was_enabled = unsafe { set_dit_enabled() };
assert!(!was_enabled);
let dit_enabled = unsafe { get_dit_enabled() };
assert!(dit_enabled);

Expand Down

0 comments on commit aa12a34

Please sign in to comment.