Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

handle.c File Reference

#include "ntrtlp.h"

Go to the source code of this file.

Functions

void RtlInitializeHandleTable (IN ULONG MaximumNumberOfHandles, IN ULONG SizeOfHandleTableEntry, OUT PRTL_HANDLE_TABLE HandleTable)
NTSTATUS RtlDestroyHandleTable (IN OUT PRTL_HANDLE_TABLE HandleTable)
PRTL_HANDLE_TABLE_ENTRY RtlAllocateHandle (IN PRTL_HANDLE_TABLE HandleTable, OUT PULONG HandleIndex OPTIONAL)
BOOLEAN RtlFreeHandle (IN PRTL_HANDLE_TABLE HandleTable, IN PRTL_HANDLE_TABLE_ENTRY Handle)
BOOLEAN RtlIsValidHandle (IN PRTL_HANDLE_TABLE HandleTable, IN PRTL_HANDLE_TABLE_ENTRY Handle)
BOOLEAN RtlIsValidIndexHandle (IN PRTL_HANDLE_TABLE HandleTable, IN ULONG HandleIndex, OUT PRTL_HANDLE_TABLE_ENTRY *Handle)


Function Documentation

PRTL_HANDLE_TABLE_ENTRY RtlAllocateHandle IN PRTL_HANDLE_TABLE  HandleTable,
OUT PULONG HandleIndex  OPTIONAL
 

Definition at line 60 of file rtl/handle.c.

References EXCEPTION_EXECUTE_HANDLER, n, NT_SUCCESS, NtAllocateVirtualMemory(), NTSTATUS(), NULL, PAGE_SIZE, and Status.

Referenced by RtlpCreateHandleForAtom().

00064 { 00065 NTSTATUS Status; 00066 PVOID BaseAddress; 00067 ULONG n; 00068 SIZE_T ReserveSize; 00069 SIZE_T CommitSize; 00070 PRTL_HANDLE_TABLE_ENTRY p, *pp; 00071 00072 if (HandleTable->FreeHandles == NULL) { 00073 try { 00074 if (HandleTable->UnCommittedHandles == NULL) { 00075 ReserveSize = HandleTable->MaximumNumberOfHandles * 00076 HandleTable->SizeOfHandleTableEntry; 00077 BaseAddress = NULL; 00078 Status = NtAllocateVirtualMemory( NtCurrentProcess(), 00079 &BaseAddress, 00080 0, 00081 &ReserveSize, 00082 MEM_RESERVE, 00083 PAGE_READWRITE 00084 ); 00085 00086 if (NT_SUCCESS( Status )) { 00087 HandleTable->CommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)BaseAddress; 00088 HandleTable->UnCommittedHandles = (PRTL_HANDLE_TABLE_ENTRY)BaseAddress; 00089 HandleTable->MaxReservedHandles = (PRTL_HANDLE_TABLE_ENTRY) 00090 ((PCHAR)BaseAddress + ReserveSize); 00091 } 00092 } 00093 else { 00094 Status = STATUS_SUCCESS; 00095 } 00096 00097 00098 if (NT_SUCCESS( Status )) { 00099 p = HandleTable->UnCommittedHandles; 00100 if (p >= HandleTable->MaxReservedHandles) { 00101 Status = STATUS_NO_MEMORY; 00102 } 00103 else { 00104 CommitSize = PAGE_SIZE; 00105 Status = NtAllocateVirtualMemory( NtCurrentProcess(), 00106 (PVOID *)&p, 00107 0, 00108 &CommitSize, 00109 MEM_COMMIT, 00110 PAGE_READWRITE 00111 ); 00112 if (NT_SUCCESS( Status )) { 00113 HandleTable->UnCommittedHandles = (PRTL_HANDLE_TABLE_ENTRY) 00114 ((PCH)p + CommitSize); 00115 } 00116 } 00117 } 00118 00119 } 00120 except( EXCEPTION_EXECUTE_HANDLER ) { 00121 Status = GetExceptionCode(); 00122 } 00123 00124 if (!NT_SUCCESS( Status )) { 00125 return NULL; 00126 } 00127 00128 pp = &HandleTable->FreeHandles; 00129 while (p < HandleTable->UnCommittedHandles) { 00130 *pp = p; 00131 pp = &p->NextFree; 00132 p = (PRTL_HANDLE_TABLE_ENTRY)((PUCHAR)p + HandleTable->SizeOfHandleTableEntry); 00133 } 00134 } 00135 00136 // 00137 // Remove handle table entry from head of free list. 00138 // 00139 00140 p = HandleTable->FreeHandles; 00141 HandleTable->FreeHandles = p->NextFree; 00142 00143 // 00144 // Clear free list link field, which also leaves the handle allocated bit 00145 // clear. This allows the caller to mark it is allocated after they are 00146 // done filling in their portion. 00147 // 00148 00149 p->NextFree = NULL; 00150 00151 00152 // 00153 // If requested, return the index of this handle table entry 00154 // 00155 if (ARGUMENT_PRESENT( HandleIndex )) { 00156 *HandleIndex = (ULONG) (((PCHAR)p - (PCHAR)HandleTable->CommittedHandles) / 00157 HandleTable->SizeOfHandleTableEntry); 00158 } 00159 00160 // 00161 // Return a pointer to the handle table entry. 00162 // 00163 00164 return p; 00165 }

NTSTATUS RtlDestroyHandleTable IN OUT PRTL_HANDLE_TABLE  HandleTable  ) 
 

Definition at line 39 of file rtl/handle.c.

References NtFreeVirtualMemory(), NTSTATUS(), and Status.

Referenced by RtlpDestroyHandleTableForAtomTable().

00042 { 00043 NTSTATUS Status; 00044 PVOID BaseAddress; 00045 SIZE_T ReserveSize; 00046 00047 BaseAddress = HandleTable->CommittedHandles; 00048 ReserveSize = (PUCHAR)(HandleTable->MaxReservedHandles) - 00049 (PUCHAR)(HandleTable->CommittedHandles); 00050 00051 Status = NtFreeVirtualMemory( NtCurrentProcess(), 00052 &BaseAddress, 00053 &ReserveSize, 00054 MEM_RELEASE 00055 ); 00056 return Status; 00057 }

BOOLEAN RtlFreeHandle IN PRTL_HANDLE_TABLE  HandleTable,
IN PRTL_HANDLE_TABLE_ENTRY  Handle
 

Definition at line 169 of file rtl/handle.c.

References DbgPrint, FALSE, Handle, RtlIsValidHandle(), and TRUE.

Referenced by RtlpCreateHandleForAtom(), and RtlpFreeHandleForAtom().

00173 { 00174 #if DBG 00175 if (!RtlIsValidHandle( HandleTable, Handle )) { 00176 DbgPrint( "RTL: RtlFreeHandle( %lx ) - invalid handle\n", Handle ); 00177 if (NtCurrentPeb()->BeingDebugged) { 00178 DbgBreakPoint(); 00179 } 00180 return FALSE; 00181 } 00182 #endif 00183 00184 RtlZeroMemory( Handle, HandleTable->SizeOfHandleTableEntry ); 00185 Handle->NextFree = HandleTable->FreeHandles; 00186 HandleTable->FreeHandles = Handle; 00187 return TRUE; 00188 }

void RtlInitializeHandleTable IN ULONG  MaximumNumberOfHandles,
IN ULONG  SizeOfHandleTableEntry,
OUT PRTL_HANDLE_TABLE  HandleTable
 

Definition at line 25 of file rtl/handle.c.

Referenced by RtlpInitializeHandleTableForAtomTable().

00030 { 00031 RtlZeroMemory( HandleTable, sizeof( *HandleTable ) ); 00032 HandleTable->MaximumNumberOfHandles = MaximumNumberOfHandles; 00033 HandleTable->SizeOfHandleTableEntry = SizeOfHandleTableEntry; 00034 00035 return; 00036 }

BOOLEAN RtlIsValidHandle IN PRTL_HANDLE_TABLE  HandleTable,
IN PRTL_HANDLE_TABLE_ENTRY  Handle
 

Definition at line 193 of file rtl/handle.c.

References FALSE, Handle, NULL, and TRUE.

Referenced by RtlFreeHandle(), and RtlIsValidIndexHandle().

00197 { 00198 if (Handle == NULL || 00199 Handle < HandleTable->CommittedHandles || 00200 Handle >= HandleTable->UnCommittedHandles || 00201 (ULONG_PTR)Handle & (HandleTable->SizeOfHandleTableEntry - 1) || 00202 !(Handle->Flags & RTL_HANDLE_ALLOCATED) 00203 ) { 00204 return FALSE; 00205 } 00206 else { 00207 return TRUE; 00208 } 00209 }

BOOLEAN RtlIsValidIndexHandle IN PRTL_HANDLE_TABLE  HandleTable,
IN ULONG  HandleIndex,
OUT PRTL_HANDLE_TABLE_ENTRY *  Handle
 

Definition at line 213 of file rtl/handle.c.

References FALSE, Handle, RtlIsValidHandle(), and TRUE.

Referenced by RtlpAtomMapAtomToHandleEntry(), and RtlpFreeHandleForAtom().

00218 { 00219 PRTL_HANDLE_TABLE_ENTRY p; 00220 00221 p = (PRTL_HANDLE_TABLE_ENTRY) 00222 ((PCHAR)HandleTable->CommittedHandles + (HandleIndex * HandleTable->SizeOfHandleTableEntry)); 00223 00224 if (RtlIsValidHandle( HandleTable, p )) { 00225 *Handle = p; 00226 return TRUE; 00227 } 00228 else { 00229 return FALSE; 00230 } 00231 }


Generated on Sat May 15 19:44:01 2004 for test by doxygen 1.3.7