ReactOS 0.4.15-dev-5667-ged97270
handle.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS ConSrvInheritHandlesTable (IN PCONSOLE_PROCESS_DATA SourceProcessData, IN PCONSOLE_PROCESS_DATA TargetProcessData)
 
VOID ConSrvFreeHandlesTable (IN PCONSOLE_PROCESS_DATA ProcessData)
 
VOID ConSrvInitObject (IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
 
NTSTATUS ConSrvInsertObject (IN PCONSOLE_PROCESS_DATA ProcessData, OUT PHANDLE Handle, IN PCONSOLE_IO_OBJECT Object, IN ULONG Access, IN BOOLEAN Inheritable, IN ULONG ShareMode)
 
NTSTATUS ConSrvRemoveObject (IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle)
 
NTSTATUS ConSrvGetObject (IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle, OUT PCONSOLE_IO_OBJECT *Object, OUT PVOID *Entry OPTIONAL, IN ULONG Access, IN BOOLEAN LockConsole, IN CONSOLE_IO_OBJECT_TYPE Type)
 
VOID ConSrvReleaseObject (IN PCONSOLE_IO_OBJECT Object, IN BOOLEAN IsConsoleLocked)
 

Function Documentation

◆ ConSrvFreeHandlesTable()

VOID ConSrvFreeHandlesTable ( IN PCONSOLE_PROCESS_DATA  ProcessData)

Definition at line 172 of file handle.c.

173{
174 RtlEnterCriticalSection(&ProcessData->HandleTableLock);
175
176 if (ProcessData->HandleTable != NULL)
177 {
178 ULONG i;
179
180 /*
181 * ProcessData->ConsoleHandle is NULL (and the assertion fails) when
182 * ConSrvFreeHandlesTable is called in ConSrvConnect during the
183 * allocation of a new console.
184 */
185 // ASSERT(ProcessData->ConsoleHandle);
186 if (ProcessData->ConsoleHandle != NULL)
187 {
188 /* Close all the console handles */
189 for (i = 0; i < ProcessData->HandleTableSize; i++)
190 {
191 ConSrvCloseHandle(&ProcessData->HandleTable[i]);
192 }
193 }
194 /* Free the handles table memory */
195 ConsoleFreeHeap(ProcessData->HandleTable);
196 ProcessData->HandleTable = NULL;
197 }
198
199 ProcessData->HandleTableSize = 0;
200
201 RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
202}
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
uint32_t ULONG
Definition: typedefs.h:59
static VOID ConSrvCloseHandle(IN PCONSOLE_IO_HANDLE Handle)
Definition: handle.c:56
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15

Referenced by ConSrvAllocateConsole(), ConSrvInheritConsole(), ConSrvInitProcessHandles(), and ConSrvRemoveConsole().

◆ ConSrvGetObject()

NTSTATUS ConSrvGetObject ( IN PCONSOLE_PROCESS_DATA  ProcessData,
IN HANDLE  Handle,
OUT PCONSOLE_IO_OBJECT Object,
OUT PVOID *Entry  OPTIONAL,
IN ULONG  Access,
IN BOOLEAN  LockConsole,
IN CONSOLE_IO_OBJECT_TYPE  Type 
)

Definition at line 318 of file handle.c.

325{
326 // NTSTATUS Status;
328 PCONSOLE_IO_HANDLE HandleEntry = NULL;
329 PCONSOLE_IO_OBJECT ObjectEntry = NULL;
330 // PCONSRV_CONSOLE ObjectConsole;
331
332 ASSERT(Object);
333 if (Entry) *Entry = NULL;
334
335 DPRINT("ConSrvGetObject -- Object: 0x%x, Handle: 0x%x\n", Object, Handle);
336
337 RtlEnterCriticalSection(&ProcessData->HandleTableLock);
338
339 if ( IsConsoleHandle(Handle) &&
340 Index < ProcessData->HandleTableSize )
341 {
342 HandleEntry = &ProcessData->HandleTable[Index];
343 ObjectEntry = HandleEntry->Object;
344 }
345
346 if ( HandleEntry == NULL ||
347 ObjectEntry == NULL ||
348 (HandleEntry->Access & Access) == 0 ||
349 /*(Type != 0 && ObjectEntry->Type != Type)*/
350 (Type != 0 && (ObjectEntry->Type & Type) == 0) )
351 {
352 DPRINT("ConSrvGetObject -- Invalid handle 0x%x of type %lu with access %lu ; retrieved object 0x%x (handle 0x%x) of type %lu with access %lu\n",
353 Handle, Type, Access, ObjectEntry, HandleEntry, (ObjectEntry ? ObjectEntry->Type : 0), (HandleEntry ? HandleEntry->Access : 0));
354
355 RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
357 }
358
359 RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
360
361 // Status = ConSrvGetConsole(ProcessData, &ObjectConsole, LockConsole);
362 // if (NT_SUCCESS(Status))
363 if (ConDrvValidateConsoleUnsafe(ObjectEntry->Console, CONSOLE_RUNNING, LockConsole))
364 {
365 _InterlockedIncrement(&ObjectEntry->Console->ReferenceCount);
366
367 /* Return the objects to the caller */
368 *Object = ObjectEntry;
369 if (Entry) *Entry = HandleEntry;
370
371 // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
372 return STATUS_SUCCESS;
373 }
374 else
375 {
376 // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
378 }
379}
Type
Definition: Type.h:7
#define HandleToULong(h)
Definition: basetsd.h:95
ULONG Handle
Definition: gdb_input.c:15
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define IsConsoleHandle(h)
Definition: console.h:14
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:83
PCONSOLE_IO_OBJECT Object
Definition: handle.c:25
struct _CONSOLE * Console
Definition: conio.h:36
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:34
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ WDFCOLLECTION _In_ ULONG Index
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:36
@ CONSOLE_RUNNING
Definition: conio.h:283

Referenced by CON_API().

◆ ConSrvInheritHandlesTable()

NTSTATUS ConSrvInheritHandlesTable ( IN PCONSOLE_PROCESS_DATA  SourceProcessData,
IN PCONSOLE_PROCESS_DATA  TargetProcessData 
)

Definition at line 120 of file handle.c.

122{
124 ULONG i, j;
125
126 RtlEnterCriticalSection(&SourceProcessData->HandleTableLock);
127
128 /* Inherit a handles table only if there is no already */
129 if (TargetProcessData->HandleTable != NULL /* || TargetProcessData->HandleTableSize != 0 */)
130 {
132 goto Quit;
133 }
134
135 /* Allocate a new handle table for the child process */
136 TargetProcessData->HandleTable = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
137 SourceProcessData->HandleTableSize
138 * sizeof(CONSOLE_IO_HANDLE));
139 if (TargetProcessData->HandleTable == NULL)
140 {
142 goto Quit;
143 }
144
145 TargetProcessData->HandleTableSize = SourceProcessData->HandleTableSize;
146
147 /*
148 * Parse the parent process' handles table and, for each handle,
149 * do a copy of it and reference it, if the handle is inheritable.
150 */
151 for (i = 0, j = 0; i < SourceProcessData->HandleTableSize; i++)
152 {
153 if (SourceProcessData->HandleTable[i].Object != NULL &&
154 SourceProcessData->HandleTable[i].Inheritable)
155 {
156 /*
157 * Copy the handle data and increment the reference count of the
158 * pointed object (via the call to ConSrvCreateHandleEntry == AdjustHandleCounts).
159 */
160 TargetProcessData->HandleTable[j] = SourceProcessData->HandleTable[i];
161 AdjustHandleCounts(&TargetProcessData->HandleTable[j], +1);
162 ++j;
163 }
164 }
165
166Quit:
167 RtlLeaveCriticalSection(&SourceProcessData->HandleTableLock);
168 return Status;
169}
LONG NTSTATUS
Definition: precomp.h:26
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static LONG AdjustHandleCounts(IN PCONSOLE_IO_HANDLE Handle, IN LONG Change)
Definition: handle.c:35
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14

Referenced by ConSrvNewProcess().

◆ ConSrvInitObject()

VOID ConSrvInitObject ( IN OUT PCONSOLE_IO_OBJECT  Object,
IN CONSOLE_IO_OBJECT_TYPE  Type,
IN PCONSOLE  Console 
)

Definition at line 211 of file handle.c.

214{
215 ASSERT(Object);
216 // if (!Object) return;
217
218 Object->Type = Type;
219 Object->Console = Console;
220 Object->ReferenceCount = 0;
221
222 Object->AccessRead = Object->AccessWrite = 0;
223 Object->ExclusiveRead = Object->ExclusiveWrite = 0;
224}
CConsole Console

Referenced by ConDrvInitInputBuffer(), and CONSOLE_SCREEN_BUFFER_Initialize().

◆ ConSrvInsertObject()

NTSTATUS ConSrvInsertObject ( IN PCONSOLE_PROCESS_DATA  ProcessData,
OUT PHANDLE  Handle,
IN PCONSOLE_IO_OBJECT  Object,
IN ULONG  Access,
IN BOOLEAN  Inheritable,
IN ULONG  ShareMode 
)

Definition at line 227 of file handle.c.

233{
234#define IO_HANDLES_INCREMENT 2 * 3
235
236 ULONG i = 0;
237 PCONSOLE_IO_HANDLE Block;
238
239 // NOTE: Commented out because calling code always lock HandleTableLock before.
240 // RtlEnterCriticalSection(&ProcessData->HandleTableLock);
241
242 ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
243 (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) );
244
245 if (ProcessData->HandleTable)
246 {
247 for (i = 0; i < ProcessData->HandleTableSize; i++)
248 {
249 if (ProcessData->HandleTable[i].Object == NULL)
250 break;
251 }
252 }
253
254 if (i >= ProcessData->HandleTableSize)
255 {
256 /* Allocate a new handles table */
258 (ProcessData->HandleTableSize +
260 if (Block == NULL)
261 {
262 // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
263 return STATUS_UNSUCCESSFUL;
264 }
265
266 /* If we previously had a handles table, free it and use the new one */
267 if (ProcessData->HandleTable)
268 {
269 /* Copy the handles from the old table to the new one */
270 RtlCopyMemory(Block,
271 ProcessData->HandleTable,
272 ProcessData->HandleTableSize * sizeof(CONSOLE_IO_HANDLE));
273 ConsoleFreeHeap(ProcessData->HandleTable);
274 }
275 ProcessData->HandleTable = Block;
276 ProcessData->HandleTableSize += IO_HANDLES_INCREMENT;
277 }
278
279 ProcessData->HandleTable[i].Object = Object;
280 ProcessData->HandleTable[i].Access = Access;
281 ProcessData->HandleTable[i].Inheritable = Inheritable;
282 ProcessData->HandleTable[i].ShareMode = ShareMode;
283 AdjustHandleCounts(&ProcessData->HandleTable[i], +1);
284 *Handle = ULongToHandle((i << 2) | 0x3);
285
286 // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
287
288 return STATUS_SUCCESS;
289}
#define ULongToHandle(h)
Definition: basetsd.h:81
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IO_HANDLES_INCREMENT

Referenced by CON_API(), and ConSrvInitProcessHandles().

◆ ConSrvReleaseObject()

VOID ConSrvReleaseObject ( IN PCONSOLE_IO_OBJECT  Object,
IN BOOLEAN  IsConsoleLocked 
)

Definition at line 382 of file handle.c.

384{
385 PCONSRV_CONSOLE ObjectConsole = (PCONSRV_CONSOLE)Object->Console;
386 ConSrvReleaseConsole(ObjectConsole, IsConsoleLocked);
387}
struct _CONSRV_CONSOLE * PCONSRV_CONSOLE
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:316

Referenced by CON_API().

◆ ConSrvRemoveObject()

NTSTATUS ConSrvRemoveObject ( IN PCONSOLE_PROCESS_DATA  ProcessData,
IN HANDLE  Handle 
)

Definition at line 292 of file handle.c.

294{
296
297 RtlEnterCriticalSection(&ProcessData->HandleTableLock);
298
299 ASSERT(ProcessData->HandleTable);
300 // ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
301 // (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) );
302
303 if (Index >= ProcessData->HandleTableSize ||
304 ProcessData->HandleTable[Index].Object == NULL)
305 {
306 RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
308 }
309
310 ASSERT(ProcessData->ConsoleHandle);
311 ConSrvCloseHandle(&ProcessData->HandleTable[Index]);
312
313 RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
314 return STATUS_SUCCESS;
315}

Referenced by CON_API().