Fix MAP_FAILED detection in pmem_mmap (#298)
mmap(2) returns MAP_FAILED ((void*)-1) on error, not NULL. The check 'if (likely(ret))' treats MAP_FAILED as truthy, so the emergency retry path is never reached and callers receive MAP_FAILED as a valid pointer. Normalize pmem_mmap() to return NULL on failure (converting MAP_FAILED to NULL in the mmap path). This confines the platform-specific error handling to one place and eliminates the need for preprocessor checks in pmem_mmap_safe() and psync_mmap_anon_emergency(). Fixes GH #226 Co-authored-by: Levi Neely <lkn@darkstar.example.net>
This commit is contained in:
parent
0f23a32793
commit
c514fa1a29
|
|
@ -6,8 +6,9 @@
|
|||
|
||||
void *pmem_mmap(size_t size) {
|
||||
#if defined(MAP_ANONYMOUS)
|
||||
return mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
void *ret = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
return (ret == MAP_FAILED) ? NULL : ret;
|
||||
#else
|
||||
return malloc(size);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue