mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-18 08:49:29 -04:00
Don't call data() on read-only mapped_file
This commit is contained in:
parent
267108e015
commit
7c98ecefd7
@ -54,12 +54,14 @@ std::error_code
|
|||||||
mmap::lock(file_off_t offset [[maybe_unused]], size_t size [[maybe_unused]]) {
|
mmap::lock(file_off_t offset [[maybe_unused]], size_t size [[maybe_unused]]) {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
||||||
|
auto data = mf_.const_data() + offset;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (::VirtualLock(mf_.data() + offset, size) == 0) {
|
if (::VirtualLock(const_cast<char*>(data), size) == 0) {
|
||||||
ec.assign(::GetLastError(), std::system_category());
|
ec.assign(::GetLastError(), std::system_category());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (::mlock(mf_.const_data() + offset, size) != 0) {
|
if (::mlock(data, size) != 0) {
|
||||||
ec.assign(errno, std::generic_category());
|
ec.assign(errno, std::generic_category());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -77,12 +79,14 @@ std::error_code mmap::release(file_off_t offset [[maybe_unused]],
|
|||||||
size += misalign;
|
size += misalign;
|
||||||
size -= size % page_size_;
|
size -= size % page_size_;
|
||||||
|
|
||||||
|
auto data = const_cast<char*>(mf_.const_data() + offset);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (::VirtualFree(mf_.data() + offset, size, MEM_DECOMMIT) == 0) {
|
if (::VirtualFree(data, size, MEM_DECOMMIT) == 0) {
|
||||||
ec.assign(::GetLastError(), std::system_category());
|
ec.assign(::GetLastError(), std::system_category());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (::madvise(mf_.data() + offset, size, MADV_DONTNEED) != 0) {
|
if (::madvise(data, size, MADV_DONTNEED) != 0) {
|
||||||
ec.assign(errno, std::generic_category());
|
ec.assign(errno, std::generic_category());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -95,12 +99,14 @@ std::error_code mmap::release_until(file_off_t offset [[maybe_unused]]) {
|
|||||||
|
|
||||||
offset -= offset % page_size_;
|
offset -= offset % page_size_;
|
||||||
|
|
||||||
|
auto data = const_cast<char*>(mf_.const_data());
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (::VirtualFree(mf_.data(), offset, MEM_DECOMMIT) == 0) {
|
if (::VirtualFree(data, offset, MEM_DECOMMIT) == 0) {
|
||||||
ec.assign(::GetLastError(), std::system_category());
|
ec.assign(::GetLastError(), std::system_category());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (::madvise(mf_.data(), offset, MADV_DONTNEED) != 0) {
|
if (::madvise(data, offset, MADV_DONTNEED) != 0) {
|
||||||
ec.assign(errno, std::generic_category());
|
ec.assign(errno, std::generic_category());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user