mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 08:06:17 +04:00
Fix user fixup handling
This commit is contained in:
parent
274addfc34
commit
33291ff5d3
@ -67,7 +67,6 @@
|
||||
use super::consts::*;
|
||||
use super::TrapFrame;
|
||||
use crate::drivers::IRQ_MANAGER;
|
||||
use crate::process::current_thread;
|
||||
use crate::signal::do_signal;
|
||||
use bitflags::*;
|
||||
use log::*;
|
||||
@ -216,7 +215,7 @@ pub extern "C" fn syscall(tf: &mut TrapFrame) {
|
||||
trace!("\nInterupt: Syscall {:#x?}", tf.rax);
|
||||
//let ret = crate::syscall::syscall(tf.rax, [tf.rdi, tf.rsi, tf.rdx, tf.r10, tf.r8, tf.r9], tf);
|
||||
//tf.rax = ret as usize;
|
||||
do_signal(tf);
|
||||
//do_signal(tf);
|
||||
}
|
||||
|
||||
fn syscall32(tf: &mut TrapFrame) {
|
||||
|
@ -100,6 +100,7 @@ impl INode for Fbdev {
|
||||
if area.offset + area.end_vaddr - area.start_vaddr > fb.framebuffer_size() {
|
||||
return Err(FsError::NoDeviceSpace);
|
||||
}
|
||||
/*
|
||||
let thread = unsafe { crate::process::current_thread() };
|
||||
thread.vm.lock().push(
|
||||
area.start_vaddr,
|
||||
@ -108,6 +109,7 @@ impl INode for Fbdev {
|
||||
Linear::new((fb.paddr() + area.offset - area.start_vaddr) as isize),
|
||||
"mmap_file",
|
||||
);
|
||||
*/
|
||||
Ok(())
|
||||
} else {
|
||||
Err(FsError::NoDevice)
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! File handle for process
|
||||
|
||||
use crate::memory::GlobalFrameAlloc;
|
||||
use crate::process::{current_thread, INodeForMap};
|
||||
use crate::process::INodeForMap;
|
||||
use crate::syscall::{MmapProt, SysResult, TimeSpec};
|
||||
use alloc::{string::String, sync::Arc};
|
||||
use core::fmt;
|
||||
@ -233,6 +233,7 @@ impl FileHandle {
|
||||
match self.inode.metadata()?.type_ {
|
||||
FileType::File => {
|
||||
let prot = MmapProt::from_bits_truncate(area.prot);
|
||||
/*
|
||||
let thread = unsafe { current_thread() };
|
||||
thread.vm.lock().push(
|
||||
area.start_vaddr,
|
||||
@ -247,6 +248,7 @@ impl FileHandle {
|
||||
},
|
||||
"mmap_file",
|
||||
);
|
||||
*/
|
||||
Ok(())
|
||||
}
|
||||
FileType::CharDevice => self.inode.mmap(area),
|
||||
|
@ -8,6 +8,7 @@
|
||||
#![feature(negative_impls)]
|
||||
#![feature(alloc_prelude)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(const_in_array_repeat_expressions)]
|
||||
#![deny(unused_must_use)]
|
||||
#![deny(stable_features)]
|
||||
#![deny(unused_unsafe)]
|
||||
|
@ -141,8 +141,9 @@ impl Drop for KernelStack {
|
||||
pub fn handle_page_fault(addr: usize) -> bool {
|
||||
debug!("page fault @ {:#x}", addr);
|
||||
|
||||
let thread = unsafe { current_thread() };
|
||||
thread.vm.lock().handle_page_fault(addr)
|
||||
let thread = current_thread().unwrap();
|
||||
let mut lock = thread.vm.lock();
|
||||
lock.handle_page_fault(addr)
|
||||
}
|
||||
|
||||
pub fn init_heap() {
|
||||
|
@ -38,15 +38,16 @@ pub fn init() {
|
||||
info!("process: init end");
|
||||
}
|
||||
|
||||
static mut THREADS: [Option<Arc<Thread>>; MAX_CPU_NUM] = [None; MAX_CPU_NUM];
|
||||
|
||||
/// Get current thread
|
||||
///
|
||||
/// `Thread` is a thread-local object.
|
||||
/// It is safe to call this once, and pass `&mut Thread` as a function argument.
|
||||
pub unsafe fn current_thread() -> &'static mut Thread {
|
||||
// trick: force downcast from trait object
|
||||
//let (process, _): (&mut Thread, *const ()) = core::mem::transmute(processor().context());
|
||||
//process
|
||||
todo!()
|
||||
/// Should only be called in kernel trap handler
|
||||
pub fn current_thread() -> Option<Arc<Thread>> {
|
||||
let cpu_id = cpu::id();
|
||||
unsafe { THREADS[cpu_id].clone() }
|
||||
}
|
||||
|
||||
pub fn spawn(thread: Arc<Thread>) {
|
||||
@ -109,6 +110,10 @@ impl Future for PageTableSwitchWrapper {
|
||||
type Output = ();
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// vmtoken might change upon sys_exec
|
||||
let cpu_id = cpu::id();
|
||||
unsafe {
|
||||
THREADS[cpu_id] = Some(self.thread.clone());
|
||||
}
|
||||
let vmtoken = self.thread.vm.lock().token();
|
||||
unsafe {
|
||||
Cr3::write(
|
||||
@ -116,6 +121,10 @@ impl Future for PageTableSwitchWrapper {
|
||||
Cr3Flags::empty(),
|
||||
);
|
||||
}
|
||||
self.inner.lock().as_mut().poll(cx)
|
||||
let res = self.inner.lock().as_mut().poll(cx);
|
||||
unsafe {
|
||||
THREADS[cpu_id] = None;
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::process::{current_thread, process, process_of, Process};
|
||||
use crate::process::{process, process_of, Process, Thread};
|
||||
use crate::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock as Mutex};
|
||||
use alloc::sync::Arc;
|
||||
use bitflags::*;
|
||||
@ -132,9 +132,8 @@ pub struct SignalFrame {
|
||||
pub ret_code: [u8; 7], // call sys_sigreturn
|
||||
}
|
||||
|
||||
pub fn do_signal(tf: &mut TrapFrame) {
|
||||
let thread = unsafe { current_thread() };
|
||||
let mut process = unsafe { current_thread().proc.lock() };
|
||||
pub fn do_signal(thread: &Arc<Thread>, tf: &mut TrapFrame) {
|
||||
let mut process = thread.proc.lock();
|
||||
while let Some((idx, info)) =
|
||||
process
|
||||
.sig_queue
|
||||
|
Loading…
Reference in New Issue
Block a user