Add lock token to FileDescription, without borrow check
This commit is contained in:
+11
-9
@@ -5,13 +5,15 @@ use core::{
|
||||
num::NonZeroUsize,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
};
|
||||
use spin::RwLock;
|
||||
use syscall::{SigProcControl, Sigcontrol, UPPER_FDTBL_TAG};
|
||||
|
||||
use crate::{
|
||||
arch::{interrupt::InterruptStack, paging::PAGE_SIZE},
|
||||
common::aligned_box::AlignedBox,
|
||||
context::{self, arch, file::FileDescriptor},
|
||||
context::{
|
||||
self, arch,
|
||||
file::{FileDescriptor, LockedFileDescription},
|
||||
},
|
||||
cpu_set::{LogicalCpuId, LogicalCpuSet},
|
||||
cpu_stats,
|
||||
ipi::{ipi, IpiKind, IpiTarget},
|
||||
@@ -19,7 +21,7 @@ use crate::{
|
||||
paging::{RmmA, RmmArch},
|
||||
percpu::PercpuBlock,
|
||||
scheme::{CallerCtx, FileHandle, SchemeId},
|
||||
sync::CleanLockToken,
|
||||
sync::{CleanLockToken, RwLock, L1},
|
||||
syscall::usercopy::UserSliceRw,
|
||||
};
|
||||
|
||||
@@ -27,7 +29,6 @@ use crate::syscall::error::{Error, Result, EAGAIN, EBADF, EEXIST, EINVAL, EMFILE
|
||||
|
||||
use super::{
|
||||
empty_cr3,
|
||||
file::FileDescription,
|
||||
memory::{AddrSpaceWrapper, GrantFileRef},
|
||||
};
|
||||
|
||||
@@ -130,7 +131,7 @@ pub struct Context {
|
||||
/// The name of the context
|
||||
pub name: ArrayString<CONTEXT_NAME_CAPAC>,
|
||||
/// The open files in the scheme
|
||||
pub files: Arc<RwLock<FdTbl>>,
|
||||
pub files: Arc<spin::RwLock<FdTbl>>,
|
||||
/// All contexts except kmain will primarily live in userspace, and enter the kernel only when
|
||||
/// interrupts or syscalls occur. This flag is set for all contexts but kmain.
|
||||
pub userspace: bool,
|
||||
@@ -190,7 +191,7 @@ impl Context {
|
||||
kstack: None,
|
||||
addr_space: None,
|
||||
name: ArrayString::new(),
|
||||
files: Arc::new(RwLock::new(FdTbl::new())),
|
||||
files: Arc::new(spin::RwLock::new(FdTbl::new())),
|
||||
userspace: false,
|
||||
fmap_ret: None,
|
||||
being_sigkilled: false,
|
||||
@@ -823,11 +824,12 @@ impl FdTbl {
|
||||
&self,
|
||||
scheme_id: SchemeId,
|
||||
scheme_number: usize,
|
||||
token: &mut CleanLockToken,
|
||||
) -> Result<FileDescriptor> {
|
||||
self.iter()
|
||||
.flatten()
|
||||
.find(|&context_fd| {
|
||||
let desc = context_fd.description.read();
|
||||
let desc = context_fd.description.read(token.token());
|
||||
desc.scheme == scheme_id && desc.number == scheme_number
|
||||
})
|
||||
.cloned()
|
||||
@@ -940,7 +942,7 @@ impl FdTbl {
|
||||
}
|
||||
|
||||
pub fn bulk_add_fds(
|
||||
descriptions: Vec<Arc<RwLock<FileDescription>>>,
|
||||
descriptions: Vec<Arc<LockedFileDescription>>,
|
||||
payload: UserSliceRw,
|
||||
cloexec: bool,
|
||||
token: &mut CleanLockToken,
|
||||
@@ -973,7 +975,7 @@ pub fn bulk_add_fds(
|
||||
}
|
||||
|
||||
pub fn bulk_insert_fds(
|
||||
descriptions: Vec<Arc<RwLock<FileDescription>>>,
|
||||
descriptions: Vec<Arc<LockedFileDescription>>,
|
||||
payload: UserSliceRw,
|
||||
cloexec: bool,
|
||||
token: &mut CleanLockToken,
|
||||
|
||||
+5
-4
@@ -3,13 +3,14 @@
|
||||
use crate::{
|
||||
event,
|
||||
scheme::{self, SchemeId},
|
||||
sync::CleanLockToken,
|
||||
sync::{CleanLockToken, L1, RwLock},
|
||||
syscall::error::Result,
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
use spin::RwLock;
|
||||
use syscall::{schemev2::NewFdFlags, RwFlags, O_APPEND, O_NONBLOCK};
|
||||
|
||||
pub type LockedFileDescription = RwLock<L1, FileDescription>;
|
||||
|
||||
/// A file description
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FileDescription {
|
||||
@@ -64,7 +65,7 @@ impl InternalFlags {
|
||||
#[must_use = "File descriptors must be closed"]
|
||||
pub struct FileDescriptor {
|
||||
/// Corresponding file description
|
||||
pub description: Arc<RwLock<FileDescription>>,
|
||||
pub description: Arc<RwLock<L1, FileDescription>>,
|
||||
/// Cloexec flag
|
||||
pub cloexec: bool,
|
||||
}
|
||||
@@ -84,7 +85,7 @@ impl FileDescription {
|
||||
impl FileDescriptor {
|
||||
pub fn close(self, token: &mut CleanLockToken) -> Result<()> {
|
||||
{
|
||||
let description = self.description.read();
|
||||
let description = self.description.read(token.token());
|
||||
if description
|
||||
.internal_flags
|
||||
.contains(InternalFlags::NOTIFY_ON_NEXT_DETACH)
|
||||
|
||||
@@ -14,11 +14,10 @@ use syscall::{error::*, flag::MapFlags, GrantFlags, MunmapFlags};
|
||||
|
||||
use crate::{
|
||||
arch::paging::PAGE_SIZE,
|
||||
context::arch::setup_new_utable,
|
||||
context::{arch::setup_new_utable, file::LockedFileDescription},
|
||||
cpu_set::LogicalCpuSet,
|
||||
memory::{
|
||||
deallocate_frame, get_page_info, init_frame, the_zeroed_frame, AddRefError, Enomem, Frame,
|
||||
PageInfo, RaiiFrame, RefCount, RefKind,
|
||||
AddRefError, Enomem, Frame, PageInfo, RaiiFrame, RefCount, RefKind, deallocate_frame, get_page_info, init_frame, the_zeroed_frame
|
||||
},
|
||||
paging::{Page, PageFlags, PageMapper, RmmA, TableKind, VirtualAddress},
|
||||
percpu::PercpuBlock,
|
||||
@@ -64,7 +63,7 @@ impl UnmapResult {
|
||||
};
|
||||
|
||||
let (scheme_id, number) = {
|
||||
let desc = description.write();
|
||||
let desc = description.write(token.token());
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
|
||||
@@ -1144,7 +1143,7 @@ pub struct Grant {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GrantFileRef {
|
||||
pub description: Arc<RwLock<FileDescription>>,
|
||||
pub description: Arc<LockedFileDescription>,
|
||||
pub base_offset: usize,
|
||||
}
|
||||
|
||||
@@ -2664,7 +2663,7 @@ fn correct_inner<'l>(
|
||||
drop(addr_space_guard);
|
||||
|
||||
let (scheme_id, scheme_number) = {
|
||||
let desc = &file_ref.description.read();
|
||||
let desc = &file_ref.description.read(token.token());
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
let user_inner = scheme::get_scheme(token.token(), scheme_id)
|
||||
|
||||
Reference in New Issue
Block a user