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]
name = "xous"
version = "0.8.3"
version = "0.9.7"
authors = ["Sean Cross <sean@xobs.io>"]
edition = "2018"
license = "MIT OR Apache-2.0"

View file

@ -1,7 +1,7 @@
use crate::{
pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage,
MemoryRange, MemorySize, MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs,
ProcessInit, Result, ScalarMessage, SysCallResult, ThreadInit, CID, PID, SID, TID,
pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage, MemoryRange,
MemorySize, MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs, ProcessInit,
Result, ScalarMessage, SysCallResult, ThreadInit, CID, PID, SID, TID,
};
use core::convert::{TryFrom, TryInto};
/* 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
/// legal to modify memory flags anymore.
UpdateMemoryFlags(
MemoryAddress, /* virt */
MemorySize, /* number of bytes */
MemoryFlags, /* new flags */
Option<PID>, /* if present, indicates the process to modify */
MemoryRange, /* range of memory to update flags for */
MemoryFlags, /* new flags */
Option<PID>, /* if present, indicates the process to modify */
),
/// Pauses execution of the current thread and returns execution to the parent
@ -658,10 +657,10 @@ impl SysCall {
],
SysCall::UpdateMemoryFlags(a1, a2, a3) => [
SysCallNumber::UpdateMemoryFlags as usize,
a1.get(),
*a2 as usize,
crate::get_bits(a3),
0,
a1.as_mut_ptr() as usize,
a1.len(),
crate::get_bits(a2),
a3.map(|m| m.get() as usize).unwrap_or(0),
0,
0,
0,
@ -910,9 +909,9 @@ impl SysCall {
),
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize),
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?,
a2 as usize,
unsafe { MemoryRange::new(a1, a2) }?,
crate::from_bits(a3).ok_or(Error::InvalidSyscall)?,
PID::new(a4 as _),
),
SysCallNumber::SetMemRegion => SysCall::SetMemRegion(
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.
/// The `size` field must be page-aligned.
pub fn return_memory(sender: MessageSender, mem: MemoryRange) -> core::result::Result<(), Error> {