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