Skip to content

Commit

Permalink
EmulatorPkg: spurious failure in WriteBlocks on X64
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
idigdoug authored and mergify[bot] committed Dec 17, 2024
1 parent 30c8a73 commit d1fccbf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions EmulatorPkg/Win/Host/WinBlockIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ WinNtBlockIoWriteBlocks (
)
{
WIN_NT_BLOCK_IO_PRIVATE *Private;
UINTN BytesWritten;
DWORD BytesWritten;
BOOL Success;
EFI_STATUS Status;
UINT64 DistanceToMove;
Expand All @@ -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);
}
Expand Down

0 comments on commit d1fccbf

Please sign in to comment.