ReactOS  0.4.15-dev-449-g64abd9f
subsysreg.c
Go to the documentation of this file.
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 {
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;
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,
55  NULL,
56  &SectionSize,
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,
73  (PVOID*)&Console->VDMBuffer,
74  0,
75  0,
76  NULL,
77  &ViewSize,
78  ViewUnmap,
79  0,
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,
96  (PVOID*)&Console->ClientVDMBuffer,
97  0,
98  0,
99  NULL,
100  &ViewSize,
101  ViewUnmap,
102  0,
104  if (!NT_SUCCESS(Status))
105  {
106  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
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);
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 */
#define CsrGetClientThread()
Definition: csrsrv.h:77
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3373
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_COMMIT
Definition: mmtypes.h:99
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3554
smooth NULL
Definition: ftsmooth.c:416
CON_API(SrvRegisterConsoleVDM, CONSOLE_REGISTERVDM, RegisterVDMRequest)
Definition: subsysreg.c:23
CSR_API(SrvVDMConsoleOperation)
Definition: subsysreg.c:143
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
CConsole Console
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
struct _CHAR_CELL CHAR_CELL
LONGLONG QuadPart
Definition: typedefs.h:113
#define PAGE_READWRITE
Definition: nt_native.h:1304