diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs
index 02bc69c7a7..6462c39c22 100644
--- a/src/context/arch/x86_64.rs
+++ b/src/context/arch/x86_64.rs
@@ -3,12 +3,10 @@ use core::{
sync::atomic::AtomicBool,
};
-use crate::{percpu::PercpuBlock, ptrace, syscall::FloatRegisters};
+use crate::syscall::FloatRegisters;
use core::mem::offset_of;
-use alloc::sync::Arc;
use spin::Once;
-use syscall::PtraceFlags;
use x86::msr;
/// This must be used by the kernel to ensure that context switches are done atomically
diff --git a/src/context/signal.rs b/src/context/signal.rs
index 7aa604832b..2eb5d89f5a 100644
--- a/src/context/signal.rs
+++ b/src/context/signal.rs
@@ -5,7 +5,7 @@ use syscall::{
PTRACE_FLAG_IGNORE, PTRACE_STOP_SIGNAL, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP,
SIGTTIN, SIGTTOU, SIG_DFL, SIG_IGN,
},
- ptrace_event, SignalStack, SigActionFlags, IntRegisters, Error, EINTR, SIGTERM,
+ ptrace_event, SignalStack, SigActionFlags, IntRegisters, SIGTERM,
};
use crate::{
diff --git a/src/memory/mod.rs b/src/memory/mod.rs
index fb8f6b6f2a..044fea7d6c 100644
--- a/src/memory/mod.rs
+++ b/src/memory/mod.rs
@@ -230,10 +230,6 @@ pub unsafe fn deallocate_frame(frame: Frame) {
const ORDER_COUNT: u32 = 11;
const MAX_ORDER: u32 = ORDER_COUNT - 1;
-pub struct FreeList {
- for_orders: [Option; ORDER_COUNT as usize],
-}
-
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Frame {
// On x86/x86_64, all memory below 1 MiB is reserved, and although some frames in that range
@@ -282,7 +278,12 @@ impl Frame {
/// Get the address of this frame
// TODO: Remove
pub fn start_address(&self) -> PhysicalAddress {
- PhysicalAddress::new(self.physaddr.get())
+ self.base()
+ }
+ /// Create a frame containing `address`
+ // TODO: Remove
+ pub fn containing_address(address: PhysicalAddress) -> Frame {
+ Self::containing(address)
}
/// Create a frame containing `address`
@@ -291,10 +292,6 @@ impl Frame {
physaddr: NonZeroUsize::new(address.data() & !PAGE_MASK).expect("frame 0x0 is reserved"),
}
}
- // TODO: Remove
- pub fn containing_address(address: PhysicalAddress) -> Frame {
- Self::containing(address)
- }
pub fn base(self) -> PhysicalAddress {
PhysicalAddress::new(self.physaddr.get())
}
@@ -303,6 +300,7 @@ impl Frame {
pub fn range_inclusive(start: Frame, end: Frame) -> impl Iterator- {
(start.physaddr.get()..=end.physaddr.get()).step_by(PAGE_SIZE).map(|number| Frame { physaddr: NonZeroUsize::new(number).unwrap() })
}
+ #[track_caller]
pub fn next_by(self, n: usize) -> Self {
Self {
physaddr: self
@@ -310,17 +308,9 @@ impl Frame {
.get()
.checked_add(n * PAGE_SIZE)
.and_then(NonZeroUsize::new)
- .expect("overflow in Frame::next_by"),
+ .expect("overflow or null in Frame::next_by")
}
}
- pub fn prev_by(self, n: usize) -> Self {
- Self {
- physaddr: self.physaddr.get().checked_sub(n.checked_mul(PAGE_SIZE).expect("unreasonable n")).and_then(NonZeroUsize::new).expect("overflow in Frame::prev_by"),
- }
- }
- pub fn align_down_to_order(self, order: u32) -> Option {
- Some(Self { physaddr: NonZeroUsize::new(self.physaddr.get() / (PAGE_SIZE << order) * (PAGE_SIZE << order))? })
- }
pub fn offset_from(self, from: Self) -> usize {
self.physaddr
.get()
@@ -399,7 +389,7 @@ enum PageInfoKind<'info> {
Free(PageInfoFree<'info>),
}
struct PageInfoUsed<'info> {
- refcount: &'info AtomicUsize,
+ _refcount: &'info AtomicUsize,
_misc: &'info AtomicUsize,
}
struct PageInfoFree<'info> {
@@ -552,6 +542,7 @@ fn init_sections(mut allocator: BumpAllocator) {
base = base.next_by(page_info_count);
}
}
+ let sections = &mut sections[..i];
sections.sort_unstable_by_key(|s| s.base);
@@ -624,7 +615,7 @@ fn init_sections(mut allocator: BumpAllocator) {
//log::info!("ORDER {order}: FIRST SKIP");
}
- if order != MAX_ORDER && !base.next_by(frames.len()).is_aligned_to_order(order + 1) {
+ if !frames.is_empty() && order != MAX_ORDER && !base.next_by(frames.len()).is_aligned_to_order(order + 1) {
// The last section page is not aligned to the next order size.
let off = frames.len() - pages_for_current_order;
@@ -689,17 +680,11 @@ pub enum AddRefError {
RcOverflow,
}
impl PageInfo {
- pub fn new() -> Self {
- Self {
- refcount: AtomicUsize::new(0),
- next: AtomicUsize::new(0),
- }
- }
fn kind(&self) -> PageInfoKind<'_> {
let prev = self.refcount.load(Ordering::Relaxed);
if prev & RC_USED_NOT_FREE == RC_USED_NOT_FREE {
- PageInfoKind::Used(PageInfoUsed { refcount: &self.refcount, _misc: &self.next })
+ PageInfoKind::Used(PageInfoUsed { _refcount: &self.refcount, _misc: &self.next })
} else {
PageInfoKind::Free(PageInfoFree { prev: &self.refcount, next: &self.next })
}
@@ -710,12 +695,6 @@ impl PageInfo {
PageInfoKind::Used(_) => None,
}
}
- fn as_used(&self) -> Option> {
- match self.kind() {
- PageInfoKind::Used(f) => Some(f),
- PageInfoKind::Free(_) => None,
- }
- }
pub fn add_ref(&self, kind: RefKind) -> Result<(), AddRefError> {
match (self.refcount().expect("cannot add_ref to free frame"), kind) {
(RefCount::One, RefKind::Cow) => self.refcount.store(RC_USED_NOT_FREE | 1, Ordering::Relaxed),
@@ -798,18 +777,6 @@ impl PageInfoFree<'_> {
self.next.store(0, Ordering::Relaxed);
}
}
-impl<'a> PageInfoUsed<'a> {
- fn make_free(self, order: u32) -> PageInfoFree<'a> {
- // !RC_USED_NOT_FREE
- self.refcount.store(order as usize, Ordering::Relaxed);
- self._misc.store(order as usize, Ordering::Relaxed);
-
- PageInfoFree {
- next: &self._misc,
- prev: &self.refcount,
- }
- }
-}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum RefKind {
Cow,
@@ -985,10 +952,3 @@ impl FrameAllocator for TheFrameAllocator {
todo!()
}
}
-impl FreeList {
- pub fn new() -> Self {
- Self {
- for_orders: [None; ORDER_COUNT as usize],
- }
- }
-}
diff --git a/src/panic.rs b/src/panic.rs
index 5a10b5e7e8..cb0144c4e6 100644
--- a/src/panic.rs
+++ b/src/panic.rs
@@ -14,7 +14,6 @@ fn rust_begin_unwind(info: &PanicInfo) -> ! {
}
println!("CPU {}, PID {:?}", cpu_id(), context::context_id());
- loop {}
// This could deadlock, but at this point we are going to halt anyways
{
diff --git a/src/percpu.rs b/src/percpu.rs
index e6d8e1fbba..b50dd3d49f 100644
--- a/src/percpu.rs
+++ b/src/percpu.rs
@@ -8,7 +8,6 @@ use syscall::PtraceFlags;
use crate::context::empty_cr3;
use crate::context::memory::AddrSpaceWrapper;
use crate::cpu_set::MAX_CPU_COUNT;
-use crate::memory::FreeList;
use crate::ptrace::Session;
use crate::{context::switch::ContextSwitchPercpu, cpu_set::LogicalCpuId};
@@ -32,8 +31,6 @@ pub struct PercpuBlock {
#[cfg(feature = "profiling")]
pub profiling: Option<&'static crate::profiling::RingBuffer>,
- //pub freelist: crate::memory::FreeList,
-
pub ptrace_flags: Cell,
pub ptrace_session: RefCell