Reduce dead code, fix aarch64.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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::{
|
||||
|
||||
+12
-52
@@ -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<Frame>; 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<Item = Frame> {
|
||||
(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<Self> {
|
||||
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<RmmA>) {
|
||||
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<RmmA>) {
|
||||
//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<PageInfoUsed<'_>> {
|
||||
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],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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<PtraceFlags>,
|
||||
pub ptrace_session: RefCell<Option<Weak<Session>>>,
|
||||
pub inside_syscall: Cell<bool>,
|
||||
@@ -141,7 +138,6 @@ impl PercpuBlock {
|
||||
ptrace_flags: Cell::new(Default::default()),
|
||||
ptrace_session: RefCell::new(None),
|
||||
inside_syscall: Cell::new(false),
|
||||
//freelist: FreeList::new(),
|
||||
|
||||
#[cfg(feature = "syscall_debug")]
|
||||
syscall_debug_info: Cell::new(SyscallDebugInfo::default()),
|
||||
|
||||
@@ -2,7 +2,6 @@ use core::num::NonZeroUsize;
|
||||
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use rmm::PhysicalAddress;
|
||||
use spin::RwLock;
|
||||
|
||||
use crate::{
|
||||
context::memory::{handle_notify_files, AddrSpace, Grant, PageSpan, AddrSpaceWrapper},
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use syscall::{EventFlags, MunmapFlags, SendFdFlags, SEEK_CUR, SEEK_END, SEEK_SET};
|
||||
|
||||
use crate::{
|
||||
context::{file::FileDescription, memory::{AddrSpace, AddrSpaceWrapper}},
|
||||
context::{file::FileDescription, memory::AddrSpaceWrapper},
|
||||
syscall::{
|
||||
error::*,
|
||||
usercopy::{UserSliceRo, UserSliceWo},
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ use crate::{
|
||||
},
|
||||
event,
|
||||
memory::Frame,
|
||||
paging::{mapper::InactiveFlusher, Page, VirtualAddress, PAGE_SIZE},
|
||||
paging::{Page, VirtualAddress, PAGE_SIZE},
|
||||
scheme::SchemeId,
|
||||
sync::WaitQueue,
|
||||
syscall::{
|
||||
|
||||
@@ -9,7 +9,7 @@ use super::{
|
||||
usercopy::UserSlice,
|
||||
};
|
||||
|
||||
use crate::{percpu::PercpuBlock, syscall::error::Result, time};
|
||||
use crate::syscall::error::Result;
|
||||
|
||||
struct ByteStr<'a>(&'a [u8]);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use alloc::sync::Arc;
|
||||
use crate::{
|
||||
context,
|
||||
paging::VirtualAddress,
|
||||
syscall::error::{Error, Result, EFAULT, EINVAL, EPERM, ESRCH},
|
||||
syscall::error::{Error, Result, EFAULT, EPERM, ESRCH},
|
||||
};
|
||||
fn enforce_root() -> Result<()> {
|
||||
let contexts = context::contexts();
|
||||
|
||||
@@ -11,13 +11,13 @@ use crate::context::{
|
||||
|
||||
use crate::{
|
||||
context, interrupt,
|
||||
paging::{mapper::PageFlushAll, Page, PageFlags, VirtualAddress, PAGE_SIZE},
|
||||
paging::{Page, VirtualAddress, PAGE_SIZE},
|
||||
ptrace,
|
||||
syscall::{
|
||||
data::{SigAction, SignalStack},
|
||||
error::*,
|
||||
flag::{
|
||||
wifcontinued, wifstopped, MapFlags, WaitFlags, PTRACE_STOP_EXIT, SIGCONT, SIGTERM,
|
||||
wifcontinued, wifstopped, MapFlags, WaitFlags, PTRACE_STOP_EXIT, SIGCONT,
|
||||
SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK, WCONTINUED, WNOHANG, WUNTRACED,
|
||||
},
|
||||
ptrace_event,
|
||||
|
||||
Reference in New Issue
Block a user