ReactOS  0.4.13-dev-544-gede3fdd
handle.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

◆ 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 401 of file handle.c.

408 {
409  // NTSTATUS Status;
411  PCONSOLE_IO_HANDLE HandleEntry = NULL;
412  PCONSOLE_IO_OBJECT ObjectEntry = NULL;
413  // PCONSOLE ObjectConsole;
414 
415  ASSERT(Object);
416  if (Entry) *Entry = NULL;
417 
418  DPRINT("ConSrvGetObject -- Object: 0x%x, Handle: 0x%x\n", Object, Handle);
419 
420  RtlEnterCriticalSection(&ProcessData->HandleTableLock);
421 
422  if ( IsConsoleHandle(Handle) &&
423  Index < ProcessData->HandleTableSize )
424  {
425  HandleEntry = &ProcessData->HandleTable[Index];
426  ObjectEntry = HandleEntry->Object;
427  }
428 
429  if ( HandleEntry == NULL ||
430  ObjectEntry == NULL ||
431  (HandleEntry->Access & Access) == 0 ||
432  /*(Type != 0 && ObjectEntry->Type != Type)*/
433  (Type != 0 && (ObjectEntry->Type & Type) == 0) )
434  {
435  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",
436  Handle, Type, Access, ObjectEntry, HandleEntry, (ObjectEntry ? ObjectEntry->Type : 0), (HandleEntry ? HandleEntry->Access : 0));
437 
438  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
439  return STATUS_INVALID_HANDLE;
440  }
441 
442  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
443 
444  // Status = ConSrvGetConsole(ProcessData, &ObjectConsole, LockConsole);
445  // if (NT_SUCCESS(Status))
446  if (ConDrvValidateConsoleUnsafe(ObjectEntry->Console, CONSOLE_RUNNING, LockConsole))
447  {
448  _InterlockedIncrement(&ObjectEntry->Console->ReferenceCount);
449 
450  /* Return the objects to the caller */
451  *Object = ObjectEntry;
452  if (Entry) *Entry = HandleEntry;
453 
454  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
455  return STATUS_SUCCESS;
456  }
457  else
458  {
459  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
460  return STATUS_INVALID_HANDLE;
461  }
462 }
struct _CONSOLE * Console
Definition: conio.h:52
Type
Definition: Type.h:6
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define HandleToULong(h)
Definition: basetsd.h:95
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
PCONSOLE_IO_OBJECT Object
Definition: handle.c:25
static const UCHAR Index[8]
Definition: usbohci.c:18
#define IsConsoleHandle(h)
Definition: console.h:14
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:120
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:50
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2777
base of all file and directory entries
Definition: entries.h:82

Referenced by CSR_API().

◆ ConSrvInitObject()

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

Definition at line 294 of file handle.c.

297 {
298  ASSERT(Object);
299  // if (!Object) return;
300 
301  Object->Type = Type;
302  Object->Console = Console;
303  Object->ReferenceCount = 0;
304 
305  Object->AccessRead = Object->AccessWrite = 0;
306  Object->ExclusiveRead = Object->ExclusiveWrite = 0;
307 }
Type
Definition: Type.h:6
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console

◆ 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 310 of file handle.c.

316 {
317 #define IO_HANDLES_INCREMENT 2 * 3
318 
319  ULONG i = 0;
320  PCONSOLE_IO_HANDLE Block;
321 
322  // NOTE: Commented out because calling code always lock HandleTableLock before.
323  // RtlEnterCriticalSection(&ProcessData->HandleTableLock);
324 
325  ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
326  (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) );
327 
328  if (ProcessData->HandleTable)
329  {
330  for (i = 0; i < ProcessData->HandleTableSize; i++)
331  {
332  if (ProcessData->HandleTable[i].Object == NULL)
333  break;
334  }
335  }
336 
337  if (i >= ProcessData->HandleTableSize)
338  {
339  /* Allocate a new handles table */
341  (ProcessData->HandleTableSize +
343  if (Block == NULL)
344  {
345  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
346  return STATUS_UNSUCCESSFUL;
347  }
348 
349  /* If we previously had a handles table, free it and use the new one */
350  if (ProcessData->HandleTable)
351  {
352  /* Copy the handles from the old table to the new one */
353  RtlCopyMemory(Block,
354  ProcessData->HandleTable,
355  ProcessData->HandleTableSize * sizeof(CONSOLE_IO_HANDLE));
356  ConsoleFreeHeap(ProcessData->HandleTable);
357  }
358  ProcessData->HandleTable = Block;
359  ProcessData->HandleTableSize += IO_HANDLES_INCREMENT;
360  }
361 
362  ProcessData->HandleTable[i].Object = Object;
363  ProcessData->HandleTable[i].Access = Access;
364  ProcessData->HandleTable[i].Inheritable = Inheritable;
365  ProcessData->HandleTable[i].ShareMode = ShareMode;
366  AdjustHandleCounts(&ProcessData->HandleTable[i], +1);
367  *Handle = ULongToHandle((i << 2) | 0x3);
368 
369  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
370 
371  return STATUS_SUCCESS;
372 }
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static LONG AdjustHandleCounts(IN PCONSOLE_IO_HANDLE Handle, IN LONG Change)
Definition: handle.c:35
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
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
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
static IUnknown Object
Definition: main.c:512
#define IO_HANDLES_INCREMENT
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by ConSrvInitHandlesTable(), and CSR_API().

◆ ConSrvReleaseObject()

VOID ConSrvReleaseObject ( IN PCONSOLE_IO_OBJECT  Object,
IN BOOLEAN  IsConsoleLocked 
)

Definition at line 465 of file handle.c.

467 {
468  ConSrvReleaseConsole(Object->Console, IsConsoleLocked);
469 }
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
static IUnknown Object
Definition: main.c:512

Referenced by CSR_API().

◆ ConSrvRemoveObject()

NTSTATUS ConSrvRemoveObject ( IN PCONSOLE_PROCESS_DATA  ProcessData,
IN HANDLE  Handle 
)

Definition at line 375 of file handle.c.

377 {
379 
380  RtlEnterCriticalSection(&ProcessData->HandleTableLock);
381 
382  ASSERT(ProcessData->HandleTable);
383  // ASSERT( (ProcessData->HandleTable == NULL && ProcessData->HandleTableSize == 0) ||
384  // (ProcessData->HandleTable != NULL && ProcessData->HandleTableSize != 0) );
385 
386  if (Index >= ProcessData->HandleTableSize ||
387  ProcessData->HandleTable[Index].Object == NULL)
388  {
389  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
390  return STATUS_INVALID_HANDLE;
391  }
392 
393  ASSERT(ProcessData->ConsoleHandle);
394  ConSrvCloseHandle(&ProcessData->HandleTable[Index]);
395 
396  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
397  return STATUS_SUCCESS;
398 }
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define HandleToULong(h)
Definition: basetsd.h:95
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2777
static VOID ConSrvCloseHandle(IN PCONSOLE_IO_HANDLE Handle)
Definition: handle.c:56

Referenced by CSR_API().