Formatting, no code change

svn path=/trunk/; revision=57921
This commit is contained in:
Timo Kreuzer 2012-12-15 13:58:24 +00:00
parent b271725de3
commit 33bacef5b3

View file

@ -2,7 +2,7 @@
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* PURPOSE: Handle table * PURPOSE: Handle table
* FILE: lib/rtl/handle.c * FILE: lib/rtl/handle.c
* PROGRAMER: Eric Kohl * PROGRAMMER: Eric Kohl
*/ */
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
@ -14,182 +14,196 @@
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
VOID NTAPI VOID
RtlInitializeHandleTable(ULONG TableSize, NTAPI
ULONG HandleSize, RtlInitializeHandleTable(
PRTL_HANDLE_TABLE HandleTable) ULONG TableSize,
ULONG HandleSize,
PRTL_HANDLE_TABLE HandleTable)
{ {
/* initialize handle table */ /* Initialize handle table */
memset(HandleTable, memset(HandleTable, 0, sizeof(RTL_HANDLE_TABLE));
0, HandleTable->MaximumNumberOfHandles = TableSize;
sizeof(RTL_HANDLE_TABLE)); HandleTable->SizeOfHandleTableEntry = HandleSize;
HandleTable->MaximumNumberOfHandles = TableSize;
HandleTable->SizeOfHandleTableEntry = HandleSize;
} }
/* /*
* @implemented * @implemented
*/ */
VOID NTAPI VOID
RtlDestroyHandleTable(PRTL_HANDLE_TABLE HandleTable) NTAPI
RtlDestroyHandleTable(
PRTL_HANDLE_TABLE HandleTable)
{ {
PVOID ArrayPointer; PVOID ArrayPointer;
SIZE_T ArraySize = 0; SIZE_T ArraySize = 0;
/* free handle array */ /* free handle array */
if (HandleTable->CommittedHandles) if (HandleTable->CommittedHandles)
{ {
ArrayPointer = (PVOID)HandleTable->CommittedHandles; ArrayPointer = (PVOID)HandleTable->CommittedHandles;
NtFreeVirtualMemory(NtCurrentProcess(), NtFreeVirtualMemory(NtCurrentProcess(),
&ArrayPointer, &ArrayPointer,
&ArraySize, &ArraySize,
MEM_RELEASE); MEM_RELEASE);
} }
} }
/* /*
* @implemented * @implemented
*/ */
PRTL_HANDLE_TABLE_ENTRY NTAPI PRTL_HANDLE_TABLE_ENTRY
RtlAllocateHandle(PRTL_HANDLE_TABLE HandleTable, NTAPI
PULONG Index) RtlAllocateHandle(
PRTL_HANDLE_TABLE HandleTable,
PULONG Index)
{ {
PRTL_HANDLE_TABLE_ENTRY *pp_new, *pph, ph; PRTL_HANDLE_TABLE_ENTRY *pp_new, *pph, ph;
NTSTATUS Status; NTSTATUS Status;
PRTL_HANDLE_TABLE_ENTRY retval; PRTL_HANDLE_TABLE_ENTRY retval;
PVOID ArrayPointer; PVOID ArrayPointer;
SIZE_T ArraySize; SIZE_T ArraySize;
pp_new = &HandleTable->FreeHandles; pp_new = &HandleTable->FreeHandles;
if (HandleTable->FreeHandles == NULL) if (HandleTable->FreeHandles == NULL)
{ {
/* no free handle available */ /* no free handle available */
if (HandleTable->UnCommittedHandles == NULL) if (HandleTable->UnCommittedHandles == NULL)
{ {
/* allocate handle array */ /* allocate handle array */
ArraySize = HandleTable->SizeOfHandleTableEntry * HandleTable->MaximumNumberOfHandles; ArraySize = HandleTable->SizeOfHandleTableEntry * HandleTable->MaximumNumberOfHandles;
ArrayPointer = NULL; ArrayPointer = NULL;
/* FIXME - only reserve handles here! */ /* FIXME - only reserve handles here! */
Status = NtAllocateVirtualMemory(NtCurrentProcess(), Status = NtAllocateVirtualMemory(NtCurrentProcess(),
(PVOID*)&ArrayPointer, (PVOID*)&ArrayPointer,
0, 0,
&ArraySize, &ArraySize,
MEM_RESERVE | MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return NULL; return NULL;
/* update handle array pointers */ /* update handle array pointers */
HandleTable->FreeHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer; HandleTable->FreeHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
HandleTable->MaxReservedHandles = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ArrayPointer + ArraySize); HandleTable->MaxReservedHandles = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ArrayPointer + ArraySize);
HandleTable->CommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer; HandleTable->CommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
HandleTable->UnCommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer; HandleTable->UnCommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)ArrayPointer;
} }
/* FIXME - should check if handles need to be committed */ /* FIXME - should check if handles need to be committed */
/* build free list in handle array */ /* build free list in handle array */
ph = HandleTable->FreeHandles; ph = HandleTable->FreeHandles;
pph = pp_new; pph = pp_new;
while (ph < HandleTable->MaxReservedHandles) while (ph < HandleTable->MaxReservedHandles)
{ {
*pph = ph; *pph = ph;
pph = &ph->NextFree; pph = &ph->NextFree;
ph = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ph + HandleTable->SizeOfHandleTableEntry); ph = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)ph + HandleTable->SizeOfHandleTableEntry);
} }
*pph = 0; *pph = 0;
} }
/* remove handle from free list */ /* remove handle from free list */
retval = *pp_new; retval = *pp_new;
*pp_new = retval->NextFree; *pp_new = retval->NextFree;
retval->NextFree = NULL; retval->NextFree = NULL;
if (Index) if (Index)
*Index = ((ULONG)((ULONG_PTR)retval - (ULONG_PTR)HandleTable->CommittedHandles) / {
HandleTable->SizeOfHandleTableEntry); *Index = ((ULONG)((ULONG_PTR)retval - (ULONG_PTR)HandleTable->CommittedHandles) /
HandleTable->SizeOfHandleTableEntry);
}
return retval; return retval;
} }
/* /*
* @implemented * @implemented
*/ */
BOOLEAN NTAPI BOOLEAN
RtlFreeHandle(PRTL_HANDLE_TABLE HandleTable, NTAPI
PRTL_HANDLE_TABLE_ENTRY Handle) RtlFreeHandle(
PRTL_HANDLE_TABLE HandleTable,
PRTL_HANDLE_TABLE_ENTRY Handle)
{ {
#if DBG #if DBG
/* check if handle is valid */ /* check if handle is valid */
if (!RtlIsValidHandle(HandleTable, Handle)) if (!RtlIsValidHandle(HandleTable, Handle))
{ {
DPRINT1("Invalid Handle! HandleTable=0x%p, Handle=0x%p, Handle->Flags=0x%x\n", DPRINT1("Invalid Handle! HandleTable=0x%p, Handle=0x%p, Handle->Flags=0x%x\n",
HandleTable, Handle, Handle ? Handle->Flags : 0); HandleTable, Handle, Handle ? Handle->Flags : 0);
return FALSE; return FALSE;
} }
#endif #endif
/* clear handle */ /* clear handle */
memset(Handle, 0, HandleTable->SizeOfHandleTableEntry); memset(Handle, 0, HandleTable->SizeOfHandleTableEntry);
/* add handle to free list */ /* add handle to free list */
Handle->NextFree = HandleTable->FreeHandles; Handle->NextFree = HandleTable->FreeHandles;
HandleTable->FreeHandles = Handle; HandleTable->FreeHandles = Handle;
return TRUE; return TRUE;
} }
/* /*
* @implemented * @implemented
*/ */
BOOLEAN NTAPI BOOLEAN
RtlIsValidHandle(PRTL_HANDLE_TABLE HandleTable, NTAPI
PRTL_HANDLE_TABLE_ENTRY Handle) RtlIsValidHandle(
PRTL_HANDLE_TABLE HandleTable,
PRTL_HANDLE_TABLE_ENTRY Handle)
{ {
if ((HandleTable != NULL) if ((HandleTable != NULL)
&& (Handle >= HandleTable->CommittedHandles) && (Handle >= HandleTable->CommittedHandles)
&& (Handle < HandleTable->MaxReservedHandles) && (Handle < HandleTable->MaxReservedHandles)
&& (Handle->Flags & RTL_HANDLE_VALID)) && (Handle->Flags & RTL_HANDLE_VALID))
return TRUE; {
return FALSE; return TRUE;
}
return FALSE;
} }
/* /*
* @implemented * @implemented
*/ */
BOOLEAN NTAPI BOOLEAN
RtlIsValidIndexHandle(IN PRTL_HANDLE_TABLE HandleTable, NTAPI
IN ULONG Index, RtlIsValidIndexHandle(
OUT PRTL_HANDLE_TABLE_ENTRY *Handle) IN PRTL_HANDLE_TABLE HandleTable,
IN ULONG Index,
OUT PRTL_HANDLE_TABLE_ENTRY *Handle)
{ {
PRTL_HANDLE_TABLE_ENTRY InternalHandle; PRTL_HANDLE_TABLE_ENTRY InternalHandle;
DPRINT("RtlIsValidIndexHandle(HandleTable %p Index 0x%lx Handle %p)\n", HandleTable, Index, Handle); DPRINT("RtlIsValidIndexHandle(HandleTable %p Index 0x%lx Handle %p)\n", HandleTable, Index, Handle);
if (HandleTable == NULL) if (HandleTable == NULL)
return FALSE; return FALSE;
DPRINT("Handles %p HandleSize 0x%lx\n", DPRINT("Handles %p HandleSize 0x%lx\n",
HandleTable->CommittedHandles, HandleTable->SizeOfHandleTableEntry); HandleTable->CommittedHandles, HandleTable->SizeOfHandleTableEntry);
InternalHandle = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)HandleTable->CommittedHandles + InternalHandle = (PRTL_HANDLE_TABLE_ENTRY)((ULONG_PTR)HandleTable->CommittedHandles +
(HandleTable->SizeOfHandleTableEntry * Index)); (HandleTable->SizeOfHandleTableEntry * Index));
if (!RtlIsValidHandle(HandleTable, InternalHandle)) if (!RtlIsValidHandle(HandleTable, InternalHandle))
return FALSE; return FALSE;
DPRINT("InternalHandle %p\n", InternalHandle); DPRINT("InternalHandle %p\n", InternalHandle);
if (Handle != NULL) if (Handle != NULL)
*Handle = InternalHandle; *Handle = InternalHandle;
return TRUE; return TRUE;
} }
/* EOF */ /* EOF */