Modified: trunk/reactos/include/ndk/extypes.h
Modified: trunk/reactos/include/ndk/rtlfuncs.h
Modified: trunk/reactos/include/ndk/rtltypes.h
Modified: trunk/reactos/include/ndk/umtypes.h
Modified: trunk/reactos/include/ntdll/rtl.h
Modified: trunk/reactos/include/ntos/rtltypes.h
Modified: trunk/reactos/lib/ntdll/ntdll.xml
Deleted: trunk/reactos/lib/ntdll/rtl/atom.c
Modified: trunk/reactos/lib/ntdll/rtl/handle.c
Modified: trunk/reactos/lib/ntdll/rtl/libsupp.c
Added: trunk/reactos/lib/rtl/atom.c
Modified: trunk/reactos/lib/rtl/rtl.xml
Deleted: trunk/reactos/ntoskrnl/include/internal/handle.h
Modified: trunk/reactos/ntoskrnl/include/ntoskrnl.h
Modified: trunk/reactos/ntoskrnl/ntoskrnl.xml
Modified: trunk/reactos/ntoskrnl/rtl/atom.c
Deleted: trunk/reactos/ntoskrnl/rtl/handle.c
Modified: trunk/reactos/ntoskrnl/rtl/libsupp.c
--- trunk/reactos/include/ndk/extypes.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ndk/extypes.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -86,7 +86,7 @@
ERESOURCE HandleTableLock;
LIST_ENTRY HandleTableList;
KEVENT HandleContentionEvent;
-} HANDLE_TABLE;
+} HANDLE_TABLE, *PHANDLE_TABLE;
#endif
--- trunk/reactos/include/ndk/rtlfuncs.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ndk/rtlfuncs.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -859,6 +859,14 @@
PULONG Value
);
+NTSTATUS
+STDCALL
+RtlHashUnicodeString(
+ IN CONST UNICODE_STRING *String,
+ IN BOOLEAN CaseInSensitive,
+ IN ULONG HashAlgorithm,
+ OUT PULONG HashValue);
+
/*
* Ansi String Functions
*/
@@ -1333,7 +1341,7 @@
/*
* Handle Table Functions
*/
-PRTL_HANDLE
+PRTL_HANDLE_TABLE_ENTRY
STDCALL
RtlAllocateHandle (
IN PRTL_HANDLE_TABLE HandleTable,
@@ -1348,7 +1356,7 @@
STDCALL
RtlFreeHandle (
IN PRTL_HANDLE_TABLE HandleTable,
- IN PRTL_HANDLE Handle
+ IN PRTL_HANDLE_TABLE_ENTRY Handle
);
VOID
@@ -1363,15 +1371,15 @@
STDCALL
RtlIsValidHandle (
IN PRTL_HANDLE_TABLE HandleTable,
- IN PRTL_HANDLE Handle
+ IN PRTL_HANDLE_TABLE_ENTRY Handle
);
BOOLEAN
STDCALL
RtlIsValidIndexHandle (
- IN PRTL_HANDLE_TABLE HandleTable,
- IN OUT PRTL_HANDLE *Handle,
- IN ULONG Index
+ IN PRTL_HANDLE_TABLE HandleTable,
+ IN OUT PRTL_HANDLE_TABLE_ENTRY *Handle,
+ IN ULONG Index
);
/*
--- trunk/reactos/include/ndk/rtltypes.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ndk/rtltypes.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -50,6 +50,13 @@
#define PDI_HEAP_TAGS 0x08 /* The heap tags */
#define PDI_HEAP_BLOCKS 0x10 /* The heap blocks */
#define PDI_LOCKS 0x20 /* The locks created by the process */
+
+/* RTL Handle Flags */
+#define RTL_HANDLE_VALID 0x1
+
+/* RTL Atom Flags */
+#define RTL_ATOM_IS_PINNED 0x1
+
/* ENUMERATIONS **************************************************************/
typedef enum
@@ -173,20 +180,23 @@
ULONG NumberOfSharedWaiters;
ULONG NumberOfExclusiveWaiters;
} DEBUG_LOCK_INFORMATION, *PDEBUG_LOCK_INFORMATION;
-typedef struct _RTL_HANDLE
+
+typedef struct _RTL_HANDLE_TABLE_ENTRY
{
- struct _RTL_HANDLE *Next; /* pointer to next free handle */
-} RTL_HANDLE, *PRTL_HANDLE;
-
+ ULONG Flags;
+ struct _RTL_HANDLE_TABLE_ENTRY *NextFree;
+} RTL_HANDLE_TABLE_ENTRY, *PRTL_HANDLE_TABLE_ENTRY;
typedef struct _RTL_HANDLE_TABLE
{
- ULONG TableSize; /* maximum number of handles */
- ULONG HandleSize; /* size of handle in bytes */
- PRTL_HANDLE Handles; /* pointer to handle array */
- PRTL_HANDLE Limit; /* limit of pointers */
- PRTL_HANDLE FirstFree; /* pointer to first free handle */
- PRTL_HANDLE LastUsed; /* pointer to last allocated handle */
+ ULONG MaximumNumberOfHandles;
+ ULONG SizeOfHandleTableEntry;
+ ULONG Reserved[2];
+ PRTL_HANDLE_TABLE_ENTRY FreeHandles;
+ PRTL_HANDLE_TABLE_ENTRY CommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY UnCommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY MaxReservedHandles;
} RTL_HANDLE_TABLE, *PRTL_HANDLE_TABLE;
+
typedef struct _LOCK_INFORMATION
{
ULONG LockCount;
@@ -346,15 +356,32 @@
SECTION_IMAGE_INFORMATION ImageInfo;
} RTL_PROCESS_INFO, *PRTL_PROCESS_INFO;
-/* FIXME: This is a Windows Type which which we are not implementing properly
- The type below however is our own implementation. We will eventually use Windows' */
-typedef struct _RTL_ATOM_TABLE
+typedef struct _RTL_ATOM_TABLE_ENTRY
{
- ULONG TableSize;
- ULONG NumberOfAtoms;
- PVOID Lock; /* fast mutex (kernel mode)/ critical section (user mode) */
- PVOID HandleTable;
- LIST_ENTRY Slot[0];
+ struct _RTL_ATOM_TABLE_ENTRY *HashLink;
+ USHORT HandleIndex;
+ USHORT Atom;
+ USHORT ReferenceCount;
+ UCHAR Flags;
+ UCHAR NameLength;
+ WCHAR Name[1];
+} RTL_ATOM_TABLE_ENTRY, *PRTL_ATOM_TABLE_ENTRY;
+
+typedef struct _RTL_ATOM_TABLE
+{
+ ULONG Signature;
+ union
+ {
+ RTL_CRITICAL_SECTION CriticalSection;
+ FAST_MUTEX FastMutex;
+ };
+ union
+ {
+ RTL_HANDLE_TABLE RtlHandleTable;
+ PHANDLE_TABLE ExHandleTable;
+ };
+ ULONG NumberOfBuckets;
+ PRTL_ATOM_TABLE_ENTRY Buckets[1];
} RTL_ATOM_TABLE, *PRTL_ATOM_TABLE;
/* Let Kernel Drivers use this */
--- trunk/reactos/include/ndk/umtypes.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ndk/umtypes.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -1382,6 +1382,10 @@
PUNICODE_PREFIX_TABLE_ENTRY LastNextEntry;
} UNICODE_PREFIX_TABLE, *PUNICODE_PREFIX_TABLE;
+/* FIXME - need FAST_MUTEX and PHANDLE_TABLE for RTL_ATOM_TABLE in umode! */
+typedef void *FAST_MUTEX;
+typedef void *PHANDLE_TABLE;
+
typedef OSVERSIONINFOW RTL_OSVERSIONINFOW;
typedef LPOSVERSIONINFOW PRTL_OSVERSIONINFOW;
typedef OSVERSIONINFOEXW RTL_OSVERSIONINFOEXW;
--- trunk/reactos/include/ntdll/rtl.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ntdll/rtl.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -132,19 +132,21 @@
PVOID DebugInfo; /* ?? */
} RTL_RESOURCE, *PRTL_RESOURCE;
-typedef struct _RTL_HANDLE
+typedef struct _RTL_HANDLE_TABLE_ENTRY
{
- struct _RTL_HANDLE *Next; /* pointer to next free handle */
-} RTL_HANDLE, *PRTL_HANDLE;
+ ULONG Flags;
+ struct _RTL_HANDLE_TABLE_ENTRY *NextFree;
+} RTL_HANDLE_TABLE_ENTRY, *PRTL_HANDLE_TABLE_ENTRY;
typedef struct _RTL_HANDLE_TABLE
{
- ULONG TableSize; /* maximum number of handles */
- ULONG HandleSize; /* size of handle in bytes */
- PRTL_HANDLE Handles; /* pointer to handle array */
- PRTL_HANDLE Limit; /* limit of pointers */
- PRTL_HANDLE FirstFree; /* pointer to first free handle */
- PRTL_HANDLE LastUsed; /* pointer to last allocated handle */
+ ULONG MaximumNumberOfHandles;
+ ULONG SizeOfHandleTableEntry;
+ ULONG Reserved[2];
+ PRTL_HANDLE_TABLE_ENTRY FreeHandles;
+ PRTL_HANDLE_TABLE_ENTRY CommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY UnCommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY MaxReservedHandles;
} RTL_HANDLE_TABLE, *PRTL_HANDLE_TABLE;
@@ -594,7 +596,7 @@
/* handle table functions */
-PRTL_HANDLE
+PRTL_HANDLE_TABLE_ENTRY
STDCALL
RtlAllocateHandle (
IN PRTL_HANDLE_TABLE HandleTable,
@@ -611,7 +613,7 @@
STDCALL
RtlFreeHandle (
IN PRTL_HANDLE_TABLE HandleTable,
- IN PRTL_HANDLE Handle
+ IN PRTL_HANDLE_TABLE_ENTRY Handle
);
VOID
@@ -626,14 +628,14 @@
STDCALL
RtlIsValidHandle (
IN PRTL_HANDLE_TABLE HandleTable,
- IN PRTL_HANDLE Handle
+ IN PRTL_HANDLE_TABLE_ENTRY Handle
);
BOOLEAN
STDCALL
RtlIsValidIndexHandle (
IN PRTL_HANDLE_TABLE HandleTable,
- IN OUT PRTL_HANDLE *Handle,
+ IN OUT PRTL_HANDLE_TABLE_ENTRY *Handle,
IN ULONG Index
);
--- trunk/reactos/include/ntos/rtltypes.h 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/include/ntos/rtltypes.h 2005-06-24 18:11:16 UTC (rev 16257)
@@ -227,18 +227,51 @@
ULONG Unknown[11];
} RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION;
+typedef struct _RTL_HANDLE_TABLE_ENTRY
+{
+ ULONG Flags;
+ struct _RTL_HANDLE_TABLE_ENTRY *NextFree;
+} RTL_HANDLE_TABLE_ENTRY, *PRTL_HANDLE_TABLE_ENTRY;
+typedef struct _RTL_HANDLE_TABLE
+{
+ ULONG MaximumNumberOfHandles;
+ ULONG SizeOfHandleTableEntry;
+ ULONG Reserved[2];
+ PRTL_HANDLE_TABLE_ENTRY FreeHandles;
+ PRTL_HANDLE_TABLE_ENTRY CommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY UnCommittedHandles;
+ PRTL_HANDLE_TABLE_ENTRY MaxReservedHandles;
+} RTL_HANDLE_TABLE, *PRTL_HANDLE_TABLE;
+
+typedef struct _RTL_ATOM_TABLE_ENTRY
+{
+ struct _RTL_ATOM_TABLE_ENTRY *HashLink;
+ USHORT HandleIndex;
+ USHORT Atom;
+ USHORT ReferenceCount;
+ UCHAR Flags;
+ UCHAR NameLength;
+ WCHAR Name[1];
+} RTL_ATOM_TABLE_ENTRY, *PRTL_ATOM_TABLE_ENTRY;
+
typedef struct _RTL_ATOM_TABLE
{
- ULONG TableSize;
- ULONG NumberOfAtoms;
- PVOID Lock; /* fast mutex (kernel mode)/ critical section (user mode) */
- PVOID HandleTable;
- LIST_ENTRY Slot[0];
+ ULONG Signature;
+ union
+ {
+ RTL_CRITICAL_SECTION CriticalSection;
+ FAST_MUTEX FastMutex;
+ };
+ union
+ {
+ RTL_HANDLE_TABLE RtlHandleTable;
+ PHANDLE_TABLE ExHandleTable;
+ };
+ ULONG NumberOfBuckets;
+ PRTL_ATOM_TABLE_ENTRY Buckets[1];
} RTL_ATOM_TABLE, *PRTL_ATOM_TABLE;
-
-
#include <pshpack1.h>
typedef struct _NLS_FILE_HEADER
--- trunk/reactos/lib/ntdll/ntdll.xml 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/lib/ntdll/ntdll.xml 2005-06-24 18:11:16 UTC (rev 16257)
@@ -36,7 +36,6 @@
<file>ftol.c</file>
</directory>
<file>apc.c</file>
- <file>atom.c</file>
<file>callback.c</file>
<file>crc32.c</file>
<file>critical.c</file>
--- trunk/reactos/lib/ntdll/rtl/atom.c 2005-06-24 16:39:49 UTC (rev 16256)
+++ trunk/reactos/lib/ntdll/rtl/atom.c 2005-06-24 18:11:16 UTC (rev 16257)
@@ -1,722 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: lib/ntdll/rtl/atom.c
- * PURPOSE: Atom managment
- * PROGRAMMER: Nobody
- * UPDATE HISTORY:
- * Created 22/05/98
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntdll.h>
-#define NDEBUG
-#include <debug.h>
-
-/* LOCAL TYPES ***************************************************************/
-
-typedef struct _RTL_ATOM_ENTRY
-{
- LIST_ENTRY List;
- UNICODE_STRING Name;
- ULONG RefCount;
- BOOLEAN Locked;
- ULONG Index;
- PRTL_HANDLE Handle;
-} RTL_ATOM_ENTRY, *PRTL_ATOM_ENTRY;
-
-typedef struct _RTL_ATOM_HANDLE
-{
- RTL_HANDLE Handle;
- PRTL_ATOM_ENTRY Entry;
-} RTL_ATOM_HANDLE, *PRTL_ATOM_HANDLE;
-
-
-/* PROTOTYPES ****************************************************************/
-
-static ULONG RtlpHashAtomName(ULONG TableSize, PWSTR AtomName);
-static BOOLEAN RtlpCheckIntegerAtom(PWSTR AtomName, PUSHORT AtomValue);
-
-static NTSTATUS RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable);
-static VOID RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable);
-static BOOLEAN RtlpLockAtomTable(PRTL_ATOM_TABLE AtomTable);
-static VOID RtlpUnlockAtomTable(PRTL_ATOM_TABLE AtomTable);
-
-static BOOLEAN RtlpCreateAtomHandleTable(PRTL_ATOM_TABLE AtomTable);
-static VOID RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable);
-
-
-/* FUNCTIONS *****************************************************************/
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlCreateAtomTable(ULONG TableSize,
- PRTL_ATOM_TABLE *AtomTable)
-{
- PRTL_ATOM_TABLE Table;
- ULONG i;
- NTSTATUS Status;
-
- DPRINT("RtlCreateAtomTable(TableSize %lu AtomTable %p)\n",
- TableSize, AtomTable);
-
- if (*AtomTable != NULL)
- {
- return STATUS_SUCCESS;
- }
-
- /* allocate atom table */
- Table = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- TableSize * sizeof(LIST_ENTRY) +
- sizeof(RTL_ATOM_TABLE));
- if (Table == NULL)
- {
- return STATUS_NO_MEMORY;
- }
-
- /* initialize atom table */
- Table->TableSize = TableSize;
-
- for (i = 0; i < TableSize; i++)
- {
- InitializeListHead(&Table->Slot[i]);
- }
-
- Status = RtlpInitAtomTableLock(Table);
- if (!NT_SUCCESS(Status))
- {
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- Table);
- return Status;
- }
-
- if (RtlpCreateAtomHandleTable(Table) == FALSE)
- {
- RtlpDestroyAtomTableLock(Table);
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- Table);
- return STATUS_NO_MEMORY;
- }
-
- *AtomTable = Table;
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlDestroyAtomTable(IN PRTL_ATOM_TABLE AtomTable)
-{
- PLIST_ENTRY Current;
- PRTL_ATOM_ENTRY AtomEntry;
- ULONG i;
-
- if (RtlpLockAtomTable(AtomTable) == FALSE)
- {
- return (STATUS_INVALID_PARAMETER);
- }
-
- /* delete all atoms */
- for (i = 0; i < AtomTable->TableSize; i++)
- {
-
- Current = AtomTable->Slot[i].Flink;
- while (Current != &AtomTable->Slot[i])
- {
- AtomEntry = (PRTL_ATOM_ENTRY)Current;
- RtlFreeUnicodeString(&AtomEntry->Name);
- RemoveEntryList(&AtomEntry->List);
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- AtomEntry);
- Current = AtomTable->Slot[i].Flink;
- }
-
- }
-
- RtlpDestroyAtomHandleTable(AtomTable);
-
- RtlpUnlockAtomTable(AtomTable);
-
- RtlpDestroyAtomTableLock(AtomTable);
-
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlEmptyAtomTable(PRTL_ATOM_TABLE AtomTable,
- BOOLEAN DeletePinned)
-{
- PLIST_ENTRY Current, Next;
- PRTL_ATOM_ENTRY AtomEntry;
- ULONG i;
-
- DPRINT("RtlEmptyAtomTable (AtomTable %p DeletePinned %x)\n",
- AtomTable, DeletePinned);
-
- if (RtlpLockAtomTable(AtomTable) == FALSE)
- {
- return (STATUS_INVALID_PARAMETER);
- }
-
- /* delete all atoms */
- for (i = 0; i < AtomTable->TableSize; i++)
- {
- Current = AtomTable->Slot[i].Flink;
- while (Current != &AtomTable->Slot[i])
- {
- Next = Current->Flink;
- AtomEntry = (PRTL_ATOM_ENTRY)Current;
-
- if ((AtomEntry->Locked == FALSE) ||
- ((AtomEntry->Locked == TRUE) && (DeletePinned == TRUE)))
- {
- RtlFreeUnicodeString(&AtomEntry->Name);
-
- RtlFreeHandle(AtomTable->HandleTable,
- AtomEntry->Handle);
-
- RemoveEntryList(&AtomEntry->List);
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- AtomEntry);
- }
- Current = Next;
- }
-
- }
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlAddAtomToAtomTable(IN PRTL_ATOM_TABLE AtomTable,
- IN PWSTR AtomName,
- OUT PRTL_ATOM Atom)
-{
- ULONG Hash;
- PLIST_ENTRY Current;
- PRTL_ATOM_ENTRY Entry;
- USHORT AtomValue;
- NTSTATUS Status;
- PRTL_ATOM_HANDLE AtomHandle;
- ULONG AtomIndex;
-
- DPRINT("RtlAddAtomToAtomTable (AtomTable %p AtomName %S Atom %p)\n",
- AtomTable, AtomName, Atom);
-
- if (RtlpCheckIntegerAtom (AtomName, &AtomValue))
- {
- /* integer atom */
- if (AtomValue >= 0xC000)
- {
- AtomValue = 0;
- Status = STATUS_INVALID_PARAMETER;
- }
- else
- {
- Status = STATUS_SUCCESS;
- }
-
- if (Atom)
- *Atom = (RTL_ATOM)AtomValue;
-
- return Status;
- }
-
- RtlpLockAtomTable(AtomTable);
-
- /* string atom */
- Hash = RtlpHashAtomName(AtomTable->TableSize, AtomName);
-
- /* search for existing atom */
- Current = AtomTable->Slot[Hash].Flink;
- while (Current != &AtomTable->Slot[Hash])
- {
- Entry = (PRTL_ATOM_ENTRY)Current;
-
- DPRINT("Comparing %S and %S\n", Entry->Name.Buffer, AtomName);
- if (_wcsicmp(Entry->Name.Buffer, AtomName) == 0)
- {
- Entry->RefCount++;
- if (Atom)
- *Atom = (RTL_ATOM)(Entry->Index + 0xC000);
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_SUCCESS;
- }
- Current = Current->Flink;
- }
-
- /* insert new atom */
- Entry = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(RTL_ATOM_ENTRY));
- if (Entry == NULL)
- {
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_NO_MEMORY;
- }
-
- InsertTailList(&AtomTable->Slot[Hash], &Entry->List);
- RtlCreateUnicodeString (&Entry->Name,
- AtomName);
- Entry->RefCount = 1;
- Entry->Locked = FALSE;
-
- /* FIXME: use general function instead !! */
- AtomHandle = (PRTL_ATOM_HANDLE)RtlAllocateHandle(AtomTable->HandleTable,
- &AtomIndex);
-
- DPRINT("AtomHandle %p AtomIndex %x\n", AtomHandle, AtomIndex);
-
- AtomHandle->Entry = Entry;
- Entry->Index = AtomIndex;
- Entry->Handle = (PRTL_HANDLE)AtomHandle;
-
- if (Atom)
- *Atom = (RTL_ATOM)(AtomIndex + 0xC000);
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlDeleteAtomFromAtomTable(IN PRTL_ATOM_TABLE AtomTable,
- IN RTL_ATOM Atom)
-{
- PRTL_ATOM_HANDLE AtomHandle;
- PRTL_ATOM_ENTRY AtomEntry;
-
- DPRINT("RtlDeleteAtomFromAtomTable (AtomTable %p Atom %x)\n",
- AtomTable, Atom);
-
- if (Atom < 0xC000)
- {
- return STATUS_SUCCESS;
- }
-
- RtlpLockAtomTable(AtomTable);
-
- /* FIXME: use general function instead !! */
- if (!RtlIsValidIndexHandle(AtomTable->HandleTable,
- (PRTL_HANDLE *)&AtomHandle,
- (ULONG)Atom - 0xC000))
- {
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_INVALID_HANDLE;
- }
-
- DPRINT("AtomHandle %x\n", AtomHandle);
- DPRINT("AtomHandle->Entry %x\n", AtomHandle->Entry);
-
- AtomEntry = AtomHandle->Entry;
-
- DPRINT("Atom name: %wZ\n", &AtomEntry->Name);
-
- AtomEntry->RefCount--;
-
- if (AtomEntry->RefCount == 0)
- {
- if (AtomEntry->Locked == TRUE)
- {
- DPRINT("Atom %wZ is locked!\n", &AtomEntry->Name);
-
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_WAS_LOCKED;
- }
-
- DPRINT("Removing atom: %wZ\n", &AtomEntry->Name);
-
- RtlFreeUnicodeString(&AtomEntry->Name);
- RemoveEntryList(&AtomEntry->List);
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- AtomEntry);
- RtlFreeHandle(AtomTable->HandleTable,
- (PRTL_HANDLE)AtomHandle);
- }
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlLookupAtomInAtomTable(IN PRTL_ATOM_TABLE AtomTable,
- IN PWSTR AtomName,
- OUT PRTL_ATOM Atom)
-{
- ULONG Hash;
- PLIST_ENTRY Current;
- PRTL_ATOM_ENTRY Entry;
- USHORT AtomValue;
- NTSTATUS Status;
-
- DPRINT("RtlLookupAtomInAtomTable (AtomTable %p AtomName %S Atom %p)\n",
- AtomTable, AtomName, Atom);
-
- if (RtlpCheckIntegerAtom (AtomName, &AtomValue))
- {
- /* integer atom */
- if (AtomValue >= 0xC000)
- {
- AtomValue = 0;
- Status = STATUS_INVALID_PARAMETER;
- }
- else
- {
- Status = STATUS_SUCCESS;
- }
-
- if (Atom)
- *Atom = (RTL_ATOM)AtomValue;
-
- return Status;
- }
-
- RtlpLockAtomTable(AtomTable);
-
- /* string atom */
- Hash = RtlpHashAtomName(AtomTable->TableSize, AtomName);
-
- /* search for existing atom */
- Current = AtomTable->Slot[Hash].Flink;
- while (Current != &AtomTable->Slot[Hash])
- {
- Entry = (PRTL_ATOM_ENTRY)Current;
-
- DPRINT("Comparing %S and %S\n", Entry->Name.Buffer, AtomName);
- if (_wcsicmp(Entry->Name.Buffer, AtomName) == 0)
- {
- if (Atom)
- *Atom = (RTL_ATOM)(Entry->Index + 0xC000);
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_SUCCESS;
- }
-
- Current = Current->Flink;
- }
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_OBJECT_NAME_NOT_FOUND;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlPinAtomInAtomTable(IN PRTL_ATOM_TABLE AtomTable,
- IN RTL_ATOM Atom)
-{
- PRTL_ATOM_HANDLE AtomHandle;
- PRTL_ATOM_ENTRY AtomEntry;
-
- DPRINT("RtlPinAtomInAtomTable (AtomTable %p Atom %x)\n",
- AtomTable, Atom);
-
- if (Atom < 0xC000)
- {
- return STATUS_SUCCESS;
- }
-
- RtlpLockAtomTable(AtomTable);
-
- /* FIXME: use general function instead !! */
- if (!RtlIsValidIndexHandle(AtomTable->HandleTable,
- (PRTL_HANDLE *)&AtomHandle,
- (ULONG)Atom - 0xC000))
- {
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_INVALID_HANDLE;
- }
-
- DPRINT("AtomHandle %x\n", AtomHandle);
- DPRINT("AtomHandle->Entry %x\n", AtomHandle->Entry);
-
- AtomEntry = AtomHandle->Entry;
-
- DPRINT("Atom name: %wZ\n", &AtomEntry->Name);
-
- AtomEntry->Locked = TRUE;
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlQueryAtomInAtomTable(PRTL_ATOM_TABLE AtomTable,
- RTL_ATOM Atom,
- PULONG RefCount,
- PULONG PinCount,
- PWSTR AtomName,
- PULONG NameLength)
-{
- ULONG Length;
- PRTL_ATOM_HANDLE AtomHandle;
- PRTL_ATOM_ENTRY AtomEntry;
-
- if (Atom < 0xC000)
- {
- if (RefCount != NULL)
- {
- *RefCount = 1;
- }
-
- if (PinCount != NULL)
- {
- *PinCount = 1;
- }
-
- if ((AtomName != NULL) && (NameLength != NULL) && (NameLength > 0))
- {
- Length = swprintf(AtomName, L"#%lu", (ULONG)Atom);
- *NameLength = Length * sizeof(WCHAR);
- }
-
- return STATUS_SUCCESS;
- }
-
- RtlpLockAtomTable(AtomTable);
-
- /* FIXME: use general function instead !! */
- if (!RtlIsValidIndexHandle(AtomTable->HandleTable,
- (PRTL_HANDLE *)&AtomHandle,
- (ULONG)Atom - 0xC000))
- {
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_INVALID_HANDLE;
- }
-
- DPRINT("AtomHandle %x\n", AtomHandle);
- DPRINT("AtomHandle->Entry %x\n", AtomHandle->Entry);
-
- AtomEntry = AtomHandle->Entry;
-
- DPRINT("Atom name: %wZ\n", &AtomEntry->Name);
-
- if (RefCount != NULL)
- {
- *RefCount = AtomEntry->RefCount;
- }
-
- if (PinCount != NULL)
- {
- *PinCount = (ULONG)AtomEntry->Locked;
- }
-
- if ((AtomName != NULL) && (NameLength != NULL))
- {
- if (*NameLength < AtomEntry->Name.Length)
- {
- *NameLength = AtomEntry->Name.Length;
- RtlpUnlockAtomTable(AtomTable);
- return STATUS_BUFFER_TOO_SMALL;
- }
-
- Length = swprintf(AtomName, L"%s", AtomEntry->Name.Buffer);
- *NameLength = Length * sizeof(WCHAR);
- }
-
- RtlpUnlockAtomTable(AtomTable);
-
- return STATUS_SUCCESS;
-}
-
-
-/* INTERNAL FUNCTIONS ********************************************************/
-
-static ULONG
-RtlpHashAtomName(ULONG TableSize,
- PWSTR AtomName)
-{
- ULONG q = 0;
- PWCHAR p;
-
- DPRINT("RtlpHashAtomName(TableSize %ld AtomName '%S')\n",
- TableSize, AtomName);
-
- /* convert the string to an internal representation */
- p = AtomName;
- while (*p != 0)
- {
- q += (ULONG)towupper(*p);
- p++;
- }
-
- DPRINT("q %lu Hash %lu\n", q, q % TableSize);
-
- return (q % TableSize);
-}
-
-
-static BOOLEAN
-RtlpCheckIntegerAtom(PWSTR AtomName,
- PUSHORT AtomValue)
-{
- UNICODE_STRING AtomString;
- USHORT LoValue;
- ULONG LongValue;
- PWCHAR p;
-
- DPRINT("RtlpCheckIntegerAtom(AtomName '%S' AtomValue %p)\n",
- AtomName, AtomValue);
-
- if (!((ULONG)AtomName & 0xFFFF0000))
- {
- LoValue = (USHORT)((ULONG)AtomName & 0xFFFF);
-
- if (LoValue >= 0xC000)
- return FALSE;
-
- if (LoValue == 0)
- LoValue = 0xC000;
-
- if (AtomValue != NULL)
- *AtomValue = LoValue;
-
- return TRUE;
- }
-
- if (*AtomName != L'#')
- return FALSE;
-
- p = AtomName;
- p++;
- while (*p)
- {
- if ((*p < L'0') || (*p > L'9'))
- return FALSE;
- p++;
- }
-
- p = AtomName;
- p++;
- RtlInitUnicodeString(&AtomString,
- p);
-
- RtlUnicodeStringToInteger(&AtomString,10, &LongValue);
-
- *AtomValue = (USHORT)(LongValue & 0x0000FFFF);
-
- return TRUE;
-}
-
-
-/* lock functions */
-
-static NTSTATUS
-RtlpInitAtomTableLock(PRTL_ATOM_TABLE AtomTable)
-{
- AtomTable->Lock = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(RTL_CRITICAL_SECTION));
- if (AtomTable->Lock == NULL)
- return STATUS_NO_MEMORY;
-
- RtlInitializeCriticalSection((PRTL_CRITICAL_SECTION)AtomTable->Lock);
-
- return STATUS_SUCCESS;
-}
-
-
-static VOID
-RtlpDestroyAtomTableLock(PRTL_ATOM_TABLE AtomTable)
-{
- if (AtomTable->Lock)
- {
- RtlDeleteCriticalSection((PRTL_CRITICAL_SECTION)AtomTable->Lock);
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- AtomTable->Lock);
- AtomTable->Lock = NULL;
- }
[truncated at 1000 lines; 2400 more skipped]