3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/rtl/libsup.c
6 * PURPOSE: Rtl library support routines
7 * PROGRAMMER: Gunnar Dalsnes
16 /* FUNCTIONS ***************************************************************/
28 IN POOL_TYPE PoolType
,
32 return RtlAllocateHeap (
40 ExAllocatePoolWithTag(
41 IN POOL_TYPE PoolType
,
46 return RtlAllocateHeap (
54 ExFreePool(IN PVOID Mem
)
64 ExFreePoolWithTag(IN PVOID Mem
, IN ULONG Tag
)
75 CHECK_PAGED_CODE_RTL(char *file
, int line
)
77 /* meaningless in user mode */
81 /* RTL Atom Tables ************************************************************/
83 typedef struct _RTL_ATOM_HANDLE
85 RTL_HANDLE_TABLE_ENTRY Handle
;
86 PRTL_ATOM_TABLE_ENTRY AtomEntry
;
87 } RTL_ATOM_HANDLE
, *PRTL_ATOM_HANDLE
;
90 RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
92 RtlInitializeCriticalSection(&AtomTable
->CriticalSection
);
93 return STATUS_SUCCESS
;
98 RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
100 RtlDeleteCriticalSection(&AtomTable
->CriticalSection
);
105 RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable
)
107 RtlEnterCriticalSection(&AtomTable
->CriticalSection
);
113 RtlpUnlockAtomTable(PRTL_ATOM_TABLE AtomTable
)
115 RtlLeaveCriticalSection(&AtomTable
->CriticalSection
);
119 /* handle functions */
122 RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
124 RtlInitializeHandleTable(0xCFFF,
125 sizeof(RTL_ATOM_HANDLE
),
126 &AtomTable
->RtlHandleTable
);
132 RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
134 RtlDestroyHandleTable(&AtomTable
->RtlHandleTable
);
138 RtlpAllocAtomTable(ULONG Size
)
140 return (PRTL_ATOM_TABLE
)RtlAllocateHeap(RtlGetProcessHeap(),
146 RtlpFreeAtomTable(PRTL_ATOM_TABLE AtomTable
)
148 RtlFreeHeap(RtlGetProcessHeap(),
153 PRTL_ATOM_TABLE_ENTRY
154 RtlpAllocAtomTableEntry(ULONG Size
)
156 return (PRTL_ATOM_TABLE_ENTRY
)RtlAllocateHeap(RtlGetProcessHeap(),
162 RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry
)
164 RtlFreeHeap(RtlGetProcessHeap(),
170 RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
172 PRTL_HANDLE_TABLE_ENTRY RtlHandleEntry
;
174 if (RtlIsValidIndexHandle(&AtomTable
->RtlHandleTable
,
176 (ULONG
)Entry
->HandleIndex
))
178 RtlFreeHandle(&AtomTable
->RtlHandleTable
,
184 RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
187 PRTL_HANDLE_TABLE_ENTRY RtlHandle
;
189 RtlHandle
= RtlAllocateHandle(&AtomTable
->RtlHandleTable
,
191 if (RtlHandle
!= NULL
)
193 PRTL_ATOM_HANDLE AtomHandle
= (PRTL_ATOM_HANDLE
)RtlHandle
;
195 /* FIXME - Handle Indexes >= 0xC000 ?! */
196 if (HandleIndex
< 0xC000)
198 Entry
->HandleIndex
= (USHORT
)HandleIndex
;
199 Entry
->Atom
= 0xC000 + (USHORT
)HandleIndex
;
201 AtomHandle
->AtomEntry
= Entry
;
202 AtomHandle
->Handle
.Flags
= RTL_HANDLE_VALID
;
208 /* set the valid flag, otherwise RtlFreeHandle will fail! */
209 AtomHandle
->Handle
.Flags
= RTL_HANDLE_VALID
;
211 RtlFreeHandle(&AtomTable
->RtlHandleTable
,
219 PRTL_ATOM_TABLE_ENTRY
220 RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable
, ULONG Index
)
222 PRTL_HANDLE_TABLE_ENTRY RtlHandle
;
224 if (RtlIsValidIndexHandle(&AtomTable
->RtlHandleTable
,
228 PRTL_ATOM_HANDLE AtomHandle
= (PRTL_ATOM_HANDLE
)RtlHandle
;
230 return AtomHandle
->AtomEntry
;