ReactOS  0.4.13-dev-687-g023794c
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 FASTCALL ConSrvInitObject (IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
 
NTSTATUS FASTCALL ConSrvInsertObject (PCONSOLE_PROCESS_DATA ProcessData, PHANDLE Handle, PCONSOLE_IO_OBJECT Object, DWORD Access, BOOL Inheritable, DWORD ShareMode)
 
NTSTATUS FASTCALL ConSrvRemoveObject (PCONSOLE_PROCESS_DATA ProcessData, HANDLE Handle)
 
NTSTATUS FASTCALL ConSrvGetObject (PCONSOLE_PROCESS_DATA ProcessData, HANDLE Handle, PCONSOLE_IO_OBJECT *Object, PVOID *Entry OPTIONAL, DWORD Access, BOOL LockConsole, CONSOLE_IO_OBJECT_TYPE Type)
 
VOID FASTCALL ConSrvReleaseObject (PCONSOLE_IO_OBJECT Object, BOOL IsConsoleLocked)
 

Function Documentation

◆ ConSrvGetObject()

NTSTATUS FASTCALL ConSrvGetObject ( PCONSOLE_PROCESS_DATA  ProcessData,
HANDLE  Handle,
PCONSOLE_IO_OBJECT Object,
PVOID *Entry  OPTIONAL,
DWORD  Access,
BOOL  LockConsole,
CONSOLE_IO_OBJECT_TYPE  Type 
)

Definition at line 407 of file handle.c.

414 {
415  // NTSTATUS Status;
417  PCONSOLE_IO_HANDLE HandleEntry = NULL;
418  PCONSOLE_IO_OBJECT ObjectEntry = NULL;
419  // PCONSOLE ObjectConsole;
420 
421  ASSERT(Object);
422  if (Entry) *Entry = NULL;
423 
424  DPRINT("ConSrvGetObject -- Object: 0x%x, Handle: 0x%x\n", Object, Handle);
425 
427 
428  if ( IsConsoleHandle(Handle) &&
429  Index < ProcessData->HandleTableSize )
430  {
431  HandleEntry = &ProcessData->HandleTable[Index];
432  ObjectEntry = HandleEntry->Object;
433  }
434 
435  if ( HandleEntry == NULL ||
436  ObjectEntry == NULL ||
437  (HandleEntry->Access & Access) == 0 ||
438  /*(Type != 0 && ObjectEntry->Type != Type)*/
439  (Type != 0 && (ObjectEntry->Type & Type) == 0) )
440  {
441  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",
442  Handle, Type, Access, ObjectEntry, HandleEntry, (ObjectEntry ? ObjectEntry->Type : 0), (HandleEntry ? HandleEntry->Access : 0));
443 
445  return STATUS_INVALID_HANDLE;
446  }
447 
449 
450  // Status = ConDrvGetConsole(&ObjectConsole, ProcessData->ConsoleHandle, LockConsole);
451  // if (NT_SUCCESS(Status))
452  if (ConDrvValidateConsoleUnsafe(ObjectEntry->Console, CONSOLE_RUNNING, LockConsole))
453  {
454  _InterlockedIncrement(&ObjectEntry->Console->ReferenceCount);
455 
456  /* Return the objects to the caller */
457  *Object = ObjectEntry;
458  if (Entry) *Entry = HandleEntry;
459 
460  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
461  return STATUS_SUCCESS;
462  }
463  else
464  {
465  // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
466  return STATUS_INVALID_HANDLE;
467  }
468 }
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
struct _CONSOLE_IO_HANDLE * HandleTable
Definition: consrv.h:50
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
RTL_CRITICAL_SECTION HandleTableLock
Definition: consrv.h:48

◆ ConSrvInitObject()

VOID FASTCALL 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

Referenced by ConDrvInitConsole(), ConDrvInitInputBuffer(), and CONSOLE_SCREEN_BUFFER_Initialize().

◆ ConSrvInsertObject()

NTSTATUS FASTCALL ConSrvInsertObject ( PCONSOLE_PROCESS_DATA  ProcessData,
PHANDLE  Handle,
PCONSOLE_IO_OBJECT  Object,
DWORD  Access,
BOOL  Inheritable,
DWORD  ShareMode 
)

Definition at line 315 of file handle.c.

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

◆ ConSrvReleaseObject()

VOID FASTCALL ConSrvReleaseObject ( PCONSOLE_IO_OBJECT  Object,
BOOL  IsConsoleLocked 
)

Definition at line 472 of file handle.c.

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

◆ ConSrvRemoveObject()

NTSTATUS FASTCALL ConSrvRemoveObject ( PCONSOLE_PROCESS_DATA  ProcessData,
HANDLE  Handle 
)

Definition at line 381 of file handle.c.

383 {
386 
388 
389  ASSERT(ProcessData->HandleTable);
390 
391  if (Index >= ProcessData->HandleTableSize ||
392  (Object = ProcessData->HandleTable[Index].Object) == NULL)
393  {
395  return STATUS_INVALID_HANDLE;
396  }
397 
398  ASSERT(ProcessData->ConsoleHandle);
399  ConSrvCloseHandleEntry(&ProcessData->HandleTable[Index]);
400 
402  return STATUS_SUCCESS;
403 }
HANDLE ConsoleHandle
Definition: consrv.h:45
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
static VOID ConSrvCloseHandleEntry(PCONSOLE_IO_HANDLE Entry)
Definition: handle.c:66
_In_ HANDLE Handle
Definition: extypes.h:390
static const UCHAR Index[8]
Definition: usbohci.c:18
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _CONSOLE_IO_HANDLE * HandleTable
Definition: consrv.h:50
unsigned int ULONG
Definition: retypes.h:1
ULONG HandleTableSize
Definition: consrv.h:49
return STATUS_SUCCESS
Definition: btrfs.c:2777
RTL_CRITICAL_SECTION HandleTableLock
Definition: consrv.h:48