#include #include #include #include namespace hv { memory_map::memory_map(std::uint64_t size, int&& fd) noexcept : is_cow(false), size(size), fd(fd), block0(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) { if(!block0) std::terminate(); } memory_map::memory_map(std::uint64_t size, int&& fd, bool _cow) noexcept : is_cow(true), size(size), fd(fd), block0(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) { if(!block0) std::terminate(); } memory_map::memory_map(std::uint64_t size, const char* file) noexcept : memory_map(size, open(file, O_RDWR)) {} memory_map::memory_map(std::uint64_t size, const char* file, bool _cow) noexcept : memory_map(size, open(file, O_RDONLY), _cow) {} memory_map::~memory_map() { munmap(block0, size); close(fd); } const_memory_map::const_memory_map(std::uint64_t size, int&& fd) noexcept : size(size), fd(fd), block0(mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0)) {} const_memory_map::const_memory_map(std::uint64_t size, const char* file) noexcept : const_memory_map(size, open(file, O_RDONLY)) {} const_memory_map::~const_memory_map() { munmap(const_cast(block0), size); close(fd); } }