#x86-64 #check #eflags #aligment

no-std x86-alignment-check

x86 aligment check flag manipulation

5 releases

0.1.6 Jun 3, 2023
0.1.5 Apr 1, 2023
0.1.3 Mar 30, 2023

#185 in No standard library

Download history 4/week @ 2025-01-02 21/week @ 2025-01-09 8/week @ 2025-01-30 68/week @ 2025-02-06 13/week @ 2025-02-13 1/week @ 2025-02-20 101/week @ 2025-02-27 4938/week @ 2025-03-06 10592/week @ 2025-03-13 5103/week @ 2025-03-20 9401/week @ 2025-03-27 17392/week @ 2025-04-03 23672/week @ 2025-04-10

56,869 downloads per month
Used in memx

MIT/Apache

12KB
145 lines

x86-alignment-check

crate Docs Rust Version Apache2/MIT licensed Test ubu Test mac Test win

x86-alignment-check is set ac flag in eflags on x86 or x86_64

Features

  • set ac flag bit into ON, its included eflags of x86.
  • x86_64 are supported too.
  • #![no_std]

Example 1: If your code is correctly controlled by alignment

First, add the following to Cargo.toml:

[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dev-dependencies]
x86-alignment-check = "*"

Second, enclose your test code with x86_alignment_check() as follows:

    use x86_alignment_check::x86_alignment_check;
    //
    let old_flag = x86_alignment_check(true);
    //
    // here your test codes, processing anythings, a bus error may occur.
    //
    let _ = x86_alignment_check(old_flag);

Finally execute cargo test

Example 2: call_once style

    let val = x86_alignment_check::ac_call_once(|| {
        // here is alignment check
        // processing anythings
        // return value for assertion
        1
    });
    assert_eq!(val, 1);

For now, assertions such as assert_eq!() cannot be included inside FnOnce, because of the rust runtime bug.

Example 3: call_once style, but not alignment check

    let val = x86_alignment_check::no_ac_call_once(|| {
        // here is not alignment check
        // processing anythings
        // return value for assertion
        1
    });
    assert_eq!(val, 1);

Changelogs

This crate's changelog here.

License

This project is licensed under either of

at your option.

No runtime deps