ReactOS 0.4.15-dev-7788-g1ad9096
dictlib.c
Go to the documentation of this file.
1/*++
2
3Copyright (C) Microsoft Corporation, 1990 - 1999
4
5Module Name:
6
7 dictlib.c
8
9Abstract:
10
11 Support library for maintaining a dictionary list (list of objects
12 referenced by a key value).
13
14Environment:
15
16 kernel mode only
17
18Notes:
19
20 This module generates a static library
21
22Revision History:
23
24--*/
25
26#include <ntddk.h>
27#include <classpnp.h>
28
29#ifdef __REACTOS__
30#undef MdlMappingNoExecute
31#define MdlMappingNoExecute 0
32#define NonPagedPoolNx NonPagedPool
33#define NonPagedPoolNxCacheAligned NonPagedPoolCacheAligned
34#undef POOL_NX_ALLOCATION
35#define POOL_NX_ALLOCATION 0
36#endif
37
38#define DICTIONARY_SIGNATURE 'tciD'
39
40#ifdef _MSC_VER
41#pragma warning(push)
42#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
43#endif
48};
49#ifdef _MSC_VER
50#pragma warning(pop)
51#endif
52
55
56
57VOID
59 IN PDICTIONARY Dictionary
60 )
61{
62 RtlZeroMemory(Dictionary, sizeof(DICTIONARY));
63 Dictionary->Signature = DICTIONARY_SIGNATURE;
64 KeInitializeSpinLock(&Dictionary->SpinLock);
65 return;
66}
67
68
71 IN PDICTIONARY Dictionary
72 )
73{
74 return Dictionary->Signature == DICTIONARY_SIGNATURE;
75}
76
79 IN PDICTIONARY Dictionary,
82 IN ULONG Tag,
84 )
85{
87 KIRQL oldIrql;
89
91
92 *Entry = NULL;
93
94 header = ExAllocatePoolWithTag(NonPagedPoolNx,
95 Size + sizeof(DICTIONARY_HEADER),
96 Tag);
97
98 if(header == NULL) {
100 }
101
103 header->Key = Key;
104
105 //
106 // Find the correct location for this entry in the dictionary.
107 //
108
109 KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
110
111 TRY {
112
113 entry = &(Dictionary->List);
114
115 while(*entry != NULL) {
116 if((*entry)->Key == Key) {
117
118 //
119 // Dictionary must have unique keys.
120 //
121
123 LEAVE;
124
125 } else if ((*entry)->Key < Key) {
126
127 //
128 // We will go ahead and insert the key in here.
129 //
130 break;
131 } else {
132 entry = &((*entry)->Next);
133 }
134 }
135
136 //
137 // If we make it here then we will go ahead and do the insertion.
138 //
139
140 header->Next = *entry;
141 *entry = header;
142
143 } FINALLY {
144 KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
145
146 if(!NT_SUCCESS(status)) {
148 } else {
149 *Entry = (PVOID) header->Data;
150 }
151 }
152 return status;
153}
154
155
156PVOID
158 IN PDICTIONARY Dictionary,
160 )
161{
163 PVOID data;
164 KIRQL oldIrql;
165
166
167 data = NULL;
168
169 KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
170
171 entry = Dictionary->List;
172 while (entry != NULL) {
173
174 if (entry->Key == Key) {
175 data = entry->Data;
176 break;
177 } else {
178 entry = entry->Next;
179 }
180 }
181
182 KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
183
184 return data;
185}
186
187
188VOID
190 IN PDICTIONARY Dictionary,
192 )
193{
196 KIRQL oldIrql;
197 BOOLEAN found;
198
199 found = FALSE;
201
202 KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
203
204 entry = &(Dictionary->List);
205 while(*entry != NULL) {
206
207 if(*entry == header) {
208 *entry = header->Next;
209 found = TRUE;
210 break;
211 } else {
212 entry = &(*entry)->Next;
213 }
214 }
215
216 KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
217
218 //
219 // calling this w/an invalid pointer invalidates the dictionary system,
220 // so NT_ASSERT() that we never try to Free something not in the list
221 //
222
223 NT_ASSERT(found);
224 if (found) {
226 }
227
228 return;
229
230}
231
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
#define FINALLY
Definition: classpnp.h:116
#define LEAVE
Definition: classpnp.h:115
#define DICTIONARY_SIGNATURE
Definition: dictlib.c:38
NTSTATUS AllocateDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key, _In_range_(0, sizeof(FILE_OBJECT_EXTENSION)) IN ULONG Size, IN ULONG Tag, OUT PVOID *Entry)
Definition: dictlib.c:78
VOID InitializeDictionary(IN PDICTIONARY Dictionary)
Definition: dictlib.c:58
BOOLEAN TestDictionarySignature(IN PDICTIONARY Dictionary)
Definition: dictlib.c:70
VOID FreeDictionaryEntry(IN PDICTIONARY Dictionary, IN PVOID Entry)
Definition: dictlib.c:189
struct _DICTIONARY_HEADER * PDICTIONARY_HEADER
Definition: dictlib.c:54
PVOID GetDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key)
Definition: dictlib.c:157
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
uint32_t entry
Definition: isohybrid.c:63
#define _In_range_(lb, ub)
Definition: ms_sal.h:571
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:83
ULONGLONG Key
Definition: dictlib.c:46
PDICTIONARY_HEADER Next
Definition: dictlib.c:45
Definition: ps.c:97
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TRY(sps, bps)
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define NT_ASSERT
Definition: rtlfuncs.h:3310
unsigned char UCHAR
Definition: xmlstorage.h:181