1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/platform/platform.h"
6
7#include <mos/mm/paging/paging.h>
8#include <mos/tasks/task_types.h>
9#include <mos/types.h>
10
11/**
12 * @brief Map a page into the current process's address space
13 *
14 * @param ctx The memory management context
15 * @param hint_addr A hint for the address to map the page at, the actual address is determined based on the @p flags
16 * @param flags Flags to control the mapping, see @ref mmap_flags_t
17 * @param vm_flags Flags to control the permissions of the mapping, see @ref vm_flags
18 * @param n_pages Number of pages to map
19 * @return ptr_t The address the page was mapped at, or 0 if the mapping failed
20 */
21ptr_t mmap_anonymous(mm_context_t *ctx, ptr_t hint_addr, mmap_flags_t flags, vm_flags vm_flags, size_t n_pages);
22
23/**
24 * @brief Map a file into the current process's address space
25 *
26 * @param ctx The memory management context
27 * @param hint_addr A hint for the address to map the page at, the actual address is determined based on the @p flags
28 * @param flags Flags to control the mapping, see @ref mmap_flags_t
29 * @param vm_flags Flags to control the permissions of the mapping, see @ref vm_flags
30 * @param n_pages Number of pages to map
31 * @param io The io object to map, the io object must be backed by a @ref file_t
32 * @param offset The offset into the file to map, must be page aligned
33 * @return ptr_t The address the page was mapped at, or 0 if the mapping failed
34 */
35ptr_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);
36
37/**
38 * @brief Unmap a page from the current process's address space
39 *
40 * @param addr The address to unmap
41 * @param size The size of the mapping to unmap
42 * @return true If the unmap succeeded
43 *
44 * @note Neither @p addr nor @p size need to be page aligned, all pages contained within
45 * the range specified will be unmapped even if they are not fully contained within the range.
46 */
47bool munmap(ptr_t addr, size_t size);
48
49/**
50 * @brief Change the permissions of a mapping
51 *
52 * @param mmctx The memory management context
53 * @param addr The address of the mapping to change
54 * @param size The size of the mapping to change
55 * @param perm The new permissions for the mapping
56 */
57bool vm_protect(mm_context_t *mmctx, ptr_t addr, size_t size, vm_flags perm);
58