How do memory-mapped files handle I/O errors?
The Linux man page referenced by vy32 explicitly states that SIGSEGV
is generated on write failure (e.g. no disk space), but it is unclear whether read failures generate such errors (e.g. when removable media has been physically removed). Wikipedia seems to be more specific on that:
I/O errors on the underlying file (e.g. its removable drive is unplugged or optical media is ejected, disk full when writing, etc.) while accessing its mapped memory are reported to the application as the SIGSEGV/SIGBUS signals on POSIX, and the EXECUTE_IN_PAGE_ERROR structured exception on Windows. All code accessing mapped memory must be prepared to handle these errors, which don't normally occur when accessing memory.
POSIX specification of mmap
does not require that the signal is delivered on error but leaves such possibility for implementations:
An implementation may generate SIGBUS signals when a reference would cause an error in the mapped object, such as out-of-space condition.