wine-staging/patches/ntdll-WriteWatches/0001-ntdll-Avoid-race-conditions-with-write-watches-in-Nt.patch
2017-09-08 00:29:26 +02:00

83 lines
3.6 KiB
Diff

From c6dc4f67d20bd4deb3c8655da9dae191af34135a Mon Sep 17 00:00:00 2001
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>.
---
dlls/kernel32/tests/virtual.c | 8 ++++----
dlls/ntdll/file.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 7366ef17384..6ad887fc34b 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -1750,16 +1750,16 @@ static void test_write_watch(void)
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 );
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 0381e558ff6..a4da492573c 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -524,6 +524,10 @@ static NTSTATUS FILE_AsyncReadService( void *user, IO_STATUS_BLOCK *iosb, NTSTAT
{
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 ) == STATUS_SUCCESS) ?
+ STATUS_PENDING : STATUS_ACCESS_VIOLATION;
else /* check to see if the transfer is complete */
status = FILE_GetNtStatus();
}
@@ -871,6 +875,13 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
/* async I/O doesn't make sense on regular files */
while ((result = pread( unix_handle, buffer, length, offset->QuadPart )) == -1)
{
+ if (errno == EFAULT)
+ {
+ if (virtual_check_buffer_for_write( buffer, length ) >= length)
+ continue;
+ else
+ errno = EFAULT;
+ }
if (errno != EINTR)
{
status = FILE_GetNtStatus();
@@ -945,6 +956,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 ) == STATUS_SUCCESS)
+ continue;
+ else
+ errno = EFAULT;
+ }
if (!total) status = FILE_GetNtStatus();
goto done;
}
--
2.14.1