mirror of
https://github.com/rcore-os/rCore.git
synced 2025-01-19 01:07:05 +04:00
fix ctrl+C
This commit is contained in:
parent
4c1650d027
commit
98d3f83a12
38
kernel/Cargo.lock
generated
38
kernel/Cargo.lock
generated
@ -421,11 +421,11 @@ dependencies = [
|
||||
"raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rboot 0.1.2",
|
||||
"rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"rcore-memory 0.1.0",
|
||||
"rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)",
|
||||
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
|
||||
@ -451,7 +451,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rcore-fs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0#f3a4aa0e4e1627c1a2d225059d94ff16caced2e1"
|
||||
dependencies = [
|
||||
"filetime 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -461,42 +461,42 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rcore-fs-devfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0#f3a4aa0e4e1627c1a2d225059d94ff16caced2e1"
|
||||
dependencies = [
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-mountfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0#f3a4aa0e4e1627c1a2d225059d94ff16caced2e1"
|
||||
dependencies = [
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-ramfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0#f3a4aa0e4e1627c1a2d225059d94ff16caced2e1"
|
||||
dependencies = [
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-sfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0#f3a4aa0e4e1627c1a2d225059d94ff16caced2e1"
|
||||
dependencies = [
|
||||
"bitvec 0.17.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -812,11 +812,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d"
|
||||
"checksum raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf"
|
||||
"checksum rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)" = "<none>"
|
||||
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)" = "<none>"
|
||||
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)" = "<none>"
|
||||
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)" = "<none>"
|
||||
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)" = "<none>"
|
||||
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=f3a4aa0)" = "<none>"
|
||||
"checksum rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)" = "<none>"
|
||||
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
||||
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
|
||||
|
@ -66,11 +66,11 @@ bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" }
|
||||
rcore-console = { git = "https://github.com/rcore-os/rcore-console", rev = "b7bacf9", default-features = false }
|
||||
rcore-memory = { path = "../crate/memory" }
|
||||
rcore-thread = { git = "https://github.com/function2-llx/rcore-thread", rev = "8c1022d" }
|
||||
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "f3a4aa0" }
|
||||
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "f3a4aa0" }
|
||||
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "f3a4aa0" }
|
||||
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "f3a4aa0" }
|
||||
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "f3a4aa0" }
|
||||
compression = { version = "0.1.4", default-features = false, features = ["gzip"] }
|
||||
num = { version = "0.2.1", default-features = false }
|
||||
num-traits = { version = "0.2.11", default-features = false }
|
||||
|
@ -133,18 +133,8 @@ impl InitStack {
|
||||
|
||||
extern "C" {
|
||||
fn trap_ret();
|
||||
pub fn goto_signal_handler(sig: i32, addr: usize);
|
||||
}
|
||||
|
||||
global_asm!(
|
||||
r#"
|
||||
.intel_syntax noprefix
|
||||
.global goto_signal_handler
|
||||
goto_signal_handler:
|
||||
jmp rsi
|
||||
"#
|
||||
);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Context(usize);
|
||||
|
||||
|
@ -31,8 +31,8 @@ impl Stdin {
|
||||
match c as i32 {
|
||||
// INTR
|
||||
0o3 => {
|
||||
for proc in foregroud_processes.iter() {
|
||||
send_signal(proc.lock(), SIGINT, -1);
|
||||
for proc in foregroud_processes {
|
||||
send_signal(proc, -1, SIGINT);
|
||||
}
|
||||
}
|
||||
_ => warn!("special char {} is unimplented", c),
|
||||
|
@ -7,7 +7,7 @@ use crate::thread;
|
||||
use alloc::{string::String, sync::Arc};
|
||||
use core::fmt;
|
||||
|
||||
use rcore_fs::vfs::FsError::NotSupported;
|
||||
use rcore_fs::vfs::FsError::{NotSupported, Interrupted};
|
||||
use rcore_fs::vfs::{FileType, FsError, INode, MMapArea, Metadata, PollStatus, Result};
|
||||
use rcore_memory::memory_set::handler::File;
|
||||
|
||||
@ -123,6 +123,11 @@ impl FileHandle {
|
||||
return Ok(read_len);
|
||||
}
|
||||
Err(FsError::Again) => {
|
||||
let thread = unsafe { current_thread() };
|
||||
if thread.int && thread.int{
|
||||
thread.int = false;
|
||||
return Err(FsError::Interrupted)
|
||||
}
|
||||
thread::yield_now();
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -43,6 +43,8 @@ pub struct Thread {
|
||||
pub vm: Arc<Mutex<MemorySet>>,
|
||||
pub proc: Arc<Mutex<Process>>,
|
||||
pub sig_mask: Sigset,
|
||||
// if syscall or library function was interrupted by a signal
|
||||
pub int: bool,
|
||||
}
|
||||
|
||||
/// Pid type
|
||||
@ -195,6 +197,7 @@ impl Thread {
|
||||
}
|
||||
.add_to_table(),
|
||||
sig_mask: Sigset::default(),
|
||||
int: false,
|
||||
})
|
||||
}
|
||||
|
||||
@ -389,6 +392,7 @@ impl Thread {
|
||||
}
|
||||
.add_to_table(),
|
||||
sig_mask: Sigset::default(),
|
||||
int: false,
|
||||
})
|
||||
}
|
||||
|
||||
@ -435,6 +439,7 @@ impl Thread {
|
||||
vm,
|
||||
proc: new_proc,
|
||||
sig_mask: self.sig_mask,
|
||||
int: false,
|
||||
})
|
||||
}
|
||||
|
||||
@ -455,6 +460,7 @@ impl Thread {
|
||||
vm: self.vm.clone(),
|
||||
proc: self.proc.clone(),
|
||||
sig_mask: self.sig_mask,
|
||||
int: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ use num::FromPrimitive;
|
||||
mod action;
|
||||
|
||||
pub use self::action::*;
|
||||
use rcore_thread::std_thread::current;
|
||||
use rcore_thread::std_thread::{current, yield_now};
|
||||
use alloc::vec::Vec;
|
||||
use crate::arch::interrupt::goto_signal_handler;
|
||||
use crate::processor;
|
||||
use crate::syscall::{SysError, SysResult};
|
||||
|
||||
#[derive(Eq, PartialEq, FromPrimitive, Debug, Copy, Clone)]
|
||||
pub enum Signal {
|
||||
@ -81,16 +81,18 @@ pub enum Signal {
|
||||
pub const SIGRTMIN: usize = 35;
|
||||
pub const SIGRTMAX: usize = 64;
|
||||
|
||||
pub fn send_signal(mut process: MutexGuard<Process, SpinNoIrq>, signal: Signal, tid: isize) {
|
||||
process.signals[signal as usize] = Some(tid);
|
||||
// process and tid must be checked
|
||||
pub fn send_signal(process: Arc<Mutex<Process>>, tid: isize, signal: Signal) {
|
||||
process.lock().signals[signal as usize] = Some(tid);
|
||||
if tid == -1 {
|
||||
info!("send {:?} to process {}", signal, process.pid);
|
||||
info!("send {:?} to process {}", signal, process.lock().pid.get());
|
||||
if let Some(current_tid) = processor().tid_option() {
|
||||
if process.threads.contains(¤t_tid) {
|
||||
if process.lock().threads.contains(¤t_tid) {
|
||||
drop(process);
|
||||
handle_signal();
|
||||
}
|
||||
} else {
|
||||
let process = process.lock();
|
||||
for &tid in process.threads.iter() {
|
||||
thread_manager().wakeup(tid);
|
||||
}
|
||||
@ -108,9 +110,7 @@ pub fn send_signal(mut process: MutexGuard<Process, SpinNoIrq>, signal: Signal,
|
||||
|
||||
#[inline(never)]
|
||||
pub(crate) fn handle_signal() {
|
||||
let mut process = unsafe { current_thread().proc.lock() };
|
||||
let pid = process.pid.get();
|
||||
let signals = process.signals.iter().enumerate().filter_map(|(signum, tid)| {
|
||||
let signals = unsafe { current_thread() }.proc.lock().signals.iter().enumerate().filter_map(|(signum, tid)| {
|
||||
// TODO: handle mask
|
||||
if let &Some(tid) = tid {
|
||||
if tid == -1 || tid as usize == current().id() {
|
||||
@ -122,20 +122,20 @@ pub(crate) fn handle_signal() {
|
||||
None
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
drop(process);
|
||||
|
||||
unsafe { current_thread() }.int = false;
|
||||
for signum in signals {
|
||||
use crate::signal::Flags;
|
||||
use Signal::*;
|
||||
|
||||
let signal = <Signal as num::FromPrimitive>::from_usize(signum).unwrap();
|
||||
info!("received signal: {:?}", signal);
|
||||
let process = crate::process::process(pid).unwrap();
|
||||
let mut process = process.lock();
|
||||
process.signals[signum as usize] = None;
|
||||
let action = process.dispositions[signum];
|
||||
let action = {
|
||||
let mut process = unsafe { current_thread() }.proc.lock();
|
||||
process.signals[signum] = None;
|
||||
process.dispositions[signum]
|
||||
};
|
||||
let flags = Flags::from_bits_truncate(action.flags);
|
||||
drop(process);
|
||||
|
||||
// enter signal handler
|
||||
match action.handler {
|
||||
@ -143,8 +143,9 @@ pub(crate) fn handle_signal() {
|
||||
match signal {
|
||||
SIGALRM | SIGHUP | SIGINT => {
|
||||
info!("default action: Term");
|
||||
// FIXME: ref please?
|
||||
crate::process::process(pid).unwrap().lock().exit(signum + 128);
|
||||
// FIXME: exit code ref please?
|
||||
unsafe { current_thread() }.proc.lock().exit(signum + 128);
|
||||
yield_now();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
@ -155,27 +156,21 @@ pub(crate) fn handle_signal() {
|
||||
unimplemented!();
|
||||
}
|
||||
_ => {
|
||||
unsafe { current_thread() }.int = true;
|
||||
if flags.contains(Flags::SA_SIGINFO) {
|
||||
// TODO
|
||||
unimplemented!();
|
||||
} else {
|
||||
unsafe {
|
||||
goto_signal_handler(signum as i32, action.handler);
|
||||
let handler: extern "C" fn(i32) = core::mem::transmute(action.handler);
|
||||
handler(signum as i32);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process may exit during signal handling
|
||||
if crate::process::process(pid).unwrap().lock().exited() {
|
||||
break;
|
||||
}
|
||||
|
||||
if flags.contains(Flags::SA_RESTART) {
|
||||
// TODO: restart the syscall
|
||||
unimplemented!();
|
||||
} else {
|
||||
// TODO: set error for interrupted syscall
|
||||
warn!("unsupported flag: {:?}", Flags::SA_RESTART);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use crate::fs::FileLike;
|
||||
use crate::process::Process;
|
||||
use crate::syscall::SysError::{EINVAL, ESPIPE};
|
||||
use rcore_fs::vfs::PollStatus;
|
||||
use rcore_thread::std_thread::current;
|
||||
|
||||
impl Syscall<'_> {
|
||||
pub fn sys_read(&mut self, fd: usize, base: *mut u8, len: usize) -> SysResult {
|
||||
@ -32,9 +33,9 @@ impl Syscall<'_> {
|
||||
info!("read: fd: {}, base: {:?}, len: {:#x}", fd, base, len);
|
||||
}
|
||||
let slice = unsafe { self.vm().check_write_array(base, len)? };
|
||||
let file_like = proc.get_file_like(fd)?;
|
||||
let len = file_like.read(slice)?;
|
||||
|
||||
let file_like = unsafe { (*UnsafeCell::new(proc).get()).get_file_like(fd)? };
|
||||
let len = file_like.read(slice)?;
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
@ -380,7 +381,7 @@ impl Syscall<'_> {
|
||||
match file_like {
|
||||
FileLike::File(_file) => {
|
||||
&crate::fs::STDIN.pushed.register_epoll_list(
|
||||
self.thread.proc.clone(),
|
||||
unsafe { current_thread() }.proc.clone(),
|
||||
thread::current().id(),
|
||||
epfd,
|
||||
*fd,
|
||||
@ -389,7 +390,7 @@ impl Syscall<'_> {
|
||||
}
|
||||
FileLike::Socket(_socket) => {
|
||||
&(*crate::drivers::SOCKET_ACTIVITY).register_epoll_list(
|
||||
self.thread.proc.clone(),
|
||||
unsafe { current_thread() }.proc.clone(),
|
||||
thread::current().id(),
|
||||
epfd,
|
||||
*fd,
|
||||
@ -1412,6 +1413,7 @@ impl From<FsError> for SysError {
|
||||
FsError::Again => SysError::EAGAIN,
|
||||
FsError::SymLoop => SysError::ELOOP,
|
||||
FsError::Busy => SysError::EBUSY,
|
||||
FsError::Interrupted => SysError::EINTR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,14 +53,14 @@ lazy_static! {
|
||||
|
||||
/// System call dispatcher
|
||||
pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
||||
let thread = unsafe { current_thread() };
|
||||
let mut syscall = Syscall { thread, tf };
|
||||
// let thread = unsafe { current_thread() };
|
||||
let mut syscall = Syscall { tf };
|
||||
syscall.syscall(id, args)
|
||||
}
|
||||
|
||||
/// All context needed for syscall
|
||||
struct Syscall<'a> {
|
||||
thread: &'a mut Thread,
|
||||
// thread: &'a mut Thread,
|
||||
tf: &'a mut TrapFrame,
|
||||
}
|
||||
|
||||
@ -68,12 +68,14 @@ impl Syscall<'_> {
|
||||
/// Get current process
|
||||
/// spinlock is tend to deadlock, use busy waiting
|
||||
pub fn process(&self) -> MutexGuard<'_, Process, SpinNoIrq> {
|
||||
self.thread.proc.busy_lock()
|
||||
unsafe { current_thread() }.proc.busy_lock()
|
||||
// self.thread.proc.busy_lock()
|
||||
}
|
||||
|
||||
/// Get current virtual memory
|
||||
pub fn vm(&self) -> MutexGuard<'_, MemorySet, SpinNoIrq> {
|
||||
self.thread.vm.lock()
|
||||
// self.thread.vm.lock()
|
||||
unsafe { current_thread() }.vm.lock()
|
||||
}
|
||||
|
||||
/// System call dispatcher
|
||||
|
@ -9,11 +9,11 @@ use alloc::sync::Weak;
|
||||
impl Syscall<'_> {
|
||||
/// Fork the current process. Return the child's PID.
|
||||
pub fn sys_fork(&mut self) -> SysResult {
|
||||
let new_thread = self.thread.fork(self.tf);
|
||||
let new_thread = unsafe { current_thread() }.fork(self.tf);
|
||||
let pid = new_thread.proc.lock().pid.get();
|
||||
let tid = thread_manager().add(new_thread);
|
||||
thread_manager().detach(tid);
|
||||
info!("fork: {} -> {}", self.thread.proc.lock().pid, pid);
|
||||
info!("fork: {} -> {}", self.process().pid, pid);
|
||||
Ok(pid)
|
||||
}
|
||||
|
||||
@ -56,9 +56,7 @@ impl Syscall<'_> {
|
||||
let parent_tid_ref = unsafe { self.vm().check_write_ptr(parent_tid)? };
|
||||
// child_tid buffer should not be set because CLONE_CHILD_SETTID flag is not specified in the current implementation
|
||||
// let child_tid_ref = unsafe { self.vm().check_write_ptr(child_tid)? };
|
||||
let mut new_thread = self
|
||||
.thread
|
||||
.clone(self.tf, newsp, newtls, child_tid as usize);
|
||||
let mut new_thread = unsafe { current_thread() }.clone(self.tf, newsp, newtls, child_tid as usize);
|
||||
if clone_flags.contains(CloneFlags::CHILD_CLEARTID) {
|
||||
new_thread.clear_child_tid = child_tid as usize;
|
||||
}
|
||||
@ -316,7 +314,8 @@ impl Syscall<'_> {
|
||||
// ref: http://man7.org/linux/man-pages/man2/set_tid_address.2.html
|
||||
// FIXME: do it in all possible ways a thread can exit
|
||||
// it has memory access so we can't move it to Thread::drop?
|
||||
let clear_child_tid = self.thread.clear_child_tid as *mut u32;
|
||||
let thread = unsafe { current_thread() };
|
||||
let clear_child_tid = thread.clear_child_tid as *mut u32;
|
||||
if !clear_child_tid.is_null() {
|
||||
info!("exit: futex {:#?} wake 1", clear_child_tid);
|
||||
if let Ok(clear_child_tid_ref) = unsafe { self.vm().check_write_ptr(clear_child_tid) } {
|
||||
@ -362,7 +361,7 @@ impl Syscall<'_> {
|
||||
|
||||
pub fn sys_set_tid_address(&mut self, tidptr: *mut u32) -> SysResult {
|
||||
info!("set_tid_address: {:?}", tidptr);
|
||||
self.thread.clear_child_tid = tidptr as usize;
|
||||
unsafe { current_thread() }.clear_child_tid = tidptr as usize;
|
||||
Ok(thread::current().id())
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::process::{PROCESSES, thread_manager, process_of};
|
||||
use crate::process::{PROCESSES, thread_manager, process_of, current_thread};
|
||||
use crate::process::{process, process_group};
|
||||
use crate::signal::*;
|
||||
use crate::syscall::SysError::{EINVAL, ESRCH};
|
||||
@ -60,7 +60,7 @@ impl Syscall<'_> {
|
||||
}
|
||||
if !oldset.is_null() {
|
||||
let oldset = unsafe { self.vm().check_write_ptr(oldset)? };
|
||||
*oldset = self.thread.sig_mask;
|
||||
*oldset = unsafe { current_thread() }.sig_mask;
|
||||
}
|
||||
if !set.is_null() {
|
||||
// let set = *unsafe { self.vm().check_read_ptr(set)? };
|
||||
@ -69,10 +69,11 @@ impl Syscall<'_> {
|
||||
const BLOCK: usize = 0;
|
||||
const UNBLOCK: usize = 1;
|
||||
const SETMASK: usize = 2;
|
||||
let thread = unsafe { current_thread() };
|
||||
match how {
|
||||
BLOCK => self.thread.sig_mask |= set,
|
||||
UNBLOCK => self.thread.sig_mask ^= self.thread.sig_mask & set,
|
||||
SETMASK => self.thread.sig_mask = set,
|
||||
BLOCK => thread.sig_mask |= set,
|
||||
UNBLOCK => thread.sig_mask ^= thread.sig_mask & set,
|
||||
SETMASK => thread.sig_mask = set,
|
||||
_ => return Err(EINVAL),
|
||||
}
|
||||
}
|
||||
@ -81,38 +82,49 @@ impl Syscall<'_> {
|
||||
|
||||
/// sending signal sig to process pid
|
||||
pub fn sys_kill(&mut self, pid: isize, signum: usize) -> SysResult {
|
||||
info!("kill: pid: {}, signum: {}", pid, signum);
|
||||
if let Some(sig) = num::FromPrimitive::from_usize(signum) {
|
||||
if let Some(signal) = num::FromPrimitive::from_usize(signum) {
|
||||
info!("kill: pid: {}, signal: {:?}", pid, signal);
|
||||
match pid {
|
||||
pid if pid > 0 => {
|
||||
if let Some(process) = process(pid as usize) {
|
||||
send_signal(process.lock(), sig, -1);
|
||||
send_signal(process, -1, signal);
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(ESRCH)
|
||||
}
|
||||
}
|
||||
0 => {
|
||||
let pgid = self.process().pgid;
|
||||
for process in process_group(pgid).iter() {
|
||||
send_signal(process.lock(), sig, -1);
|
||||
for process in process_group(pgid) {
|
||||
send_signal(process, -1, signal);
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
-1 => {
|
||||
// TODO: check permissions
|
||||
// sig is sent to every process for which the calling process
|
||||
// has permission to send signals, except for process 1 (init)
|
||||
for process in PROCESSES.read().values() {
|
||||
if let Some(process) = process.upgrade() {
|
||||
send_signal(process.lock(), sig, -1);
|
||||
send_signal(process, -1, signal);
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
_ => {
|
||||
let pgid = -pid;
|
||||
for process in process_group(pgid as i32).iter() {
|
||||
send_signal(process.lock(), sig, -1);
|
||||
let process_group = process_group((-pid) as i32);
|
||||
if process_group.is_empty() {
|
||||
Err(ESRCH)
|
||||
} else {
|
||||
for process in process_group {
|
||||
send_signal(process, -1, signal);
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
} else {
|
||||
info!("kill: pid: {}, signal: UNKNOWN", pid);
|
||||
Err(EINVAL)
|
||||
}
|
||||
}
|
||||
@ -122,13 +134,13 @@ impl Syscall<'_> {
|
||||
if let Some(signal) = signal {
|
||||
info!("tkill: tid: {}, signal: {:?}", tid, signal);
|
||||
if let Some(process) = process_of(tid) {
|
||||
send_signal(process.lock(), signal, tid as isize);
|
||||
send_signal(process, tid as isize, signal);
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(ESRCH)
|
||||
}
|
||||
} else {
|
||||
info!("tkill: tid: {}, signal: UNKNOWN", tid, );
|
||||
info!("tkill: tid: {}, signal: UNKNOWN", tid);
|
||||
Err(EINVAL)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user