2017-04-02 18:17:52 -07:00
|
|
|
From d587367c1f1e2dbe9b284b32027db068691838eb Mon Sep 17 00:00:00 2001
|
2015-02-09 21:40:25 -08:00
|
|
|
From: Dmitry Timoshkov <dmitry@baikal.ru>
|
|
|
|
Date: Tue, 10 Feb 2015 06:36:52 +0100
|
|
|
|
Subject: ntdll: Avoid race-conditions with write watches in NtReadFile.
|
|
|
|
|
|
|
|
Rebased against kernel32-NamedPipe patchset by Sebastian Lackner <sebastian@fds-team.de>.
|
|
|
|
---
|
2017-04-02 18:17:52 -07:00
|
|
|
dlls/kernel32/tests/virtual.c | 8 ++++----
|
|
|
|
dlls/ntdll/file.c | 18 ++++++++++++++++++
|
|
|
|
2 files changed, 22 insertions(+), 4 deletions(-)
|
2015-02-09 21:40:25 -08:00
|
|
|
|
2015-10-29 17:01:13 -07:00
|
|
|
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
|
2017-04-02 18:17:52 -07:00
|
|
|
index 40de97ada2..4765cd6c58 100644
|
2015-10-29 17:01:13 -07:00
|
|
|
--- a/dlls/kernel32/tests/virtual.c
|
|
|
|
+++ b/dlls/kernel32/tests/virtual.c
|
2017-04-02 18:17:52 -07:00
|
|
|
@@ -1722,16 +1722,16 @@ static void test_write_watch(void)
|
2015-10-29 17:01:13 -07:00
|
|
|
|
|
|
|
num_bytes = 0;
|
|
|
|
success = GetOverlappedResult( readpipe, &overlapped, &num_bytes, TRUE );
|
|
|
|
- todo_wine ok( success, "GetOverlappedResult failed %u\n", GetLastError() );
|
|
|
|
- todo_wine ok( num_bytes == sizeof(testdata), "wrong number of bytes read\n" );
|
|
|
|
- todo_wine ok( !memcmp( base, testdata, sizeof(testdata)), "didn't receive expected data\n" );
|
|
|
|
+ ok( success, "GetOverlappedResult failed %u\n", GetLastError() );
|
|
|
|
+ ok( num_bytes == sizeof(testdata), "wrong number of bytes read\n" );
|
|
|
|
+ ok( !memcmp( base, testdata, sizeof(testdata)), "didn't receive expected data\n" );
|
|
|
|
|
|
|
|
count = 64;
|
|
|
|
memset( results, 0, sizeof(results) );
|
|
|
|
ret = pGetWriteWatch( WRITE_WATCH_FLAG_RESET, base, size, results, &count, &pagesize );
|
|
|
|
ok( !ret, "GetWriteWatch failed %u\n", GetLastError() );
|
|
|
|
todo_wine ok( count == 1, "wrong count %lu\n", count );
|
|
|
|
- todo_wine ok( results[0] == base, "wrong result %p\n", results[0] );
|
|
|
|
+ ok( results[0] == base, "wrong result %p\n", results[0] );
|
|
|
|
|
|
|
|
CloseHandle( readpipe );
|
|
|
|
CloseHandle( writepipe );
|
2015-02-09 21:40:25 -08:00
|
|
|
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
|
2017-04-02 18:17:52 -07:00
|
|
|
index c153e7bb5c..34fd08fb0b 100644
|
2015-02-09 21:40:25 -08:00
|
|
|
--- a/dlls/ntdll/file.c
|
|
|
|
+++ b/dlls/ntdll/file.c
|
2017-04-02 18:17:52 -07:00
|
|
|
@@ -514,6 +514,10 @@ static NTSTATUS FILE_AsyncReadService( void *user, IO_STATUS_BLOCK *iosb,
|
|
|
|
{
|
|
|
|
if (errno == EAGAIN || errno == EINTR)
|
|
|
|
status = STATUS_PENDING;
|
|
|
|
+ else if (errno == EFAULT)
|
|
|
|
+ status = (wine_uninterrupted_write_memory( &fileio->buffer[fileio->already], NULL,
|
|
|
|
+ fileio->count - fileio->already ) >= (fileio->count - fileio->already)) ?
|
|
|
|
+ STATUS_PENDING : STATUS_ACCESS_VIOLATION;
|
|
|
|
else /* check to see if the transfer is complete */
|
|
|
|
status = FILE_GetNtStatus();
|
2015-02-09 21:40:25 -08:00
|
|
|
}
|
2017-04-02 18:17:52 -07:00
|
|
|
@@ -875,6 +879,13 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
|
2015-02-09 21:40:25 -08:00
|
|
|
/* async I/O doesn't make sense on regular files */
|
|
|
|
while ((result = pread( unix_handle, buffer, length, offset->QuadPart )) == -1)
|
|
|
|
{
|
2017-04-02 18:17:52 -07:00
|
|
|
+ if (errno == EFAULT)
|
|
|
|
+ {
|
|
|
|
+ if (virtual_check_buffer_for_write( buffer, length ) >= length)
|
|
|
|
+ continue;
|
|
|
|
+ else
|
|
|
|
+ errno = EFAULT;
|
|
|
|
+ }
|
2015-02-09 21:40:25 -08:00
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
status = FILE_GetNtStatus();
|
2017-04-02 18:17:52 -07:00
|
|
|
@@ -949,6 +960,13 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
|
|
|
|
else if (errno != EAGAIN)
|
|
|
|
{
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
+ if (errno == EFAULT)
|
|
|
|
+ {
|
|
|
|
+ if (wine_uninterrupted_write_memory( (char *)buffer + total, NULL, length - total ) >= (length - total))
|
|
|
|
+ continue;
|
|
|
|
+ else
|
|
|
|
+ errno = EFAULT;
|
|
|
|
+ }
|
|
|
|
if (!total) status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
2015-02-09 21:40:25 -08:00
|
|
|
--
|
2017-04-02 18:17:52 -07:00
|
|
|
2.11.0
|
2015-02-09 21:40:25 -08:00
|
|
|
|