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
28 #define DICTIONARY_SIGNATURE 'dsig'
30 typedef struct _DICTIONARY_HEADER
{
31 struct _DICTIONARY_HEADER
* Next
;
34 } DICTIONARY_HEADER
, *PDICTIONARY_HEADER
;
40 IN PDICTIONARY Dictionary
43 RtlZeroMemory(Dictionary
, sizeof(DICTIONARY
));
44 Dictionary
->Signature
= DICTIONARY_SIGNATURE
;
45 KeInitializeSpinLock(&Dictionary
->SpinLock
);
51 TestDictionarySignature(
52 IN PDICTIONARY Dictionary
55 return Dictionary
->Signature
== DICTIONARY_SIGNATURE
;
60 AllocateDictionaryEntry(
61 IN PDICTIONARY Dictionary
,
68 PDICTIONARY_HEADER header
;
70 PDICTIONARY_HEADER
*entry
;
72 NTSTATUS status
= STATUS_SUCCESS
;
76 header
= ExAllocatePoolWithTag(NonPagedPool
,
77 Size
+ sizeof(DICTIONARY_HEADER
),
81 return STATUS_INSUFFICIENT_RESOURCES
;
84 RtlZeroMemory(header
, sizeof(DICTIONARY_HEADER
) + Size
);
88 // Find the correct location for this entry in the dictionary.
91 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
95 entry
= &(Dictionary
->List
);
97 while(*entry
!= NULL
) {
98 if((*entry
)->Key
== Key
) {
101 // Dictionary must have unique keys.
104 status
= STATUS_OBJECT_NAME_COLLISION
;
107 } else if ((*entry
)->Key
< Key
) {
110 // We will go ahead and insert the key in here.
114 entry
= &((*entry
)->Next
);
119 // If we make it here then we will go ahead and do the insertion.
122 header
->Next
= *entry
;
126 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
128 if(!NT_SUCCESS(status
)) {
131 *Entry
= (PVOID
) header
->Data
;
140 IN PDICTIONARY Dictionary
,
144 PDICTIONARY_HEADER entry
;
151 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
153 entry
= Dictionary
->List
;
154 while (entry
!= NULL
) {
156 if (entry
->Key
== Key
) {
164 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
172 IN PDICTIONARY Dictionary
,
176 PDICTIONARY_HEADER header
;
177 PDICTIONARY_HEADER
*entry
;
182 header
= CONTAINING_RECORD(Entry
, DICTIONARY_HEADER
, Data
);
184 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
186 entry
= &(Dictionary
->List
);
187 while(*entry
!= NULL
) {
189 if(*entry
== header
) {
190 *entry
= header
->Next
;
194 entry
= &(*entry
)->Next
;
198 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
201 // calling this w/an invalid pointer invalidates the dictionary system,
202 // so ASSERT() that we never try to Free something not in the list