Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmulatorPkg: spurious failure in WriteBlocks on X64 #6487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

idigdoug
Copy link
Contributor

@idigdoug idigdoug commented Dec 1, 2024

Description

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.

  • Breaking change?
    • Breaking change - Does this PR cause a break in build or boot behavior?
    • Examples: Does it add a new library class or move a module to a different repo.
  • Impacts security?
    • Security - Does this PR have a direct security impact?
    • Examples: Crypto algorithm change or buffer overflow fix.
  • Includes tests?
    • Tests - Does this PR include any explicit test code?
    • Examples: Unit tests or integration tests.

How This Was Tested

  • Observed spurious failures in WriteBlocks.
  • Applied fix.
  • WriteBlocks now works as expected.

Integration Instructions

N/A

@idigdoug idigdoug force-pushed the WinBlockIoWrite branch 2 times, most recently from 88ad346 to d4617af Compare December 1, 2024 21:30
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants