3 Copyright (C) Microsoft Corporation, 1990 - 1999
11 Support library for maintaining a dictionary list (list of objects
12 referenced by a key value).
20 This module generates a static library
29 #define DICTIONARY_SIGNATURE (((ULONG)'dict' << 32) + 'sig ')
31 struct _DICTIONARY_HEADER
{
32 struct _DICTIONARY_HEADER
* Next
;
37 struct _DICTIONARY_HEADER
;
38 typedef struct _DICTIONARY_HEADER DICTIONARY_HEADER
, *PDICTIONARY_HEADER
;
43 IN PDICTIONARY Dictionary
46 RtlZeroMemory(Dictionary
, sizeof(Dictionary
));
47 Dictionary
->Signature
= DICTIONARY_SIGNATURE
;
48 KeInitializeSpinLock(&Dictionary
->SpinLock
);
54 TestDictionarySignature(
55 IN PDICTIONARY Dictionary
58 return Dictionary
->Signature
== DICTIONARY_SIGNATURE
;
62 AllocateDictionaryEntry(
63 IN PDICTIONARY Dictionary
,
70 PDICTIONARY_HEADER header
;
72 PDICTIONARY_HEADER
*entry
;
74 NTSTATUS status
= STATUS_SUCCESS
;
78 header
= ExAllocatePoolWithTag(NonPagedPool
,
79 Size
+ sizeof(DICTIONARY_HEADER
),
83 return STATUS_INSUFFICIENT_RESOURCES
;
86 RtlZeroMemory(header
, sizeof(DICTIONARY_HEADER
) + Size
);
90 // Find the correct location for this entry in the dictionary.
93 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
97 entry
= &(Dictionary
->List
);
99 while(*entry
!= NULL
) {
100 if((*entry
)->Key
== Key
) {
103 // Dictionary must have unique keys.
106 status
= STATUS_OBJECT_NAME_COLLISION
;
109 } else if ((*entry
)->Key
< Key
) {
112 // We will go ahead and insert the key in here.
116 entry
= &((*entry
)->Next
);
121 // If we make it here then we will go ahead and do the insertion.
124 header
->Next
= *entry
;
128 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
130 if(!NT_SUCCESS(status
)) {
133 *Entry
= (PVOID
) header
->Data
;
142 IN PDICTIONARY Dictionary
,
146 PDICTIONARY_HEADER entry
;
153 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
155 entry
= Dictionary
->List
;
156 while (entry
!= NULL
) {
158 if (entry
->Key
== Key
) {
166 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
174 IN PDICTIONARY Dictionary
,
178 PDICTIONARY_HEADER header
;
179 PDICTIONARY_HEADER
*entry
;
184 header
= CONTAINING_RECORD(Entry
, DICTIONARY_HEADER
, Data
);
186 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
188 entry
= &(Dictionary
->List
);
189 while(*entry
!= NULL
) {
191 if(*entry
== header
) {
192 *entry
= header
->Next
;
196 entry
= &(*entry
)->Next
;
200 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
203 // calling this w/an invalid pointer invalidates the dictionary system,
204 // so ASSERT() that we never try to Free something not in the list