ReactOS 0.4.17-dev-243-g1369312
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 309 of file atom.c.

312{
313 USHORT AtomValue;
314 PRTL_ATOM_TABLE_ENTRY *HashLink;
317
318 DPRINT("RtlAddAtomToAtomTable (AtomTable %p AtomName %S Atom %p)\n",
319 AtomTable, AtomName, Atom);
320
321 if (RtlpCheckIntegerAtom (AtomName, &AtomValue))
322 {
323 /* integer atom */
324 if (AtomValue >= 0xC000)
325 {
327 }
328 else if (Atom != NULL)
329 {
330 *Atom = (RTL_ATOM)AtomValue;
331 }
332
333 return Status;
334 }
335
336 RtlpLockAtomTable(AtomTable);
337
338 /* string atom, hash it and try to find an existing atom with the same name */
339 Entry = RtlpHashAtomName(AtomTable, AtomName, &HashLink);
340
341 if (Entry != NULL)
342 {
343 /* found another atom, increment the reference counter unless it's pinned */
344
345 if (!(Entry->Flags & RTL_ATOM_IS_PINNED))
346 {
347 if (++Entry->ReferenceCount == 0)
348 {
349 /* FIXME - references overflowed, pin the atom? */
350 Entry->Flags |= RTL_ATOM_IS_PINNED;
351 }
352 }
353
354 if (Atom != NULL)
355 {
356 *Atom = (RTL_ATOM)Entry->Atom;
357 }
358 }
359 else
360 {
361 /* couldn't find an existing atom, HashLink now points to either the
362 HashLink pointer of the previous atom or to the bucket so we can
363 simply add it to the list */
364 if (HashLink != NULL)
365 {
366 ULONG AtomNameLen = (ULONG)wcslen(AtomName);
367
368 if (AtomNameLen > RTL_MAXIMUM_ATOM_LENGTH)
369 {
371 goto end;
372 }
373
375 sizeof(Entry->Name) +
376 (AtomNameLen + 1) * sizeof(WCHAR));
377 if (Entry != NULL)
378 {
379 Entry->HashLink = NULL;
380 Entry->ReferenceCount = 1;
381 Entry->Flags = 0x0;
382
383 Entry->NameLength = (UCHAR)AtomNameLen;
384 RtlCopyMemory(Entry->Name,
385 AtomName,
386 (AtomNameLen + 1) * sizeof(WCHAR));
387
388 if (RtlpCreateAtomHandle(AtomTable, Entry))
389 {
390 /* append the atom to the list */
391 *HashLink = Entry;
392
393 if (Atom != NULL)
394 {
395 *Atom = (RTL_ATOM)Entry->Atom;
396 }
397 }
398 else
399 {
402 }
403 }
404 else
405 {
407 }
408 }
409 else
410 {
411 /* The caller supplied an empty atom name! */
413 }
414 }
415end:
416 RtlpUnlockAtomTable(AtomTable);
417
418 return Status;
419}
LONG NTSTATUS
Definition: precomp.h:26
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
Status
Definition: gdiplustypes.h:24
GLuint GLuint end
Definition: gl.h:1545
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:375
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry(ULONG Size)
Definition: libsupp.c:425
BOOLEAN RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:376
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:384
VOID RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry)
Definition: libsupp.c:433
BOOLEAN RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
Definition: libsupp.c:455
Entry
Definition: section.c:5216
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
Definition: rtltypes.h:1691
unsigned char UCHAR
Definition: typedefs.h:53
#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

◆ 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->Signature = 'motA';
178 Table->NumberOfBuckets = TableSize;
179
181 if (!NT_SUCCESS(Status))
182 {
184 return Status;
185 }
186
188 {
191 return STATUS_NO_MEMORY;
192 }
193
194 *AtomTable = Table;
195 return STATUS_SUCCESS;
196}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
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:417
BOOLEAN RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:393
NTSTATUS RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:361
VOID RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable)
Definition: libsupp.c:369
PRTL_ATOM_TABLE RtlpAllocAtomTable(ULONG Size)
Definition: libsupp.c:409
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4330

◆ RtlDeleteAtomFromAtomTable()

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

Definition at line 427 of file atom.c.

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

◆ RtlDestroyAtomTable()

NTSTATUS NTAPI RtlDestroyAtomTable ( IN PRTL_ATOM_TABLE  AtomTable)

Definition at line 204 of file atom.c.

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

Referenced by IntWinStaObjectDelete(), and main().

◆ RtlEmptyAtomTable()

NTSTATUS NTAPI RtlEmptyAtomTable ( PRTL_ATOM_TABLE  AtomTable,
BOOLEAN  DeletePinned 
)

Definition at line 255 of file atom.c.

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

◆ RtlLookupAtomInAtomTable()

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

Definition at line 496 of file atom.c.

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

◆ RtlpAllocAtomTable()

PRTL_ATOM_TABLE RtlpAllocAtomTable ( ULONG  Size)

Definition at line 409 of file libsupp.c.

410{
411 return (PRTL_ATOM_TABLE)RtlAllocateHeap(RtlGetProcessHeap(),
413 Size);
414}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
#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:4539

Referenced by RtlCreateAtomTable().

◆ RtlpAllocAtomTableEntry()

PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry ( ULONG  Size)

Definition at line 425 of file libsupp.c.

426{
427 return (PRTL_ATOM_TABLE_ENTRY)RtlAllocateHeap(RtlGetProcessHeap(),
429 Size);
430}

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
#define L(x)
Definition: resources.c:13
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)
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 455 of file libsupp.c.

456{
457 ULONG HandleIndex;
458 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
459
460 RtlHandle = RtlAllocateHandle(&AtomTable->RtlHandleTable,
461 &HandleIndex);
462 if (RtlHandle != NULL)
463 {
464 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
465
466 /* FIXME - Handle Indexes >= 0xC000 ?! */
467 if (HandleIndex < 0xC000)
468 {
469 Entry->HandleIndex = (USHORT)HandleIndex;
470 Entry->Atom = 0xC000 + (USHORT)HandleIndex;
471
472 AtomHandle->AtomEntry = Entry;
473 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
474
475 return TRUE;
476 }
477 else
478 {
479 /* set the valid flag, otherwise RtlFreeHandle will fail! */
480 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
481
482 RtlFreeHandle(&AtomTable->RtlHandleTable,
483 RtlHandle);
484 }
485 }
486
487 return FALSE;
488}
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:370
RTL_HANDLE_TABLE_ENTRY Handle
Definition: libsupp.c:356
PRTL_ATOM_TABLE_ENTRY AtomEntry
Definition: libsupp.c:357
Definition: rtltypes.h:1241
ULONG Flags
Definition: rtltypes.h:1244

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCreateAtomHandleTable()

BOOLEAN RtlpCreateAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 393 of file libsupp.c.

394{
396 sizeof(RTL_ATOM_HANDLE),
397 &AtomTable->RtlHandleTable);
398
399 return TRUE;
400}
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 403 of file libsupp.c.

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

Referenced by RtlDestroyAtomTable().

◆ RtlpDestroyAtomTableLock()

VOID RtlpDestroyAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 369 of file libsupp.c.

370{
371 RtlDeleteCriticalSection(&AtomTable->CriticalSection);
372}
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 441 of file libsupp.c.

442{
443 PRTL_HANDLE_TABLE_ENTRY RtlHandleEntry;
444
445 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
446 (ULONG)Entry->HandleIndex,
447 &RtlHandleEntry))
448 {
449 RtlFreeHandle(&AtomTable->RtlHandleTable,
450 RtlHandleEntry);
451 }
452}
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 417 of file libsupp.c.

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

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomTableEntry()

VOID RtlpFreeAtomTableEntry ( PRTL_ATOM_TABLE_ENTRY  Entry)

Definition at line 433 of file libsupp.c.

434{
435 RtlFreeHeap(RtlGetProcessHeap(),
436 0,
437 Entry);
438}

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

◆ RtlpGetAtomEntry()

PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry ( PRTL_ATOM_TABLE  AtomTable,
ULONG  Index 
)

Definition at line 491 of file libsupp.c.

492{
493 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
494
495 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
496 Index,
497 &RtlHandle))
498 {
499 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
500
501 return AtomHandle->AtomEntry;
502 }
503
504 return NULL;
505}
_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}
LPWSTR Name
Definition: desk.c:124
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
static int Hash(const char *)
Definition: reader.c:2237
NTSYSAPI NTSTATUS NTAPI RtlHashUnicodeString(_In_ CONST UNICODE_STRING *String, _In_ BOOLEAN CaseInSensitive, _In_ ULONG HashAlgorithm, _Out_ PULONG HashValue)
UCHAR NameLength
Definition: rtltypes.h:1697
WCHAR Name[1]
Definition: rtltypes.h:1698
static int Link(const char **args)
Definition: vfdcmd.c:2414
#define HASH_STRING_ALGORITHM_X65599
Definition: winternl.h:4523

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

◆ RtlPinAtomInAtomTable()

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

Definition at line 547 of file atom.c.

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

◆ RtlpInitAtomTableLock()

NTSTATUS RtlpInitAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 361 of file libsupp.c.

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

Referenced by RtlCreateAtomTable().

◆ RtlpLockAtomTable()

BOOLEAN RtlpLockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 376 of file libsupp.c.

377{
378 RtlEnterCriticalSection(&AtomTable->CriticalSection);
379 return TRUE;
380}
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 384 of file libsupp.c.

385{
386 RtlLeaveCriticalSection(&AtomTable->CriticalSection);
387}
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 601 of file atom.c.

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

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

Referenced by NtQueryInformationAtom().