ntdll: Fall back to read() on noexec filesystems also for non-image mappings.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-11-17 11:54:51 +01:00
parent 02d0d68bca
commit 2e364d25cc
1 changed files with 22 additions and 11 deletions

View File

@ -1164,19 +1164,30 @@ static NTSTATUS map_file_into_view( struct file_view *view, int fd, size_t start
if (mmap( (char *)view->base + start, size, prot, flags, fd, offset ) != (void *)-1) if (mmap( (char *)view->base + start, size, prot, flags, fd, offset ) != (void *)-1)
goto done; goto done;
if ((errno == EPERM) && (prot & PROT_EXEC)) switch (errno)
ERR( "failed to set %08x protection on file map, noexec filesystem?\n", prot ); {
case EINVAL: /* file offset is not page-aligned, fall back to read() */
/* mmap() failed; if this is because the file offset is not */ if (flags & MAP_SHARED) return STATUS_INVALID_PARAMETER;
/* page-aligned (EINVAL), or because the underlying filesystem */ break;
/* does not support mmap() (ENOEXEC,ENODEV), we do it by hand. */ case ENOEXEC:
if ((errno != ENOEXEC) && (errno != EINVAL) && (errno != ENODEV)) return FILE_GetNtStatus(); case ENODEV: /* filesystem doesn't support mmap(), fall back to read() */
if (flags & MAP_SHARED) /* we cannot fake shared mappings */ if (flags & MAP_SHARED)
{ {
if (errno == EINVAL) return STATUS_INVALID_PARAMETER;
ERR( "shared writable mmap not supported, broken filesystem?\n" ); ERR( "shared writable mmap not supported, broken filesystem?\n" );
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
} }
break;
case EPERM: /* noexec filesystem, fall back to read() */
if (flags & MAP_SHARED)
{
if (prot & PROT_EXEC) ERR( "failed to set PROT_EXEC on file map, noexec filesystem?\n" );
return STATUS_ACCESS_DENIED;
}
if (prot & PROT_EXEC) WARN( "failed to set PROT_EXEC on file map, noexec filesystem?\n" );
break;
default:
return FILE_GetNtStatus();
}
} }
/* Reserve the memory with an anonymous mmap */ /* Reserve the memory with an anonymous mmap */