From 08958745ba055626ac10f1ed7c4a9a679bd8f038 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 23 Jun 2022 23:55:31 +0800 Subject: [PATCH] kernel: implement AdjustProcessLimit syscall Implement the syscall to adjust a process' limit. Currently this only supports adjusting the heap maximum and the heap size. In order to adjust a limit, you must first present the current limit. This can be obtained by requesting a bogus value. The current limit is returned as part of the result. Signed-off-by: Sean Cross --- kernel/src/syscall.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 925af42d0..675001e2d 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -717,8 +717,9 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR MemoryRange::new( start, // 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 } - ).unwrap() + if length == 0 { 4096 } else { length }, + ) + .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))?; 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 SysCall::SetExceptionHandler(pc, sp) => SystemServices::with_mut(|ss| { ss.set_exception_handler(pid, pc, sp)