mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-09 22:08:56 +08:00
fix(windows-shim): reject mmap MAP_FIXED with ENOTSUP
The Windows mmap shim cannot honour MAP_FIXED safely: VirtualAlloc / MapViewOfFile cannot replace existing mappings at a caller-supplied address, so accepting the flag would silently fall through to a non-fixed allocation and the caller would get back an address that does not match the one it asked for. The shim header documents this contract; the implementation now matches it by returning MAP_FAILED with errno set to ENOTSUP when MAP_FIXED is requested. Fixes the MAP_FIXED expectation in the mmap unit tests, which now get the expected MAP_FAILED return instead of a surprise fallback mapping at a different address. Signed-off-by: Nuno Marques <n.marques21@hotmail.com>
This commit is contained in:
@@ -60,6 +60,14 @@ static DWORD mman_page_protect(int prot)
|
||||
|
||||
extern "C" void *mmap(void *, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
/* MAP_FIXED is rejected because the Windows backend (VirtualAlloc /
|
||||
* MapViewOfFile) cannot safely replace existing mappings at a caller
|
||||
* supplied address. The shim header documents this contract. */
|
||||
if (flags & MAP_FIXED) {
|
||||
errno = ENOTSUP;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
const bool anon = (flags & (MAP_ANON | MAP_ANONYMOUS)) != 0;
|
||||
|
||||
if (anon || fd < 0) {
|
||||
|
||||
Reference in New Issue
Block a user