From f20e809d8c160f804f9b1e65ef0b7e646926c70b Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 23 Jun 2022 23:51:39 +0800 Subject: [PATCH] xous: add AdjustProcessLimit syscall This syscal will be used to adjust various process limits. Currently it only contains the ability to adjust the heap size and maximum. Signed-off-by: Sean Cross --- xous-rs/src/definitions.rs | 6 +++++ xous-rs/src/definitions/limits.rs | 5 ++++ xous-rs/src/syscall.rs | 43 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 xous-rs/src/definitions/limits.rs diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index ba751c703..9f2a84f15 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -75,6 +75,9 @@ pub use memoryflags::*; pub mod messages; pub use messages::*; +pub mod limits; +pub use limits::*; + use crate::arch::ProcessStartup; /// Server ID @@ -194,6 +197,7 @@ pub enum Error { UseBeforeInit = 24, DoubleFree = 25, DebugInProgress = 26, + InvalidLimit = 27, } impl Error { @@ -226,6 +230,7 @@ impl Error { 24 => UseBeforeInit, 25 => DoubleFree, 26 => DebugInProgress, + 27 => InvalidLimit, _ => UnknownError, } } @@ -258,6 +263,7 @@ impl Error { UseBeforeInit => 24, DoubleFree => 25, DebugInProgress => 26, + InvalidLimit => 27, UnknownError => usize::MAX, } } diff --git a/xous-rs/src/definitions/limits.rs b/xous-rs/src/definitions/limits.rs new file mode 100644 index 000000000..fad084241 --- /dev/null +++ b/xous-rs/src/definitions/limits.rs @@ -0,0 +1,5 @@ +#[repr(usize)] +pub enum Limits { + HeapMaximum = 1, + HeapSize = 2, +} \ No newline at end of file diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 6735f61e9..364d3ce00 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -427,6 +427,36 @@ pub enum SysCall { usize, /* stack pointer */ ), + /// Adjust one of the limits within this process. Note that you must pass + /// the current limit value in order to set the new limit. The current limit + /// value is always returned, so this function may need to be called twice -- + /// once in order to get the current limit, and again to set the new limit. + /// + /// ## Arguments + /// + /// * **Index**: The item to adjust. Currently the following limits + /// are supported: + /// 1: Maximum heap size + /// 2: Current heap size + /// * **Current Limit**: Pass the current limit value here. The current + /// limit must match in order for the new limit to take + /// effect. This is used to avoid a race condition if two + /// threads try to set the same limit. + /// * **Proposed Limit**: The new value that you would like to use. + /// + /// ## Returns + /// + /// Returns a Scalar2 containing `(Index, Limit)`. + /// + /// ## Errors + /// + /// * **InvalidLimit**: The specified index was not valid + AdjustProcessLimit( + usize, /* process limit index */ + usize, /* expected current limit */ + usize, /* proposed new limit */ + ), + /// This syscall does not exist. It captures all possible /// arguments so detailed analysis can be performed. Invalid(usize, usize, usize, usize, usize, usize, usize), @@ -470,6 +500,7 @@ pub enum SysCallNumber { Disconnect = 35, JoinThread = 36, SetExceptionHandler = 37, + AdjustProcessLimit = 38, Invalid, } @@ -513,6 +544,7 @@ impl SysCallNumber { 35 => Disconnect, 36 => JoinThread, 37 => SetExceptionHandler, + 38 => AdjustProcessLimit, _ => Invalid, } } @@ -867,6 +899,16 @@ impl SysCall { 0, 0, ], + SysCall::AdjustProcessLimit(index, current, new) => [ + SysCallNumber::AdjustProcessLimit as usize, + *index, + *current, + *new, + 0, + 0, + 0, + 0, + ], SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [ SysCallNumber::Invalid as usize, *a1, @@ -1030,6 +1072,7 @@ impl SysCall { SysCallNumber::Disconnect => SysCall::Disconnect(a1 as _), SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _), SysCallNumber::SetExceptionHandler => SysCall::SetExceptionHandler(a1 as _, a2 as _), + SysCallNumber::AdjustProcessLimit => SysCall::AdjustProcessLimit(a1, a2, a3), SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7), }) }