]> git.proxmox.com Git - mirror_qemu.git/blame - include/qemu/mmap-alloc.h
Merge tag 'pull-riscv-to-apply-20240110' of https://github.com/alistair23/qemu into...
[mirror_qemu.git] / include / qemu / mmap-alloc.h
CommitLineData
2a6a4076
MA
1#ifndef QEMU_MMAP_ALLOC_H
2#define QEMU_MMAP_ALLOC_H
794e8f30 3
fa45f8da
PX
4typedef enum {
5 QEMU_FS_TYPE_UNKNOWN = 0,
6 QEMU_FS_TYPE_TMPFS,
7 QEMU_FS_TYPE_HUGETLBFS,
8 QEMU_FS_TYPE_NUM,
9} QemuFsType;
794e8f30 10
7197fb40 11size_t qemu_fd_getpagesize(int fd);
fa45f8da 12QemuFsType qemu_fd_getfs(int fd);
7197fb40 13
2ac0f162 14/**
b444f5c0
DH
15 * qemu_ram_mmap: mmap anonymous memory, the specified file or device.
16 *
17 * mmap() abstraction to map guest RAM, simplifying flag handling, taking
18 * care of alignment requirements and installing guard pages.
2ac0f162
ZY
19 *
20 * Parameters:
21 * @fd: the file or the device to mmap
22 * @size: the number of bytes to be mmaped
23 * @align: if not zero, specify the alignment of the starting mapping address;
24 * otherwise, the alignment in use will be determined by QEMU.
b444f5c0 25 * @qemu_map_flags: QEMU_MAP_* flags
44a4ff31 26 * @map_offset: map starts at offset of map_offset from the start of fd
2ac0f162 27 *
b444f5c0
DH
28 * Internally, MAP_PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set
29 * implicitly based on other parameters.
30 *
2ac0f162
ZY
31 * Return:
32 * On success, return a pointer to the mapped area.
33 * On failure, return MAP_FAILED.
34 */
35void *qemu_ram_mmap(int fd,
36 size_t size,
37 size_t align,
b444f5c0 38 uint32_t qemu_map_flags,
44a4ff31 39 off_t map_offset);
794e8f30 40
53adb9d4 41void qemu_ram_munmap(int fd, void *ptr, size_t size);
794e8f30 42
5b3e3431
PM
43/*
44 * Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example,
45 * consumed by qemu_ram_mmap().
46 */
47
48/* Map PROT_READ instead of PROT_READ | PROT_WRITE. */
49#define QEMU_MAP_READONLY (1 << 0)
50
51/* Use MAP_SHARED instead of MAP_PRIVATE. */
52#define QEMU_MAP_SHARED (1 << 1)
53
54/*
55 * Use MAP_SYNC | MAP_SHARED_VALIDATE if supported. Ignored without
56 * QEMU_MAP_SHARED. If mapping fails, warn and fallback to !QEMU_MAP_SYNC.
57 */
58#define QEMU_MAP_SYNC (1 << 2)
59
60/*
61 * Use MAP_NORESERVE to skip reservation of swap space (or huge pages if
62 * applicable). Bail out if not supported/effective.
63 */
64#define QEMU_MAP_NORESERVE (1 << 3)
65
794e8f30 66#endif