2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/ntdll/rtl/libsup.c
5 * PURPOSE: Rtl library support routines
6 * PROGRAMMER: Gunnar Dalsnes
9 /* INCLUDES *****************************************************************/
15 /* FUNCTIONS ***************************************************************/
28 return NtCurrentPeb();
36 RtlAcquirePebLock(VOID
)
38 PPEB Peb
= NtCurrentPeb ();
39 Peb
->FastPebLockRoutine (Peb
->FastPebLock
);
47 RtlReleasePebLock(VOID
)
49 PPEB Peb
= NtCurrentPeb ();
50 Peb
->FastPebUnlockRoutine (Peb
->FastPebLock
);
58 RtlGetNtGlobalFlags(VOID
)
60 PPEB pPeb
= NtCurrentPeb();
61 return pPeb
->NtGlobalFlag
;
66 RtlpAllocateMemory(UINT Bytes
,
69 UNREFERENCED_PARAMETER(Tag
);
71 return RtlAllocateHeap(RtlGetProcessHeap(),
79 RtlpFreeMemory(PVOID Mem
,
82 UNREFERENCED_PARAMETER(Tag
);
84 RtlFreeHeap(RtlGetProcessHeap(),
92 CHECK_PAGED_CODE_RTL(char *file
, int line
)
94 /* meaningless in user mode */
98 /* RTL Atom Tables ************************************************************/
100 typedef struct _RTL_ATOM_HANDLE
102 RTL_HANDLE_TABLE_ENTRY Handle
;
103 PRTL_ATOM_TABLE_ENTRY AtomEntry
;
104 } RTL_ATOM_HANDLE
, *PRTL_ATOM_HANDLE
;
107 RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
109 RtlInitializeCriticalSection(&AtomTable
->CriticalSection
);
110 return STATUS_SUCCESS
;
115 RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
117 RtlDeleteCriticalSection(&AtomTable
->CriticalSection
);
122 RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable
)
124 RtlEnterCriticalSection(&AtomTable
->CriticalSection
);
130 RtlpUnlockAtomTable(PRTL_ATOM_TABLE AtomTable
)
132 RtlLeaveCriticalSection(&AtomTable
->CriticalSection
);
136 /* handle functions */
139 RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
141 RtlInitializeHandleTable(0xCFFF,
142 sizeof(RTL_ATOM_HANDLE
),
143 &AtomTable
->RtlHandleTable
);
149 RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
151 RtlDestroyHandleTable(&AtomTable
->RtlHandleTable
);
155 RtlpAllocAtomTable(ULONG Size
)
157 return (PRTL_ATOM_TABLE
)RtlAllocateHeap(RtlGetProcessHeap(),
163 RtlpFreeAtomTable(PRTL_ATOM_TABLE AtomTable
)
165 RtlFreeHeap(RtlGetProcessHeap(),
170 PRTL_ATOM_TABLE_ENTRY
171 RtlpAllocAtomTableEntry(ULONG Size
)
173 return (PRTL_ATOM_TABLE_ENTRY
)RtlAllocateHeap(RtlGetProcessHeap(),
179 RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry
)
181 RtlFreeHeap(RtlGetProcessHeap(),
187 RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
189 PRTL_HANDLE_TABLE_ENTRY RtlHandleEntry
;
191 if (RtlIsValidIndexHandle(&AtomTable
->RtlHandleTable
,
192 (ULONG
)Entry
->HandleIndex
,
195 RtlFreeHandle(&AtomTable
->RtlHandleTable
,
201 RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
204 PRTL_HANDLE_TABLE_ENTRY RtlHandle
;
206 RtlHandle
= RtlAllocateHandle(&AtomTable
->RtlHandleTable
,
208 if (RtlHandle
!= NULL
)
210 PRTL_ATOM_HANDLE AtomHandle
= (PRTL_ATOM_HANDLE
)RtlHandle
;
212 /* FIXME - Handle Indexes >= 0xC000 ?! */
213 if (HandleIndex
< 0xC000)
215 Entry
->HandleIndex
= (USHORT
)HandleIndex
;
216 Entry
->Atom
= 0xC000 + (USHORT
)HandleIndex
;
218 AtomHandle
->AtomEntry
= Entry
;
219 AtomHandle
->Handle
.Flags
= RTL_HANDLE_VALID
;
225 /* set the valid flag, otherwise RtlFreeHandle will fail! */
226 AtomHandle
->Handle
.Flags
= RTL_HANDLE_VALID
;
228 RtlFreeHandle(&AtomTable
->RtlHandleTable
,
236 PRTL_ATOM_TABLE_ENTRY
237 RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable
, ULONG Index
)
239 PRTL_HANDLE_TABLE_ENTRY RtlHandle
;
241 if (RtlIsValidIndexHandle(&AtomTable
->RtlHandleTable
,
245 PRTL_ATOM_HANDLE AtomHandle
= (PRTL_ATOM_HANDLE
)RtlHandle
;
247 return AtomHandle
->AtomEntry
;