xref: /reactos/win32ss/user/winsrv/consrv/subsysreg.c (revision 8a978a17)
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 /* API_NUMBER: ConsolepRegisterVDM */
23 CON_API(SrvRegisterConsoleVDM,
24         CONSOLE_REGISTERVDM, RegisterVDMRequest)
25 {
26     NTSTATUS Status;
27 
28     DPRINT1("SrvRegisterConsoleVDM(%d)\n", RegisterVDMRequest->RegisterFlags);
29 
30     if (RegisterVDMRequest->RegisterFlags != 0)
31     {
32         LARGE_INTEGER SectionSize;
33         SIZE_T Size, ViewSize = 0;
34         HANDLE ProcessHandle;
35 
36         /*
37          * Remember the handle to the process so that we can close or unmap
38          * correctly the allocated resources when the client releases the
39          * screen buffer.
40          */
41         ProcessHandle = CsrGetClientThread()->Process->ProcessHandle;
42         Console->VDMClientProcess = ProcessHandle;
43 
44         Console->VDMBufferSize = RegisterVDMRequest->VDMBufferSize;
45 
46         Size = Console->VDMBufferSize.X * Console->VDMBufferSize.Y
47                                         * sizeof(CHAR_CELL);
48 
49         /*
50          * Create a memory section for the VDM buffer, to share with the client.
51          */
52         SectionSize.QuadPart = Size;
53         Status = NtCreateSection(&Console->VDMBufferSection,
54                                  SECTION_ALL_ACCESS,
55                                  NULL,
56                                  &SectionSize,
57                                  PAGE_READWRITE,
58                                  SEC_COMMIT,
59                                  NULL);
60         if (!NT_SUCCESS(Status))
61         {
62             DPRINT1("Error: Impossible to create a shared section, Status = 0x%08lx\n", Status);
63             return Status;
64         }
65 
66         /*
67          * Create a view for our needs.
68          */
69         ViewSize = 0;
70         Console->VDMBuffer = NULL;
71         Status = NtMapViewOfSection(Console->VDMBufferSection,
72                                     NtCurrentProcess(),
73                                     (PVOID*)&Console->VDMBuffer,
74                                     0,
75                                     0,
76                                     NULL,
77                                     &ViewSize,
78                                     ViewUnmap,
79                                     0,
80                                     PAGE_READWRITE);
81         if (!NT_SUCCESS(Status))
82         {
83             DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
84             NtClose(Console->VDMBufferSection);
85             return Status;
86         }
87 
88         /*
89          * Create a view for the client. We must keep a trace of it so that
90          * we can unmap it when the client releases the VDM buffer.
91          */
92         ViewSize = 0;
93         Console->ClientVDMBuffer = NULL;
94         Status = NtMapViewOfSection(Console->VDMBufferSection,
95                                     ProcessHandle,
96                                     (PVOID*)&Console->ClientVDMBuffer,
97                                     0,
98                                     0,
99                                     NULL,
100                                     &ViewSize,
101                                     ViewUnmap,
102                                     0,
103                                     PAGE_READWRITE);
104         if (!NT_SUCCESS(Status))
105         {
106             DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
107             NtUnmapViewOfSection(NtCurrentProcess(), Console->VDMBuffer);
108             NtClose(Console->VDMBufferSection);
109             return Status;
110         }
111 
112         // TODO: Duplicate the event handles.
113 
114         RegisterVDMRequest->VDMBuffer = Console->ClientVDMBuffer;
115 
116         return STATUS_SUCCESS;
117     }
118     else
119     {
120         /* RegisterFlags == 0 means we are unregistering the VDM */
121 
122         // TODO: Close the duplicated handles.
123 
124         if (Console->VDMBuffer)
125         {
126             /*
127              * Uninitialize the graphics screen buffer
128              * in the reverse way we initialized it.
129              */
130             NtUnmapViewOfSection(Console->VDMClientProcess, Console->ClientVDMBuffer);
131             NtUnmapViewOfSection(NtCurrentProcess(), Console->VDMBuffer);
132             NtClose(Console->VDMBufferSection);
133         }
134         Console->VDMBuffer = Console->ClientVDMBuffer = NULL;
135 
136         Console->VDMBufferSize.X = Console->VDMBufferSize.Y = 0;
137 
138         return STATUS_SUCCESS;
139     }
140 }
141 
142 /* API_NUMBER: ConsolepVDMOperation */
143 CSR_API(SrvVDMConsoleOperation)
144 {
145     DPRINT1("%s not yet implemented\n", __FUNCTION__);
146     return STATUS_NOT_IMPLEMENTED;
147 }
148 
149 
150 /*
151  * OS/2 Subsystem
152  */
153 
154 /* API_NUMBER: ConsolepRegisterOS2 */
155 CSR_API(SrvRegisterConsoleOS2)
156 {
157     DPRINT1("%s not yet implemented\n", __FUNCTION__);
158     return STATUS_NOT_IMPLEMENTED;
159 }
160 
161 /* API_NUMBER: ConsolepSetOS2OemFormat */
162 CSR_API(SrvSetConsoleOS2OemFormat)
163 {
164     DPRINT1("%s not yet implemented\n", __FUNCTION__);
165     return STATUS_NOT_IMPLEMENTED;
166 }
167 
168 
169 /*
170  * IME Subsystem
171  */
172 
173 /* API_NUMBER: ConsolepRegisterConsoleIME */
174 CSR_API(SrvRegisterConsoleIME)
175 {
176     DPRINT1("%s not yet implemented\n", __FUNCTION__);
177     return STATUS_NOT_IMPLEMENTED;
178 }
179 
180 /* API_NUMBER: ConsolepUnregisterConsoleIME */
181 CSR_API(SrvUnregisterConsoleIME)
182 {
183     DPRINT1("%s not yet implemented\n", __FUNCTION__);
184     return STATUS_NOT_IMPLEMENTED;
185 }
186 
187 /* EOF */
188