mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
Merge remote-tracking branch 'origin/adjust-process-limit' into vault
This commit is contained in:
commit
f72f21a1f4
4 changed files with 72 additions and 2 deletions
|
|
@ -717,8 +717,9 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
||||||
MemoryRange::new(
|
MemoryRange::new(
|
||||||
start,
|
start,
|
||||||
// 0-length MemoryRanges are disallowed -- so return 4096 as the minimum in any case, even though it's a lie
|
// 0-length MemoryRanges are disallowed -- so return 4096 as the minimum in any case, even though it's a lie
|
||||||
if length == 0 { 4096 } else { length }
|
if length == 0 { 4096 } else { length },
|
||||||
).unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -920,6 +921,21 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
||||||
MemoryManager::with_mut(|mm| mm.update_memory_flags(range, flags))?;
|
MemoryManager::with_mut(|mm| mm.update_memory_flags(range, flags))?;
|
||||||
Ok(xous_kernel::Result::Ok)
|
Ok(xous_kernel::Result::Ok)
|
||||||
}
|
}
|
||||||
|
SysCall::AdjustProcessLimit(index, current, new) => match index {
|
||||||
|
1 => arch::process::Process::with_inner_mut(|p| {
|
||||||
|
if p.mem_heap_max == current {
|
||||||
|
p.mem_heap_max = new;
|
||||||
|
}
|
||||||
|
Ok(xous_kernel::Result::Scalar2(index, p.mem_heap_max))
|
||||||
|
}),
|
||||||
|
2 => arch::process::Process::with_inner_mut(|p| {
|
||||||
|
if p.mem_heap_size == current && new < p.mem_heap_max {
|
||||||
|
p.mem_heap_size = new;
|
||||||
|
}
|
||||||
|
Ok(xous_kernel::Result::Scalar2(index, p.mem_heap_size))
|
||||||
|
}),
|
||||||
|
_ => Err(xous_kernel::Error::InvalidLimit),
|
||||||
|
},
|
||||||
/* https://github.com/betrusted-io/xous-core/issues/90
|
/* https://github.com/betrusted-io/xous-core/issues/90
|
||||||
SysCall::SetExceptionHandler(pc, sp) => SystemServices::with_mut(|ss| {
|
SysCall::SetExceptionHandler(pc, sp) => SystemServices::with_mut(|ss| {
|
||||||
ss.set_exception_handler(pid, pc, sp)
|
ss.set_exception_handler(pid, pc, sp)
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ pub use memoryflags::*;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
|
|
||||||
|
pub mod limits;
|
||||||
|
pub use limits::*;
|
||||||
|
|
||||||
use crate::arch::ProcessStartup;
|
use crate::arch::ProcessStartup;
|
||||||
|
|
||||||
/// Server ID
|
/// Server ID
|
||||||
|
|
@ -194,6 +197,7 @@ pub enum Error {
|
||||||
UseBeforeInit = 24,
|
UseBeforeInit = 24,
|
||||||
DoubleFree = 25,
|
DoubleFree = 25,
|
||||||
DebugInProgress = 26,
|
DebugInProgress = 26,
|
||||||
|
InvalidLimit = 27,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
|
@ -226,6 +230,7 @@ impl Error {
|
||||||
24 => UseBeforeInit,
|
24 => UseBeforeInit,
|
||||||
25 => DoubleFree,
|
25 => DoubleFree,
|
||||||
26 => DebugInProgress,
|
26 => DebugInProgress,
|
||||||
|
27 => InvalidLimit,
|
||||||
_ => UnknownError,
|
_ => UnknownError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -258,6 +263,7 @@ impl Error {
|
||||||
UseBeforeInit => 24,
|
UseBeforeInit => 24,
|
||||||
DoubleFree => 25,
|
DoubleFree => 25,
|
||||||
DebugInProgress => 26,
|
DebugInProgress => 26,
|
||||||
|
InvalidLimit => 27,
|
||||||
UnknownError => usize::MAX,
|
UnknownError => usize::MAX,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
xous-rs/src/definitions/limits.rs
Normal file
5
xous-rs/src/definitions/limits.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#[repr(usize)]
|
||||||
|
pub enum Limits {
|
||||||
|
HeapMaximum = 1,
|
||||||
|
HeapSize = 2,
|
||||||
|
}
|
||||||
|
|
@ -427,6 +427,36 @@ pub enum SysCall {
|
||||||
usize, /* stack pointer */
|
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
|
/// This syscall does not exist. It captures all possible
|
||||||
/// arguments so detailed analysis can be performed.
|
/// arguments so detailed analysis can be performed.
|
||||||
Invalid(usize, usize, usize, usize, usize, usize, usize),
|
Invalid(usize, usize, usize, usize, usize, usize, usize),
|
||||||
|
|
@ -470,6 +500,7 @@ pub enum SysCallNumber {
|
||||||
Disconnect = 35,
|
Disconnect = 35,
|
||||||
JoinThread = 36,
|
JoinThread = 36,
|
||||||
SetExceptionHandler = 37,
|
SetExceptionHandler = 37,
|
||||||
|
AdjustProcessLimit = 38,
|
||||||
Invalid,
|
Invalid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -513,6 +544,7 @@ impl SysCallNumber {
|
||||||
35 => Disconnect,
|
35 => Disconnect,
|
||||||
36 => JoinThread,
|
36 => JoinThread,
|
||||||
37 => SetExceptionHandler,
|
37 => SetExceptionHandler,
|
||||||
|
38 => AdjustProcessLimit,
|
||||||
_ => Invalid,
|
_ => Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -867,6 +899,16 @@ impl SysCall {
|
||||||
0,
|
0,
|
||||||
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) => [
|
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [
|
||||||
SysCallNumber::Invalid as usize,
|
SysCallNumber::Invalid as usize,
|
||||||
*a1,
|
*a1,
|
||||||
|
|
@ -1030,6 +1072,7 @@ impl SysCall {
|
||||||
SysCallNumber::Disconnect => SysCall::Disconnect(a1 as _),
|
SysCallNumber::Disconnect => SysCall::Disconnect(a1 as _),
|
||||||
SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _),
|
SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _),
|
||||||
SysCallNumber::SetExceptionHandler => SysCall::SetExceptionHandler(a1 as _, a2 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),
|
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue