ReactOS  0.4.15-dev-5137-g826bd41
ntvdm.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "bios/bios.h"
#include "cpu/cpu.h"
#include "dos/dem.h"
#include <ndk/psfuncs.h>
#include "./console/console.c"
Include dependency graph for ntvdm.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS NTAPI NtVdmConfigureBios (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
static NTSTATUS NTAPI NtVdmConfigureRom (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
static NTSTATUS NTAPI NtVdmConfigureFloppy (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
static NTSTATUS NTAPI NtVdmConfigureHDD (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
static BOOL LoadGlobalSettings (IN PNTVDM_SETTINGS Settings)
 
static VOID FreeGlobalSettings (IN PNTVDM_SETTINGS Settings)
 
static VOID ConsoleCleanup (VOID)
 
VOID VdmShutdown (BOOLEAN Immediate)
 
VOID DisplayMessage (IN LPCWSTR Format,...)
 
VOID PrintMessageAnsi (IN CHAR_PRINT CharPrint, IN LPCSTR Format,...)
 
INT wmain (INT argc, WCHAR *argv[])
 

Variables

NTVDM_SETTINGS GlobalSettings
 
INT NtVdmArgc
 
WCHAR ** NtVdmArgv
 
WCHAR NtVdmPath [MAX_PATH]
 
ULONG NtVdmPathSize
 
static RTL_QUERY_REGISTRY_TABLE NtVdmConfigurationTable []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file ntvdm.c.

Function Documentation

◆ ConsoleCleanup()

static VOID ConsoleCleanup ( VOID  )
static

Referenced by VdmShutdown().

◆ DisplayMessage()

VOID DisplayMessage ( IN LPCWSTR  Format,
  ... 
)

Definition at line 360 of file ntvdm.c.

361 {
362 #ifndef WIN2K_COMPLIANT
363  WCHAR StaticBuffer[256];
364  LPWSTR Buffer = StaticBuffer; // Use the static buffer by default.
365 #else
366  WCHAR Buffer[2048]; // Large enough. If not, increase it by hand.
367 #endif
368  size_t MsgLen;
369  va_list args;
370 
371  va_start(args, Format);
372 
373 #ifndef WIN2K_COMPLIANT
374  /*
375  * Retrieve the message length and if it is too long, allocate
376  * an auxiliary buffer; otherwise use the static buffer.
377  * The string is built to be NULL-terminated.
378  */
379  MsgLen = _vscwprintf(Format, args);
380  if (MsgLen >= ARRAYSIZE(StaticBuffer))
381  {
382  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, (MsgLen + 1) * sizeof(WCHAR));
383  if (Buffer == NULL)
384  {
385  /* Allocation failed, use the static buffer and display a suitable error message */
386  Buffer = StaticBuffer;
387  Format = L"DisplayMessage()\nOriginal message is too long and allocating an auxiliary buffer failed.";
388  MsgLen = wcslen(Format);
389  }
390  }
391 #else
392  MsgLen = ARRAYSIZE(Buffer) - 1;
393 #endif
394 
395  RtlZeroMemory(Buffer, (MsgLen + 1) * sizeof(WCHAR));
396  _vsnwprintf(Buffer, MsgLen, Format, args);
397 
398  va_end(args);
399 
400  /* Display the message */
401  DPRINT1("\n\nNTVDM Subsystem\n%S\n\n", Buffer);
402  MessageBoxW(hConsoleWnd, Buffer, L"NTVDM Subsystem", MB_OK);
403 
404 #ifndef WIN2K_COMPLIANT
405  /* Free the buffer if needed */
406  if (Buffer != StaticBuffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
407 #endif
408 }
#define args
Definition: format.c:66
HWND hConsoleWnd
Definition: console.c:20
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
Definition: match.c:390
#define L(x)
Definition: ntvdm.h:50
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
va_start(ap, x)
_Check_return_ _CRTIMP int __cdecl _vscwprintf(_In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList)
_CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, va_list _Args)
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ FreeGlobalSettings()

static VOID FreeGlobalSettings ( IN PNTVDM_SETTINGS  Settings)
static

Definition at line 284 of file ntvdm.c.

285 {
286  USHORT i;
287 
288  ASSERT(Settings);
289 
290  if (Settings->BiosFileName.Buffer)
291  RtlFreeAnsiString(&Settings->BiosFileName);
292 
293  if (Settings->RomFiles.Buffer)
294  RtlFreeAnsiString(&Settings->RomFiles);
295 
296  for (i = 0; i < ARRAYSIZE(Settings->FloppyDisks); ++i)
297  {
298  if (Settings->FloppyDisks[i].Buffer)
299  RtlFreeUnicodeString(&Settings->FloppyDisks[i]);
300  }
301 
302  for (i = 0; i < ARRAYSIZE(Settings->HardDisks); ++i)
303  {
304  if (Settings->HardDisks[i].Buffer)
305  RtlFreeUnicodeString(&Settings->HardDisks[i]);
306  }
307 }
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61

Referenced by VdmShutdown().

◆ LoadGlobalSettings()

static BOOL LoadGlobalSettings ( IN PNTVDM_SETTINGS  Settings)
static

Definition at line 254 of file ntvdm.c.

255 {
257 
258  ASSERT(Settings);
259 
260  /*
261  * Now we can do:
262  * - CPU core choice
263  * - Video choice
264  * - Sound choice
265  * - Mem?
266  * - ...
267  * - Standalone mode?
268  * - Debug settings
269  */
271  L"NTVDM",
273  Settings,
274  NULL);
275  if (!NT_SUCCESS(Status))
276  {
277  DPRINT1("NTVDM registry settings cannot be fully initialized, using default ones. Status = 0x%08lx\n", Status);
278  }
279 
280  return NT_SUCCESS(Status);
281 }
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
LONG NTSTATUS
Definition: precomp.h:26
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
#define L(x)
Definition: ntvdm.h:50
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static RTL_QUERY_REGISTRY_TABLE NtVdmConfigurationTable[]
Definition: ntvdm.c:167
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8

Referenced by wmain().

◆ NtVdmConfigureBios()

static NTSTATUS NTAPI NtVdmConfigureBios ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)
static

Definition at line 42 of file ntvdm.c.

48 {
50  UNICODE_STRING ValueString;
51 
52  /* Check for the type of the value */
53  if (ValueType != REG_SZ)
54  {
55  RtlInitEmptyAnsiString(&Settings->BiosFileName, NULL, 0);
56  return STATUS_SUCCESS;
57  }
58 
59  /* Convert the UNICODE string to ANSI and store it */
60  RtlInitEmptyUnicodeString(&ValueString, (PWCHAR)ValueData, ValueLength);
61  ValueString.Length = ValueString.MaximumLength;
62  RtlUnicodeStringToAnsiString(&Settings->BiosFileName, &ValueString, TRUE);
63 
64  return STATUS_SUCCESS;
65 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
struct _NTVDM_SETTINGS * PNTVDM_SETTINGS
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define REG_SZ
Definition: layer.c:22
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271

◆ NtVdmConfigureFloppy()

static NTSTATUS NTAPI NtVdmConfigureFloppy ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)
static

Definition at line 96 of file ntvdm.c.

102 {
105  ULONG DiskNumber = PtrToUlong(EntryContext);
106 
107  ASSERT(DiskNumber < ARRAYSIZE(Settings->FloppyDisks));
108 
109  /* Check whether the Hard Disk entry was not already configured */
110  if (Settings->FloppyDisks[DiskNumber].Buffer != NULL)
111  {
112  DPRINT1("Floppy Disk %d -- '%wZ' already configured\n", DiskNumber, &Settings->FloppyDisks[DiskNumber]);
113  return STATUS_SUCCESS;
114  }
115 
116  /* Check for the type of the value */
117  if (ValueType != REG_SZ)
118  {
119  RtlInitEmptyUnicodeString(&Settings->FloppyDisks[DiskNumber], NULL, 0);
120  return STATUS_SUCCESS;
121  }
122 
123  /* Initialize the string */
124  Success = RtlCreateUnicodeString(&Settings->FloppyDisks[DiskNumber], (PCWSTR)ValueData);
125  ASSERT(Success);
126 
127  return STATUS_SUCCESS;
128 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
struct _NTVDM_SETTINGS * PNTVDM_SETTINGS
unsigned char BOOLEAN
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4182
#define PtrToUlong(u)
Definition: config.h:107
#define ASSERT(a)
Definition: mode.c:44
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define REG_SZ
Definition: layer.c:22

◆ NtVdmConfigureHDD()

static NTSTATUS NTAPI NtVdmConfigureHDD ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)
static

Definition at line 132 of file ntvdm.c.

138 {
141  ULONG DiskNumber = PtrToUlong(EntryContext);
142 
143  ASSERT(DiskNumber < ARRAYSIZE(Settings->HardDisks));
144 
145  /* Check whether the Hard Disk entry was not already configured */
146  if (Settings->HardDisks[DiskNumber].Buffer != NULL)
147  {
148  DPRINT1("Hard Disk %d -- '%wZ' already configured\n", DiskNumber, &Settings->HardDisks[DiskNumber]);
149  return STATUS_SUCCESS;
150  }
151 
152  /* Check for the type of the value */
153  if (ValueType != REG_SZ)
154  {
155  RtlInitEmptyUnicodeString(&Settings->HardDisks[DiskNumber], NULL, 0);
156  return STATUS_SUCCESS;
157  }
158 
159  /* Initialize the string */
160  Success = RtlCreateUnicodeString(&Settings->HardDisks[DiskNumber], (PCWSTR)ValueData);
161  ASSERT(Success);
162 
163  return STATUS_SUCCESS;
164 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
struct _NTVDM_SETTINGS * PNTVDM_SETTINGS
unsigned char BOOLEAN
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4182
#define PtrToUlong(u)
Definition: config.h:107
#define ASSERT(a)
Definition: mode.c:44
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define REG_SZ
Definition: layer.c:22

◆ NtVdmConfigureRom()

static NTSTATUS NTAPI NtVdmConfigureRom ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)
static

Definition at line 69 of file ntvdm.c.

75 {
77  UNICODE_STRING ValueString;
78 
79  /* Check for the type of the value */
80  if (ValueType != REG_MULTI_SZ)
81  {
82  RtlInitEmptyAnsiString(&Settings->RomFiles, NULL, 0);
83  return STATUS_SUCCESS;
84  }
85 
86  /* Convert the UNICODE string to ANSI and store it */
87  RtlInitEmptyUnicodeString(&ValueString, (PWCHAR)ValueData, ValueLength);
88  ValueString.Length = ValueString.MaximumLength;
89  RtlUnicodeStringToAnsiString(&Settings->RomFiles, &ValueString, TRUE);
90 
91  return STATUS_SUCCESS;
92 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2592
#define REG_MULTI_SZ
Definition: nt_native.h:1501
struct _NTVDM_SETTINGS * PNTVDM_SETTINGS
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271

◆ PrintMessageAnsi()

VOID PrintMessageAnsi ( IN CHAR_PRINT  CharPrint,
IN LPCSTR  Format,
  ... 
)

Definition at line 416 of file ntvdm.c.

418 {
419  static CHAR CurChar = 0;
420  LPSTR str;
421 
422 #ifndef WIN2K_COMPLIANT
423  CHAR StaticBuffer[256];
424  LPSTR Buffer = StaticBuffer; // Use the static buffer by default.
425 #else
426  CHAR Buffer[2048]; // Large enough. If not, increase it by hand.
427 #endif
428  size_t MsgLen;
429  va_list args;
430 
431  va_start(args, Format);
432 
433 #ifndef WIN2K_COMPLIANT
434  /*
435  * Retrieve the message length and if it is too long, allocate
436  * an auxiliary buffer; otherwise use the static buffer.
437  * The string is built to be NULL-terminated.
438  */
439  MsgLen = _vscprintf(Format, args);
440  if (MsgLen >= ARRAYSIZE(StaticBuffer))
441  {
442  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, (MsgLen + 1) * sizeof(CHAR));
443  if (Buffer == NULL)
444  {
445  /* Allocation failed, use the static buffer and display a suitable error message */
446  Buffer = StaticBuffer;
447  Format = "DisplayMessageAnsi()\nOriginal message is too long and allocating an auxiliary buffer failed.";
448  MsgLen = strlen(Format);
449  }
450  }
451 #else
452  MsgLen = ARRAYSIZE(Buffer) - 1;
453 #endif
454 
455  RtlZeroMemory(Buffer, (MsgLen + 1) * sizeof(CHAR));
456  _vsnprintf(Buffer, MsgLen, Format, args);
457 
458  va_end(args);
459 
460  /* Display the message */
461  // DPRINT1("\n\nNTVDM DOS32\n%s\n\n", Buffer);
462 
463  MsgLen = strlen(Buffer);
464  str = Buffer;
465  while (MsgLen--)
466  {
467  if (*str == '\n' && CurChar != '\r')
468  CharPrint('\r');
469 
470  CurChar = *str++;
471  CharPrint(CurChar);
472  }
473 
474 #ifndef WIN2K_COMPLIANT
475  /* Free the buffer if needed */
476  if (Buffer != StaticBuffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
477 #endif
478 }
#define args
Definition: format.c:66
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
char CHAR
Definition: xmlstorage.h:175
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
char * LPSTR
Definition: xmlstorage.h:182
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
const WCHAR * str
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
va_start(ap, x)
_Check_return_ _CRTIMP int __cdecl _vscprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define _vsnprintf
Definition: xmlstorage.h:202
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by BiosRomBasic().

◆ VdmShutdown()

VOID VdmShutdown ( BOOLEAN  Immediate)

HACK!! HACK!!

Definition at line 317 of file ntvdm.c.

318 {
319  /*
320  * Immediate = TRUE: Immediate shutdown;
321  * FALSE: Delayed shutdown.
322  */
323  static BOOLEAN MustShutdown = FALSE;
324 
325  /* If a shutdown is ongoing, just return */
326  if (MustShutdown)
327  {
328  DPRINT1("Shutdown is ongoing...\n");
329  Sleep(INFINITE);
330  return;
331  }
332 
333  /* First notify DOS to see whether we can shut down now */
334  MustShutdown = DosShutdown(Immediate);
335  /*
336  * In case we perform an immediate shutdown, or the DOS says
337  * we can shut down, do it now.
338  */
339  MustShutdown = MustShutdown || Immediate;
340 
341  if (MustShutdown)
342  {
344 
345  BiosCleanup();
346  EmulatorCleanup();
347  ConsoleCleanup();
348 
350 
351  DPRINT1("\n\n\nNTVDM - Exiting...\n\n\n");
352  /* Some VDDs rely on the fact that NTVDM calls ExitProcess on Windows */
353  ExitProcess(0);
354  }
355 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOLEAN DosShutdown(BOOLEAN Immediate)
Definition: dem.c:1331
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
VOID BiosCleanup(VOID)
Definition: bios.c:153
VOID EmulatorCleanup(VOID)
Definition: emulator.c:639
VOID EmulatorTerminate(VOID)
Definition: emulator.c:503
static VOID ConsoleCleanup(VOID)
#define DPRINT1
Definition: precomp.h:8
static VOID FreeGlobalSettings(IN PNTVDM_SETTINGS Settings)
Definition: ntvdm.c:284
#define INFINITE
Definition: serial.h:102
NTVDM_SETTINGS GlobalSettings
Definition: ntvdm.c:28

Referenced by ConsoleCtrlHandler(), MenuEventHandler(), and wmain().

◆ wmain()

INT wmain ( INT  argc,
WCHAR argv[] 
)

Definition at line 481 of file ntvdm.c.

482 {
483  BOOL Success;
484 
485 #ifdef STANDALONE
486 
487  if (argc < 2)
488  {
489  wprintf(L"\nReactOS Virtual DOS Machine\n\n"
490  L"Usage: NTVDM <executable> [<parameters>]\n");
491  return 0;
492  }
493 
494 #else
495 
496  /* For non-STANDALONE builds, we must be started as a VDM */
498  ULONG VdmPower = 0;
501  &VdmPower,
502  sizeof(VdmPower),
503  NULL);
504  if (!NT_SUCCESS(Status) || (VdmPower == 0))
505  {
506  /* Not a VDM, bail out */
507  return 0;
508  }
509 
510 #endif
511 
512  NtVdmArgc = argc;
513  NtVdmArgv = argv;
514 
515 #ifdef ADVANCED_DEBUGGING
516  {
517  INT i = 20;
518 
519  printf("Waiting for debugger (10 secs)..");
520  while (i--)
521  {
522  printf(".");
523  if (IsDebuggerPresent())
524  {
525  DbgBreakPoint();
526  break;
527  }
528  Sleep(500);
529  }
530  printf("Continue\n");
531  }
532 #endif
533 
534  DPRINT1("\n\n\n"
535  "NTVDM - Starting...\n"
536  "Command Line: '%s'\n"
537  "\n\n",
538  GetCommandLineA());
539 
540  /*
541  * Retrieve the full directory of the current running NTVDM instance.
542  * In case of failure, use the default SystemRoot\System32 path.
543  */
545  NtVdmPath[_countof(NtVdmPath) - 1] = UNICODE_NULL; // Ensure NULL-termination (see WinXP bug)
546 
549  if (Success)
550  {
551  /* Find the last path separator, remove it as well as the file name */
552  PWCHAR pch = wcsrchr(NtVdmPath, L'\\');
553  if (pch)
554  *pch = UNICODE_NULL;
555  }
556  else
557  {
558  /* We failed, use the default SystemRoot\System32 path */
561  if (!Success)
562  {
563  /* We failed again, try to do it ourselves */
564  NtVdmPathSize = (ULONG)wcslen(SharedUserData->NtSystemRoot) + _countof("\\System32") - 1;
566  if (Success)
567  {
570  L"%s\\System32",
571  SharedUserData->NtSystemRoot));
572  }
573  if (!Success)
574  {
575  wprintf(L"FATAL: Could not retrieve NTVDM path.\n");
576  goto Cleanup;
577  }
578  }
579  }
581 
582  /* Load the global VDM settings */
584 
585  /* Initialize the console */
586  if (!ConsoleInit())
587  {
588  wprintf(L"FATAL: A problem occurred when trying to initialize the console.\n");
589  goto Cleanup;
590  }
591 
592  /* Initialize the emulator */
594  {
595  wprintf(L"FATAL: Failed to initialize the emulator.\n");
596  goto Cleanup;
597  }
598 
599  /* Initialize the system BIOS and option ROMs */
602  {
603  wprintf(L"FATAL: Failed to initialize the VDM BIOS.\n");
604  goto Cleanup;
605  }
606 
607  /* Let's go! Start simulation */
608  CpuSimulate();
609 
610  /* Quit the VDM */
611 Cleanup:
612  VdmShutdown(TRUE);
613  return 0;
614 }
BOOL WINAPI IsDebuggerPresent(VOID)
Definition: debugger.c:615
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
static int argc
Definition: ServiceArgs.c:12
INT NtVdmArgc
Definition: ntvdm.c:31
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOLEAN ConsoleInit(void)
Definition: hardware.c:924
#define TRUE
Definition: types.h:120
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
uint16_t * PWCHAR
Definition: typedefs.h:56
WCHAR NtVdmPath[MAX_PATH]
Definition: ntvdm.c:35
#define wprintf(...)
Definition: whoami.c:18
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
ANSI_STRING RomFiles
Definition: ntvdm.h:87
#define pch(ap)
Definition: match.c:418
VOID CpuSimulate(VOID)
Definition: cpu.c:167
static BOOL LoadGlobalSettings(IN PNTVDM_SETTINGS Settings)
Definition: ntvdm.c:254
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
VOID NTAPI DbgBreakPoint(VOID)
unsigned int BOOL
Definition: ntddk_ex.h:94
WCHAR ** NtVdmArgv
Definition: ntvdm.c:32
VOID VdmShutdown(BOOLEAN Immediate)
Definition: ntvdm.c:317
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define printf
Definition: freeldr.h:94
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
Definition: emulator.c:510
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define _countof(array)
Definition: sndvol32.h:68
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2004
#define SharedUserData
ANSI_STRING BiosFileName
Definition: ntvdm.h:86
#define wcsrchr
Definition: compat.h:16
static const WCHAR Cleanup[]
Definition: register.c:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
ULONG NtVdmPathSize
Definition: ntvdm.c:36
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define DPRINT1
Definition: precomp.h:8
static HANDLE ConsoleOutput
Definition: console.c:17
BOOLEAN BiosInitialize(IN LPCSTR BiosFileName, IN LPCSTR RomFiles OPTIONAL)
Definition: bios.c:60
unsigned int ULONG
Definition: retypes.h:1
NTVDM_SETTINGS GlobalSettings
Definition: ntvdm.c:28
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Variable Documentation

◆ GlobalSettings

◆ NtVdmArgc

INT NtVdmArgc

Definition at line 31 of file ntvdm.c.

Referenced by DosStart(), and wmain().

◆ NtVdmArgv

WCHAR** NtVdmArgv

Definition at line 32 of file ntvdm.c.

Referenced by DosStart(), and wmain().

◆ NtVdmConfigurationTable

RTL_QUERY_REGISTRY_TABLE NtVdmConfigurationTable[]
static

Definition at line 167 of file ntvdm.c.

Referenced by LoadGlobalSettings().

◆ NtVdmPath

WCHAR NtVdmPath[MAX_PATH]

Definition at line 35 of file ntvdm.c.

Referenced by CmosInitialize(), and wmain().

◆ NtVdmPathSize

ULONG NtVdmPathSize

Definition at line 36 of file ntvdm.c.

Referenced by wmain().