369d6dc4de
There is currently no way to open(O_RDONLY) and mmap(PROT_READ) when creating a memory region from a file. This functionality is needed since the underlying host file may not allow writing. Add a bool readonly argument to memory_region_init_ram_from_file() and the APIs it calls. Extend memory_region_init_ram_from_file() rather than introducing a memory_region_init_rom_from_file() API so that callers can easily make a choice between read/write and read-only at runtime without calling different APIs. No new RAMBlock flag is introduced for read-only because it's unclear whether RAMBlocks need to know that they are read-only. Pass a bool readonly argument instead. Both of these design decisions can be changed in the future. It just seemed like the simplest approach to me. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Liam Merwick <liam.merwick@oracle.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20210104171320.575838-2-stefanha@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
35 lines
967 B
C
35 lines
967 B
C
#ifndef QEMU_MMAP_ALLOC_H
|
|
#define QEMU_MMAP_ALLOC_H
|
|
|
|
|
|
size_t qemu_fd_getpagesize(int fd);
|
|
|
|
size_t qemu_mempath_getpagesize(const char *mem_path);
|
|
|
|
/**
|
|
* qemu_ram_mmap: mmap the specified file or device.
|
|
*
|
|
* Parameters:
|
|
* @fd: the file or the device to mmap
|
|
* @size: the number of bytes to be mmaped
|
|
* @align: if not zero, specify the alignment of the starting mapping address;
|
|
* otherwise, the alignment in use will be determined by QEMU.
|
|
* @readonly: true for a read-only mapping, false for read/write.
|
|
* @shared: map has RAM_SHARED flag.
|
|
* @is_pmem: map has RAM_PMEM flag.
|
|
*
|
|
* Return:
|
|
* On success, return a pointer to the mapped area.
|
|
* On failure, return MAP_FAILED.
|
|
*/
|
|
void *qemu_ram_mmap(int fd,
|
|
size_t size,
|
|
size_t align,
|
|
bool readonly,
|
|
bool shared,
|
|
bool is_pmem);
|
|
|
|
void qemu_ram_munmap(int fd, void *ptr, size_t size);
|
|
|
|
#endif
|