xous-rs: implement UpdateMemoryFlags syscall

Implement this syscall and create a wrapper function
`update_memory_flags()`.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-02-07 13:37:23 +08:00
parent 5fddf7c230
commit 80df40d8fa
2 changed files with 29 additions and 14 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "xous" name = "xous"
version = "0.8.3" version = "0.9.7"
authors = ["Sean Cross <sean@xobs.io>"] authors = ["Sean Cross <sean@xobs.io>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage, pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage, MemoryRange,
MemoryRange, MemorySize, MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs, MemorySize, MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs, ProcessInit,
ProcessInit, Result, ScalarMessage, SysCallResult, ThreadInit, CID, PID, SID, TID, Result, ScalarMessage, SysCallResult, ThreadInit, CID, PID, SID, TID,
}; };
use core::convert::{TryFrom, TryInto}; use core::convert::{TryFrom, TryInto};
/* https://github.com/betrusted-io/xous-core/issues/90 /* https://github.com/betrusted-io/xous-core/issues/90
@ -122,10 +122,9 @@ pub enum SysCall {
/// * **MemoryInUse**: The given PID has already been started, and it is not /// * **MemoryInUse**: The given PID has already been started, and it is not
/// legal to modify memory flags anymore. /// legal to modify memory flags anymore.
UpdateMemoryFlags( UpdateMemoryFlags(
MemoryAddress, /* virt */ MemoryRange, /* range of memory to update flags for */
MemorySize, /* number of bytes */ MemoryFlags, /* new flags */
MemoryFlags, /* new flags */ Option<PID>, /* if present, indicates the process to modify */
Option<PID>, /* if present, indicates the process to modify */
), ),
/// Pauses execution of the current thread and returns execution to the parent /// Pauses execution of the current thread and returns execution to the parent
@ -658,10 +657,10 @@ impl SysCall {
], ],
SysCall::UpdateMemoryFlags(a1, a2, a3) => [ SysCall::UpdateMemoryFlags(a1, a2, a3) => [
SysCallNumber::UpdateMemoryFlags as usize, SysCallNumber::UpdateMemoryFlags as usize,
a1.get(), a1.as_mut_ptr() as usize,
*a2 as usize, a1.len(),
crate::get_bits(a3), crate::get_bits(a2),
0, a3.map(|m| m.get() as usize).unwrap_or(0),
0, 0,
0, 0,
0, 0,
@ -910,9 +909,9 @@ impl SysCall {
), ),
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize), SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize),
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags( SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?, unsafe { MemoryRange::new(a1, a2) }?,
a2 as usize,
crate::from_bits(a3).ok_or(Error::InvalidSyscall)?, crate::from_bits(a3).ok_or(Error::InvalidSyscall)?,
PID::new(a4 as _),
), ),
SysCallNumber::SetMemRegion => SysCall::SetMemRegion( SysCallNumber::SetMemRegion => SysCall::SetMemRegion(
pid_from_usize(a1)?, pid_from_usize(a1)?,
@ -1160,6 +1159,22 @@ pub fn unmap_memory(range: MemoryRange) -> core::result::Result<(), Error> {
} }
} }
/// Update the permissions on the given memory range. Note that permissions may
/// only be stripped here -- they may never be added.
pub fn update_memory_flags(
range: MemoryRange,
flags: MemoryFlags,
) -> core::result::Result<Result, Error> {
let result = rsyscall(SysCall::UpdateMemoryFlags(range, flags, None))?;
if let Result::Ok = result {
Ok(Result::Ok)
} else if let Result::Error(e) = result {
Err(e)
} else {
Err(Error::InternalError)
}
}
/// Map the given physical address to the given virtual address. /// Map the given physical address to the given virtual address.
/// The `size` field must be page-aligned. /// The `size` field must be page-aligned.
pub fn return_memory(sender: MessageSender, mem: MemoryRange) -> core::result::Result<(), Error> { pub fn return_memory(sender: MessageSender, mem: MemoryRange) -> core::result::Result<(), Error> {