Sync with trunk r63878.
[reactos.git] / win32ss / user / winsrv / consrv / subsysreg.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/subsysreg.c
5 * PURPOSE: Registration APIs for VDM, OS2 and IME subsystems
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "consrv.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* PUBLIC SERVER APIS *********************************************************/
17
18 /*
19 * VDM Subsystem
20 */
21
22 CSR_API(SrvRegisterConsoleVDM)
23 {
24 NTSTATUS Status;
25 PCONSOLE_REGISTERVDM RegisterVDMRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.RegisterVDMRequest;
26 PCONSOLE Console;
27
28 DPRINT1("SrvRegisterConsoleVDM(%d)\n", RegisterVDMRequest->RegisterFlags);
29
30 Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
31 &Console, TRUE);
32 if (!NT_SUCCESS(Status))
33 {
34 DPRINT1("Can't get console\n");
35 return Status;
36 }
37
38 if (RegisterVDMRequest->RegisterFlags != 0)
39 {
40 LARGE_INTEGER SectionSize;
41 ULONG Size, ViewSize = 0;
42 HANDLE ProcessHandle;
43
44 /*
45 * Remember the handle to the process so that we can close or unmap
46 * correctly the allocated resources when the client releases the
47 * screen buffer.
48 */
49 ProcessHandle = CsrGetClientThread()->Process->ProcessHandle;
50 Console->VDMClientProcess = ProcessHandle;
51
52 Console->VDMBufferSize = RegisterVDMRequest->VDMBufferSize;
53
54 Size = Console->VDMBufferSize.X * Console->VDMBufferSize.Y
55 * sizeof(CHAR_CELL);
56
57 /*
58 * Create a memory section for the VDM buffer, to share with the client.
59 */
60 SectionSize.QuadPart = Size;
61 Status = NtCreateSection(&Console->VDMBufferSection,
62 SECTION_ALL_ACCESS,
63 NULL,
64 &SectionSize,
65 PAGE_READWRITE,
66 SEC_COMMIT,
67 NULL);
68 if (!NT_SUCCESS(Status))
69 {
70 DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
71 goto Quit;
72 }
73
74 /*
75 * Create a view for our needs.
76 */
77 ViewSize = 0;
78 Console->VDMBuffer = NULL;
79 Status = NtMapViewOfSection(Console->VDMBufferSection,
80 NtCurrentProcess(),
81 (PVOID*)&Console->VDMBuffer,
82 0,
83 0,
84 NULL,
85 &ViewSize,
86 ViewUnmap,
87 0,
88 PAGE_READWRITE);
89 if (!NT_SUCCESS(Status))
90 {
91 DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
92 NtClose(Console->VDMBufferSection);
93 goto Quit;
94 }
95
96 /*
97 * Create a view for the client. We must keep a trace of it so that
98 * we can unmap it when the client releases the VDM buffer.
99 */
100 ViewSize = 0;
101 Console->ClientVDMBuffer = NULL;
102 Status = NtMapViewOfSection(Console->VDMBufferSection,
103 ProcessHandle,
104 (PVOID*)&Console->ClientVDMBuffer,
105 0,
106 0,
107 NULL,
108 &ViewSize,
109 ViewUnmap,
110 0,
111 PAGE_READWRITE);
112 if (!NT_SUCCESS(Status))
113 {
114 DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
115 NtUnmapViewOfSection(NtCurrentProcess(), Console->VDMBuffer);
116 NtClose(Console->VDMBufferSection);
117 goto Quit;
118 }
119
120 // TODO: Duplicate the event handles.
121
122 RegisterVDMRequest->VDMBuffer = Console->ClientVDMBuffer;
123
124 Status = STATUS_SUCCESS;
125 }
126 else
127 {
128 /* RegisterFlags == 0 means we are unregistering the VDM */
129
130 // TODO: Close the duplicated handles.
131
132 if (Console->VDMBuffer)
133 {
134 /*
135 * Uninitialize the graphics screen buffer
136 * in the reverse way we initialized it.
137 */
138 NtUnmapViewOfSection(Console->VDMClientProcess, Console->ClientVDMBuffer);
139 NtUnmapViewOfSection(NtCurrentProcess(), Console->VDMBuffer);
140 NtClose(Console->VDMBufferSection);
141 }
142 Console->VDMBuffer = Console->ClientVDMBuffer = NULL;
143
144 Console->VDMBufferSize.X = Console->VDMBufferSize.Y = 0;
145 }
146
147 Quit:
148 ConSrvReleaseConsole(Console, TRUE);
149 return Status;
150 }
151
152 CSR_API(SrvVDMConsoleOperation)
153 {
154 DPRINT1("%s not yet implemented\n", __FUNCTION__);
155 return STATUS_NOT_IMPLEMENTED;
156 }
157
158
159 /*
160 * OS/2 Subsystem
161 */
162
163 CSR_API(SrvRegisterConsoleOS2)
164 {
165 DPRINT1("%s not yet implemented\n", __FUNCTION__);
166 return STATUS_NOT_IMPLEMENTED;
167 }
168
169 CSR_API(SrvSetConsoleOS2OemFormat)
170 {
171 DPRINT1("%s not yet implemented\n", __FUNCTION__);
172 return STATUS_NOT_IMPLEMENTED;
173 }
174
175
176 /*
177 * IME Subsystem
178 */
179
180 CSR_API(SrvRegisterConsoleIME)
181 {
182 DPRINT1("%s not yet implemented\n", __FUNCTION__);
183 return STATUS_NOT_IMPLEMENTED;
184 }
185
186 CSR_API(SrvUnregisterConsoleIME)
187 {
188 DPRINT1("%s not yet implemented\n", __FUNCTION__);
189 return STATUS_NOT_IMPLEMENTED;
190 }
191
192 /* EOF */