silk.platform.linux.mapping.
Anonymous memory mappings from the Linux kernel, for programs that run without libc.
When to use#
Use Mapping.allocate in a raw Linux program, after startup reads the page size from the
AT_PAGESZ auxiliary vector entry. Other programs get memory from the Allocator effect.
Details#
This module exists only on Linux on x86_64 and aarch64, with the libc profile set to none.
Each Mapping owns its whole mapping. Dropping the mapping releases it with munmap. Errors
are Linux error numbers, such as 22 for EINVAL.
Gotchas#
A raw pointer from Mapping.pointer does not keep the mapping alive. If the program traps,
the mapping is not always released.
Import as Mapping with import silk.platform.linux.mapping { Mapping }.
Public declarations: 1.
Mapping#
pub struct MappingOne anonymous mapping from the Linux kernel that starts as zeros, and an aligned range inside
it. It exists only on Linux on x86_64 and aarch64, with the libc profile set to none.
Details#
Drop is automatic and releases the mapping. Use Mapping.release to get the error from
munmap. Errors are Linux error numbers, such as 22 for EINVAL.
Gotchas#
A raw pointer from Mapping.pointer does not keep the mapping alive. If the program traps,
the mapping is not always released.
Implementation Drop for Mapping#
impl Drop for MappingOperation drop#
fn drop(self: &mut Mapping) -> ()Implementation Mapping#
impl MappingAssociated function allocate#
pub fn allocate(length: usize, alignment: usize, pageSize: usize) -> Result<Mapping, usize>Maps zeroed memory with at least length bytes that start at an address aligned to
alignment.
Details#
pageSize must be the page size of the process, from AT_PAGESZ. The mapping is larger
than length when it needs space to align the start.
Errors#
22(EINVAL) iflength,alignment, orpageSizeis 0, ifalignmentorpageSizeis not a power of two, or if the size computation overflows.The Linux error number from
mmapif the kernel cannot make the mapping.
Method length#
pub fn length(self: &Mapping) -> usizeReturns the usable byte count that was requested. It does not include the alignment space.
Method pointer#
pub unsafe fn pointer(self: &mut Mapping) -> ?[*]mut u8Returns a pointer to the start of the aligned usable range.
Gotchas#
The pointer does not own the mapping and does not keep it alive. Keep the Mapping alive
and access at most Mapping.length bytes. The bytes are zero at first.
Associated function release#
pub fn release(value: Mapping) -> usizeReleases the whole mapping now and returns the result of munmap.
Details#
Returns 0 on success or the Linux error number. After release, drop does not try to
release the mapping again.
Category: Native platform.
Profiles: aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu-no-libc.