asterinas/kernel/src/syscall/brk.rs

26 lines
781 B
Rust
Raw Normal View History

2024-01-03 03:22:36 +00:00
// SPDX-License-Identifier: MPL-2.0
use crate::{prelude::*, syscall::SyscallReturn};
2022-09-16 03:14:46 +00:00
/// expand the user heap to new heap end, returns the new heap end if expansion succeeds.
pub fn sys_brk(heap_end: u64, ctx: &Context) -> Result<SyscallReturn> {
2022-09-16 03:14:46 +00:00
let new_heap_end = if heap_end == 0 {
None
} else {
Some(heap_end as usize)
};
2022-11-09 07:14:12 +00:00
debug!("new heap end = {:x?}", heap_end);
2026-01-12 03:21:40 +00:00
2025-10-24 14:56:19 +00:00
let user_space = ctx.user_space();
let user_heap = user_space.vmar().process_vm().heap();
2022-09-16 03:14:46 +00:00
2026-01-12 03:21:40 +00:00
let current_heap_end = match new_heap_end {
2025-12-11 09:29:27 +00:00
Some(addr) => user_heap
2026-01-12 03:21:40 +00:00
.modify_heap_end(addr, ctx)
.unwrap_or_else(|cur_heap_end| cur_heap_end),
None => user_heap.heap_end(),
2025-12-11 09:29:27 +00:00
};
2026-01-12 03:21:40 +00:00
Ok(SyscallReturn::Return(current_heap_end as _))
2022-09-16 03:14:46 +00:00
}