diff --git a/src/file_reader.cpp b/src/file_reader.cpp index 7a1d06b0..0ca1caa2 100644 --- a/src/file_reader.cpp +++ b/src/file_reader.cpp @@ -146,11 +146,13 @@ mmapReadOnly(int fd, offset_type offset, size_type size) #endif const auto p = (char*)mmap(NULL, size, PROT_READ, MAP_FLAGS, fd, offset); - if (p == MAP_FAILED) - throw std::runtime_error(Formatter() - << "Cannot mmap size " << size << " at off " - << offset << " : " << strerror(errno)); - + if (p == MAP_FAILED) { + // mmap may fails for a lot of reason. + // Most of them (io error, too big size...) may not recoverable but some of + // them may be relative to mmap only and a "simple" read from the file would work. + // Let's throw a MMapException to fallback to read (and potentially fail again there). + throw MMapException(); + } return p; }