MOS Source Code
Loading...
Searching...
No Matches
mmap.c File Reference
#include "mos/io/io.h"
#include "mos/mm/mm.h"
#include "mos/mm/paging/table_ops.h"
#include "mos/platform/platform.h"
#include "mos/syslog/printk.h"
#include <mos/mm/cow.h>
#include <mos/mm/mm_types.h>
#include <mos/mm/mmap.h>
#include <mos/mm/paging/paging.h>
#include <mos/mos_global.h>
#include <mos/tasks/process.h>
#include <mos/tasks/task_types.h>
+ Include dependency graph for mmap.c:

Go to the source code of this file.

Functions

static bool mmap_verify_arguments (ptr_t *hint_addr, mmap_flags_t mmap_flags)
 Check if the mmap flags are valid.
 
ptr_t mmap_anonymous (mm_context_t *ctx, ptr_t hint_addr, mmap_flags_t flags, vm_flags vm_flags, size_t n_pages)
 Map a page into the current process's address space.
 
ptr_t mmap_file (mm_context_t *ctx, ptr_t hint_addr, mmap_flags_t flags, vm_flags vm_flags, size_t n_pages, io_t *io, off_t offset)
 Map a file into the current process's address space.
 
bool munmap (ptr_t addr, size_t size)
 Unmap a page from the current process's address space.
 
bool vm_protect (mm_context_t *mmctx, ptr_t addr, size_t size, vm_flags perm)
 Change the permissions of a mapping.
 

Function Documentation

◆ mmap_verify_arguments()

static bool mmap_verify_arguments ( ptr_t * hint_addr,
mmap_flags_t mmap_flags )
static

Check if the mmap flags are valid.

Parameters
hint_addrThe hint address
mmap_flagsThe mmap flags

Definition at line 23 of file mmap.c.

Referenced by mmap_anonymous(), and mmap_file().

◆ mmap_anonymous()

ptr_t mmap_anonymous ( mm_context_t * ctx,
ptr_t hint_addr,
mmap_flags_t flags,
vm_flags vm_flags,
size_t n_pages )

Map a page into the current process's address space.

Parameters
ctxThe memory management context
hint_addrA hint for the address to map the page at, the actual address is determined based on the flags
flagsFlags to control the mapping, see mmap_flags_t
vm_flagsFlags to control the permissions of the mapping, see vm_flags
n_pagesNumber of pages to map
Returns
ptr_t The address the page was mapped at, or 0 if the mapping failed

Definition at line 54 of file mmap.c.

+ Here is the call graph for this function:

◆ mmap_file()

ptr_t mmap_file ( mm_context_t * ctx,
ptr_t hint_addr,
mmap_flags_t flags,
vm_flags vm_flags,
size_t n_pages,
io_t * io,
off_t offset )

Map a file into the current process's address space.

Parameters
ctxThe memory management context
hint_addrA hint for the address to map the page at, the actual address is determined based on the flags
flagsFlags to control the mapping, see mmap_flags_t
vm_flagsFlags to control the permissions of the mapping, see vm_flags
n_pagesNumber of pages to map
ioThe io object to map, the io object must be backed by a file_t
offsetThe offset into the file to map, must be page aligned
Returns
ptr_t The address the page was mapped at, or 0 if the mapping failed

Definition at line 73 of file mmap.c.

Referenced by elf_map_segment().

+ Here is the call graph for this function:

◆ munmap()

bool munmap ( ptr_t addr,
size_t size )

Unmap a page from the current process's address space.

Parameters
addrThe address to unmap
sizeThe size of the mapping to unmap
Returns
true If the unmap succeeded
Note
Neither addr nor size need to be page aligned, all pages contained within the range specified will be unmapped even if they are not fully contained within the range.

Definition at line 111 of file mmap.c.

+ Here is the call graph for this function:

◆ vm_protect()

bool vm_protect ( mm_context_t * mmctx,
ptr_t addr,
size_t size,
vm_flags perm )

Change the permissions of a mapping.

Parameters
mmctxThe memory management context
addrThe address of the mapping to change
sizeThe size of the mapping to change
permThe new permissions for the mapping

Definition at line 144 of file mmap.c.

+ Here is the call graph for this function: