#include "shm.h" #include #include #include #include #include namespace ipc { namespace shm { handle_t acquire(std::string const & name, std::size_t size) { if (name.empty() || size == 0) { return nullptr; } int fd = ::shm_open(name.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { return nullptr; } if (::ftruncate(fd, static_cast(size)) != 0) { ::close(fd); return nullptr; } void* mem = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ::close(fd); if (mem == MAP_FAILED) { return nullptr; } return mem; } void release(handle_t h, std::size_t size) { if (h == nullptr) { return; } ::munmap(h, size); } void* open(handle_t h) { return h; } void close(void* /*mem*/) { } } // namespace shm } // namespace ipc