3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/rtl/libsupp.c
6 * PURPOSE: Rtl library support routines
8 * PROGRAMMERS: No programmer listed.
11 /* INCLUDES ******************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
27 RtlpAllocateMemory(UINT Bytes
,
30 return ExAllocatePoolWithTag(PagedPool
,
37 RtlpFreeMemory(PVOID Mem
,
40 ExFreePoolWithTag(Mem
,
48 RtlAcquirePebLock(VOID
)
57 RtlReleasePebLock(VOID
)
67 return ((PEPROCESS
)(KeGetCurrentThread()->ApcState
.Process
))->Peb
;
72 RtlDeleteCriticalSection(
73 PRTL_CRITICAL_SECTION CriticalSection
)
75 return STATUS_SUCCESS
;
80 RtlSetCriticalSectionSpinCount(
81 PRTL_CRITICAL_SECTION CriticalSection
,
90 RtlEnterCriticalSection(
91 PRTL_CRITICAL_SECTION CriticalSection
)
93 ExAcquireFastMutex((PFAST_MUTEX
) CriticalSection
);
94 return STATUS_SUCCESS
;
99 RtlInitializeCriticalSection(
100 PRTL_CRITICAL_SECTION CriticalSection
)
102 ExInitializeFastMutex((PFAST_MUTEX
)CriticalSection
);
103 return STATUS_SUCCESS
;
108 RtlLeaveCriticalSection(
109 PRTL_CRITICAL_SECTION CriticalSection
)
111 ExReleaseFastMutex((PFAST_MUTEX
) CriticalSection
);
112 return STATUS_SUCCESS
;
117 RtlTryEnterCriticalSection(
118 PRTL_CRITICAL_SECTION CriticalSection
)
120 return ExTryToAcquireFastMutex((PFAST_MUTEX
) CriticalSection
);
126 RtlInitializeCriticalSectionAndSpinCount(
127 PRTL_CRITICAL_SECTION CriticalSection
,
130 ExInitializeFastMutex((PFAST_MUTEX
)CriticalSection
);
131 return STATUS_SUCCESS
;
137 CHECK_PAGED_CODE_RTL(char *file
, int line
)
139 if(KeGetCurrentIrql() > APC_LEVEL
)
141 DbgPrint("%s:%i: Pagable code called at IRQL > APC_LEVEL (%d)\n", file
, line
, KeGetCurrentIrql());
147 /* RTL Atom Tables ************************************************************/
150 RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
152 ExInitializeFastMutex(&AtomTable
->FastMutex
);
154 return STATUS_SUCCESS
;
159 RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable
)
165 RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable
)
167 ExAcquireFastMutex(&AtomTable
->FastMutex
);
172 RtlpUnlockAtomTable(PRTL_ATOM_TABLE AtomTable
)
174 ExReleaseFastMutex(&AtomTable
->FastMutex
);
178 RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
180 AtomTable
->ExHandleTable
= ExCreateHandleTable(NULL
);
181 return (AtomTable
->ExHandleTable
!= NULL
);
185 AtomDeleteHandleCallback(PHANDLE_TABLE HandleTable
,
194 RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable
)
196 if (AtomTable
->ExHandleTable
)
198 ExDestroyHandleTable(AtomTable
->ExHandleTable
,
199 AtomDeleteHandleCallback
,
201 AtomTable
->ExHandleTable
= NULL
;
206 RtlpAllocAtomTable(ULONG Size
)
208 PRTL_ATOM_TABLE Table
= ExAllocatePool(NonPagedPool
,
220 RtlpFreeAtomTable(PRTL_ATOM_TABLE AtomTable
)
222 ExFreePool(AtomTable
);
225 PRTL_ATOM_TABLE_ENTRY
226 RtlpAllocAtomTableEntry(ULONG Size
)
228 PRTL_ATOM_TABLE_ENTRY Entry
= ExAllocatePool(NonPagedPool
,
240 RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry
)
246 RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
248 ExDestroyHandle(AtomTable
->ExHandleTable
,
249 (LONG
)Entry
->HandleIndex
);
253 RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable
, PRTL_ATOM_TABLE_ENTRY Entry
)
255 HANDLE_TABLE_ENTRY ExEntry
;
258 ExEntry
.u1
.Object
= Entry
;
259 ExEntry
.u2
.GrantedAccess
= 0x1; /* FIXME - valid handle */
261 HandleIndex
= ExCreateHandle(AtomTable
->ExHandleTable
,
263 if (HandleIndex
!= EX_INVALID_HANDLE
)
265 /* FIXME - Handle Indexes >= 0xC000 ?! */
266 if (HandleIndex
< 0xC000)
268 Entry
->HandleIndex
= (USHORT
)HandleIndex
;
269 Entry
->Atom
= 0xC000 + (USHORT
)HandleIndex
;
274 ExDestroyHandle(AtomTable
->ExHandleTable
,
281 PRTL_ATOM_TABLE_ENTRY
282 RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable
, ULONG Index
)
284 PHANDLE_TABLE_ENTRY ExEntry
;
286 ExEntry
= ExMapHandleToPointer(AtomTable
->ExHandleTable
,
290 PRTL_ATOM_TABLE_ENTRY Entry
;
292 Entry
= ExEntry
->u1
.Object
;
294 ExUnlockHandleTableEntry(AtomTable
->ExHandleTable
,
302 /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
304 RtlpCreateUnicodeString(
305 IN OUT PUNICODE_STRING UniDest
,
307 IN POOL_TYPE PoolType
)
311 Length
= (wcslen (Source
) + 1) * sizeof(WCHAR
);
312 UniDest
->Buffer
= ExAllocatePoolWithTag(PoolType
, Length
, TAG('U', 'S', 'T', 'R'));
313 if (UniDest
->Buffer
== NULL
)
316 RtlCopyMemory (UniDest
->Buffer
,
320 UniDest
->MaximumLength
= Length
;
321 UniDest
->Length
= Length
- sizeof (WCHAR
);