cc8d6ded65f6da710a0c60953751efe9a41ca966
[reactos.git] / subsystems / win / basesrv / vdm.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Base API Server DLL
4 * FILE: subsystems/win/basesrv/vdm.c
5 * PURPOSE: Virtual DOS Machines (VDM) Support
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 * Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include "basesrv.h"
13 #include "vdm.h"
14
15 #define NDEBUG
16 #include <debug.h>
17
18 /* GLOBALS ********************************************************************/
19
20 BOOLEAN FirstVDM = TRUE;
21 LIST_ENTRY VDMConsoleListHead;
22 RTL_CRITICAL_SECTION DosCriticalSection;
23
24 /* FUNCTIONS ******************************************************************/
25
26 NTSTATUS NTAPI BaseSrvGetConsoleRecord(HANDLE ConsoleHandle, PVDM_CONSOLE_RECORD *Record)
27 {
28 PLIST_ENTRY i;
29 PVDM_CONSOLE_RECORD CurrentRecord = NULL;
30
31 /* Search for a record that has the same console handle */
32 for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
33 {
34 CurrentRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);
35 if (CurrentRecord->ConsoleHandle == ConsoleHandle) break;
36 }
37
38 *Record = CurrentRecord;
39 return CurrentRecord ? STATUS_SUCCESS : STATUS_NOT_FOUND;
40 }
41
42 VOID NTAPI BaseInitializeVDM(VOID)
43 {
44 /* Initialize the list head */
45 InitializeListHead(&VDMConsoleListHead);
46
47 /* Initialize the critical section */
48 RtlInitializeCriticalSection(&DosCriticalSection);
49 }
50
51 /* PUBLIC SERVER APIS *********************************************************/
52
53 CSR_API(BaseSrvCheckVDM)
54 {
55 PBASE_CHECK_VDM CheckVdmRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CheckVDMRequest;
56
57 /* Validate the message buffers */
58 if (!CsrValidateMessageBuffer(ApiMessage,
59 (PVOID*)&CheckVdmRequest->CmdLine,
60 CheckVdmRequest->CmdLen,
61 sizeof(*CheckVdmRequest->CmdLine))
62 || !CsrValidateMessageBuffer(ApiMessage,
63 (PVOID*)&CheckVdmRequest->AppName,
64 CheckVdmRequest->AppLen,
65 sizeof(*CheckVdmRequest->AppName))
66 || !CsrValidateMessageBuffer(ApiMessage,
67 (PVOID*)&CheckVdmRequest->PifFile,
68 CheckVdmRequest->PifLen,
69 sizeof(*CheckVdmRequest->PifFile))
70 || !CsrValidateMessageBuffer(ApiMessage,
71 (PVOID*)&CheckVdmRequest->CurDirectory,
72 CheckVdmRequest->CurDirectoryLen,
73 sizeof(*CheckVdmRequest->CurDirectory))
74 || !CsrValidateMessageBuffer(ApiMessage,
75 (PVOID*)&CheckVdmRequest->Desktop,
76 CheckVdmRequest->DesktopLen,
77 sizeof(*CheckVdmRequest->Desktop))
78 || !CsrValidateMessageBuffer(ApiMessage,
79 (PVOID*)&CheckVdmRequest->Title,
80 CheckVdmRequest->TitleLen,
81 sizeof(*CheckVdmRequest->Title))
82 || !CsrValidateMessageBuffer(ApiMessage,
83 (PVOID*)&CheckVdmRequest->Reserved,
84 CheckVdmRequest->ReservedLen,
85 sizeof(*CheckVdmRequest->Reserved)))
86 {
87 return STATUS_INVALID_PARAMETER;
88 }
89
90 // TODO: NOT IMPLEMENTED
91 return STATUS_NOT_IMPLEMENTED;
92 }
93
94 CSR_API(BaseSrvUpdateVDMEntry)
95 {
96 DPRINT1("%s not yet implemented\n", __FUNCTION__);
97 return STATUS_NOT_IMPLEMENTED;
98 }
99
100 CSR_API(BaseSrvGetNextVDMCommand)
101 {
102 DPRINT1("%s not yet implemented\n", __FUNCTION__);
103 return STATUS_NOT_IMPLEMENTED;
104 }
105
106 CSR_API(BaseSrvExitVDM)
107 {
108 DPRINT1("%s not yet implemented\n", __FUNCTION__);
109 return STATUS_NOT_IMPLEMENTED;
110 }
111
112 CSR_API(BaseSrvIsFirstVDM)
113 {
114 PBASE_IS_FIRST_VDM IsFirstVDMRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.IsFirstVDMRequest;
115
116 /* Return the result */
117 IsFirstVDMRequest->FirstVDM = FirstVDM;
118
119 /* Clear the first VDM flag */
120 FirstVDM = FALSE;
121
122 return STATUS_SUCCESS;
123 }
124
125 CSR_API(BaseSrvGetVDMExitCode)
126 {
127 DPRINT1("%s not yet implemented\n", __FUNCTION__);
128 return STATUS_NOT_IMPLEMENTED;
129 }
130
131 CSR_API(BaseSrvSetReenterCount)
132 {
133 DPRINT1("%s not yet implemented\n", __FUNCTION__);
134 return STATUS_NOT_IMPLEMENTED;
135 }
136
137 CSR_API(BaseSrvSetVDMCurDirs)
138 {
139 DPRINT1("%s not yet implemented\n", __FUNCTION__);
140 return STATUS_NOT_IMPLEMENTED;
141 }
142
143 CSR_API(BaseSrvGetVDMCurDirs)
144 {
145 NTSTATUS Status;
146 PBASE_GETSET_VDM_CURDIRS VDMCurrentDirsRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.VDMCurrentDirsRequest;
147 PVDM_CONSOLE_RECORD ConsoleRecord;
148
149 /* Validate the output buffer */
150 if (!CsrValidateMessageBuffer(ApiMessage,
151 (PVOID*)&VDMCurrentDirsRequest->lpszzCurDirs,
152 VDMCurrentDirsRequest->cchCurDirs,
153 sizeof(*VDMCurrentDirsRequest->lpszzCurDirs)))
154 {
155 return STATUS_INVALID_PARAMETER;
156 }
157
158 /* Enter the critical section */
159 RtlEnterCriticalSection(&DosCriticalSection);
160
161 /* Find the console record */
162 Status = BaseSrvGetConsoleRecord(VDMCurrentDirsRequest->ConsoleHandle, &ConsoleRecord);
163 if (!NT_SUCCESS(Status)) goto Cleanup;
164
165 /* Check if the buffer is large enough */
166 if (VDMCurrentDirsRequest->cchCurDirs < ConsoleRecord->CurDirsLength)
167 {
168 Status = STATUS_BUFFER_TOO_SMALL;
169 goto Cleanup;
170 }
171
172 /* Copy the data */
173 RtlMoveMemory(VDMCurrentDirsRequest->lpszzCurDirs,
174 ConsoleRecord->CurrentDirs,
175 ConsoleRecord->CurDirsLength);
176
177 Cleanup:
178 /* Leave the critical section */
179 RtlLeaveCriticalSection(&DosCriticalSection);
180
181 return Status;
182 }
183
184 CSR_API(BaseSrvBatNotification)
185 {
186 DPRINT1("%s not yet implemented\n", __FUNCTION__);
187 return STATUS_NOT_IMPLEMENTED;
188 }
189
190 CSR_API(BaseSrvRegisterWowExec)
191 {
192 DPRINT1("%s not yet implemented\n", __FUNCTION__);
193 return STATUS_NOT_IMPLEMENTED;
194 }
195
196 CSR_API(BaseSrvRefreshIniFileMapping)
197 {
198 DPRINT1("%s not yet implemented\n", __FUNCTION__);
199 return STATUS_NOT_IMPLEMENTED;
200 }
201
202 /* EOF */