BOOLEAN FirstVDM = TRUE;
LIST_ENTRY VDMConsoleListHead;
RTL_CRITICAL_SECTION DosCriticalSection;
+RTL_CRITICAL_SECTION WowCriticalSection;
/* FUNCTIONS ******************************************************************/
return CurrentRecord ? STATUS_SUCCESS : STATUS_NOT_FOUND;
}
+ULONG NTAPI GetNextDosSesId(VOID)
+{
+ ULONG SessionId;
+ PLIST_ENTRY i;
+ PVDM_CONSOLE_RECORD CurrentRecord = NULL;
+ BOOLEAN Found;
+
+ /* Search for an available session ID */
+ for (SessionId = 1; SessionId != 0; SessionId++)
+ {
+ Found = FALSE;
+
+ /* Check if the ID is already in use */
+ for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
+ {
+ CurrentRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);
+ if (CurrentRecord->SessionId == SessionId) Found = TRUE;
+ }
+
+ /* If not, we found one */
+ if (!Found) break;
+ }
+
+ ASSERT(SessionId != 0);
+
+ /* Return the session ID */
+ return SessionId;
+}
+
VOID NTAPI BaseInitializeVDM(VOID)
{
/* Initialize the list head */
/* Initialize the critical section */
RtlInitializeCriticalSection(&DosCriticalSection);
+ RtlInitializeCriticalSection(&WowCriticalSection);
}
/* PUBLIC SERVER APIS *********************************************************/
CSR_API(BaseSrvCheckVDM)
{
+ NTSTATUS Status;
PBASE_CHECK_VDM CheckVdmRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CheckVDMRequest;
+ PRTL_CRITICAL_SECTION CriticalSection = NULL;
+ PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
/* Validate the message buffers */
if (!CsrValidateMessageBuffer(ApiMessage,
return STATUS_INVALID_PARAMETER;
}
- // TODO: NOT IMPLEMENTED
- return STATUS_NOT_IMPLEMENTED;
+ CriticalSection = (CheckVdmRequest->BinaryType != BINARY_TYPE_SEPARATE_WOW)
+ ? &DosCriticalSection
+ : &WowCriticalSection;
+
+ /* Enter the critical section */
+ RtlEnterCriticalSection(CriticalSection);
+
+ /* Check if this is a DOS or WOW VDM */
+ if (CheckVdmRequest->BinaryType != BINARY_TYPE_SEPARATE_WOW)
+ {
+ /* Get the console record */
+ Status = BaseSrvGetConsoleRecord(CheckVdmRequest->ConsoleHandle,
+ &ConsoleRecord);
+
+ if (!NT_SUCCESS(Status))
+ {
+ /* Allocate a new console record */
+ ConsoleRecord = (PVDM_CONSOLE_RECORD)RtlAllocateHeap(BaseSrvHeap,
+ HEAP_ZERO_MEMORY,
+ sizeof(VDM_CONSOLE_RECORD));
+ if (ConsoleRecord == NULL)
+ {
+ Status = STATUS_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ /* Initialize the console record */
+ ConsoleRecord->ConsoleHandle = CheckVdmRequest->ConsoleHandle;
+ ConsoleRecord->CurrentDirs = NULL;
+ ConsoleRecord->CurDirsLength = 0;
+ ConsoleRecord->SessionId = GetNextDosSesId();
+ InitializeListHead(&ConsoleRecord->DosListHead);
+
+ /* Add the console record */
+ InsertTailList(&VDMConsoleListHead, &ConsoleRecord->Entry);
+ }
+
+ // TODO: NOT IMPLEMENTED
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+ }
+ else
+ {
+ // TODO: NOT IMPLEMENTED
+ UNIMPLEMENTED;
+ return STATUS_NOT_IMPLEMENTED;
+ }
+
+Cleanup:
+ /* Leave the critical section */
+ RtlLeaveCriticalSection(CriticalSection);
+
+ return Status;
}
CSR_API(BaseSrvUpdateVDMEntry)
CSR_API(BaseSrvGetVDMExitCode)
{
- DPRINT1("%s not yet implemented\n", __FUNCTION__);
- return STATUS_NOT_IMPLEMENTED;
+ NTSTATUS Status;
+ PBASE_GET_VDM_EXIT_CODE GetVDMExitCodeRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetVDMExitCodeRequest;
+ PLIST_ENTRY i = NULL;
+ PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
+ PVDM_DOS_RECORD DosRecord = NULL;
+
+ /* Enter the critical section */
+ RtlEnterCriticalSection(&DosCriticalSection);
+
+ /* Get the console record */
+ Status = BaseSrvGetConsoleRecord(GetVDMExitCodeRequest->ConsoleHandle, &ConsoleRecord);
+ if (!NT_SUCCESS(Status)) goto Cleanup;
+
+ /* Search for a DOS record that has the same parent process handle */
+ for (i = ConsoleRecord->DosListHead.Flink; i != &ConsoleRecord->DosListHead; i = i->Flink)
+ {
+ DosRecord = CONTAINING_RECORD(i, VDM_DOS_RECORD, Entry);
+ if (DosRecord->ParentProcess == GetVDMExitCodeRequest->hParent) break;
+ }
+
+ /* Check if no DOS record was found */
+ if (i == &ConsoleRecord->DosListHead)
+ {
+ Status = STATUS_NOT_FOUND;
+ goto Cleanup;
+ }
+
+ /* Check if this task is still running */
+ if (DosRecord->State == VDM_READY)
+ {
+ GetVDMExitCodeRequest->ExitCode = STATUS_PENDING;
+ goto Cleanup;
+ }
+
+ /* Return the exit code */
+ GetVDMExitCodeRequest->ExitCode = DosRecord->ExitCode;
+
+ /* Since this is a zombie task record, remove it */
+ RemoveEntryList(&DosRecord->Entry);
+ RtlFreeHeap(BaseSrvHeap, 0, DosRecord);
+
+Cleanup:
+ /* Leave the critical section */
+ RtlLeaveCriticalSection(&DosCriticalSection);
+
+ return Status;
}
CSR_API(BaseSrvSetReenterCount)
CSR_API(BaseSrvSetVDMCurDirs)
{
- DPRINT1("%s not yet implemented\n", __FUNCTION__);
- return STATUS_NOT_IMPLEMENTED;
+ NTSTATUS Status;
+ PBASE_GETSET_VDM_CURDIRS VDMCurrentDirsRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.VDMCurrentDirsRequest;
+ PVDM_CONSOLE_RECORD ConsoleRecord;
+ PCHAR Buffer = NULL;
+
+ /* Validate the input buffer */
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&VDMCurrentDirsRequest->lpszzCurDirs,
+ VDMCurrentDirsRequest->cchCurDirs,
+ sizeof(*VDMCurrentDirsRequest->lpszzCurDirs)))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* Enter the critical section */
+ RtlEnterCriticalSection(&DosCriticalSection);
+
+ /* Find the console record */
+ Status = BaseSrvGetConsoleRecord(VDMCurrentDirsRequest->ConsoleHandle, &ConsoleRecord);
+ if (!NT_SUCCESS(Status)) goto Cleanup;
+
+ if (ConsoleRecord->CurrentDirs == NULL)
+ {
+ /* Allocate memory for the current directory information */
+ Buffer = RtlAllocateHeap(BaseSrvHeap,
+ HEAP_ZERO_MEMORY,
+ VDMCurrentDirsRequest->cchCurDirs);
+ }
+ else
+ {
+ /* Resize the amount of allocated memory */
+ Buffer = RtlReAllocateHeap(BaseSrvHeap,
+ HEAP_ZERO_MEMORY,
+ ConsoleRecord->CurrentDirs,
+ VDMCurrentDirsRequest->cchCurDirs);
+ }
+
+ if (Buffer == NULL)
+ {
+ /* Allocation failed */
+ Status = STATUS_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ /* Update the console record */
+ ConsoleRecord->CurrentDirs = Buffer;
+ ConsoleRecord->CurDirsLength = VDMCurrentDirsRequest->cchCurDirs;
+
+ /* Copy the data */
+ RtlMoveMemory(ConsoleRecord->CurrentDirs,
+ VDMCurrentDirsRequest->lpszzCurDirs,
+ VDMCurrentDirsRequest->cchCurDirs);
+
+Cleanup:
+ /* Leave the critical section */
+ RtlLeaveCriticalSection(&DosCriticalSection);
+
+ return Status;
}
CSR_API(BaseSrvGetVDMCurDirs)
Status = BaseSrvGetConsoleRecord(VDMCurrentDirsRequest->ConsoleHandle, &ConsoleRecord);
if (!NT_SUCCESS(Status)) goto Cleanup;
+ /* Return the actual size of the current directory information */
+ VDMCurrentDirsRequest->cchCurDirs = ConsoleRecord->CurDirsLength;
+
/* Check if the buffer is large enough */
if (VDMCurrentDirsRequest->cchCurDirs < ConsoleRecord->CurDirsLength)
{