Skip to content

Commit 7f52cff

Browse files
committed
[NTVDM]
Always use MemRead and MemWrite to read/write memory. svn path=/trunk/; revision=67082
1 parent 81c9b44 commit 7f52cff

File tree

1 file changed

+17
-2
lines changed
  • reactos/subsystems/mvdm/ntvdm/dos/dos32krnl

1 file changed

+17
-2
lines changed

reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define NDEBUG
1313

1414
#include "emulator.h"
15+
#include "../../memory.h"
1516

1617
#include "dos.h"
1718
#include "dos/dem.h"
@@ -409,16 +410,24 @@ WORD DosReadFile(WORD FileHandle,
409410
if (SftEntry->Type == DOS_SFT_ENTRY_WIN32)
410411
{
411412
DWORD BytesRead32 = 0;
413+
LPVOID LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
414+
ASSERT(LocalBuffer != NULL);
412415

413416
/* Read the file */
414-
if (!ReadFile(SftEntry->Handle, FAR_POINTER(Buffer), Count, &BytesRead32, NULL))
417+
if (ReadFile(SftEntry->Handle, LocalBuffer, Count, &BytesRead32, NULL))
418+
{
419+
/* Write to the memory */
420+
MemWrite(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, LOWORD(BytesRead32));
421+
}
422+
else
415423
{
416424
/* Store the error code */
417425
Result = (WORD)GetLastError();
418426
}
419427

420428
/* The number of bytes read is always 16-bit */
421429
*BytesRead = LOWORD(BytesRead32);
430+
RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
422431
}
423432
else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE)
424433
{
@@ -457,16 +466,22 @@ WORD DosWriteFile(WORD FileHandle,
457466
if (SftEntry->Type == DOS_SFT_ENTRY_WIN32)
458467
{
459468
DWORD BytesWritten32 = 0;
469+
LPVOID LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
470+
ASSERT(LocalBuffer != NULL);
471+
472+
/* Read from the memory */
473+
MemRead(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, Count);
460474

461475
/* Write the file */
462-
if (!WriteFile(SftEntry->Handle, FAR_POINTER(Buffer), Count, &BytesWritten32, NULL))
476+
if (!WriteFile(SftEntry->Handle, LocalBuffer, Count, &BytesWritten32, NULL))
463477
{
464478
/* Store the error code */
465479
Result = (WORD)GetLastError();
466480
}
467481

468482
/* The number of bytes written is always 16-bit */
469483
*BytesWritten = LOWORD(BytesWritten32);
484+
RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
470485
}
471486
else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE)
472487
{

0 commit comments

Comments
 (0)