Commit e04da6bb authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

Add a test for ReadFile/WriteFile fault handling, make it pass under

Wine.
parent c33c2da8
...@@ -449,13 +449,15 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, ...@@ -449,13 +449,15 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite,
status = NtWriteFile(hFile, hEvent, NULL, NULL, piosb, status = NtWriteFile(hFile, hEvent, NULL, NULL, piosb,
buffer, bytesToWrite, poffset, NULL); buffer, bytesToWrite, poffset, NULL);
if (status != STATUS_PENDING && bytesWritten)
*bytesWritten = piosb->Information;
if (status) if (status)
{ {
SetLastError( RtlNtStatusToDosError(status) ); SetLastError( RtlNtStatusToDosError(status) );
return FALSE; return FALSE;
} }
if (bytesWritten) *bytesWritten = piosb->Information;
return TRUE; return TRUE;
} }
......
...@@ -1265,6 +1265,61 @@ static void test_async_file_errors(void) ...@@ -1265,6 +1265,61 @@ static void test_async_file_errors(void)
/*printf("Error = %ld\n", GetLastError());*/ /*printf("Error = %ld\n", GetLastError());*/
} }
static void test_read_write(void)
{
DWORD bytes, ret;
HANDLE hFile;
char temp_path[MAX_PATH];
char filename[MAX_PATH];
static const char prefix[] = "pfx";
ret = GetTempPathA(MAX_PATH, temp_path);
ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
ret = GetTempFileNameA(temp_path, prefix, 0, filename);
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS, 0);
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %ld\n", GetLastError());
SetLastError(12345678);
bytes = 12345678;
ret = WriteFile(hFile, NULL, 0, &bytes, NULL);
ok(ret && GetLastError() == 12345678,
"ret = %ld, error %ld\n", ret, GetLastError());
ok(!bytes, "bytes = %ld\n", bytes);
SetLastError(12345678);
bytes = 12345678;
ret = WriteFile(hFile, NULL, 10, &bytes, NULL);
ok((!ret && GetLastError() == ERROR_INVALID_USER_BUFFER) || /* Win2k */
(ret && GetLastError() == 12345678), /* Win9x */
"ret = %ld, error %ld\n", ret, GetLastError());
ok(!bytes || /* Win2k */
bytes == 10, /* Win9x */
"bytes = %ld\n", bytes);
SetLastError(12345678);
bytes = 12345678;
ret = ReadFile(hFile, NULL, 0, &bytes, NULL);
ok(ret && GetLastError() == 12345678,
"ret = %ld, error %ld\n", ret, GetLastError());
ok(!bytes, "bytes = %ld\n", bytes);
SetLastError(12345678);
bytes = 12345678;
ret = ReadFile(hFile, NULL, 10, &bytes, NULL);
ok(!ret && (GetLastError() == ERROR_NOACCESS || /* Win2k */
GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */
"ret = %ld, error %ld\n", ret, GetLastError());
ok(!bytes, "bytes = %ld\n", bytes);
ok(CloseHandle(hFile), "CloseHandle: error %ld\n", GetLastError());
ok(DeleteFileA(filename), "DeleteFileA: error %ld\n", GetLastError());
}
START_TEST(file) START_TEST(file)
{ {
test__hread( ); test__hread( );
...@@ -1292,4 +1347,5 @@ START_TEST(file) ...@@ -1292,4 +1347,5 @@ START_TEST(file)
test_MapFile(); test_MapFile();
test_GetFileType(); test_GetFileType();
test_async_file_errors(); test_async_file_errors();
test_read_write();
} }
...@@ -531,8 +531,12 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent, ...@@ -531,8 +531,12 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
while ((io_status->Information = read( unix_handle, buffer, length )) == -1) while ((io_status->Information = read( unix_handle, buffer, length )) == -1)
{ {
if ((errno == EAGAIN) || (errno == EINTR)) continue; if ((errno == EAGAIN) || (errno == EINTR)) continue;
if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" ); if (errno == EFAULT)
io_status->u.Status = FILE_GetNtStatus(); {
io_status->Information = 0;
io_status->u.Status = STATUS_ACCESS_VIOLATION;
}
else io_status->u.Status = FILE_GetNtStatus();
break; break;
} }
wine_server_release_fd( hFile, unix_handle ); wine_server_release_fd( hFile, unix_handle );
...@@ -724,8 +728,12 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent, ...@@ -724,8 +728,12 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
while ((io_status->Information = write( unix_handle, buffer, length )) == -1) while ((io_status->Information = write( unix_handle, buffer, length )) == -1)
{ {
if ((errno == EAGAIN) || (errno == EINTR)) continue; if ((errno == EAGAIN) || (errno == EINTR)) continue;
if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" ); if (errno == EFAULT)
if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL; {
io_status->Information = 0;
io_status->u.Status = STATUS_INVALID_USER_BUFFER;
}
else if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL;
else io_status->u.Status = FILE_GetNtStatus(); else io_status->u.Status = FILE_GetNtStatus();
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment