-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! mm: improve soundness of PageRef methods
- Loading branch information
Showing
3 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use core::arch::asm; | ||
|
||
/// Copy `size` bytes from `src` to `dst`. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function has all the safety requirements of `core::ptr::copy` except | ||
/// that data races (both on `src` and `dst`) are explicitly permitted. | ||
#[inline(always)] | ||
pub unsafe fn copy_bytes(src: usize, dst: usize, size: usize) { | ||
unsafe { | ||
asm!( | ||
"rep movsb", | ||
inout("rsi") src => _, | ||
inout("rdi") dst => _, | ||
inout("rcx") size => _, | ||
options(nostack), | ||
); | ||
} | ||
} | ||
|
||
/// Set `size` bytes at `dst` to `val`. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function has all the safety requirements of `core::ptr::write_bytes` except | ||
/// that data races are explicitly permitted. | ||
#[inline(always)] | ||
pub unsafe fn write_bytes(dst: usize, size: usize, value: u8) { | ||
unsafe { | ||
asm!( | ||
"rep stosb", | ||
inout("rdi") dst => _, | ||
inout("rcx") size => _, | ||
in("al") value, | ||
options(nostack), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters