ReactOS  0.4.15-dev-1201-gb2cf5a4
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)) {
147  FREE_POOL(header);
148  } else {
149  *Entry = (PVOID) header->Data;
150  }
151  }
152  return status;
153 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define FINALLY
Definition: classpnp.h:116
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2706
LONG NTSTATUS
Definition: precomp.h:26
#define LEAVE
Definition: classpnp.h:115
#define TRY(sps, bps)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
uint32_t entry
Definition: isohybrid.c:63
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
struct CFHEADER header
Definition: fdi.c:101
base of all file and directory entries
Definition: entries.h:82
Definition: ps.c:97

◆ 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) {
225  FREE_POOL(header);
226  }
227 
228  return;
229 
230 }
#define TRUE
Definition: types.h:120
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define FREE_POOL(_PoolPtr)
Definition: cdrom.h:782
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
uint32_t entry
Definition: isohybrid.c:63
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct CFHEADER header
Definition: fdi.c:101
base of all file and directory entries
Definition: entries.h:82
#define NT_ASSERT
Definition: rtlfuncs.h:3312

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 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
uint32_t entry
Definition: isohybrid.c:63
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

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 }
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
#define DICTIONARY_SIGNATURE
Definition: dictlib.c:38
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ TestDictionarySignature()

BOOLEAN TestDictionarySignature ( IN PDICTIONARY  Dictionary)

Definition at line 70 of file dictlib.c.

73 {
74  return Dictionary->Signature == DICTIONARY_SIGNATURE;
75 }
#define DICTIONARY_SIGNATURE
Definition: dictlib.c:38