mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 16:33:24 +00:00
Rename get_current_userspace
to current_userspace
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
96de617ad9
commit
39d303c72f
@ -41,7 +41,7 @@ pub struct CurrentUserSpace<'a>(&'a VmSpace);
|
|||||||
/// This is slower than [`Context::user_space`]. Don't use this getter
|
/// This is slower than [`Context::user_space`]. Don't use this getter
|
||||||
/// If you get the access to the [`Context`].
|
/// If you get the access to the [`Context`].
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! get_current_userspace {
|
macro_rules! current_userspace {
|
||||||
() => {
|
() => {
|
||||||
CurrentUserSpace::new(&ostd::task::Task::current().unwrap())
|
CurrentUserSpace::new(&ostd::task::Task::current().unwrap())
|
||||||
};
|
};
|
||||||
@ -55,7 +55,7 @@ impl<'a> CurrentUserSpace<'a> {
|
|||||||
///
|
///
|
||||||
/// If you have access to a [`Context`], it is preferable to call [`Context::user_space`].
|
/// If you have access to a [`Context`], it is preferable to call [`Context::user_space`].
|
||||||
///
|
///
|
||||||
/// Otherwise, you can use the `get_current_userspace` macro
|
/// Otherwise, you can use the `current_userspace` macro
|
||||||
/// to obtain an instance of `CurrentUserSpace` if it will only be used once.
|
/// to obtain an instance of `CurrentUserSpace` if it will only be used once.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use alloc::format;
|
use alloc::format;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
current_userspace,
|
||||||
device::tty::{line_discipline::LineDiscipline, new_job_control_and_ldisc},
|
device::tty::{line_discipline::LineDiscipline, new_job_control_and_ldisc},
|
||||||
events::IoEvents,
|
events::IoEvents,
|
||||||
fs::{
|
fs::{
|
||||||
@ -13,7 +14,6 @@ use crate::{
|
|||||||
inode_handle::FileIo,
|
inode_handle::FileIo,
|
||||||
utils::{AccessMode, Inode, InodeMode, IoctlCmd},
|
utils::{AccessMode, Inode, InodeMode, IoctlCmd},
|
||||||
},
|
},
|
||||||
get_current_userspace,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::{
|
process::{
|
||||||
signal::{PollHandle, Pollable, Pollee},
|
signal::{PollHandle, Pollable, Pollee},
|
||||||
@ -165,11 +165,11 @@ impl FileIo for PtyMaster {
|
|||||||
match cmd {
|
match cmd {
|
||||||
IoctlCmd::TCGETS => {
|
IoctlCmd::TCGETS => {
|
||||||
let termios = self.output.termios();
|
let termios = self.output.termios();
|
||||||
get_current_userspace!().write_val(arg, &termios)?;
|
current_userspace!().write_val(arg, &termios)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TCSETS => {
|
IoctlCmd::TCSETS => {
|
||||||
let termios = get_current_userspace!().read_val(arg)?;
|
let termios = current_userspace!().read_val(arg)?;
|
||||||
self.output.set_termios(termios);
|
self.output.set_termios(termios);
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ impl FileIo for PtyMaster {
|
|||||||
}
|
}
|
||||||
IoctlCmd::TIOCGPTN => {
|
IoctlCmd::TIOCGPTN => {
|
||||||
let idx = self.index();
|
let idx = self.index();
|
||||||
get_current_userspace!().write_val(arg, &idx)?;
|
current_userspace!().write_val(arg, &idx)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCGPTPEER => {
|
IoctlCmd::TIOCGPTPEER => {
|
||||||
@ -212,11 +212,11 @@ impl FileIo for PtyMaster {
|
|||||||
}
|
}
|
||||||
IoctlCmd::TIOCGWINSZ => {
|
IoctlCmd::TIOCGWINSZ => {
|
||||||
let winsize = self.output.window_size();
|
let winsize = self.output.window_size();
|
||||||
get_current_userspace!().write_val(arg, &winsize)?;
|
current_userspace!().write_val(arg, &winsize)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCSWINSZ => {
|
IoctlCmd::TIOCSWINSZ => {
|
||||||
let winsize = get_current_userspace!().read_val(arg)?;
|
let winsize = current_userspace!().read_val(arg)?;
|
||||||
self.output.set_window_size(winsize);
|
self.output.set_window_size(winsize);
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
@ -228,12 +228,12 @@ impl FileIo for PtyMaster {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
let fg_pgid = foreground.pgid();
|
let fg_pgid = foreground.pgid();
|
||||||
get_current_userspace!().write_val(arg, &fg_pgid)?;
|
current_userspace!().write_val(arg, &fg_pgid)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCSPGRP => {
|
IoctlCmd::TIOCSPGRP => {
|
||||||
let pgid = {
|
let pgid = {
|
||||||
let pgid: i32 = get_current_userspace!().read_val(arg)?;
|
let pgid: i32 = current_userspace!().read_val(arg)?;
|
||||||
if pgid < 0 {
|
if pgid < 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ impl FileIo for PtyMaster {
|
|||||||
}
|
}
|
||||||
IoctlCmd::FIONREAD => {
|
IoctlCmd::FIONREAD => {
|
||||||
let len = self.input.lock().len() as i32;
|
let len = self.input.lock().len() as i32;
|
||||||
get_current_userspace!().write_val(arg, &len)?;
|
current_userspace!().write_val(arg, &len)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
_ => Ok(0),
|
_ => Ok(0),
|
||||||
@ -376,12 +376,12 @@ impl FileIo for PtySlave {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let fg_pgid = foreground.pgid();
|
let fg_pgid = foreground.pgid();
|
||||||
get_current_userspace!().write_val(arg, &fg_pgid)?;
|
current_userspace!().write_val(arg, &fg_pgid)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCSPGRP => {
|
IoctlCmd::TIOCSPGRP => {
|
||||||
let pgid = {
|
let pgid = {
|
||||||
let pgid: i32 = get_current_userspace!().read_val(arg)?;
|
let pgid: i32 = current_userspace!().read_val(arg)?;
|
||||||
if pgid < 0 {
|
if pgid < 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ impl FileIo for PtySlave {
|
|||||||
}
|
}
|
||||||
IoctlCmd::FIONREAD => {
|
IoctlCmd::FIONREAD => {
|
||||||
let buffer_len = self.master().slave_buf_len() as i32;
|
let buffer_len = self.master().slave_buf_len() as i32;
|
||||||
get_current_userspace!().write_val(arg, &buffer_len)?;
|
current_userspace!().write_val(arg, &buffer_len)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
_ => Ok(0),
|
_ => Ok(0),
|
||||||
|
@ -7,13 +7,13 @@ use spin::Once;
|
|||||||
|
|
||||||
use self::{driver::TtyDriver, line_discipline::LineDiscipline};
|
use self::{driver::TtyDriver, line_discipline::LineDiscipline};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
current_userspace,
|
||||||
events::IoEvents,
|
events::IoEvents,
|
||||||
fs::{
|
fs::{
|
||||||
device::{Device, DeviceId, DeviceType},
|
device::{Device, DeviceId, DeviceType},
|
||||||
inode_handle::FileIo,
|
inode_handle::FileIo,
|
||||||
utils::IoctlCmd,
|
utils::IoctlCmd,
|
||||||
},
|
},
|
||||||
get_current_userspace,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::{
|
process::{
|
||||||
signal::{signals::kernel::KernelSignal, PollHandle, Pollable},
|
signal::{signals::kernel::KernelSignal, PollHandle, Pollable},
|
||||||
@ -103,7 +103,7 @@ impl FileIo for Tty {
|
|||||||
// Get terminal attributes
|
// Get terminal attributes
|
||||||
let termios = self.ldisc.termios();
|
let termios = self.ldisc.termios();
|
||||||
trace!("get termios = {:?}", termios);
|
trace!("get termios = {:?}", termios);
|
||||||
get_current_userspace!().write_val(arg, &termios)?;
|
current_userspace!().write_val(arg, &termios)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCGPGRP => {
|
IoctlCmd::TIOCGPGRP => {
|
||||||
@ -112,13 +112,13 @@ impl FileIo for Tty {
|
|||||||
};
|
};
|
||||||
let fg_pgid = foreground.pgid();
|
let fg_pgid = foreground.pgid();
|
||||||
debug!("fg_pgid = {}", fg_pgid);
|
debug!("fg_pgid = {}", fg_pgid);
|
||||||
get_current_userspace!().write_val(arg, &fg_pgid)?;
|
current_userspace!().write_val(arg, &fg_pgid)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCSPGRP => {
|
IoctlCmd::TIOCSPGRP => {
|
||||||
// Set the process group id of fg progress group
|
// Set the process group id of fg progress group
|
||||||
let pgid = {
|
let pgid = {
|
||||||
let pgid: i32 = get_current_userspace!().read_val(arg)?;
|
let pgid: i32 = current_userspace!().read_val(arg)?;
|
||||||
if pgid < 0 {
|
if pgid < 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
return_errno_with_message!(Errno::EINVAL, "negative pgid");
|
||||||
}
|
}
|
||||||
@ -133,20 +133,20 @@ impl FileIo for Tty {
|
|||||||
}
|
}
|
||||||
IoctlCmd::TCSETS => {
|
IoctlCmd::TCSETS => {
|
||||||
// Set terminal attributes
|
// Set terminal attributes
|
||||||
let termios = get_current_userspace!().read_val(arg)?;
|
let termios = current_userspace!().read_val(arg)?;
|
||||||
debug!("set termios = {:?}", termios);
|
debug!("set termios = {:?}", termios);
|
||||||
self.ldisc.set_termios(termios);
|
self.ldisc.set_termios(termios);
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TCSETSW => {
|
IoctlCmd::TCSETSW => {
|
||||||
let termios = get_current_userspace!().read_val(arg)?;
|
let termios = current_userspace!().read_val(arg)?;
|
||||||
debug!("set termios = {:?}", termios);
|
debug!("set termios = {:?}", termios);
|
||||||
self.ldisc.set_termios(termios);
|
self.ldisc.set_termios(termios);
|
||||||
// TODO: drain output buffer
|
// TODO: drain output buffer
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TCSETSF => {
|
IoctlCmd::TCSETSF => {
|
||||||
let termios = get_current_userspace!().read_val(arg)?;
|
let termios = current_userspace!().read_val(arg)?;
|
||||||
debug!("set termios = {:?}", termios);
|
debug!("set termios = {:?}", termios);
|
||||||
self.ldisc.set_termios(termios);
|
self.ldisc.set_termios(termios);
|
||||||
self.ldisc.drain_input();
|
self.ldisc.drain_input();
|
||||||
@ -155,11 +155,11 @@ impl FileIo for Tty {
|
|||||||
}
|
}
|
||||||
IoctlCmd::TIOCGWINSZ => {
|
IoctlCmd::TIOCGWINSZ => {
|
||||||
let winsize = self.ldisc.window_size();
|
let winsize = self.ldisc.window_size();
|
||||||
get_current_userspace!().write_val(arg, &winsize)?;
|
current_userspace!().write_val(arg, &winsize)?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
IoctlCmd::TIOCSWINSZ => {
|
IoctlCmd::TIOCSWINSZ => {
|
||||||
let winsize = get_current_userspace!().read_val(arg)?;
|
let winsize = current_userspace!().read_val(arg)?;
|
||||||
self.ldisc.set_window_size(winsize);
|
self.ldisc.set_window_size(winsize);
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
cpu::LinuxAbi,
|
cpu::LinuxAbi,
|
||||||
|
current_userspace,
|
||||||
fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask},
|
fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask},
|
||||||
get_current_userspace,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::posix_thread::allocate_posix_tid,
|
process::posix_thread::allocate_posix_tid,
|
||||||
thread::{AsThread, Tid},
|
thread::{AsThread, Tid},
|
||||||
@ -392,7 +392,7 @@ fn clone_parent_settid(
|
|||||||
if let Some(addr) =
|
if let Some(addr) =
|
||||||
parent_tidptr.filter(|_| clone_flags.contains(CloneFlags::CLONE_PARENT_SETTID))
|
parent_tidptr.filter(|_| clone_flags.contains(CloneFlags::CLONE_PARENT_SETTID))
|
||||||
{
|
{
|
||||||
get_current_userspace!().write_val(addr, &child_tid)?;
|
current_userspace!().write_val(addr, &child_tid)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use super::{futex::futex_wake, robust_list::wake_robust_futex, thread_table, PosixThread};
|
use super::{futex::futex_wake, robust_list::wake_robust_futex, thread_table, PosixThread};
|
||||||
use crate::{
|
use crate::{
|
||||||
get_current_userspace,
|
current_userspace,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::{do_exit_group, TermStatus},
|
process::{do_exit_group, TermStatus},
|
||||||
thread::{Thread, Tid},
|
thread::{Thread, Tid},
|
||||||
@ -25,7 +25,7 @@ pub fn do_exit(thread: &Thread, posix_thread: &PosixThread, term_status: TermSta
|
|||||||
// If clear_ctid !=0 ,do a futex wake and write zero to the clear_ctid addr.
|
// If clear_ctid !=0 ,do a futex wake and write zero to the clear_ctid addr.
|
||||||
if *clear_ctid != 0 {
|
if *clear_ctid != 0 {
|
||||||
// FIXME: the correct write length?
|
// FIXME: the correct write length?
|
||||||
if let Err(e) = get_current_userspace!().write_val(*clear_ctid, &0u32) {
|
if let Err(e) = current_userspace!().write_val(*clear_ctid, &0u32) {
|
||||||
debug!("Ignore error during exit process: {:?}", e);
|
debug!("Ignore error during exit process: {:?}", e);
|
||||||
}
|
}
|
||||||
futex_wake(*clear_ctid, 1, None)?;
|
futex_wake(*clear_ctid, 1, None)?;
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
use ostd::task::Task;
|
use ostd::task::Task;
|
||||||
|
|
||||||
use crate::{
|
use crate::{current_userspace, prelude::*, process::posix_thread::futex::futex_wake, thread::Tid};
|
||||||
get_current_userspace, prelude::*, process::posix_thread::futex::futex_wake, thread::Tid,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Pod)]
|
#[derive(Clone, Copy, Debug, Pod)]
|
||||||
@ -105,7 +103,7 @@ impl Iterator for FutexIter<'_> {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let Ok(robust_list) = get_current_userspace!().read_val::<RobustList>(self.entry_ptr)
|
let Ok(robust_list) = current_userspace!().read_val::<RobustList>(self.entry_ptr)
|
||||||
else {
|
else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ pub use sig_stack::{SigStack, SigStackFlags};
|
|||||||
|
|
||||||
use super::posix_thread::PosixThread;
|
use super::posix_thread::PosixThread;
|
||||||
use crate::{
|
use crate::{
|
||||||
get_current_userspace,
|
current_userspace,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::{do_exit_group, TermStatus},
|
process::{do_exit_group, TermStatus},
|
||||||
};
|
};
|
||||||
@ -249,7 +249,7 @@ fn use_alternate_signal_stack(posix_thread: &PosixThread) -> Option<usize> {
|
|||||||
|
|
||||||
fn write_u64_to_user_stack(rsp: u64, value: u64) -> Result<u64> {
|
fn write_u64_to_user_stack(rsp: u64, value: u64) -> Result<u64> {
|
||||||
let rsp = rsp - 8;
|
let rsp = rsp - 8;
|
||||||
get_current_userspace!().write_val(rsp as Vaddr, &value)?;
|
current_userspace!().write_val(rsp as Vaddr, &value)?;
|
||||||
Ok(rsp)
|
Ok(rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_current_userspace,
|
current_userspace,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::posix_thread::futex::{
|
process::posix_thread::futex::{
|
||||||
futex_op_and_flags_from_u32, futex_requeue, futex_wait, futex_wait_bitset, futex_wake,
|
futex_op_and_flags_from_u32, futex_requeue, futex_wait, futex_wait_bitset, futex_wake,
|
||||||
@ -46,7 +46,7 @@ pub fn sys_futex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let timeout = {
|
let timeout = {
|
||||||
let time_spec: timespec_t = get_current_userspace!().read_val(timeout_addr)?;
|
let time_spec: timespec_t = current_userspace!().read_val(timeout_addr)?;
|
||||||
Duration::try_from(time_spec)?
|
Duration::try_from(time_spec)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use ostd::{
|
|||||||
use super::{oops, Thread};
|
use super::{oops, Thread};
|
||||||
use crate::{
|
use crate::{
|
||||||
cpu::LinuxAbi,
|
cpu::LinuxAbi,
|
||||||
get_current_userspace,
|
current_userspace,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
process::{posix_thread::AsPosixThread, signal::handle_pending_signal},
|
process::{posix_thread::AsPosixThread, signal::handle_pending_signal},
|
||||||
syscall::handle_syscall,
|
syscall::handle_syscall,
|
||||||
@ -47,7 +47,7 @@ pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>)
|
|||||||
// Make sure the store operation completes before the clone call returns control to user space
|
// Make sure the store operation completes before the clone call returns control to user space
|
||||||
// in the child process.
|
// in the child process.
|
||||||
if is_userspace_vaddr(child_tid_ptr) {
|
if is_userspace_vaddr(child_tid_ptr) {
|
||||||
get_current_userspace!()
|
current_userspace!()
|
||||||
.write_val(child_tid_ptr, ¤t_posix_thread.tid())
|
.write_val(child_tid_ptr, ¤t_posix_thread.tid())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use core::cmp::min;
|
|||||||
use ostd::task::Task;
|
use ostd::task::Task;
|
||||||
|
|
||||||
use super::{ip::CSocketAddrInet, unix, vsock::CSocketAddrVm};
|
use super::{ip::CSocketAddrInet, unix, vsock::CSocketAddrVm};
|
||||||
use crate::{get_current_userspace, net::socket::SocketAddr, prelude::*};
|
use crate::{current_userspace, net::socket::SocketAddr, prelude::*};
|
||||||
|
|
||||||
/// Address family.
|
/// Address family.
|
||||||
///
|
///
|
||||||
@ -146,7 +146,7 @@ pub fn read_socket_addr_from_user(addr: Vaddr, addr_len: usize) -> Result<Socket
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut storage = Storage::new_zeroed();
|
let mut storage = Storage::new_zeroed();
|
||||||
get_current_userspace!().read_bytes(
|
current_userspace!().read_bytes(
|
||||||
addr,
|
addr,
|
||||||
&mut VmWriter::from(&mut storage.as_bytes_mut()[..addr_len]),
|
&mut VmWriter::from(&mut storage.as_bytes_mut()[..addr_len]),
|
||||||
)?;
|
)?;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_current_userspace,
|
current_userspace,
|
||||||
net::socket::{ip::stream::CongestionControl, LingerOption},
|
net::socket::{ip::stream::CongestionControl, LingerOption},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ macro_rules! impl_read_write_for_pod_type {
|
|||||||
if (max_len as usize) < core::mem::size_of::<$pod_ty>() {
|
if (max_len as usize) < core::mem::size_of::<$pod_ty>() {
|
||||||
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
||||||
}
|
}
|
||||||
crate::get_current_userspace!().read_val::<$pod_ty>(addr)
|
crate::current_userspace!().read_val::<$pod_ty>(addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ macro_rules! impl_read_write_for_pod_type {
|
|||||||
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::get_current_userspace!().write_val(addr, self)?;
|
crate::current_userspace!().write_val(addr, self)?;
|
||||||
Ok(write_len)
|
Ok(write_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ impl ReadFromUser for bool {
|
|||||||
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
||||||
}
|
}
|
||||||
|
|
||||||
let val = get_current_userspace!().read_val::<i32>(addr)?;
|
let val = current_userspace!().read_val::<i32>(addr)?;
|
||||||
|
|
||||||
Ok(val != 0)
|
Ok(val != 0)
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ impl WriteToUser for bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let val = if *self { 1i32 } else { 0i32 };
|
let val = if *self { 1i32 } else { 0i32 };
|
||||||
get_current_userspace!().write_val(addr, &val)?;
|
current_userspace!().write_val(addr, &val)?;
|
||||||
Ok(write_len)
|
Ok(write_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ impl WriteToUser for Option<Error> {
|
|||||||
Some(error) => error.error() as i32,
|
Some(error) => error.error() as i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
get_current_userspace!().write_val(addr, &val)?;
|
current_userspace!().write_val(addr, &val)?;
|
||||||
Ok(write_len)
|
Ok(write_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ impl ReadFromUser for LingerOption {
|
|||||||
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
||||||
}
|
}
|
||||||
|
|
||||||
let c_linger = get_current_userspace!().read_val::<CLinger>(addr)?;
|
let c_linger = current_userspace!().read_val::<CLinger>(addr)?;
|
||||||
|
|
||||||
Ok(LingerOption::from(c_linger))
|
Ok(LingerOption::from(c_linger))
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ impl WriteToUser for LingerOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let linger = CLinger::from(*self);
|
let linger = CLinger::from(*self);
|
||||||
get_current_userspace!().write_val(addr, &linger)?;
|
current_userspace!().write_val(addr, &linger)?;
|
||||||
Ok(write_len)
|
Ok(write_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ impl WriteToUser for LingerOption {
|
|||||||
impl ReadFromUser for CongestionControl {
|
impl ReadFromUser for CongestionControl {
|
||||||
fn read_from_user(addr: Vaddr, max_len: u32) -> Result<Self> {
|
fn read_from_user(addr: Vaddr, max_len: u32) -> Result<Self> {
|
||||||
let mut bytes = vec![0; max_len as usize];
|
let mut bytes = vec![0; max_len as usize];
|
||||||
get_current_userspace!().read_bytes(addr, &mut VmWriter::from(bytes.as_mut_slice()))?;
|
current_userspace!().read_bytes(addr, &mut VmWriter::from(bytes.as_mut_slice()))?;
|
||||||
let name = String::from_utf8(bytes).unwrap();
|
let name = String::from_utf8(bytes).unwrap();
|
||||||
CongestionControl::new(&name)
|
CongestionControl::new(&name)
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ impl WriteToUser for CongestionControl {
|
|||||||
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
return_errno_with_message!(Errno::EINVAL, "max_len is too short");
|
||||||
}
|
}
|
||||||
|
|
||||||
get_current_userspace!().write_bytes(addr, &mut VmReader::from(name))?;
|
current_userspace!().write_bytes(addr, &mut VmReader::from(name))?;
|
||||||
|
|
||||||
Ok(write_len)
|
Ok(write_len)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user