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
;
39 IN PDICTIONARY Dictionary
42 RtlZeroMemory(Dictionary
, sizeof(DICTIONARY
));
43 Dictionary
->Signature
= DICTIONARY_SIGNATURE
;
44 KeInitializeSpinLock(&Dictionary
->SpinLock
);
50 TestDictionarySignature(
51 IN PDICTIONARY Dictionary
54 return Dictionary
->Signature
== DICTIONARY_SIGNATURE
;
58 AllocateDictionaryEntry(
59 IN PDICTIONARY Dictionary
,
66 PDICTIONARY_HEADER header
;
68 PDICTIONARY_HEADER
*entry
;
70 NTSTATUS status
= STATUS_SUCCESS
;
74 header
= ExAllocatePoolWithTag(NonPagedPool
,
75 Size
+ sizeof(DICTIONARY_HEADER
),
79 return STATUS_INSUFFICIENT_RESOURCES
;
82 RtlZeroMemory(header
, sizeof(DICTIONARY_HEADER
) + Size
);
86 // Find the correct location for this entry in the dictionary.
89 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
93 entry
= &(Dictionary
->List
);
95 while(*entry
!= NULL
) {
96 if((*entry
)->Key
== Key
) {
99 // Dictionary must have unique keys.
102 status
= STATUS_OBJECT_NAME_COLLISION
;
105 } else if ((*entry
)->Key
< Key
) {
108 // We will go ahead and insert the key in here.
112 entry
= &((*entry
)->Next
);
117 // If we make it here then we will go ahead and do the insertion.
120 header
->Next
= *entry
;
124 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
126 if(!NT_SUCCESS(status
)) {
129 *Entry
= (PVOID
) header
->Data
;
138 IN PDICTIONARY Dictionary
,
142 PDICTIONARY_HEADER entry
;
149 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
151 entry
= Dictionary
->List
;
152 while (entry
!= NULL
) {
154 if (entry
->Key
== Key
) {
162 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
170 IN PDICTIONARY Dictionary
,
174 PDICTIONARY_HEADER header
;
175 PDICTIONARY_HEADER
*entry
;
180 header
= CONTAINING_RECORD(Entry
, DICTIONARY_HEADER
, Data
);
182 KeAcquireSpinLock(&(Dictionary
->SpinLock
), &oldIrql
);
184 entry
= &(Dictionary
->List
);
185 while(*entry
!= NULL
) {
187 if(*entry
== header
) {
188 *entry
= header
->Next
;
192 entry
= &(*entry
)->Next
;
196 KeReleaseSpinLock(&(Dictionary
->SpinLock
), oldIrql
);
199 // calling this w/an invalid pointer invalidates the dictionary system,
200 // so ASSERT() that we never try to Free something not in the list