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>
10 /* INCLUDES *******************************************************************/
18 /* GLOBALS ********************************************************************/
20 BOOLEAN FirstVDM
= TRUE
;
21 LIST_ENTRY VDMConsoleListHead
;
22 RTL_CRITICAL_SECTION DosCriticalSection
;
24 /* FUNCTIONS ******************************************************************/
26 NTSTATUS NTAPI
BaseSrvGetConsoleRecord(HANDLE ConsoleHandle
, PVDM_CONSOLE_RECORD
*Record
)
29 PVDM_CONSOLE_RECORD CurrentRecord
= NULL
;
31 /* Search for a record that has the same console handle */
32 for (i
= VDMConsoleListHead
.Flink
; i
!= &VDMConsoleListHead
; i
= i
->Flink
)
34 CurrentRecord
= CONTAINING_RECORD(i
, VDM_CONSOLE_RECORD
, Entry
);
35 if (CurrentRecord
->ConsoleHandle
== ConsoleHandle
) break;
38 *Record
= CurrentRecord
;
39 return CurrentRecord
? STATUS_SUCCESS
: STATUS_NOT_FOUND
;
42 VOID NTAPI
BaseInitializeVDM(VOID
)
44 /* Initialize the list head */
45 InitializeListHead(&VDMConsoleListHead
);
47 /* Initialize the critical section */
48 RtlInitializeCriticalSection(&DosCriticalSection
);
51 /* PUBLIC SERVER APIS *********************************************************/
53 CSR_API(BaseSrvCheckVDM
)
55 PBASE_CHECK_VDM CheckVdmRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.CheckVDMRequest
;
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
)))
87 return STATUS_INVALID_PARAMETER
;
90 // TODO: NOT IMPLEMENTED
91 return STATUS_NOT_IMPLEMENTED
;
94 CSR_API(BaseSrvUpdateVDMEntry
)
96 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
97 return STATUS_NOT_IMPLEMENTED
;
100 CSR_API(BaseSrvGetNextVDMCommand
)
102 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
103 return STATUS_NOT_IMPLEMENTED
;
106 CSR_API(BaseSrvExitVDM
)
108 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
109 return STATUS_NOT_IMPLEMENTED
;
112 CSR_API(BaseSrvIsFirstVDM
)
114 PBASE_IS_FIRST_VDM IsFirstVDMRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.IsFirstVDMRequest
;
116 /* Return the result */
117 IsFirstVDMRequest
->FirstVDM
= FirstVDM
;
119 /* Clear the first VDM flag */
122 return STATUS_SUCCESS
;
125 CSR_API(BaseSrvGetVDMExitCode
)
127 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
128 return STATUS_NOT_IMPLEMENTED
;
131 CSR_API(BaseSrvSetReenterCount
)
133 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
134 return STATUS_NOT_IMPLEMENTED
;
137 CSR_API(BaseSrvSetVDMCurDirs
)
140 PBASE_GETSET_VDM_CURDIRS VDMCurrentDirsRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.VDMCurrentDirsRequest
;
141 PVDM_CONSOLE_RECORD ConsoleRecord
;
144 /* Validate the input buffer */
145 if (!CsrValidateMessageBuffer(ApiMessage
,
146 (PVOID
*)&VDMCurrentDirsRequest
->lpszzCurDirs
,
147 VDMCurrentDirsRequest
->cchCurDirs
,
148 sizeof(*VDMCurrentDirsRequest
->lpszzCurDirs
)))
150 return STATUS_INVALID_PARAMETER
;
153 /* Enter the critical section */
154 RtlEnterCriticalSection(&DosCriticalSection
);
156 /* Find the console record */
157 Status
= BaseSrvGetConsoleRecord(VDMCurrentDirsRequest
->ConsoleHandle
, &ConsoleRecord
);
158 if (!NT_SUCCESS(Status
)) goto Cleanup
;
160 if (ConsoleRecord
->CurrentDirs
== NULL
)
162 /* Allocate memory for the current directory information */
163 Buffer
= RtlAllocateHeap(BaseSrvHeap
,
165 VDMCurrentDirsRequest
->cchCurDirs
);
169 /* Resize the amount of allocated memory */
170 Buffer
= RtlReAllocateHeap(BaseSrvHeap
,
172 ConsoleRecord
->CurrentDirs
,
173 VDMCurrentDirsRequest
->cchCurDirs
);
178 /* Allocation failed */
179 Status
= STATUS_NO_MEMORY
;
183 /* Update the console record */
184 ConsoleRecord
->CurrentDirs
= Buffer
;
185 ConsoleRecord
->CurDirsLength
= VDMCurrentDirsRequest
->cchCurDirs
;
188 RtlMoveMemory(ConsoleRecord
->CurrentDirs
,
189 VDMCurrentDirsRequest
->lpszzCurDirs
,
190 VDMCurrentDirsRequest
->cchCurDirs
);
193 /* Leave the critical section */
194 RtlLeaveCriticalSection(&DosCriticalSection
);
199 CSR_API(BaseSrvGetVDMCurDirs
)
202 PBASE_GETSET_VDM_CURDIRS VDMCurrentDirsRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.VDMCurrentDirsRequest
;
203 PVDM_CONSOLE_RECORD ConsoleRecord
;
205 /* Validate the output buffer */
206 if (!CsrValidateMessageBuffer(ApiMessage
,
207 (PVOID
*)&VDMCurrentDirsRequest
->lpszzCurDirs
,
208 VDMCurrentDirsRequest
->cchCurDirs
,
209 sizeof(*VDMCurrentDirsRequest
->lpszzCurDirs
)))
211 return STATUS_INVALID_PARAMETER
;
214 /* Enter the critical section */
215 RtlEnterCriticalSection(&DosCriticalSection
);
217 /* Find the console record */
218 Status
= BaseSrvGetConsoleRecord(VDMCurrentDirsRequest
->ConsoleHandle
, &ConsoleRecord
);
219 if (!NT_SUCCESS(Status
)) goto Cleanup
;
221 /* Return the actual size of the current directory information */
222 VDMCurrentDirsRequest
->cchCurDirs
= ConsoleRecord
->CurDirsLength
;
224 /* Check if the buffer is large enough */
225 if (VDMCurrentDirsRequest
->cchCurDirs
< ConsoleRecord
->CurDirsLength
)
227 Status
= STATUS_BUFFER_TOO_SMALL
;
232 RtlMoveMemory(VDMCurrentDirsRequest
->lpszzCurDirs
,
233 ConsoleRecord
->CurrentDirs
,
234 ConsoleRecord
->CurDirsLength
);
237 /* Leave the critical section */
238 RtlLeaveCriticalSection(&DosCriticalSection
);
243 CSR_API(BaseSrvBatNotification
)
245 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
246 return STATUS_NOT_IMPLEMENTED
;
249 CSR_API(BaseSrvRegisterWowExec
)
251 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
252 return STATUS_NOT_IMPLEMENTED
;
255 CSR_API(BaseSrvRefreshIniFileMapping
)
257 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
258 return STATUS_NOT_IMPLEMENTED
;