Author: aandrejevic Date: Tue Apr 22 20:46:50 2014 New Revision: 62892
URL: http://svn.reactos.org/svn/reactos?rev=62892&view=rev Log: [NTVDM] Quit when ntvdm becomes the last process attached to the console.
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c branches/ntvdm/subsystems/ntvdm/ntvdm.h
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?r... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] Tue Apr 22 20:46:50 2014 @@ -34,6 +34,7 @@ static DWORD OrgConsoleInputMode, OrgConsoleOutputMode; static CONSOLE_CURSOR_INFO OrgConsoleCursorInfo; static CONSOLE_SCREEN_BUFFER_INFO OrgConsoleBufferInfo; +static HANDLE CommandThread = NULL;
static HMENU hConsoleMenu = NULL; static INT VdmMenuPos = -1; @@ -196,6 +197,11 @@ EmulatorInterrupt(0x23); break; } + case CTRL_LAST_CLOSE_EVENT: + { + if (CommandThread) TerminateThread(CommandThread, 0); + break; + } default: { /* Stop the VDM if the user logs out or closes the console */ @@ -278,6 +284,9 @@ { /* Set the handler routine */ SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); + + /* Enable the CTRL_LAST_CLOSE_EVENT */ + SetLastConsoleEventActive();
/* Get the input handle to the real console, and check for success */ ConsoleInput = CreateFileW(L"CONIN$", @@ -368,10 +377,8 @@ if (ConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleInput); }
-INT wmain(INT argc, WCHAR *argv[]) -{ -#ifndef STANDALONE - +DWORD WINAPI CommandThreadProc(LPVOID Parameter) +{ VDM_COMMAND_INFO CommandInfo; CHAR CmdLine[MAX_PATH]; CHAR AppName[MAX_PATH]; @@ -379,54 +386,7 @@ CHAR Desktop[MAX_PATH]; CHAR Title[MAX_PATH];
-#else - - CHAR CommandLine[DOS_CMDLINE_LENGTH]; - - if (argc == 2 && argv[1] != NULL) - { - WideCharToMultiByte(CP_ACP, 0, argv[1], -1, CommandLine, sizeof(CommandLine), NULL, NULL); - } - else - { - wprintf(L"\nReactOS Virtual DOS Machine\n\n" - L"Usage: NTVDM <executable>\n"); - return 0; - } - -#endif - - DPRINT1("\n\n\nNTVDM - Starting...\n\n\n"); - - /* Initialize the console */ - if (!ConsoleInit()) - { - wprintf(L"FATAL: A problem occurred when trying to initialize the console\n"); - goto Cleanup; - } - - /* Initialize the emulator */ - if (!EmulatorInitialize(ConsoleInput, ConsoleOutput)) - { - wprintf(L"FATAL: Failed to initialize the emulator\n"); - goto Cleanup; - } - - /* Initialize the system BIOS */ - if (!BiosInitialize(NULL)) - { - wprintf(L"FATAL: Failed to initialize the VDM BIOS.\n"); - goto Cleanup; - } - - /* Initialize the VDM DOS kernel */ - if (!DosInitialize(NULL)) - { - wprintf(L"FATAL: Failed to initialize the VDM DOS kernel.\n"); - goto Cleanup; - } - -#ifndef STANDALONE + UNREFERENCED_PARAMETER(Parameter);
while (TRUE) { @@ -454,7 +414,7 @@ if (!DosCreateProcess(AppName, 0)) { DisplayMessage(L"Could not start '%S'", AppName); - goto Cleanup; + break; }
/* Start simulation */ @@ -463,6 +423,74 @@ /* Perform another screen refresh */ VgaRefreshDisplay(); } + + return 0; +} + +INT wmain(INT argc, WCHAR *argv[]) +{ +#ifdef STANDALONE + + CHAR CommandLine[DOS_CMDLINE_LENGTH]; + + if (argc == 2 && argv[1] != NULL) + { + WideCharToMultiByte(CP_ACP, 0, argv[1], -1, CommandLine, sizeof(CommandLine), NULL, NULL); + } + else + { + wprintf(L"\nReactOS Virtual DOS Machine\n\n" + L"Usage: NTVDM <executable>\n"); + return 0; + } + +#endif + + DPRINT1("\n\n\nNTVDM - Starting...\n\n\n"); + + /* Initialize the console */ + if (!ConsoleInit()) + { + wprintf(L"FATAL: A problem occurred when trying to initialize the console\n"); + goto Cleanup; + } + + /* Initialize the emulator */ + if (!EmulatorInitialize(ConsoleInput, ConsoleOutput)) + { + wprintf(L"FATAL: Failed to initialize the emulator\n"); + goto Cleanup; + } + + /* Initialize the system BIOS */ + if (!BiosInitialize(NULL)) + { + wprintf(L"FATAL: Failed to initialize the VDM BIOS.\n"); + goto Cleanup; + } + + /* Initialize the VDM DOS kernel */ + if (!DosInitialize(NULL)) + { + wprintf(L"FATAL: Failed to initialize the VDM DOS kernel.\n"); + goto Cleanup; + } + +#ifndef STANDALONE + + /* Create the GetNextVDMCommand thread */ + CommandThread = CreateThread(NULL, 0, &CommandThreadProc, NULL, 0, NULL); + if (CommandThread == NULL) + { + wprintf(L"FATAL: Failed to create the command processing thread: %d\n", GetLastError()); + goto Cleanup; + } + + /* Wait for the command thread to exit */ + WaitForSingleObject(CommandThread, INFINITE); + + /* Close the thread handle */ + CloseHandle(CommandThread);
#else
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.h?r... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] Tue Apr 22 20:46:50 2014 @@ -29,6 +29,8 @@
#include <debug.h>
+DWORD WINAPI SetLastConsoleEventActive(VOID); + /* FUNCTIONS ******************************************************************/
VOID DisplayMessage(LPCWSTR Format, ...);