X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=subsystems%2Fwin%2Fbasesrv%2Fvdm.c;h=4227311610445270441f733cd77eaa0af4f6f9c7;hp=82e2d2480840beac68a4124d88e5ec0465cca7e6;hb=60dd86e7acd00d27121b394a8982fe55b23416c0;hpb=9b24de4f6459713526c066ff925192c4c0186f6a;ds=sidebyside diff --git a/subsystems/win/basesrv/vdm.c b/subsystems/win/basesrv/vdm.c index 82e2d248084..42273116104 100644 --- a/subsystems/win/basesrv/vdm.c +++ b/subsystems/win/basesrv/vdm.c @@ -209,8 +209,52 @@ CSR_API(BaseSrvIsFirstVDM) 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)