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