Switch from the memoffset crate to the offset_of feature

The memoffset crate requires const_refs_to_cell to work in const
contexts. This feature has some known issues around it's semantics. The
offset_of feature however is currently on track for stabilization.
This commit is contained in:
bjorn3
2023-12-12 20:40:25 +01:00
committed by Jeremy Soller
parent 2aea52a94b
commit a7165f822f
12 changed files with 12 additions and 23 deletions
Generated
-10
View File
@@ -96,7 +96,6 @@ dependencies = [
"goblin",
"linked_list_allocator 0.9.1",
"log",
"memoffset",
"paste",
"raw-cpuid",
"redox_syscall",
@@ -152,15 +151,6 @@ version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "paste"
version = "1.0.9"
-1
View File
@@ -14,7 +14,6 @@ bitflags = "1.2.1"
bitfield = "0.13.2"
linked_list_allocator = "0.9.0"
log = "0.4"
memoffset = { version = "0.6", features = ["unstable_const"] }
redox_syscall = { path = "syscall" }
slab_allocator = { path = "slab_allocator", optional = true }
# FIXME: There is some undefined behavior probably in the kernel, which forces us to use spin 0.9.0 and not 0.9.2.
+1 -1
View File
@@ -90,7 +90,7 @@ pub struct TssWrapper(pub TaskStateSegment);
pub unsafe fn pcr() -> *mut ProcessorControlRegion {
let mut ret: *mut ProcessorControlRegion;
core::arch::asm!("mov {}, gs:[{}]", out(reg) ret, const(memoffset::offset_of!(ProcessorControlRegion, self_ref)));
core::arch::asm!("mov {}, gs:[{}]", out(reg) ret, const(core::mem::offset_of!(ProcessorControlRegion, self_ref)));
ret
}
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
syscall,
syscall::flag::{PTRACE_FLAG_IGNORE, PTRACE_STOP_PRE_SYSCALL, PTRACE_STOP_POST_SYSCALL},
};
use memoffset::offset_of;
use core::mem::offset_of;
use x86::{bits32::task::TaskStateSegment, msr, segmentation::SegmentSelector};
pub unsafe fn init() {}
+3 -3
View File
@@ -85,10 +85,10 @@ pub struct ProcessorControlRegion {
}
const _: () = {
if memoffset::offset_of!(ProcessorControlRegion, tss) % 16 != 0 {
if core::mem::offset_of!(ProcessorControlRegion, tss) % 16 != 0 {
panic!("PCR is incorrectly defined, TSS alignment is too small");
}
if memoffset::offset_of!(ProcessorControlRegion, gdt) % 8 != 0 {
if core::mem::offset_of!(ProcessorControlRegion, gdt) % 8 != 0 {
panic!("PCR is incorrectly defined, GDT alignment is too small");
}
};
@@ -98,7 +98,7 @@ pub unsafe fn pcr() -> *mut ProcessorControlRegion {
// obtaining FSBASE/GSBASE using mov gs:[gs_self_ref] is faster than using the (probably
// microcoded) instructions.
let mut ret: *mut ProcessorControlRegion;
core::arch::asm!("mov {}, gs:[{}]", out(reg) ret, const(memoffset::offset_of!(ProcessorControlRegion, self_ref)));
core::arch::asm!("mov {}, gs:[{}]", out(reg) ret, const(core::mem::offset_of!(ProcessorControlRegion, self_ref)));
ret
}
+1 -1
View File
@@ -405,7 +405,7 @@ macro_rules! interrupt_stack {
inner = sym inner,
IA32_GS_BASE = const(x86::msr::IA32_GS_BASE),
PCR_GDT_OFFSET = const(memoffset::offset_of!(crate::gdt::ProcessorControlRegion, gdt)),
PCR_GDT_OFFSET = const(core::mem::offset_of!(crate::gdt::ProcessorControlRegion, gdt)),
options(noreturn),
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
syscall,
syscall::flag::{PTRACE_FLAG_IGNORE, PTRACE_STOP_PRE_SYSCALL, PTRACE_STOP_POST_SYSCALL},
};
use memoffset::offset_of;
use core::mem::offset_of;
use x86::{bits64::{rflags::RFlags, task::TaskStateSegment}, msr, segmentation::SegmentSelector};
pub unsafe fn init() {
+1 -1
View File
@@ -3,7 +3,7 @@ use core::arch::asm;
use core::mem;
use core::ptr;
use core::sync::atomic::{AtomicBool, Ordering};
use memoffset::offset_of;
use core::mem::offset_of;
use spin::Once;
use crate::{push_scratch, pop_scratch};
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::interrupt::handler::ScratchRegisters;
use crate::paging::{RmmA, RmmArch, TableKind};
use crate::syscall::FloatRegisters;
use memoffset::offset_of;
use core::mem::offset_of;
use spin::Once;
/// This must be used by the kernel to ensure that context switches are done atomically
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::interrupt::handler::ScratchRegisters;
use crate::paging::{RmmA, RmmArch, TableKind};
use crate::syscall::FloatRegisters;
use memoffset::offset_of;
use core::mem::offset_of;
use spin::Once;
use x86::msr;
+1 -1
View File
@@ -44,10 +44,10 @@
#![feature(allocator_api)]
#![feature(asm_const)] // TODO: Relax requirements of most asm invocations
#![feature(const_refs_to_cell)]
#![feature(int_roundings)]
#![feature(let_chains)]
#![feature(naked_functions)]
#![feature(offset_of)]
#![feature(sync_unsafe_cell)]
#![no_std]
#![no_main]
+1 -1
View File
@@ -348,7 +348,7 @@ pub fn fstat(fd: FileHandle, user_buf: UserSliceWo) -> Result<()> {
// for retrieving the scheme ID from a file descriptor.
// TODO: Less hacky method.
let st_dev = scheme_id.get().try_into().map_err(|_| Error::new(EOVERFLOW))?;
user_buf.advance(memoffset::offset_of!(Stat, st_dev)).and_then(|b| b.limit(8)).ok_or(Error::new(EIO))?.copy_from_slice(&u64::to_ne_bytes(st_dev))?;
user_buf.advance(core::mem::offset_of!(Stat, st_dev)).and_then(|b| b.limit(8)).ok_or(Error::new(EIO))?.copy_from_slice(&u64::to_ne_bytes(st_dev))?;
Ok(())
})