Remove some dead code.
This commit is contained in:
@@ -10,9 +10,7 @@ use spin::Once;
|
||||
|
||||
use crate::{
|
||||
device::cpu::registers::{control_regs, tlb},
|
||||
interrupt::handler::ScratchRegisters,
|
||||
paging::{RmmA, RmmArch, TableKind},
|
||||
pop_scratch, push_scratch,
|
||||
syscall::FloatRegisters,
|
||||
percpu::PercpuBlock,
|
||||
};
|
||||
@@ -97,33 +95,6 @@ impl Context {
|
||||
self.tpidrro_el0
|
||||
}
|
||||
|
||||
pub unsafe fn signal_stack(&mut self, handler: extern "C" fn(usize), sig: u8) {
|
||||
let lr = self.lr.clone();
|
||||
self.push_pair((sig as usize, lr));
|
||||
self.push_pair((0 as usize, handler as usize));
|
||||
self.set_lr(signal_handler_wrapper as usize);
|
||||
}
|
||||
|
||||
// It isn't possible to implement "just push one value to stack" on aarch64
|
||||
// https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/using-the-stack-in-aarch32-and-aarch64
|
||||
// Looks like QEMU TCG doesn't care about it, so it works in it, but not on bare metal or kvm
|
||||
// Reverese to be compatible with ldp and stp instructions
|
||||
// TODO: optimize?
|
||||
pub unsafe fn push_pair(&mut self, pair: (usize, usize)) {
|
||||
self.sp -= 1 * mem::size_of::<usize>();
|
||||
*(self.sp as *mut usize) = pair.1;
|
||||
self.sp -= 1 * mem::size_of::<usize>();
|
||||
*(self.sp as *mut usize) = pair.0;
|
||||
}
|
||||
|
||||
pub unsafe fn pop_pair(&mut self) -> (usize, usize) {
|
||||
let a = *(self.sp as *const usize);
|
||||
self.sp += 1 * mem::size_of::<usize>();
|
||||
let b = *(self.sp as *const usize);
|
||||
self.sp += 1 * mem::size_of::<usize>();
|
||||
(a, b)
|
||||
}
|
||||
|
||||
pub fn dump(&self) {
|
||||
println!("elr_el1: 0x{:016x}", self.elr_el1);
|
||||
println!("sp_el0: 0x{:016x}", self.sp_el0);
|
||||
@@ -336,40 +307,3 @@ unsafe extern "C" fn switch_to_inner(_prev: &mut Context, _next: &mut Context) {
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct SignalHandlerStack {
|
||||
scratch: ScratchRegisters,
|
||||
padding: usize,
|
||||
handler: extern "C" fn(usize),
|
||||
sig: usize,
|
||||
lr: usize,
|
||||
}
|
||||
|
||||
#[naked]
|
||||
unsafe extern "C" fn signal_handler_wrapper() {
|
||||
#[inline(never)]
|
||||
unsafe extern "C" fn inner(stack: &SignalHandlerStack) {
|
||||
(stack.handler)(stack.sig);
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
core::arch::asm!(
|
||||
concat!(
|
||||
push_scratch!(),
|
||||
"
|
||||
mov x0, sp
|
||||
bl {inner}
|
||||
",
|
||||
pop_scratch!(),
|
||||
"
|
||||
add sp, sp, 32
|
||||
ldr x30, [sp, #-8]
|
||||
ret
|
||||
"
|
||||
),
|
||||
inner = sym inner,
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ use alloc::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
gdt::{pcr, GDT_USER_FS, GDT_USER_GS},
|
||||
interrupt::handler::ScratchRegisters,
|
||||
paging::{RmmA, RmmArch, TableKind},
|
||||
percpu::PercpuBlock,
|
||||
pop_scratch, push_scratch,
|
||||
syscall::FloatRegisters,
|
||||
};
|
||||
|
||||
@@ -68,23 +66,6 @@ impl Context {
|
||||
pub fn set_stack(&mut self, address: usize) {
|
||||
self.esp = address;
|
||||
}
|
||||
|
||||
pub unsafe fn signal_stack(&mut self, handler: extern "C" fn(usize), sig: u8) {
|
||||
self.push_stack(sig as usize);
|
||||
self.push_stack(handler as usize);
|
||||
self.push_stack(signal_handler_wrapper as usize);
|
||||
}
|
||||
|
||||
pub unsafe fn push_stack(&mut self, value: usize) {
|
||||
self.esp -= mem::size_of::<usize>();
|
||||
*(self.esp as *mut usize) = value;
|
||||
}
|
||||
|
||||
pub unsafe fn pop_stack(&mut self) -> usize {
|
||||
let value = *(self.esp as *const usize);
|
||||
self.esp += mem::size_of::<usize>();
|
||||
value
|
||||
}
|
||||
}
|
||||
impl super::Context {
|
||||
pub fn get_fx_regs(&self) -> FloatRegisters {
|
||||
@@ -221,39 +202,3 @@ unsafe extern "cdecl" fn switch_to_inner() {
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct SignalHandlerStack {
|
||||
scratch: ScratchRegisters,
|
||||
handler: extern "C" fn(usize),
|
||||
sig: usize,
|
||||
eip: usize,
|
||||
}
|
||||
|
||||
#[naked]
|
||||
unsafe extern "C" fn signal_handler_wrapper() {
|
||||
#[inline(never)]
|
||||
unsafe extern "C" fn inner(stack: &SignalHandlerStack) {
|
||||
(stack.handler)(stack.sig);
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
core::arch::asm!(
|
||||
concat!(
|
||||
"push eax",
|
||||
push_scratch!(),
|
||||
"
|
||||
push esp
|
||||
call {inner}
|
||||
pop esp
|
||||
",
|
||||
pop_scratch!(),
|
||||
"
|
||||
add esp, 8
|
||||
ret
|
||||
",
|
||||
),
|
||||
inner = sym inner,
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
use core::{
|
||||
mem,
|
||||
ptr::{addr_of, addr_of_mut},
|
||||
sync::atomic::AtomicBool,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
interrupt::handler::ScratchRegisters,
|
||||
pop_scratch, push_scratch,
|
||||
syscall::FloatRegisters, percpu::PercpuBlock,
|
||||
};
|
||||
use crate::{syscall::FloatRegisters, percpu::PercpuBlock};
|
||||
|
||||
use core::mem::offset_of;
|
||||
use spin::Once;
|
||||
@@ -84,23 +79,6 @@ impl Context {
|
||||
pub fn set_stack(&mut self, address: usize) {
|
||||
self.rsp = address;
|
||||
}
|
||||
|
||||
pub unsafe fn signal_stack(&mut self, handler: extern "C" fn(usize), sig: u8) {
|
||||
self.push_stack(sig as usize);
|
||||
self.push_stack(handler as usize);
|
||||
self.push_stack(signal_handler_wrapper as usize);
|
||||
}
|
||||
|
||||
pub unsafe fn push_stack(&mut self, value: usize) {
|
||||
self.rsp -= mem::size_of::<usize>();
|
||||
*(self.rsp as *mut usize) = value;
|
||||
}
|
||||
|
||||
pub unsafe fn pop_stack(&mut self) -> usize {
|
||||
let value = *(self.rsp as *const usize);
|
||||
self.rsp += mem::size_of::<usize>();
|
||||
value
|
||||
}
|
||||
}
|
||||
impl super::Context {
|
||||
pub fn get_fx_regs(&self) -> FloatRegisters {
|
||||
@@ -299,38 +277,3 @@ unsafe extern "sysv64" fn switch_to_inner(_prev: &mut Context, _next: &mut Conte
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[repr(packed)]
|
||||
pub struct SignalHandlerStack {
|
||||
scratch: ScratchRegisters,
|
||||
handler: extern "C" fn(usize),
|
||||
sig: usize,
|
||||
rip: usize,
|
||||
}
|
||||
|
||||
#[naked]
|
||||
unsafe extern "C" fn signal_handler_wrapper() {
|
||||
#[inline(never)]
|
||||
unsafe extern "C" fn inner(stack: &SignalHandlerStack) {
|
||||
(stack.handler)(stack.sig);
|
||||
}
|
||||
|
||||
// Push scratch registers
|
||||
core::arch::asm!(
|
||||
concat!(
|
||||
"push rax",
|
||||
push_scratch!(),
|
||||
"
|
||||
mov rdi, rsp
|
||||
call {inner}
|
||||
",
|
||||
pop_scratch!(),
|
||||
"
|
||||
add rsp, 16
|
||||
ret
|
||||
"
|
||||
),
|
||||
inner = sym inner,
|
||||
options(noreturn)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use alloc::{borrow::Cow, boxed::Box, collections::VecDeque, sync::Arc, vec::Vec};
|
||||
use alloc::{borrow::Cow, sync::Arc, vec::Vec};
|
||||
use core::{cmp::Ordering, mem, num::NonZeroUsize};
|
||||
use spin::RwLock;
|
||||
|
||||
use crate::{
|
||||
arch::{interrupt::InterruptStack, paging::PAGE_SIZE},
|
||||
common::{aligned_box::AlignedBox, unique::Unique},
|
||||
common::aligned_box::AlignedBox,
|
||||
context::{self, arch, file::FileDescriptor, memory::AddrSpace},
|
||||
cpu_set::{LogicalCpuId, LogicalCpuSet},
|
||||
ipi::{ipi, IpiKind, IpiTarget},
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
use alloc::{collections::BTreeMap, sync::Arc};
|
||||
use core::{iter, mem};
|
||||
use core::iter;
|
||||
|
||||
use spinning_top::RwSpinlock;
|
||||
|
||||
|
||||
+12
-7
@@ -3,11 +3,11 @@ use core::{cell::Cell, mem, ops::Bound, sync::atomic::Ordering};
|
||||
use spinning_top::guard::ArcRwSpinlockWriteGuard;
|
||||
|
||||
use crate::{
|
||||
context::{arch, contexts, signal::signal_handler, Context},
|
||||
context::{self, arch, contexts, Context},
|
||||
cpu_set::LogicalCpuId,
|
||||
interrupt,
|
||||
percpu::PercpuBlock,
|
||||
ptrace, time,
|
||||
time,
|
||||
};
|
||||
|
||||
use super::{ContextId, Status};
|
||||
@@ -24,6 +24,7 @@ unsafe fn update_runnable(context: &mut Context, cpu_id: LogicalCpuId) -> Update
|
||||
}
|
||||
|
||||
// Ignore contexts stopped by ptrace
|
||||
// TODO: ContextStatus::HardBlocked?
|
||||
if context.ptrace_stop {
|
||||
return UpdateResult::Skip;
|
||||
}
|
||||
@@ -198,13 +199,17 @@ pub unsafe fn switch() -> bool {
|
||||
|
||||
arch::switch_to(prev_context, next_context);
|
||||
|
||||
if percpu.switch_internals.switch_signal.replace(false) {
|
||||
crate::context::signal::signal_handler();
|
||||
}
|
||||
|
||||
// NOTE: After switch_to is called, the return address can even be different from the
|
||||
// current return address, meaning that we cannot use local variables here, and that we
|
||||
// need to use the `switch_finish_hook` to be able to release the locks.
|
||||
// need to use the `switch_finish_hook` to be able to release the locks. Newly created
|
||||
// contexts will return directly to the function pointer passed to context::spawn, and not
|
||||
// reach this code until the next context switch back.
|
||||
|
||||
// We can't reuse the `percpu` variable, since it's from the stack before the last
|
||||
// context::switch, and can thus point to another CPU's percpu block.
|
||||
if PercpuBlock::current().switch_internals.switch_signal.replace(false) {
|
||||
context::signal::signal_handler();
|
||||
}
|
||||
|
||||
true
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ use crate::{
|
||||
self,
|
||||
file::FileDescriptor,
|
||||
memory::{handle_notify_files, Grant, PageSpan, AddrSpaceWrapper},
|
||||
Context, ContextId, Status, context::{SignalState, HardBlockedReason, Altstack, SignalHandler},
|
||||
Context, ContextId, Status, context::{HardBlockedReason, Altstack, SignalHandler},
|
||||
},
|
||||
memory::PAGE_SIZE,
|
||||
ptrace,
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ pub use self::{
|
||||
|
||||
use self::{
|
||||
data::{Map, SigAction, TimeSpec},
|
||||
error::{Error, Result, EINTR, EOVERFLOW, ENOSYS},
|
||||
error::{Error, Result, EOVERFLOW, ENOSYS},
|
||||
flag::{EventFlags, MapFlags, WaitFlags},
|
||||
number::*,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@ pub struct UserSlice<const READ: bool, const WRITE: bool> {
|
||||
}
|
||||
pub type UserSliceRo = UserSlice<true, false>;
|
||||
pub type UserSliceWo = UserSlice<false, true>;
|
||||
pub type UserSliceRw = UserSlice<true, true>;
|
||||
|
||||
impl<const READ: bool, const WRITE: bool> UserSlice<READ, WRITE> {
|
||||
pub fn empty() -> Self {
|
||||
@@ -211,11 +210,6 @@ impl UserSliceWo {
|
||||
Self::new(base, size)
|
||||
}
|
||||
}
|
||||
impl UserSliceRw {
|
||||
pub fn rw(base: usize, size: usize) -> Result<Self> {
|
||||
Self::new(base, size)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_kernel_mem(slice: &[u8]) -> bool {
|
||||
(slice.as_ptr() as usize) >= crate::USER_END_OFFSET
|
||||
|
||||
Reference in New Issue
Block a user