wine-staging/patches/ntdll-WriteWatches/0001-ntdll-Avoid-race-conditions-with-write-watches-in-Nt.patch

83 lines
3.6 KiB
Diff
Raw Normal View History

From d587367c1f1e2dbe9b284b32027db068691838eb 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 40de97ada2..4765cd6c58 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -1722,16 +1722,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 c153e7bb5c..34fd08fb0b 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -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();
}
@@ -875,6 +879,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();
@@ -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;
}
--
2.11.0