diff options
author | 2019-07-27 00:05:50 +0300 | |
---|---|---|
committer | 2019-07-27 00:16:43 +0300 | |
commit | 3c33d6c29bb546d8774d03825c10a28038c7f7e4 (patch) | |
tree | 90b095f86f5d8e9d88683d81f08eaaa719c7b605 | |
parent | c5af691304d11b6b1a3df5dae6c546bd2a7fac4a (diff) | |
download | rust-x86-3c33d6c29bb546d8774d03825c10a28038c7f7e4.tar.gz rust-x86-3c33d6c29bb546d8774d03825c10a28038c7f7e4.tar.zst rust-x86-3c33d6c29bb546d8774d03825c10a28038c7f7e4.zip |
Always inline functions that operate on FLAGS register
Non-inlined functions have a function prologue[1] that contain instructions
which can mess with the FLAGS register before we have a chance to read it.
[1]: https://en.wikipedia.org/wiki/Function_prologue
-rw-r--r-- | src/bits32/eflags.rs | 4 | ||||
-rw-r--r-- | src/bits64/rflags.rs | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/bits32/eflags.rs b/src/bits32/eflags.rs index 10ed325..aa4d23e 100644 --- a/src/bits32/eflags.rs +++ b/src/bits32/eflags.rs @@ -67,6 +67,7 @@ impl EFlags { } #[cfg(target_arch = "x86")] +#[inline(always)] pub unsafe fn read() -> EFlags { let r: u32; asm!("pushfl; popl $0" : "=r"(r) :: "memory"); @@ -74,6 +75,7 @@ pub unsafe fn read() -> EFlags { } #[cfg(target_arch = "x86")] +#[inline(always)] pub unsafe fn set(val: EFlags) { asm!("pushl $0; popfl" :: "r"(val.bits()) : "memory" "flags"); } @@ -88,6 +90,7 @@ pub unsafe fn set(val: EFlags) { /// /// This instruction is only valid in Ring 0 and requires /// that the CPU supports the instruction (check CPUID). +#[inline(always)] pub unsafe fn clac() { asm!("clac" ::: "memory" "flags" : "volatile"); } @@ -102,6 +105,7 @@ pub unsafe fn clac() { /// /// This instruction is only valid in Ring 0 and requires /// that the CPU supports the instruction (check CPUID). +#[inline(always)] pub unsafe fn stac() { asm!("stac" ::: "memory" "flags" : "volatile"); } diff --git a/src/bits64/rflags.rs b/src/bits64/rflags.rs index 5f6fa11..970e19a 100644 --- a/src/bits64/rflags.rs +++ b/src/bits64/rflags.rs @@ -76,6 +76,7 @@ impl RFlags { } #[cfg(target_arch = "x86_64")] +#[inline(always)] pub unsafe fn read() -> RFlags { let r: u64; asm!("pushfq; popq $0" : "=r"(r) :: "memory"); @@ -83,6 +84,7 @@ pub unsafe fn read() -> RFlags { } #[cfg(target_arch = "x86_64")] +#[inline(always)] pub unsafe fn set(val: RFlags) { asm!("pushq $0; popfq" :: "r"(val.bits()) : "memory" "flags"); } |