ReactOS 0.4.15-dev-8236-g99f0937
dictlib.c File Reference
#include <ntddk.h>
#include <classpnp.h>
Include dependency graph for dictlib.c:

Go to the source code of this file.

Classes

struct  _DICTIONARY_HEADER
 

Macros

#define DICTIONARY_SIGNATURE   'tciD'
 

Typedefs

typedef struct _DICTIONARY_HEADER DICTIONARY_HEADER
 
typedef struct _DICTIONARY_HEADERPDICTIONARY_HEADER
 

Functions

VOID InitializeDictionary (IN PDICTIONARY Dictionary)
 
BOOLEAN TestDictionarySignature (IN PDICTIONARY Dictionary)
 
NTSTATUS AllocateDictionaryEntry (IN PDICTIONARY Dictionary, IN ULONGLONG Key, _In_range_(0, sizeof(FILE_OBJECT_EXTENSION)) IN ULONG Size, IN ULONG Tag, OUT PVOID *Entry)
 
PVOID GetDictionaryEntry (IN PDICTIONARY Dictionary, IN ULONGLONG Key)
 
VOID FreeDictionaryEntry (IN PDICTIONARY Dictionary, IN PVOID Entry)
 

Macro Definition Documentation

◆ DICTIONARY_SIGNATURE

#define DICTIONARY_SIGNATURE   'tciD'

Definition at line 38 of file dictlib.c.

Typedef Documentation

◆ DICTIONARY_HEADER

Definition at line 54 of file dictlib.c.

◆ PDICTIONARY_HEADER

Definition at line 54 of file dictlib.c.

Function Documentation

◆ AllocateDictionaryEntry()

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 at line 78 of file dictlib.c.

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}
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 NULL
Definition: types.h:112
#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
uint32_t entry
Definition: isohybrid.c:63
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:83
Definition: ps.c:97
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#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

◆ FreeDictionaryEntry()

VOID FreeDictionaryEntry ( IN PDICTIONARY  Dictionary,
IN PVOID  Entry 
)

Definition at line 189 of file dictlib.c.

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}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by ClasspCreateClose().

◆ GetDictionaryEntry()

PVOID GetDictionaryEntry ( IN PDICTIONARY  Dictionary,
IN ULONGLONG  Key 
)

Definition at line 157 of file dictlib.c.

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}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by _IRQL_requires_max_().

◆ InitializeDictionary()

VOID InitializeDictionary ( IN PDICTIONARY  Dictionary)

Definition at line 58 of file dictlib.c.

61{
62 RtlZeroMemory(Dictionary, sizeof(DICTIONARY));
63 Dictionary->Signature = DICTIONARY_SIGNATURE;
64 KeInitializeSpinLock(&Dictionary->SpinLock);
65 return;
66}
#define DICTIONARY_SIGNATURE
Definition: dictlib.c:38
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604

◆ TestDictionarySignature()

BOOLEAN TestDictionarySignature ( IN PDICTIONARY  Dictionary)

Definition at line 70 of file dictlib.c.

73{
74 return Dictionary->Signature == DICTIONARY_SIGNATURE;
75}