ReactOS 0.4.15-dev-7928-g68a8619
atom.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for atom.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS RtlpInitAtomTableLock (PRTL_ATOM_TABLE AtomTable)
 
VOID RtlpDestroyAtomTableLock (PRTL_ATOM_TABLE AtomTable)
 
BOOLEAN RtlpLockAtomTable (PRTL_ATOM_TABLE AtomTable)
 
VOID RtlpUnlockAtomTable (PRTL_ATOM_TABLE AtomTable)
 
BOOLEAN RtlpCreateAtomHandleTable (PRTL_ATOM_TABLE AtomTable)
 
VOID RtlpDestroyAtomHandleTable (PRTL_ATOM_TABLE AtomTable)
 
PRTL_ATOM_TABLE RtlpAllocAtomTable (ULONG Size)
 
VOID RtlpFreeAtomTable (PRTL_ATOM_TABLE AtomTable)
 
PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry (ULONG Size)
 
VOID RtlpFreeAtomTableEntry (PRTL_ATOM_TABLE_ENTRY Entry)
 
BOOLEAN RtlpCreateAtomHandle (PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
 
VOID RtlpFreeAtomHandle (PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
 
PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry (PRTL_ATOM_TABLE AtomTable, ULONG Index)
 
static PRTL_ATOM_TABLE_ENTRY RtlpHashAtomName (IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM_TABLE_ENTRY **HashLink)
 
static BOOLEAN RtlpCheckIntegerAtom (PWSTR AtomName, PUSHORT AtomValue)
 
NTSTATUS NTAPI RtlCreateAtomTable (IN ULONG TableSize, IN OUT PRTL_ATOM_TABLE *AtomTable)
 
NTSTATUS NTAPI RtlDestroyAtomTable (IN PRTL_ATOM_TABLE AtomTable)
 
NTSTATUS NTAPI RtlEmptyAtomTable (PRTL_ATOM_TABLE AtomTable, BOOLEAN DeletePinned)
 
NTSTATUS NTAPI RtlAddAtomToAtomTable (IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM Atom)
 
NTSTATUS NTAPI RtlDeleteAtomFromAtomTable (IN PRTL_ATOM_TABLE AtomTable, IN RTL_ATOM Atom)
 
NTSTATUS NTAPI RtlLookupAtomInAtomTable (IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM Atom)
 
NTSTATUS NTAPI RtlPinAtomInAtomTable (IN PRTL_ATOM_TABLE AtomTable, IN RTL_ATOM Atom)
 
NTSTATUS NTAPI RtlQueryAtomInAtomTable (PRTL_ATOM_TABLE AtomTable, RTL_ATOM Atom, PULONG RefCount, PULONG PinCount, PWSTR AtomName, PULONG NameLength)
 
NTSTATUS NTAPI RtlQueryAtomListInAtomTable (IN PRTL_ATOM_TABLE AtomTable, IN ULONG MaxAtomCount, OUT ULONG *AtomCount, OUT RTL_ATOM *AtomList)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file atom.c.

Function Documentation

◆ RtlAddAtomToAtomTable()

NTSTATUS NTAPI RtlAddAtomToAtomTable ( IN PRTL_ATOM_TABLE  AtomTable,
IN PWSTR  AtomName,
OUT PRTL_ATOM  Atom 
)

Definition at line 308 of file atom.c.

311{
312 USHORT AtomValue;
313 PRTL_ATOM_TABLE_ENTRY *HashLink;
316
317 DPRINT("RtlAddAtomToAtomTable (AtomTable %p AtomName %S Atom %p)\n",
318 AtomTable, AtomName, Atom);
319
320 if (RtlpCheckIntegerAtom (AtomName, &AtomValue))
321 {
322 /* integer atom */
323 if (AtomValue >= 0xC000)
324 {
326 }
327 else if (Atom != NULL)
328 {
329 *Atom = (RTL_ATOM)AtomValue;
330 }
331
332 return Status;
333 }
334
335 RtlpLockAtomTable(AtomTable);
336
337 /* string atom, hash it and try to find an existing atom with the same name */
338 Entry = RtlpHashAtomName(AtomTable, AtomName, &HashLink);
339
340 if (Entry != NULL)
341 {
342 /* found another atom, increment the reference counter unless it's pinned */
343
344 if (!(Entry->Flags & RTL_ATOM_IS_PINNED))
345 {
346 if (++Entry->ReferenceCount == 0)
347 {
348 /* FIXME - references overflowed, pin the atom? */
349 Entry->Flags |= RTL_ATOM_IS_PINNED;
350 }
351 }
352
353 if (Atom != NULL)
354 {
355 *Atom = (RTL_ATOM)Entry->Atom;
356 }
357 }
358 else
359 {
360 /* couldn't find an existing atom, HashLink now points to either the
361 HashLink pointer of the previous atom or to the bucket so we can
362 simply add it to the list */
363 if (HashLink != NULL)
364 {
365 ULONG AtomNameLen = (ULONG)wcslen(AtomName);
366
367 if (AtomNameLen > RTL_MAXIMUM_ATOM_LENGTH)
368 {
370 goto end;
371 }
372
374 sizeof(Entry->Name) +
375 (AtomNameLen + 1) * sizeof(WCHAR));
376 if (Entry != NULL)
377 {
378 Entry->HashLink = NULL;
379 Entry->ReferenceCount = 1;
380 Entry->Flags = 0x0;
381
382 Entry->NameLength = (UCHAR)AtomNameLen;
383 RtlCopyMemory(Entry->Name,
384 AtomName,
385 (AtomNameLen + 1) * sizeof(WCHAR));
386
387 if (RtlpCreateAtomHandle(AtomTable, Entry))
388 {
389 /* append the atom to the list */
390 *HashLink = Entry;
391
392 if (Atom != NULL)
393 {
394 *Atom = (RTL_ATOM)Entry->Atom;
395 }
396 }
397 else
398 {
401 }
402 }
403 else
404 {
406 }
407 }
408 else
409 {
410 /* The caller supplied an empty atom name! */
412 }
413 }
414end:
415 RtlpUnlockAtomTable(AtomTable);
416
417 return Status;
418}
LONG NTSTATUS
Definition: precomp.h:26
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
GLuint GLuint end
Definition: gl.h:1545
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned short RTL_ATOM
Definition: atom.c:42
#define RTL_MAXIMUM_ATOM_LENGTH
Definition: rtltypes.h:36
#define RTL_ATOM_IS_PINNED
Definition: rtltypes.h:381
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned short USHORT
Definition: pedump.c:61
PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry(ULONG Size)
Definition: libsupp.c:423
BOOLEAN RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:374
static PRTL_ATOM_TABLE_ENTRY RtlpHashAtomName(IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM_TABLE_ENTRY **HashLink)
Definition: atom.c:39
static BOOLEAN RtlpCheckIntegerAtom(PWSTR AtomName, PUSHORT AtomValue)
Definition: atom.c:86
VOID RtlpUnlockAtomTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:382
VOID RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry)
Definition: libsupp.c:431
BOOLEAN RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
Definition: libsupp.c:453
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:83
Definition: rtltypes.h:1672
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RtlCreateAtomTable()

NTSTATUS NTAPI RtlCreateAtomTable ( IN ULONG  TableSize,
IN OUT PRTL_ATOM_TABLE AtomTable 
)

Definition at line 150 of file atom.c.

153{
156
157 DPRINT("RtlCreateAtomTable(TableSize %lu AtomTable %p)\n",
158 TableSize, AtomTable);
159
160 if (*AtomTable != NULL)
161 {
162 return STATUS_SUCCESS;
163 }
164
165 /* Use default if size was incorrect */
166 if (TableSize <= 1) TableSize = 37;
167
168 /* allocate atom table */
170 sizeof(RTL_ATOM_TABLE));
171 if (Table == NULL)
172 {
173 return STATUS_NO_MEMORY;
174 }
175
176 /* initialize atom table */
177 Table->NumberOfBuckets = TableSize;
178
180 if (!NT_SUCCESS(Status))
181 {
183 return Status;
184 }
185
187 {
190 return STATUS_NO_MEMORY;
191 }
192
193 *AtomTable = Table;
194 return STATUS_SUCCESS;
195}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASMGENDATA Table[]
Definition: genincdata.c:61
struct atom_table * RTL_ATOM_TABLE
Definition: atom.c:43
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
VOID RtlpFreeAtomTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:415
BOOLEAN RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:391
NTSTATUS RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:359
VOID RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:367
PRTL_ATOM_TABLE RtlpAllocAtomTable(ULONG Size)
Definition: libsupp.c:407
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4327

◆ RtlDeleteAtomFromAtomTable()

NTSTATUS NTAPI RtlDeleteAtomFromAtomTable ( IN PRTL_ATOM_TABLE  AtomTable,
IN RTL_ATOM  Atom 
)

Definition at line 426 of file atom.c.

429{
432
433 DPRINT("RtlDeleteAtomFromAtomTable (AtomTable %p Atom %x)\n",
434 AtomTable, Atom);
435
436 if (Atom >= 0xC000)
437 {
438 RtlpLockAtomTable(AtomTable);
439
440 Entry = RtlpGetAtomEntry(AtomTable, (ULONG)((USHORT)Atom - 0xC000));
441
442 if (Entry != NULL && Entry->Atom == (USHORT)Atom)
443 {
444 if (!(Entry->Flags & RTL_ATOM_IS_PINNED))
445 {
446 if (--Entry->ReferenceCount == 0)
447 {
448 PRTL_ATOM_TABLE_ENTRY *HashLink;
449
450 /* it's time to delete the atom. we need to unlink it from
451 the list. The easiest way is to take the atom name and
452 hash it again, this way we get the pointer to either
453 the hash bucket or the previous atom that links to the
454 one we want to delete. This way we can easily bypass
455 this item. */
456 if (RtlpHashAtomName(AtomTable, Entry->Name, &HashLink) != NULL)
457 {
458 /* bypass this atom */
459 *HashLink = Entry->HashLink;
460
461 RtlpFreeAtomHandle(AtomTable, Entry);
462
464 }
465 else
466 {
467 /* WTF?! This should never happen!!! */
468 ASSERT(FALSE);
469 }
470 }
471 }
472 else
473 {
474 /* tried to delete a pinned atom, do nothing and return
475 STATUS_WAS_LOCKED, which is NOT a failure code! */
477 }
478 }
479 else
480 {
482 }
483
484 RtlpUnlockAtomTable(AtomTable);
485 }
486
487 return Status;
488}
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define STATUS_WAS_LOCKED
Definition: ntstatus.h:139
PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable, ULONG Index)
Definition: libsupp.c:489
VOID RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
Definition: libsupp.c:439

◆ RtlDestroyAtomTable()

NTSTATUS NTAPI RtlDestroyAtomTable ( IN PRTL_ATOM_TABLE  AtomTable)

Definition at line 203 of file atom.c.

205{
206 PRTL_ATOM_TABLE_ENTRY *CurrentBucket, *LastBucket;
207 PRTL_ATOM_TABLE_ENTRY CurrentEntry, NextEntry;
208
209 DPRINT("RtlDestroyAtomTable (AtomTable %p)\n", AtomTable);
210
211 if (!RtlpLockAtomTable(AtomTable))
212 {
214 }
215
216 /* delete all atoms */
217 LastBucket = AtomTable->Buckets + AtomTable->NumberOfBuckets;
218 for (CurrentBucket = AtomTable->Buckets;
219 CurrentBucket != LastBucket;
220 CurrentBucket++)
221 {
222 NextEntry = *CurrentBucket;
223 *CurrentBucket = NULL;
224
225 while (NextEntry != NULL)
226 {
227 CurrentEntry = NextEntry;
228 NextEntry = NextEntry->HashLink;
229
230 /* no need to delete the atom handle, the handles will all be freed
231 up when destroying the atom handle table! */
232
233 RtlpFreeAtomTableEntry(CurrentEntry);
234 }
235 }
236
238
239 RtlpUnlockAtomTable(AtomTable);
240
241 RtlpDestroyAtomTableLock(AtomTable);
242
243 RtlpFreeAtomTable(AtomTable);
244
245 return STATUS_SUCCESS;
246}
VOID RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:401
struct _RTL_ATOM_TABLE_ENTRY * HashLink
Definition: rtltypes.h:1673

Referenced by IntWinStaObjectDelete(), and main().

◆ RtlEmptyAtomTable()

NTSTATUS NTAPI RtlEmptyAtomTable ( PRTL_ATOM_TABLE  AtomTable,
BOOLEAN  DeletePinned 
)

Definition at line 254 of file atom.c.

257{
258 PRTL_ATOM_TABLE_ENTRY *CurrentBucket, *LastBucket;
259 PRTL_ATOM_TABLE_ENTRY CurrentEntry, NextEntry, *PtrEntry;
260
261 DPRINT("RtlEmptyAtomTable (AtomTable %p DeletePinned %x)\n",
262 AtomTable, DeletePinned);
263
264 if (RtlpLockAtomTable(AtomTable) == FALSE)
265 {
267 }
268
269 /* delete all atoms */
270 LastBucket = AtomTable->Buckets + AtomTable->NumberOfBuckets;
271 for (CurrentBucket = AtomTable->Buckets;
272 CurrentBucket != LastBucket;
273 CurrentBucket++)
274 {
275 NextEntry = *CurrentBucket;
276 PtrEntry = CurrentBucket;
277
278 while (NextEntry != NULL)
279 {
280 CurrentEntry = NextEntry;
281 NextEntry = NextEntry->HashLink;
282
283 if (DeletePinned || !(CurrentEntry->Flags & RTL_ATOM_IS_PINNED))
284 {
285 *PtrEntry = NextEntry;
286
287 RtlpFreeAtomHandle(AtomTable, CurrentEntry);
288
289 RtlpFreeAtomTableEntry(CurrentEntry);
290 }
291 else
292 {
293 PtrEntry = &CurrentEntry->HashLink;
294 }
295 }
296 }
297
298 RtlpUnlockAtomTable(AtomTable);
299
300 return STATUS_SUCCESS;
301}
UCHAR Flags
Definition: rtltypes.h:1677

◆ RtlLookupAtomInAtomTable()

NTSTATUS NTAPI RtlLookupAtomInAtomTable ( IN PRTL_ATOM_TABLE  AtomTable,
IN PWSTR  AtomName,
OUT PRTL_ATOM  Atom 
)

Definition at line 495 of file atom.c.

498{
499 PRTL_ATOM_TABLE_ENTRY Entry, *HashLink;
500 USHORT AtomValue;
501 RTL_ATOM FoundAtom = 0;
503
504 DPRINT("RtlLookupAtomInAtomTable (AtomTable %p AtomName %S Atom %p)\n",
505 AtomTable, AtomName, Atom);
506
507 if (RtlpCheckIntegerAtom (AtomName, &AtomValue))
508 {
509 /* integer atom */
510 if (AtomValue >= 0xC000)
511 {
513 }
514 else if (Atom != NULL)
515 {
516 *Atom = (RTL_ATOM)AtomValue;
517 }
518
519 return Status;
520 }
521
522 RtlpLockAtomTable(AtomTable);
524
525 /* string atom */
526 Entry = RtlpHashAtomName(AtomTable, AtomName, &HashLink);
527 if (Entry != NULL)
528 {
530 FoundAtom = (RTL_ATOM)Entry->Atom;
531 }
532
533 RtlpUnlockAtomTable(AtomTable);
534 if (NT_SUCCESS(Status) && Atom != NULL)
535 {
536 *Atom = FoundAtom;
537 }
538 return Status;
539}
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

◆ RtlpAllocAtomTable()

PRTL_ATOM_TABLE RtlpAllocAtomTable ( ULONG  Size)

Definition at line 407 of file libsupp.c.

408{
409 return (PRTL_ATOM_TABLE)RtlAllocateHeap(RtlGetProcessHeap(),
411 Size);
412}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by RtlCreateAtomTable().

◆ RtlpAllocAtomTableEntry()

PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry ( ULONG  Size)

Definition at line 423 of file libsupp.c.

424{
425 return (PRTL_ATOM_TABLE_ENTRY)RtlAllocateHeap(RtlGetProcessHeap(),
427 Size);
428}

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCheckIntegerAtom()

static BOOLEAN RtlpCheckIntegerAtom ( PWSTR  AtomName,
PUSHORT  AtomValue 
)
static

Definition at line 86 of file atom.c.

89{
90 UNICODE_STRING AtomString;
91 ULONG LongValue;
92 USHORT LoValue;
93 PWCHAR p;
94
95 DPRINT("RtlpCheckIntegerAtom(AtomName '%S' AtomValue %p)\n",
96 AtomName, AtomValue);
97
98 if (!((ULONG_PTR)AtomName & 0xFFFF0000))
99 {
100 LoValue = (USHORT)((ULONG_PTR)AtomName & 0xFFFF);
101
102 if (LoValue == 0)
103 LoValue = 0xC000;
104
105 if (AtomValue != NULL)
106 *AtomValue = LoValue;
107
108 return TRUE;
109 }
110
111 /*
112 * AtomName cannot be NULL because this
113 * case was caught by the previous test.
114 */
115 ASSERT(AtomName != NULL);
116
117 if (*AtomName != L'#')
118 return FALSE;
119
120 p = AtomName;
121 p++;
122 while (*p)
123 {
124 if ((*p < L'0') || (*p > L'9'))
125 return FALSE;
126 p++;
127 }
128
129 p = AtomName;
130 p++;
131 RtlInitUnicodeString(&AtomString, p);
132
133 DPRINT("AtomString: %wZ\n", &AtomString);
134
135 RtlUnicodeStringToInteger(&AtomString, 10, &LongValue);
136
137 DPRINT("LongValue: %lu\n", LongValue);
138
139 *AtomValue = (USHORT)(LongValue & 0x0000FFFF);
140
141 return TRUE;
142}
#define TRUE
Definition: types.h:120
GLfloat GLfloat p
Definition: glext.h:8902
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define L(x)
Definition: ntvdm.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by RtlAddAtomToAtomTable(), and RtlLookupAtomInAtomTable().

◆ RtlpCreateAtomHandle()

BOOLEAN RtlpCreateAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 453 of file libsupp.c.

454{
455 ULONG HandleIndex;
456 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
457
458 RtlHandle = RtlAllocateHandle(&AtomTable->RtlHandleTable,
459 &HandleIndex);
460 if (RtlHandle != NULL)
461 {
462 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
463
464 /* FIXME - Handle Indexes >= 0xC000 ?! */
465 if (HandleIndex < 0xC000)
466 {
467 Entry->HandleIndex = (USHORT)HandleIndex;
468 Entry->Atom = 0xC000 + (USHORT)HandleIndex;
469
470 AtomHandle->AtomEntry = Entry;
471 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
472
473 return TRUE;
474 }
475 else
476 {
477 /* set the valid flag, otherwise RtlFreeHandle will fail! */
478 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
479
480 RtlFreeHandle(&AtomTable->RtlHandleTable,
481 RtlHandle);
482 }
483 }
484
485 return FALSE;
486}
struct _RTL_ATOM_HANDLE * PRTL_ATOM_HANDLE
NTSYSAPI BOOLEAN NTAPI RtlFreeHandle(_In_ PRTL_HANDLE_TABLE HandleTable, _In_ PRTL_HANDLE_TABLE_ENTRY Handle)
NTSYSAPI PRTL_HANDLE_TABLE_ENTRY NTAPI RtlAllocateHandle(_In_ PRTL_HANDLE_TABLE HandleTable, _Inout_ PULONG Index)
#define RTL_HANDLE_VALID
Definition: rtltypes.h:376
RTL_HANDLE_TABLE_ENTRY Handle
Definition: libsupp.c:354
PRTL_ATOM_TABLE_ENTRY AtomEntry
Definition: libsupp.c:355
Definition: rtltypes.h:1247
ULONG Flags
Definition: rtltypes.h:1250

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCreateAtomHandleTable()

BOOLEAN RtlpCreateAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 391 of file libsupp.c.

392{
394 sizeof(RTL_ATOM_HANDLE),
395 &AtomTable->RtlHandleTable);
396
397 return TRUE;
398}
NTSYSAPI VOID NTAPI RtlInitializeHandleTable(_In_ ULONG TableSize, _In_ ULONG HandleSize, _In_ PRTL_HANDLE_TABLE HandleTable)

Referenced by RtlCreateAtomTable().

◆ RtlpDestroyAtomHandleTable()

VOID RtlpDestroyAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 401 of file libsupp.c.

402{
403 RtlDestroyHandleTable(&AtomTable->RtlHandleTable);
404}
NTSYSAPI VOID NTAPI RtlDestroyHandleTable(_Inout_ PRTL_HANDLE_TABLE HandleTable)

Referenced by RtlDestroyAtomTable().

◆ RtlpDestroyAtomTableLock()

VOID RtlpDestroyAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 367 of file libsupp.c.

368{
369 RtlDeleteCriticalSection(&AtomTable->CriticalSection);
370}
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomHandle()

VOID RtlpFreeAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 439 of file libsupp.c.

440{
441 PRTL_HANDLE_TABLE_ENTRY RtlHandleEntry;
442
443 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
444 (ULONG)Entry->HandleIndex,
445 &RtlHandleEntry))
446 {
447 RtlFreeHandle(&AtomTable->RtlHandleTable,
448 RtlHandleEntry);
449 }
450}
NTSYSAPI BOOLEAN WINAPI RtlIsValidIndexHandle(const RTL_HANDLE_TABLE *, ULONG Index, RTL_HANDLE **)

Referenced by RtlDeleteAtomFromAtomTable(), and RtlEmptyAtomTable().

◆ RtlpFreeAtomTable()

VOID RtlpFreeAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 415 of file libsupp.c.

416{
417 RtlFreeHeap(RtlGetProcessHeap(),
418 0,
419 AtomTable);
420}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomTableEntry()

VOID RtlpFreeAtomTableEntry ( PRTL_ATOM_TABLE_ENTRY  Entry)

Definition at line 431 of file libsupp.c.

432{
433 RtlFreeHeap(RtlGetProcessHeap(),
434 0,
435 Entry);
436}

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), and RtlEmptyAtomTable().

◆ RtlpGetAtomEntry()

PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry ( PRTL_ATOM_TABLE  AtomTable,
ULONG  Index 
)

Definition at line 489 of file libsupp.c.

490{
491 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
492
493 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
494 Index,
495 &RtlHandle))
496 {
497 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
498
499 return AtomHandle->AtomEntry;
500 }
501
502 return NULL;
503}
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by RtlDeleteAtomFromAtomTable(), RtlPinAtomInAtomTable(), and RtlQueryAtomInAtomTable().

◆ RtlpHashAtomName()

static PRTL_ATOM_TABLE_ENTRY RtlpHashAtomName ( IN PRTL_ATOM_TABLE  AtomTable,
IN PWSTR  AtomName,
OUT PRTL_ATOM_TABLE_ENTRY **  HashLink 
)
static

Definition at line 39 of file atom.c.

43{
45 ULONG Hash;
46
47 RtlInitUnicodeString(&Name, AtomName);
48
49 if (Name.Length != 0 &&
51 TRUE,
53 &Hash)))
54 {
57
58 Link = &AtomTable->Buckets[Hash % AtomTable->NumberOfBuckets];
59
60 /* search for an existing entry */
61 Current = *Link;
62 while (Current != NULL)
63 {
64 if (Current->NameLength == Name.Length / sizeof(WCHAR) &&
65 !_wcsicmp(Current->Name, Name.Buffer))
66 {
67 *HashLink = Link;
68 return Current;
69 }
70
71 Link = &Current->HashLink;
72 Current = Current->HashLink;
73 }
74
75 /* no matching atom found, return the hash link */
76 *HashLink = Link;
77 }
78 else
79 *HashLink = NULL;
80
81 return NULL;
82}
struct NameRec_ * Name
Definition: cdprocs.h:460
static int Hash(const char *)
Definition: reader.c:2257
#define HASH_STRING_ALGORITHM_X65599
Definition: rtlstr.c:33
NTSYSAPI NTSTATUS NTAPI RtlHashUnicodeString(_In_ CONST UNICODE_STRING *String, _In_ BOOLEAN CaseInSensitive, _In_ ULONG HashAlgorithm, _Out_ PULONG HashValue)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
UCHAR NameLength
Definition: rtltypes.h:1678
WCHAR Name[1]
Definition: rtltypes.h:1679
static int Link(const char **args)
Definition: vfdcmd.c:2414

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), and RtlLookupAtomInAtomTable().

◆ RtlPinAtomInAtomTable()

NTSTATUS NTAPI RtlPinAtomInAtomTable ( IN PRTL_ATOM_TABLE  AtomTable,
IN RTL_ATOM  Atom 
)

Definition at line 546 of file atom.c.

548{
550
551 DPRINT("RtlPinAtomInAtomTable (AtomTable %p Atom %x)\n",
552 AtomTable, Atom);
553
554 if (Atom >= 0xC000)
555 {
557
558 RtlpLockAtomTable(AtomTable);
559
560 Entry = RtlpGetAtomEntry(AtomTable, (ULONG)((USHORT)Atom - 0xC000));
561
562 if (Entry != NULL && Entry->Atom == (USHORT)Atom)
563 {
564 Entry->Flags |= RTL_ATOM_IS_PINNED;
565 }
566 else
567 {
569 }
570
571 RtlpUnlockAtomTable(AtomTable);
572 }
573
574 return Status;
575}

◆ RtlpInitAtomTableLock()

NTSTATUS RtlpInitAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 359 of file libsupp.c.

360{
361 RtlInitializeCriticalSection(&AtomTable->CriticalSection);
362 return STATUS_SUCCESS;
363}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlCreateAtomTable().

◆ RtlpLockAtomTable()

BOOLEAN RtlpLockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 374 of file libsupp.c.

375{
376 RtlEnterCriticalSection(&AtomTable->CriticalSection);
377 return TRUE;
378}
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), RtlEmptyAtomTable(), RtlLookupAtomInAtomTable(), RtlPinAtomInAtomTable(), RtlQueryAtomInAtomTable(), and RtlQueryAtomListInAtomTable().

◆ RtlpUnlockAtomTable()

VOID RtlpUnlockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 382 of file libsupp.c.

383{
384 RtlLeaveCriticalSection(&AtomTable->CriticalSection);
385}
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), RtlEmptyAtomTable(), RtlLookupAtomInAtomTable(), RtlPinAtomInAtomTable(), RtlQueryAtomInAtomTable(), and RtlQueryAtomListInAtomTable().

◆ RtlQueryAtomInAtomTable()

NTSTATUS NTAPI RtlQueryAtomInAtomTable ( PRTL_ATOM_TABLE  AtomTable,
RTL_ATOM  Atom,
PULONG  RefCount,
PULONG  PinCount,
PWSTR  AtomName,
PULONG  NameLength 
)

Definition at line 600 of file atom.c.

607{
609 BOOL Unlock = FALSE;
610
611 union
612 {
613 /* A RTL_ATOM_TABLE_ENTRY has a "WCHAR Name[1]" entry at the end.
614 * Make sure we reserve enough room to facilitate a 12 character name */
615 RTL_ATOM_TABLE_ENTRY AtomTableEntry;
616 WCHAR StringBuffer[sizeof(RTL_ATOM_TABLE_ENTRY) / sizeof(WCHAR) + 12];
617 } NumberEntry;
620
621 if (Atom < 0xC000)
622 {
623 /* Synthesize an entry */
624 NumberEntry.AtomTableEntry.Atom = Atom;
625 NumberEntry.AtomTableEntry.NameLength = swprintf(NumberEntry.AtomTableEntry.Name,
626 L"#%lu",
627 (ULONG)Atom);
628 NumberEntry.AtomTableEntry.ReferenceCount = 1;
629 NumberEntry.AtomTableEntry.Flags = RTL_ATOM_IS_PINNED;
630 Entry = &NumberEntry.AtomTableEntry;
631 }
632 else
633 {
634 RtlpLockAtomTable(AtomTable);
635 Unlock = TRUE;
636
637 Entry = RtlpGetAtomEntry(AtomTable, (ULONG)((USHORT)Atom - 0xC000));
638 }
639
640 if (Entry != NULL && Entry->Atom == (USHORT)Atom)
641 {
642 DPRINT("Atom name: %wZ\n", &Entry->Name);
643
644 if (RefCount != NULL)
645 {
646 *RefCount = Entry->ReferenceCount;
647 }
648
649 if (PinCount != NULL)
650 {
651 *PinCount = ((Entry->Flags & RTL_ATOM_IS_PINNED) != 0);
652 }
653
654 if (NULL != NameLength)
655 {
656 Length = Entry->NameLength * sizeof(WCHAR);
657 if (NULL != AtomName)
658 {
659 if (*NameLength < Length + sizeof(WCHAR))
660 {
661 if (*NameLength < 4)
662 {
663 *NameLength = Length;
665 }
666 else
667 {
668 Length = *NameLength - sizeof(WCHAR);
669 }
670 }
671 if (NT_SUCCESS(Status))
672 {
673 RtlCopyMemory(AtomName, Entry->Name, Length);
674 AtomName[Length / sizeof(WCHAR)] = L'\0';
675 *NameLength = Length;
676 }
677 }
678 else
679 {
680 *NameLength = Length;
681 }
682 }
683 else if (NULL != AtomName)
684 {
686 }
687 }
688 else
689 {
691 }
692
693 if (Unlock) RtlpUnlockAtomTable(AtomTable);
694
695 return Status;
696}
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
struct _RTL_ATOM_TABLE_ENTRY RTL_ATOM_TABLE_ENTRY
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ Unlock
Definition: ntsecapi.h:294
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ const GUID _In_ ULONG PinCount
Definition: strmini.h:505

◆ RtlQueryAtomListInAtomTable()

NTSTATUS NTAPI RtlQueryAtomListInAtomTable ( IN PRTL_ATOM_TABLE  AtomTable,
IN ULONG  MaxAtomCount,
OUT ULONG AtomCount,
OUT RTL_ATOM AtomList 
)

Definition at line 704 of file atom.c.

709{
710 PRTL_ATOM_TABLE_ENTRY *CurrentBucket, *LastBucket;
711 PRTL_ATOM_TABLE_ENTRY CurrentEntry;
712 ULONG Atoms = 0;
714
715 RtlpLockAtomTable(AtomTable);
716
717 LastBucket = AtomTable->Buckets + AtomTable->NumberOfBuckets;
718 for (CurrentBucket = AtomTable->Buckets;
719 CurrentBucket != LastBucket;
720 CurrentBucket++)
721 {
722 CurrentEntry = *CurrentBucket;
723
724 while (CurrentEntry != NULL)
725 {
726 if (MaxAtomCount > 0)
727 {
728 *(AtomList++) = (RTL_ATOM)CurrentEntry->Atom;
729 MaxAtomCount--;
730 }
731 else
732 {
733 /* buffer too small, but don't bail. we need to determine the
734 total number of atoms in the table! */
736 }
737
738 Atoms++;
739 CurrentEntry = CurrentEntry->HashLink;
740 }
741 }
742
743 *AtomCount = Atoms;
744
745 RtlpUnlockAtomTable(AtomTable);
746
747 return Status;
748}
USHORT Atom
Definition: rtltypes.h:1675
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

Referenced by NtQueryInformationAtom().