From d1fccbf494a4f38f803cb8288dd6b08ec7b98dcc Mon Sep 17 00:00:00 2001 From: "Doug Cook (WINDOWS)" Date: Sat, 30 Nov 2024 17:32:03 -0800 Subject: [PATCH] EmulatorPkg: spurious failure in WriteBlocks on X64 WinNtBlockIoWriteBlocks can spuriously fail on X64. This occurs because &BytesWritten is a `UINTN*` (i.e. `UINT64*`) but is cast to `LPDWORD` (i.e. `UINT32*`). Only the low 32 bits are initialized by WriteFile, so the high 32 bits are uninitialized. This means we will spuriously fail the `BytesWritten != BufferSize` test. This doesn't occur on X86-32 since UINTN is the same as DWORD in that case. Fix is to declare BytesWritten as DWORD to match the type expected by WriteFile. This also makes the cast unnecessary. Signed-off-by: Doug Cook --- EmulatorPkg/Win/Host/WinBlockIo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EmulatorPkg/Win/Host/WinBlockIo.c b/EmulatorPkg/Win/Host/WinBlockIo.c index c7cfbee2e0..e90376d5fb 100644 --- a/EmulatorPkg/Win/Host/WinBlockIo.c +++ b/EmulatorPkg/Win/Host/WinBlockIo.c @@ -356,7 +356,7 @@ WinNtBlockIoWriteBlocks ( ) { WIN_NT_BLOCK_IO_PRIVATE *Private; - UINTN BytesWritten; + DWORD BytesWritten; BOOL Success; EFI_STATUS Status; UINT64 DistanceToMove; @@ -375,7 +375,7 @@ WinNtBlockIoWriteBlocks ( return WinNtBlockIoError (Private->Media); } - Success = WriteFile (Private->NtHandle, Buffer, (DWORD)BufferSize, (LPDWORD)&BytesWritten, NULL); + Success = WriteFile (Private->NtHandle, Buffer, (DWORD)BufferSize, &BytesWritten, NULL); if (!Success || (BytesWritten != BufferSize)) { return WinNtBlockIoError (Private->Media); }