mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
fix mxcsr; flock
This commit is contained in:
parent
0cce66c876
commit
9a02550bcb
@ -19,9 +19,12 @@ __alltraps:
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
sub rsp, 8
|
||||
stmxcsr -8(rsp)
|
||||
|
||||
.att_syntax
|
||||
subq $0x8, %rsp
|
||||
stmxcsr 0(%rsp)
|
||||
|
||||
.intel_syntax noprefix
|
||||
# push fs.base
|
||||
xor rax, rax
|
||||
mov ecx, 0xC0000100
|
||||
@ -75,8 +78,11 @@ skip_fxrstor:
|
||||
mov ecx, 0xC0000100
|
||||
wrmsr # msr[ecx] <= edx:eax
|
||||
|
||||
LDMXCSR rsp
|
||||
add rsp, 8
|
||||
.att_syntax
|
||||
ldmxcsr 0(%rsp)
|
||||
addq $0x8, %rsp
|
||||
|
||||
.intel_syntax noprefix
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
@ -146,6 +152,11 @@ syscall_entry:
|
||||
push r14
|
||||
push r15
|
||||
|
||||
.att_syntax
|
||||
subq $0x8, %rsp
|
||||
stmxcsr 0(%rsp)
|
||||
|
||||
.intel_syntax noprefix
|
||||
# push fs.base
|
||||
xor rax, rax
|
||||
mov ecx, 0xC0000100
|
||||
@ -201,6 +212,11 @@ skip_fxrstor1:
|
||||
mov ecx, 0xC0000100
|
||||
wrmsr # msr[ecx] <= edx:eax
|
||||
|
||||
.att_syntax
|
||||
ldmxcsr 0(%rsp)
|
||||
addq $0x8, %rsp
|
||||
|
||||
.intel_syntax noprefix
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
|
@ -28,7 +28,7 @@ pub struct TrapFrame {
|
||||
// Pushed by __alltraps at 'trap.asm'
|
||||
pub fsbase: usize,
|
||||
|
||||
pub mxcsr: u32,
|
||||
pub mxcsr: usize,
|
||||
pub r15: usize,
|
||||
pub r14: usize,
|
||||
pub r13: usize,
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
mod fbdev;
|
||||
mod random;
|
||||
mod shm;
|
||||
mod stdio;
|
||||
mod tty;
|
||||
mod shm;
|
||||
|
||||
pub use fbdev::*;
|
||||
pub use random::*;
|
||||
pub use shm::*;
|
||||
pub use stdio::*;
|
||||
pub use tty::*;
|
||||
pub use shm::*;
|
||||
|
@ -13,12 +13,35 @@ use rcore_memory::memory_set::handler::File;
|
||||
|
||||
use crate::sync::SpinLock as Mutex;
|
||||
use crate::syscall::SysError::{EAGAIN, ESPIPE};
|
||||
use bitflags::_core::cell::Cell;
|
||||
use spin::RwLock;
|
||||
|
||||
enum Flock {
|
||||
None = 0,
|
||||
Shared = 1,
|
||||
Exclusive = 2,
|
||||
}
|
||||
|
||||
struct OpenFileDescription {
|
||||
offset: u64,
|
||||
options: OpenOptions,
|
||||
flock: Flock,
|
||||
}
|
||||
|
||||
impl OpenFileDescription {
|
||||
fn create(options: OpenOptions) -> Arc<RwLock<Self>> {
|
||||
Arc::new(RwLock::new(OpenFileDescription {
|
||||
offset: 0,
|
||||
options,
|
||||
flock: Flock::None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FileHandle {
|
||||
inode: Arc<dyn INode>,
|
||||
offset: Arc<Mutex<u64>>,
|
||||
pub options: Arc<Mutex<OpenOptions>>,
|
||||
description: Arc<RwLock<OpenFileDescription>>,
|
||||
pub path: String,
|
||||
pub pipe: bool, // specify if this is pipe, socket, or FIFO
|
||||
pub fd_cloexec: bool,
|
||||
@ -50,8 +73,7 @@ impl FileHandle {
|
||||
) -> Self {
|
||||
return FileHandle {
|
||||
inode,
|
||||
offset: Arc::new(Mutex::new(0)),
|
||||
options: Arc::new(Mutex::new(options)),
|
||||
description: OpenFileDescription::create(options),
|
||||
path,
|
||||
pipe,
|
||||
fd_cloexec,
|
||||
@ -62,27 +84,31 @@ impl FileHandle {
|
||||
pub fn dup(&self, fd_cloexec: bool) -> Self {
|
||||
FileHandle {
|
||||
inode: self.inode.clone(),
|
||||
offset: self.offset.clone(),
|
||||
options: self.options.clone(),
|
||||
description: self.description.clone(),
|
||||
path: self.path.clone(),
|
||||
pipe: self.pipe,
|
||||
fd_cloexec, // this field do not share
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_options(&self, arg: usize) {
|
||||
if arg & 0x800 > 0 {
|
||||
self.description.write().options.nonblock = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
// let mut offset_inner = self.offset.lock();
|
||||
let offset = *self.offset.lock() as usize;
|
||||
let len = self.read_at(offset, buf)?;
|
||||
*self.offset.lock() += len as u64;
|
||||
let len = self.read_at(self.description.read().offset as usize, buf)?;
|
||||
self.description.write().offset += len as u64;
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
pub fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
if !self.options.lock().read {
|
||||
pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let options = &self.description.read().options;
|
||||
if !options.read {
|
||||
return Err(FsError::InvalidParam); // FIXME: => EBADF
|
||||
}
|
||||
if !self.options.lock().nonblock {
|
||||
if !options.nonblock {
|
||||
// block
|
||||
loop {
|
||||
match self.inode.read_at(offset, buf) {
|
||||
@ -104,17 +130,19 @@ impl FileHandle {
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||
let offset = match self.options.lock().append {
|
||||
let description = self.description.read();
|
||||
let offset = match description.options.append {
|
||||
true => self.inode.metadata()?.size as u64,
|
||||
false => *self.offset.lock(),
|
||||
false => description.offset
|
||||
} as usize;
|
||||
drop(description);
|
||||
let len = self.write_at(offset, buf)?;
|
||||
*self.offset.lock() += len as u64;
|
||||
self.description.write().offset += len as u64;
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
pub fn write_at(&mut self, offset: usize, buf: &[u8]) -> Result<usize> {
|
||||
if !self.options.lock().write {
|
||||
pub fn write_at(&self, offset: usize, buf: &[u8]) -> Result<usize> {
|
||||
if !self.description.read().options.write {
|
||||
return Err(FsError::InvalidParam); // FIXME: => EBADF
|
||||
}
|
||||
let len = self.inode.write_at(offset, buf)?;
|
||||
@ -123,17 +151,17 @@ impl FileHandle {
|
||||
}
|
||||
|
||||
pub fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
|
||||
let mut offset_inner = self.offset.lock();
|
||||
*offset_inner = match pos {
|
||||
let mut description = self.description.write();
|
||||
description.offset = match pos {
|
||||
SeekFrom::Start(offset) => offset,
|
||||
SeekFrom::End(offset) => (self.inode.metadata()?.size as i64 + offset) as u64,
|
||||
SeekFrom::Current(offset) => (*offset_inner as i64 + offset) as u64,
|
||||
SeekFrom::Current(offset) => (description.offset as i64 + offset) as u64,
|
||||
};
|
||||
Ok(*offset_inner)
|
||||
Ok(description.offset)
|
||||
}
|
||||
|
||||
pub fn set_len(&mut self, len: u64) -> Result<()> {
|
||||
if !self.options.lock().write {
|
||||
if !self.description.read().options.write {
|
||||
return Err(FsError::InvalidParam); // FIXME: => EBADF
|
||||
}
|
||||
self.inode.resize(len as usize)?;
|
||||
@ -157,22 +185,24 @@ impl FileHandle {
|
||||
}
|
||||
|
||||
pub fn read_entry(&mut self) -> Result<String> {
|
||||
if !self.options.lock().read {
|
||||
let mut description = self.description.write();
|
||||
if !description.options.read {
|
||||
return Err(FsError::InvalidParam); // FIXME: => EBADF
|
||||
}
|
||||
let mut offset_inner = self.offset.lock();
|
||||
let name = self.inode.get_entry(*offset_inner as usize)?;
|
||||
*offset_inner += 1;
|
||||
let mut offset = &mut description.offset;
|
||||
let name = self.inode.get_entry(*offset as usize)?;
|
||||
*offset += 1;
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
pub fn read_entry_with_metadata(&mut self) -> Result<(Metadata, String)> {
|
||||
if !self.options.lock().read {
|
||||
let mut description = self.description.write();
|
||||
if !description.options.read {
|
||||
return Err(FsError::InvalidParam); // FIXME: => EBADF
|
||||
}
|
||||
let mut offset_inner = self.offset.lock();
|
||||
let ret = self.inode.get_entry_with_metadata(*offset_inner as usize)?;
|
||||
*offset_inner += 1;
|
||||
let mut offset = &mut description.offset;
|
||||
let ret = self.inode.get_entry_with_metadata(*offset as usize)?;
|
||||
*offset += 1;
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
@ -217,10 +247,11 @@ impl FileHandle {
|
||||
|
||||
impl fmt::Debug for FileHandle {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let description = self.description.read();
|
||||
return f
|
||||
.debug_struct("FileHandle")
|
||||
.field("offset", &self.offset)
|
||||
.field("options", &self.options)
|
||||
.field("offset", &description.offset)
|
||||
.field("options", &description.options)
|
||||
.field("path", &self.path)
|
||||
.finish();
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ use rcore_fs_devfs::{
|
||||
};
|
||||
use rcore_fs_mountfs::MountFS;
|
||||
use rcore_fs_ramfs::RamFS;
|
||||
use rcore_fs_sfs::{SimpleFileSystem, INodeImpl};
|
||||
use rcore_fs_sfs::{INodeImpl, SimpleFileSystem};
|
||||
|
||||
use self::devfs::{Fbdev, RandomINode};
|
||||
|
||||
pub use self::devfs::{TtyINode, STDIN, STDOUT, ShmINode};
|
||||
pub use self::devfs::{ShmINode, TtyINode, STDIN, STDOUT};
|
||||
pub use self::file::*;
|
||||
pub use self::file_like::*;
|
||||
pub use self::pipe::Pipe;
|
||||
@ -121,7 +121,6 @@ pub trait INodeExt {
|
||||
|
||||
impl INodeExt for dyn INode {
|
||||
fn read_as_vec(&self) -> Result<Vec<u8>> {
|
||||
|
||||
let size = self.metadata()?.size;
|
||||
let mut buf = Vec::with_capacity(size);
|
||||
unsafe {
|
||||
|
@ -7,12 +7,12 @@ use rcore_fs::vfs::*;
|
||||
|
||||
use crate::sync::Condvar;
|
||||
use crate::sync::SpinNoIrqLock as Mutex;
|
||||
use crate::syscall::SysError::EAGAIN;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeSet;
|
||||
use core::cmp::min;
|
||||
use rcore_fs::vfs::FsError::Again;
|
||||
use rcore_thread::std_thread::{park, yield_now};
|
||||
use alloc::collections::BTreeSet;
|
||||
use crate::syscall::SysError::EAGAIN;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PipeEnd {
|
||||
|
@ -79,9 +79,7 @@ impl Condvar {
|
||||
} else {
|
||||
for condvar in condvars {
|
||||
let mut queue = condvar.wait_queue.lock();
|
||||
if queue.iter().find(|&t| {
|
||||
Arc::ptr_eq(t, &token)
|
||||
}).is_none() {
|
||||
if queue.iter().find(|&t| Arc::ptr_eq(t, &token)).is_none() {
|
||||
queue.push_front(token.clone());
|
||||
}
|
||||
}
|
||||
|
@ -770,7 +770,6 @@ impl Syscall<'_> {
|
||||
let mut proc = self.process();
|
||||
// let file_like = proc.get_file_like(fd)?;
|
||||
let file = proc.get_file(fd)?;
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
@ -1268,9 +1267,7 @@ impl Syscall<'_> {
|
||||
}
|
||||
F_GETFD => Ok(file.fd_cloexec as usize),
|
||||
F_SETFL => {
|
||||
if arg & 0x800 > 0 {
|
||||
file.options.lock().nonblock = true;
|
||||
}
|
||||
file.set_options(arg);
|
||||
Ok(0)
|
||||
}
|
||||
F_DUPFD_CLOEXEC => {
|
||||
@ -1841,8 +1838,6 @@ impl IoVecs {
|
||||
if readv {
|
||||
vm.check_write_array(iov.base, iov.len)?;
|
||||
} else {
|
||||
|
||||
|
||||
vm.check_read_array(iov.base, iov.len)?;
|
||||
}
|
||||
slices.push(slice::from_raw_parts_mut(iov.base, iov.len));
|
||||
|
@ -62,7 +62,13 @@ impl Syscall<'_> {
|
||||
}
|
||||
|
||||
pub fn sys_tkill(&mut self, tgid: i32, tid: i32, sig: i32) -> SysResult {
|
||||
info!("tkill: [{}] tgid: {}, tid: {}, sig: {}", thread::current().id(), tgid, tid, sig);
|
||||
info!(
|
||||
"tkill: [{}] tgid: {}, tid: {}, sig: {}",
|
||||
thread::current().id(),
|
||||
tgid,
|
||||
tid,
|
||||
sig
|
||||
);
|
||||
self.unimplemented("tkill", Ok(0))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user