std/sys/mman

The std/sys/mman module provides a Zen-C interface for memory mapping and protection functions, wrapping POSIX sys/mman.h.

Overview

Usage

import "std/sys/mman.zc"
import "std/io.zc"

fn main() {
    let size: usize = 4096;
    let prot = Z_PROT_READ | Z_PROT_WRITE;
    let flags = Z_MAP_PRIVATE | Z_MAP_ANONYMOUS;
    
    let addr = Memory::mmap(size, prot, flags);
    if ((isize)addr == Z_MAP_FAILED) {
        println("Mapping failed");
        return 0;
    }
    
    // Use memory...
    
    Memory::munmap(addr, size);
}

Struct Definition

struct Memory {}

Methods

Memory Methods

MethodSignatureDescription
mmapMemory::mmap(len: usize, prot: int, flags: int) -> void*Creates a new mapping in the virtual address space of the calling process.
munmapMemory::munmap(addr: void*, len: usize) -> boolDeletes the mappings for the specified address range. Returns true on success.
mprotectMemory::mprotect(addr: void*, len: usize, prot: int) -> boolChanges the access protections for the calling process's memory pages. Returns true on success.

Constants

Protection Flags

Visibility Flags

Error Values