libgfortran checks mmap results against MAP_FAILED.
Fixed libgfortran's shared memory initialization to correctly detect mmap failures, preventing segfaults and misleading error messages.
The libgfortran library’s shared memory initialization now correctly checks the result of mmap against MAP_FAILED. Previously, it incorrectly compared the result to NULL, leading to unnoticed mmap failures. This could cause segfaults on first access or confusing ‘no common state’ errors, as observed in the supervisor restarting images.
In Details
The shared_memory_init function in libgfortran/caf/shmem/shared_memory.c incorrectly checked the return value of mmap for failure. POSIX systems signal mmap failure by returning MAP_FAILED (typically (void*)-1), not NULL. This commit corrects the check to MAP_FAILED, ensuring that mmap failures are detected and handled properly, preventing subsequent memory access errors.
- mmap
- Memory map. A system call that maps files or devices into memory. It's used here to establish shared memory segments for inter-process communication.
- MAP_FAILED
- A special return value from
mmapindicating that the memory mapping failed. It's typically defined as(void*)-1. - libgfortran
- The GNU Fortran runtime library, providing support for Fortran programs compiled by GCC.
- CAF
- Coarray Fortran. A Fortran language feature for parallel programming, allowing explicit parallel data structures (corays) and synchronization.