diff options
author | 2022-06-03 23:40:59 -0700 | |
---|---|---|
committer | 2022-06-03 23:40:59 -0700 | |
commit | d8cbc9e028bb90f86814bae82275e81104e9d167 (patch) | |
tree | 95554863d3472d8759c66f9472e9d3846870323b | |
parent | 10092fdb0b92bd89e7d8c06176986f041e11f495 (diff) | |
download | rust-x86-d8cbc9e028bb90f86814bae82275e81104e9d167.tar.gz rust-x86-d8cbc9e028bb90f86814bae82275e81104e9d167.tar.zst rust-x86-d8cbc9e028bb90f86814bae82275e81104e9d167.zip |
Macros for fs/gs deref.
-rw-r--r-- | CHANGELOG.md | 9 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/bits64/segmentation.rs | 46 |
3 files changed, 44 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index af5cdc1..ccc665e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.49.0] - 2022-06-03 + +- Removed `bits64::segmentation::fs_deref()`: Users should replace calls to + `fs_deref` with the more general `fbits64::segmentation::s_deref!` macro. + `fs_deref!(0)` is equivalent to `fs_deref()`. +- Removed `bits64::segmentation::gs_deref()`: Users should replace calls to + `gs_deref` with the more general `bits64::segmentation::gs_deref!` macro. + `fs_deref!(0)` is equivalent to `fs_deref()`. + ## [0.48.0] - 2022-05-23 - Added `const new` constructor for X2APIC struct @@ -1,6 +1,6 @@ [package] name = "x86" -version = "0.48.0" +version = "0.49.0" authors = [ "Gerd Zellweger <mail@gerdzellweger.com>", "Eric Kidd <git@randomhacks.net>", diff --git a/src/bits64/segmentation.rs b/src/bits64/segmentation.rs index 36e3171..78c39a8 100644 --- a/src/bits64/segmentation.rs +++ b/src/bits64/segmentation.rs @@ -191,28 +191,50 @@ pub unsafe fn rdfsbase() -> u64 { fs_base } -/// "Dereferences" the fs register at offset 0. +/// "Dereferences" the fs register at `offset`. /// /// # Safety -/// fs needs to point to valid address. +/// - Offset needs to be within valid memory relative to what the fs register +/// points to. #[cfg(target_arch = "x86_64")] -pub unsafe fn fs_deref() -> u64 { - let fs: u64; - asm!("movq %fs:0x0, {0}", out(reg) fs, options(att_syntax)); - fs +#[macro_export] +macro_rules! fs_deref { + ($offset:expr) => {{ + let fs: u64; + core::arch::asm!("movq %fs:{offset}, {result}", + offset = const ($offset), + result = out(reg) fs, + options(att_syntax) + ); + fs + }}; } -/// "Dereferences" the gs register at offset 0. +#[cfg(target_arch = "x86_64")] +pub use fs_deref; + +/// "Dereferences" the gs register at `offset`. /// /// # Safety -/// gs needs to point to valid address. +/// - Offset needs to be within valid memory relative to what the gs register +/// points to. #[cfg(target_arch = "x86_64")] -pub unsafe fn gs_deref() -> u64 { - let gs: u64; - asm!("movq %gs:0x0, {0}", out(reg) gs, options(att_syntax)); - gs +#[macro_export] +macro_rules! gs_deref { + ($offset:expr) => {{ + let gs: u64; + core::arch::asm!("movq %gs:{offset}, {result}", + offset = const ($offset), + result = out(reg) gs, + options(att_syntax) + ); + gs + }}; } +#[cfg(target_arch = "x86_64")] +pub use gs_deref; + /// Swap the GS register. /// /// Exchanges the current GS base register value with the value contained |