qemu/include/qemu/mmap-alloc.h
<<
>>
Prefs
   1#ifndef QEMU_MMAP_ALLOC_H
   2#define QEMU_MMAP_ALLOC_H
   3
   4
   5size_t qemu_fd_getpagesize(int fd);
   6
   7/**
   8 * qemu_ram_mmap: mmap anonymous memory, the specified file or device.
   9 *
  10 * mmap() abstraction to map guest RAM, simplifying flag handling, taking
  11 * care of alignment requirements and installing guard pages.
  12 *
  13 * Parameters:
  14 *  @fd: the file or the device to mmap
  15 *  @size: the number of bytes to be mmaped
  16 *  @align: if not zero, specify the alignment of the starting mapping address;
  17 *          otherwise, the alignment in use will be determined by QEMU.
  18 *  @qemu_map_flags: QEMU_MAP_* flags
  19 *  @map_offset: map starts at offset of map_offset from the start of fd
  20 *
  21 * Internally, MAP_PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set
  22 * implicitly based on other parameters.
  23 *
  24 * Return:
  25 *  On success, return a pointer to the mapped area.
  26 *  On failure, return MAP_FAILED.
  27 */
  28void *qemu_ram_mmap(int fd,
  29                    size_t size,
  30                    size_t align,
  31                    uint32_t qemu_map_flags,
  32                    off_t map_offset);
  33
  34void qemu_ram_munmap(int fd, void *ptr, size_t size);
  35
  36/*
  37 * Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example,
  38 * consumed by qemu_ram_mmap().
  39 */
  40
  41/* Map PROT_READ instead of PROT_READ | PROT_WRITE. */
  42#define QEMU_MAP_READONLY   (1 << 0)
  43
  44/* Use MAP_SHARED instead of MAP_PRIVATE. */
  45#define QEMU_MAP_SHARED     (1 << 1)
  46
  47/*
  48 * Use MAP_SYNC | MAP_SHARED_VALIDATE if supported. Ignored without
  49 * QEMU_MAP_SHARED. If mapping fails, warn and fallback to !QEMU_MAP_SYNC.
  50 */
  51#define QEMU_MAP_SYNC       (1 << 2)
  52
  53/*
  54 * Use MAP_NORESERVE to skip reservation of swap space (or huge pages if
  55 * applicable). Bail out if not supported/effective.
  56 */
  57#define QEMU_MAP_NORESERVE  (1 << 3)
  58
  59#endif
  60