suppress debug info for timing syscalls

master
Harry Cheng 6 years ago
parent b4b3cd20b2
commit 384f6dd1c3

10
kernel/Cargo.lock generated

@ -393,8 +393,8 @@ dependencies = [
"pc-keyboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pci 0.0.1 (git+https://github.com/rcore-os/pci-rs)",
"raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs)",
"rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs)",
"rcore-fs 0.1.0",
"rcore-fs-sfs 0.1.0",
"rcore-memory 0.1.0",
"rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread)",
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
@ -409,7 +409,6 @@ dependencies = [
[[package]]
name = "rcore-fs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs#ee0d0b31a1cea4c905100cef501a3bc522ded00d"
dependencies = [
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -417,11 +416,10 @@ dependencies = [
[[package]]
name = "rcore-fs-sfs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs#ee0d0b31a1cea4c905100cef501a3bc522ded00d"
dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs)",
"rcore-fs 0.1.0",
"spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -732,8 +730,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d"
"checksum rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs)" = "<none>"
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs)" = "<none>"
"checksum rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread)" = "<none>"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"

@ -65,8 +65,10 @@ smoltcp = { git = "https://github.com/rcore-os/smoltcp", default-features = fals
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" }
rcore-memory = { path = "../crate/memory" }
rcore-thread = { git = "https://github.com/rcore-os/rcore-thread" }
rcore-fs = { git = "https://github.com/rcore-os/rcore-fs" }
rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs" }
# rcore-fs = { git = "https://github.com/rcore-os/rcore-fs" }
# rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs" }
rcore-fs = { path = "../../rcore-fs/rcore-fs" }
rcore-fs-sfs = { path = "../../rcore-fs/rcore-fs-sfs" }
[target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = { git = "https://github.com/rcore-os/bootloader", branch = "vga" }

@ -128,12 +128,12 @@ fn double_fault(tf: &TrapFrame) {
loop {}
}
fn divide_error(tf: &TrapFrame) {
fn divide_error(tf: &mut TrapFrame) {
error!("\nEXCEPTION: Divide Error");
error(tf);
}
fn general_protection_fault(tf: &TrapFrame) {
fn general_protection_fault(tf: &mut TrapFrame) {
error!("\nEXCEPTION: General Protection Fault");
error(tf);
}
@ -182,7 +182,6 @@ fn vsyscall(addr: usize, tf: &mut TrapFrame) -> bool {
0xffffffffff600000 => 96,
_ => return false
};
debug!("vsyscall emulation");
let caller = unsafe { (tf.rsp as *mut u32).read() };
let ret = crate::syscall::syscall(id, [tf.rdi, tf.rsi, tf.rdx, tf.r10, tf.r8, tf.r9], tf);
tf.rip = caller as usize;
@ -255,7 +254,7 @@ fn invalid_opcode(tf: &mut TrapFrame) {
}
}
fn error(tf: &TrapFrame) {
fn error(tf: &mut TrapFrame) {
crate::trap::error(tf);
}

@ -0,0 +1,70 @@
// /dev/null
use alloc::{string::String, sync::Arc, vec::Vec};
use core::any::Any;
use rcore_fs::vfs::*;
pub struct DevNull {}
impl DevNull {
pub fn new() -> Self {
DevNull {}
}
}
macro_rules! impl_inode {
() => {
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
fn sync_all(&self) -> Result<()> { Ok(()) }
fn sync_data(&self) -> Result<()> { Ok(()) }
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) }
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<(usize, String)> { Err(FsError::NotDir) }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};
}
impl INode for DevNull {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
for i in buf.iter_mut() {
*i = 0
}
Ok(buf.len())
}
fn write_at(&self, _offset: usize, buf: &[u8]) -> Result<usize> {
Ok(buf.len())
}
fn poll(&self) -> Result<PollStatus> {
Ok(PollStatus {
read: true,
write: true,
error: false,
})
}
fn metadata(&self) -> Result<Metadata> {
Ok(Metadata {
dev: 0,
inode: 0,
size: 0,
blk_size: 0,
blocks: 0,
atime: Timespec { sec: 0, nsec: 0 },
mtime: Timespec { sec: 0, nsec: 0 },
ctime: Timespec { sec: 0, nsec: 0 },
type_: FileType::CharDevice,
mode: 0,
nlinks: 0,
uid: 0,
gid: 0,
rdev: 0,
})
}
impl_inode!();
}

@ -124,7 +124,7 @@ impl FileHandle {
self.inode.lookup_follow(path, max_follow)
}
pub fn read_entry(&mut self) -> Result<String> {
pub fn read_entry(&mut self) -> Result<(usize, String)> {
if !self.options.read {
return Err(FsError::InvalidParam); // FIXME: => EBADF
}

@ -12,6 +12,7 @@ pub use self::pipe::Pipe;
pub use self::pseudo::*;
pub use self::stdio::{STDIN, STDOUT};
pub use self::vga::*;
pub use self::devnull::DevNull;
mod device;
mod file;
@ -20,6 +21,7 @@ mod ioctl;
mod pipe;
mod pseudo;
mod stdio;
mod devnull;
pub mod vga;
// Hard link user programs

@ -79,7 +79,7 @@ macro_rules! impl_inode {
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<(usize, String)> { Err(FsError::NotDir) }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }

@ -31,7 +31,7 @@ macro_rules! impl_inode {
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<(usize, String)> { Err(FsError::NotDir) }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }

@ -66,7 +66,7 @@ macro_rules! impl_inode {
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<(usize, String)> { Err(FsError::NotDir) }
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
match cmd as usize {
TCGETS | TIOCGWINSZ | TIOCSPGRP => {

@ -19,7 +19,7 @@ macro_rules! impl_inode {
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<(usize, String)> { Err(FsError::NotDir) }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};

@ -506,12 +506,12 @@ impl Syscall<'_> {
}
let mut writer = DirentBufWriter::new(buf);
loop {
let name = match file.read_entry() {
let entry = match file.read_entry() {
Err(FsError::EntryNotFound) => break,
r => r,
}?;
// TODO: get ino from dirent
let ok = writer.try_write(0, DirentType::from_type(&info.type_).bits(), &name);
debug!("getdents64: got {}", entry.1);
let ok = writer.try_write(entry.0 as u64, DirentType::from_type(&info.type_).bits(), &entry.1);
if !ok {
break;
}
@ -706,7 +706,7 @@ impl Syscall<'_> {
let (dir_path, file_name) = split_path(&path);
let dir_inode = proc.lookup_inode_at(dirfd, dir_path, true)?;
let file_inode = dir_inode.find(file_name)?;
if file_inode.metadata()?.type_ == FileType::Dir {
if file_inode.metadata()?.type_ == FileType::Dir && !flags.contains(AtFlags::REMOVEDIR) {
return Err(SysError::EISDIR);
}
dir_inode.unlink(file_name)?;
@ -908,6 +908,10 @@ impl Process {
info!("/dev/fb0 will be opened");
return Ok(Arc::new(Vga::default()));
}
"/dev/null" => {
info!("/dev/null will be opened");
return Ok(Arc::new(DevNull::new()));
}
_ => {}
}
let (fd_dir_path, fd_name) = split_path(&path);
@ -969,6 +973,8 @@ impl From<FsError> for SysError {
FsError::IOCTLError => SysError::EINVAL,
FsError::NoDevice => SysError::EINVAL,
FsError::Again => SysError::EAGAIN,
FsError::Busy => SysError::EBUSY,
FsError::SymLoop => SysError::ELOOP,
}
}
}
@ -977,6 +983,7 @@ bitflags! {
struct AtFlags: usize {
const EMPTY_PATH = 0x1000;
const SYMLINK_NOFOLLOW = 0x100;
const REMOVEDIR = 0x200;
}
}

@ -76,7 +76,7 @@ impl Syscall<'_> {
let cid = cpu::id();
let pid = self.process().pid.clone();
let tid = processor().tid();
if !pid.is_init() {
if !pid.is_init() && id != SYS_GETTIMEOFDAY {
// we trust pid 0 process
debug!("{}:{}:{} syscall id {} begin", cid, pid, tid, id);
}
@ -155,6 +155,7 @@ impl Syscall<'_> {
self.sys_ppoll(args[0] as *mut PollFd, args[1], args[2] as *const TimeSpec)
} // ignore sigmask
SYS_EPOLL_CREATE1 => self.unimplemented("epoll_create1", Err(SysError::ENOSYS)),
SYS_EPOLL_CTL => self.unimplemented("epoll_ctl", Err(SysError::EPERM)),
// file system
SYS_STATFS => self.unimplemented("statfs", Err(SysError::EACCES)),
@ -241,6 +242,7 @@ impl Syscall<'_> {
SYS_EXIT => self.sys_exit(args[0] as usize),
SYS_EXIT_GROUP => self.sys_exit_group(args[0]),
SYS_WAIT4 => self.sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4
SYS_WAITID => self.sys_waitid(args[0] as u32, args[1] as isize, args[2] as *mut SignalInfo, args[3] as i32),
SYS_SET_TID_ADDRESS => self.sys_set_tid_address(args[0] as *mut u32),
SYS_FUTEX => self.sys_futex(
args[0],
@ -321,7 +323,7 @@ impl Syscall<'_> {
}
}
};
if !pid.is_init() {
if !pid.is_init() && id != SYS_GETTIMEOFDAY {
// we trust pid 0 process
info!("=> {:x?}", ret);
}
@ -474,6 +476,7 @@ pub enum SysError {
ENOLCK = 37,
ENOSYS = 38,
ENOTEMPTY = 39,
ELOOP = 40,
ENOTSOCK = 80,
ENOPROTOOPT = 92,
EPFNOSUPPORT = 96,

@ -39,25 +39,22 @@ impl Syscall<'_> {
warn!("sys_clone is calling sys_fork instead, ignoring other args");
return self.sys_fork();
}
if (flags != 0x7d0f00) && (flags != 0x5d0f00) {
//0x5d0f00 is the args from gcc of alpine linux
//warn!("sys_clone only support musl pthread_create");
panic!(
"sys_clone only support sys_fork OR musl pthread_create without flags{:x}",
flags
);
//return Err(SysError::ENOSYS);
}
let parent_tid_ref = unsafe { self.vm().check_write_ptr(parent_tid)? };
let child_tid_ref = unsafe { self.vm().check_write_ptr(child_tid)? };
let new_thread = self
.thread
.clone(self.tf, newsp, newtls, child_tid as usize);
let tid = processor().manager().add(new_thread);
processor().manager().detach(tid);
info!("clone: {} -> {}", thread::current().id(), tid);
*parent_tid_ref = tid as u32;
*child_tid_ref = tid as u32;
if clone_flags.contains(CloneFlags::PARENT_SETTID) {
let parent_tid_ref = unsafe { self.vm().check_write_ptr(parent_tid)? };
*parent_tid_ref = tid as u32;
}
if clone_flags.contains(CloneFlags::CHILD_SETTID) {
let child_tid_ref = unsafe { self.vm().check_write_ptr(child_tid)? };
*child_tid_ref = tid as u32;
}
Ok(tid)
}
@ -70,12 +67,6 @@ impl Syscall<'_> {
} else {
None
};
#[derive(Debug)]
enum WaitFor {
AnyChild,
AnyChildInGroup,
Pid(usize),
}
let target = match pid {
-1 => WaitFor::AnyChild,
0 => WaitFor::AnyChildInGroup,
@ -129,6 +120,79 @@ impl Syscall<'_> {
}
}
pub fn sys_waitid(&mut self, idType: u32, id: isize, signalInfo: *mut SignalInfo, options: i32) -> SysResult {
let flags = WaitOptions::from_bits_truncate(options);
let target = match idType {
0 => WaitFor::AnyChild,
1 => WaitFor::Pid(id as usize),
2 => WaitFor::AnyChildInGroup,
_ => unimplemented!(),
};
let signalInfo = if !signalInfo.is_null() {
Some(unsafe { self.vm().check_write_ptr(signalInfo)? })
} else {
None
};
loop {
let mut proc = self.process();
// check child_exit_code
let find = match target {
WaitFor::AnyChild | WaitFor::AnyChildInGroup => proc
.child_exit_code
.iter()
.next()
.map(|(&pid, &code)| (pid, code)),
WaitFor::Pid(pid) => proc.child_exit_code.get(&pid).map(|&code| (pid, code)),
};
// if found, return
if let Some((pid, exit_code)) = find {
if !flags.contains(WaitOptions::NOWAIT) {
proc.child_exit_code.remove(&pid);
}
if let Some(signalInfo) = signalInfo {
let mut si = &mut *signalInfo;
si.fields.common.first.piduid.pid = pid as i32;
si.fields.common.second.child.status = exit_code as i32;
si.number = 20; // SIGCHLD
si.code = 1; // CLD_EXITED
}
return Ok(pid);
}
// if not, check pid
let invalid = {
let children: Vec<_> = proc
.children
.iter()
.filter_map(|weak| weak.upgrade())
.collect();
match target {
WaitFor::AnyChild | WaitFor::AnyChildInGroup => children.len() == 0,
WaitFor::Pid(pid) => children
.iter()
.find(|p| p.lock().pid.get() == pid)
.is_none(),
}
};
if invalid {
if flags.contains(WaitOptions::NOHANG) {
return Ok(0);
} else {
return Err(SysError::ECHILD);
}
}
info!(
"waitid: thread {} -> {:?}, sleep",
thread::current().id(),
target
);
let condvar = proc.child_exit.clone();
condvar.wait(proc);
}
}
/// Replaces the current ** process ** with a new process image
///
/// `argv` is an array of argument strings passed to the new program.
@ -340,3 +404,127 @@ bitflags! {
const IO = 0x80000000;
}
}
bitflags! {
pub struct WaitOptions: i32 {
const EXITED = 0x00000004;
const STOPPED = 0x00000002;
const CONTINUED = 0x00000008;
const NOHANG = 0x00000001;
const NOWAIT = 0x01000000;
}
}
#[derive(Debug)]
enum WaitFor {
AnyChild,
AnyChildInGroup,
Pid(usize),
}
#[cfg(not(arch = "mips"))]
#[repr(C)]
pub struct SignalInfo {
number: i32,
errorNumber: i32,
code: i32,
fields: SignalInfoFields,
}
#[cfg(arch = "mips")]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfo {
number: i32,
code: i32,
errorNumber: i32,
fields: SignalInfoFields,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalInfoFields {
_pad: [u8; 128 - 2 * 4 - 8],
common: SignalInfoFieldsCommon,
sigfault: SignalInfoSigfault,
sigpoll: SignalInfoSigpoll,
sigsys: SignalInfoSigsys,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalInfoFieldsCommon {
first: SignalInfoFieldsCommon1,
second: SignalInfoFieldsCommon2,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalInfoFieldsCommon1 {
piduid: SignalInfoPidUid,
timer: SignalInfoTimer,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoPidUid {
pid: i32,
uid: i32
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoTimer {
timerId: i32,
overrun: i32,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalInfoFieldsCommon2 {
value: SignalValue,
child: SignalChild,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalValue {
int: i32,
ptr: usize,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalChild {
status: i32,
utime: i64,
stime: i64,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoSigfault {
addr: usize,
addrLsb: i16,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SignalInfoSigfault1 {
pkey: u32,
addrBnd: SignalInfoSigfaultAddrBnd,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoSigfaultAddrBnd {
lower: usize,
uppwe: usize
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoSigpoll {
band: i64,
fd: i32
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SignalInfoSigsys {
callAddr: usize,
syscall: i32,
arch: u32,
}

@ -7,7 +7,7 @@ use lazy_static::lazy_static;
impl Syscall<'_> {
pub fn sys_gettimeofday(&mut self, tv: *mut TimeVal, tz: *const u8) -> SysResult {
info!("gettimeofday: tv: {:?}, tz: {:?}", tv, tz);
// info!("gettimeofday: tv: {:?}, tz: {:?}", tv, tz);
if tz as usize != 0 {
return Err(SysError::EINVAL);
}
@ -20,7 +20,7 @@ impl Syscall<'_> {
}
pub fn sys_clock_gettime(&mut self, clock: usize, ts: *mut TimeSpec) -> SysResult {
info!("clock_gettime: clock: {:?}, ts: {:?}", clock, ts);
// info!("clock_gettime: clock: {:?}, ts: {:?}", clock, ts);
let ts = unsafe { self.vm().check_write_ptr(ts)? };

@ -1 +1 @@
Subproject commit bbcee244e80eecd9b69839462d3ed89ef78f8d88
Subproject commit b055c8df6258bc887e121d40979816fa578cc00a
Loading…
Cancel
Save