Skip to content

Commit 66a37da

Browse files
committed
Remove array-init dependency, move wr/rd base instructions to segmentation submodule, fix CI
1 parent 52fc1d0 commit 66a37da

File tree

8 files changed

+111
-119
lines changed

8 files changed

+111
-119
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,26 @@ jobs:
6262
- name: "Run cargo build"
6363
run: cargo build
6464

65+
- name: "Run cargo build for stable without instructions"
66+
run: cargo build --no-default-features
67+
6568
- name: "Run cargo build for stable"
66-
run: cargo build --no-default-features --features stable
69+
run: cargo build --no-default-features --features external_asm,instructions
6770
if: runner.os != 'Windows'
6871

6972
- name: "Run cargo build for stable on musl"
70-
run: cargo build --target x86_64-unknown-linux-musl --no-default-features --features stable
73+
run: cargo build --target x86_64-unknown-linux-musl --no-default-features --features external_asm,instructions
7174
if: runner.os == 'Linux'
7275

7376
- name: "Run cargo test"
7477
run: cargo test
7578

7679
- name: "Run cargo test for stable"
77-
run: cargo test --no-default-features --features stable
80+
run: cargo test --no-default-features --features external_asm,instructions
7881
if: runner.os != 'Windows'
7982

8083
- name: "Run cargo test for stable on musl"
81-
run: cargo test --target x86_64-unknown-linux-musl --no-default-features --features stable
84+
run: cargo test --target x86_64-unknown-linux-musl --no-default-features --features external_asm,instructions
8285
if: runner.os == 'Linux'
8386

8487
- name: 'Deny Warnings'

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ edition = "2018"
2828
[dependencies]
2929
bit_field = "0.9.0"
3030
bitflags = "1.0.4"
31-
array-init = { version = "0.1.1", optional = true }
3231

3332
[build-dependencies]
3433
cc = { version = "1.0.37", optional = true }
@@ -37,7 +36,7 @@ cc = { version = "1.0.37", optional = true }
3736
default = [ "nightly", "instructions" ]
3837
instructions = []
3938
deny-warnings = []
40-
external_asm = [ "cc", "array-init" ]
39+
external_asm = [ "cc" ]
4140
nightly = [ "inline_asm", "const_fn", "abi_x86_interrupt" ]
4241
inline_asm = []
4342
abi_x86_interrupt = []

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Support for x86_64 specific instructions (e.g. TLB flush), registers (e.g. contr
77

88
## Crate Feature Flags
99

10-
* `nightly`: This is the default.
10+
* `nightly`: Enables features only available on nightly Rust; enabled by default.
1111
* `instructions`: Enabled by default, turns on x86\_64 specific instructions, and dependent features. Only available for x86\_64 targets.
1212
* `external_asm`: Use this to build with non-nightly rust. Needs `default-features = false, features = ["instructions"]`. Is unsupported on Windows.
1313

src/instructions/mod.rs

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -66,102 +66,3 @@ pub fn read_rip() -> u64 {
6666
}
6767
rip
6868
}
69-
70-
/// Writes the FS segment base address
71-
///
72-
/// ## Safety
73-
///
74-
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
75-
///
76-
/// The caller must ensure that this write operation has no unsafe side
77-
/// effects, as the FS segment base address is often used for thread
78-
/// local storage.
79-
#[inline]
80-
pub unsafe fn wrfsbase(val: u64) {
81-
#[cfg(feature = "inline_asm")]
82-
#[inline(always)]
83-
unsafe fn inner(val: u64) {
84-
llvm_asm!("wrfsbase $0" :: "r"(val) :: "volatile")
85-
}
86-
87-
#[cfg(not(feature = "inline_asm"))]
88-
#[inline(always)]
89-
unsafe fn inner(val: u64) {
90-
crate::asm::x86_64_asm_wrfsbase(val)
91-
}
92-
93-
inner(val)
94-
}
95-
96-
/// Reads the FS segment base address
97-
///
98-
/// ## Safety
99-
///
100-
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
101-
#[inline]
102-
pub unsafe fn rdfsbase() -> u64 {
103-
#[cfg(feature = "inline_asm")]
104-
#[inline(always)]
105-
unsafe fn inner() -> u64 {
106-
let val: u64;
107-
llvm_asm!("rdfsbase $0" : "=r" (val) ::: "volatile");
108-
val
109-
}
110-
111-
#[cfg(not(feature = "inline_asm"))]
112-
#[inline(always)]
113-
unsafe fn inner() -> u64 {
114-
crate::asm::x86_64_asm_rdfsbase()
115-
}
116-
117-
inner()
118-
}
119-
120-
/// Writes the GS segment base address
121-
///
122-
/// ## Safety
123-
///
124-
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
125-
///
126-
/// The caller must ensure that this write operation has no unsafe side
127-
/// effects, as the GS segment base address might be in use.
128-
#[inline]
129-
pub unsafe fn wrgsbase(val: u64) {
130-
#[cfg(feature = "inline_asm")]
131-
#[inline(always)]
132-
unsafe fn inner(val: u64) {
133-
llvm_asm!("wrgsbase $0" :: "r"(val) :: "volatile")
134-
}
135-
136-
#[cfg(not(feature = "inline_asm"))]
137-
#[inline(always)]
138-
unsafe fn inner(val: u64) {
139-
crate::asm::x86_64_asm_wrgsbase(val)
140-
}
141-
142-
inner(val)
143-
}
144-
145-
/// Reads the GS segment base address
146-
///
147-
/// ## Safety
148-
///
149-
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
150-
#[inline]
151-
pub unsafe fn rdgsbase() -> u64 {
152-
#[cfg(feature = "inline_asm")]
153-
#[inline(always)]
154-
unsafe fn inner() -> u64 {
155-
let val: u64;
156-
llvm_asm!("rdgsbase $0" : "=r" (val) ::: "volatile");
157-
val
158-
}
159-
160-
#[cfg(not(feature = "inline_asm"))]
161-
#[inline(always)]
162-
unsafe fn inner() -> u64 {
163-
crate::asm::x86_64_asm_rdgsbase()
164-
}
165-
166-
inner()
167-
}

src/instructions/segmentation.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,102 @@ pub fn cs() -> SegmentSelector {
140140
SegmentSelector(segment)
141141
}
142142
}
143+
144+
/// Writes the FS segment base address
145+
///
146+
/// ## Safety
147+
///
148+
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
149+
///
150+
/// The caller must ensure that this write operation has no unsafe side
151+
/// effects, as the FS segment base address is often used for thread
152+
/// local storage.
153+
#[inline]
154+
pub unsafe fn wrfsbase(val: u64) {
155+
#[cfg(feature = "inline_asm")]
156+
#[inline(always)]
157+
unsafe fn inner(val: u64) {
158+
llvm_asm!("wrfsbase $0" :: "r"(val) :: "volatile")
159+
}
160+
161+
#[cfg(not(feature = "inline_asm"))]
162+
#[inline(always)]
163+
unsafe fn inner(val: u64) {
164+
crate::asm::x86_64_asm_wrfsbase(val)
165+
}
166+
167+
inner(val)
168+
}
169+
170+
/// Reads the FS segment base address
171+
///
172+
/// ## Safety
173+
///
174+
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
175+
#[inline]
176+
pub unsafe fn rdfsbase() -> u64 {
177+
#[cfg(feature = "inline_asm")]
178+
#[inline(always)]
179+
unsafe fn inner() -> u64 {
180+
let val: u64;
181+
llvm_asm!("rdfsbase $0" : "=r" (val) ::: "volatile");
182+
val
183+
}
184+
185+
#[cfg(not(feature = "inline_asm"))]
186+
#[inline(always)]
187+
unsafe fn inner() -> u64 {
188+
crate::asm::x86_64_asm_rdfsbase()
189+
}
190+
191+
inner()
192+
}
193+
194+
/// Writes the GS segment base address
195+
///
196+
/// ## Safety
197+
///
198+
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
199+
///
200+
/// The caller must ensure that this write operation has no unsafe side
201+
/// effects, as the GS segment base address might be in use.
202+
#[inline]
203+
pub unsafe fn wrgsbase(val: u64) {
204+
#[cfg(feature = "inline_asm")]
205+
#[inline(always)]
206+
unsafe fn inner(val: u64) {
207+
llvm_asm!("wrgsbase $0" :: "r"(val) :: "volatile")
208+
}
209+
210+
#[cfg(not(feature = "inline_asm"))]
211+
#[inline(always)]
212+
unsafe fn inner(val: u64) {
213+
crate::asm::x86_64_asm_wrgsbase(val)
214+
}
215+
216+
inner(val)
217+
}
218+
219+
/// Reads the GS segment base address
220+
///
221+
/// ## Safety
222+
///
223+
/// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
224+
#[inline]
225+
pub unsafe fn rdgsbase() -> u64 {
226+
#[cfg(feature = "inline_asm")]
227+
#[inline(always)]
228+
unsafe fn inner() -> u64 {
229+
let val: u64;
230+
llvm_asm!("rdgsbase $0" : "=r" (val) ::: "volatile");
231+
val
232+
}
233+
234+
#[cfg(not(feature = "inline_asm"))]
235+
#[inline(always)]
236+
unsafe fn inner() -> u64 {
237+
crate::asm::x86_64_asm_rdgsbase()
238+
}
239+
240+
inner()
241+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! const_fn {
3232
}
3333
}
3434

35-
#[cfg(all(feature = "instructions", not(feature = "inline_asm")))]
35+
#[cfg(all(feature = "instructions", feature = "external_asm"))]
3636
pub(crate) mod asm;
3737

3838
pub mod addr;

src/registers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod model_specific;
55
pub mod rflags;
66

77
#[cfg(feature = "instructions")]
8-
pub use crate::instructions::{rdfsbase, rdgsbase, wrfsbase, wrgsbase};
8+
pub use crate::instructions::segmentation::{rdfsbase, rdgsbase, wrfsbase, wrgsbase};
99

1010
#[cfg(all(feature = "instructions", feature = "inline_asm"))]
1111
pub use crate::instructions::read_rip;

src/structures/paging/page_table.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,14 @@ pub struct PageTable {
185185

186186
impl PageTable {
187187
/// Creates an empty page table.
188-
#[cfg(feature = "const_fn")]
189188
#[inline]
190-
pub const fn new() -> Self {
189+
pub fn new() -> Self {
191190
const EMPTY: PageTableEntry = PageTableEntry::new();
192191
PageTable {
193192
entries: [EMPTY; ENTRY_COUNT],
194193
}
195194
}
196195

197-
/// Creates an empty page table.
198-
#[cfg(not(feature = "const_fn"))]
199-
#[inline]
200-
pub fn new() -> Self {
201-
PageTable {
202-
entries: array_init::array_init(|_| PageTableEntry::new()),
203-
}
204-
}
205-
206196
/// Clears all entries.
207197
#[inline]
208198
pub fn zero(&mut self) {

0 commit comments

Comments
 (0)