⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

sys_munmap

Function sys_munmap 

Source
pub fn sys_munmap(_addr: usize, _len: usize) -> SyscallResult<()>
Expand description

Unmap a previously mapped memory region from the calling process’s address space.

Removes the virtual memory mapping starting at addr for len bytes. Any physical frames backing the region are freed (unless shared with another process via copy-on-write or explicit sharing). Both addr and len must be page-aligned.

Partial unmapping is supported: if the specified range covers only part of an existing mapping, that mapping is split and only the requested portion is removed. Accessing unmapped addresses after this call will result in a page fault.

§Arguments

  • addr - Start address of the region to unmap. Must be page-aligned (4 KiB boundary).
  • len - Number of bytes to unmap. Must be page-aligned and greater than zero. The actual unmapped range is [addr, addr + len).

§Returns

  • Ok(()) on successful unmapping.

§Errors

§Examples

use veridian_kernel::pkg::sdk::syscall_api::{sys_mmap, sys_munmap};

// Map and then unmap a 4 KiB region
let addr = sys_mmap(0, 4096, 0x1 | 0x2).expect("mmap failed");
sys_munmap(addr, 4096).expect("munmap failed");
// Accessing `addr` after this point causes a page fault