-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Describe the bug, including details regarding any error messages, version, and platform.
Problem
The __map_mman_error() function in cpp/src/arrow/io/mman.h does not properly map Windows error codes to POSIX errno values. The function currently has a TODO comment and returns raw Windows error codes (DWORD values like 2, 5, 6, etc.) instead of POSIX errno values (like ENOENT, EACCES, EBADF, etc.).
Repro
The function is called internally by Windows memory mapping operations (mmap, munmap, mprotect, msync, mlock, munlock) when Windows API calls fail. The current implementation:
// In cpp/src/arrow/io/mman.h, line 42-46 (before fix)
static inline int __map_mman_error(const DWORD err, const int deferr) {
if (err == 0) return 0;
// TODO: implement
return err; // Returns raw Windows error code (e.g., 2, 5, 6, 112)
}
When memory mapping operations fail on Windows, GetLastError() returns Windows error codes (e.g., ERROR_FILE_NOT_FOUND = 2, ERROR_ACCESS_DENIED = 5, ERROR_NOT_ENOUGH_MEMORY = 8). These values are then assigned to errno, which should contain POSIX errno values.
Output
This breaks errno-based error handling because:
-
Windows error codes (typically small integers like 2-112) are not valid POSIX errno values
-
Code that checks errno == ENOENT will fail even when ERROR_FILE_NOT_FOUND (2) occurs
-
Error messages and error handling logic expecting POSIX errno values receive raw Windows error codes instead
For example, when CreateFileMapping fails with ERROR_FILE_NOT_FOUND (2), errno is set to 2 instead of ENOENT (which is typically 2 on many systems, but this is coincidental and not guaranteed).
Expected Behavior
The function should map Windows error codes to POSIX errno values, matching Arrow's existing WinErrorToErrno() conventions. Common mappings should include:
ERROR_FILE_NOT_FOUND(2) →ENOENTERROR_ACCESS_DENIED(5) →EACCESERROR_INVALID_HANDLE(6) →EBADFERROR_NOT_ENOUGH_MEMORY(8) →ENOMEMERROR_DISK_FULL(112) →ENOSPC- etc
Component(s)
C++