2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ex/atom.c
5 * PURPOSE: Executive Atom Functions
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
10 /* INCLUDES *****************************************************************/
14 #include <internal/debug.h>
16 /* GLOBALS ****************************************************************/
19 * FIXME: this is WRONG! The global atom table should live in the WinSta struct
20 * and accessed through a win32k callout (received in PsEstablishWin32Callouts)
21 * NOTE: There is a session/win32k global atom table also, but its private to
22 * win32k. Its used for RegisterWindowMessage() and for window classes.
25 PRTL_ATOM_TABLE GlobalAtomTable
;
27 /* PRIVATE FUNCTIONS *********************************************************/
31 ExpGetGlobalAtomTable(VOID
)
35 /* Return it if we have one */
36 if (GlobalAtomTable
) return GlobalAtomTable
;
39 Status
= RtlCreateAtomTable(37, &GlobalAtomTable
);
41 /* If we couldn't create it, return NULL */
42 if (!NT_SUCCESS(Status
)) return NULL
;
44 /* Return the newly created one */
45 return GlobalAtomTable
;
50 RtlpQueryAtomInformation(PRTL_ATOM_TABLE AtomTable
,
52 PATOM_BASIC_INFORMATION AtomInformation
,
53 ULONG AtomInformationLength
,
61 NameLength
= AtomInformationLength
- sizeof(ATOM_BASIC_INFORMATION
) + sizeof(WCHAR
);
62 Status
= RtlQueryAtomInAtomTable(AtomTable
,
66 AtomInformation
->Name
,
69 if (!NT_SUCCESS(Status
)) return Status
;
70 DPRINT("NameLength: %lu\n", NameLength
);
72 if (ReturnLength
!= NULL
)
74 *ReturnLength
= NameLength
+ sizeof(ATOM_BASIC_INFORMATION
);
77 if (NameLength
+ sizeof(ATOM_BASIC_INFORMATION
) > AtomInformationLength
)
79 return STATUS_INFO_LENGTH_MISMATCH
;
82 AtomInformation
->UsageCount
= (USHORT
)UsageCount
;
83 AtomInformation
->Flags
= (USHORT
)Flags
;
84 AtomInformation
->NameLength
= (USHORT
)NameLength
;
86 return STATUS_SUCCESS
;
91 RtlpQueryAtomTableInformation(PRTL_ATOM_TABLE AtomTable
,
93 PATOM_TABLE_INFORMATION AtomInformation
,
94 ULONG AtomInformationLength
,
100 Length
= sizeof(ATOM_TABLE_INFORMATION
);
101 DPRINT("RequiredLength: %lu\n", Length
);
103 if (ReturnLength
) *ReturnLength
= Length
;
105 if (Length
> AtomInformationLength
) return STATUS_INFO_LENGTH_MISMATCH
;
107 Status
= RtlQueryAtomListInAtomTable(AtomTable
,
108 (AtomInformationLength
- Length
) /
110 &AtomInformation
->NumberOfAtoms
,
111 AtomInformation
->Atoms
);
112 if (NT_SUCCESS(Status
))
114 ReturnLength
+= AtomInformation
->NumberOfAtoms
* sizeof(RTL_ATOM
);
115 if (ReturnLength
!= NULL
) *ReturnLength
= Length
;
121 /* FUNCTIONS ****************************************************************/
128 NtAddAtom(IN PWSTR AtomName
,
129 IN ULONG AtomNameLength
,
132 PRTL_ATOM_TABLE AtomTable
= ExpGetGlobalAtomTable();
134 /* Check for the table */
135 if (AtomTable
== NULL
) return STATUS_ACCESS_DENIED
;
139 /* Call the worker function */
140 return RtlAddAtomToAtomTable(AtomTable
, AtomName
, Atom
);
148 NtDeleteAtom(IN RTL_ATOM Atom
)
150 PRTL_ATOM_TABLE AtomTable
= ExpGetGlobalAtomTable();
152 /* Check for valid table */
153 if (AtomTable
== NULL
) return STATUS_ACCESS_DENIED
;
155 /* Call worker function */
156 return RtlDeleteAtomFromAtomTable(AtomTable
, Atom
);
164 NtFindAtom(IN PWSTR AtomName
,
165 IN ULONG AtomNameLength
,
168 PRTL_ATOM_TABLE AtomTable
= ExpGetGlobalAtomTable();
170 /* Check for valid table */
171 if (AtomTable
== NULL
) return STATUS_ACCESS_DENIED
;
175 /* Call worker function */
176 return RtlLookupAtomInAtomTable(AtomTable
, AtomName
, Atom
);
184 NtQueryInformationAtom(RTL_ATOM Atom
,
185 ATOM_INFORMATION_CLASS AtomInformationClass
,
186 PVOID AtomInformation
,
187 ULONG AtomInformationLength
,
190 PRTL_ATOM_TABLE AtomTable
= ExpGetGlobalAtomTable();
193 /* Check for valid table */
194 if (AtomTable
== NULL
) return STATUS_ACCESS_DENIED
;
199 switch (AtomInformationClass
)
201 case AtomBasicInformation
:
202 Status
= RtlpQueryAtomInformation(AtomTable
,
205 AtomInformationLength
,
209 case AtomTableInformation
:
210 Status
= RtlpQueryAtomTableInformation(AtomTable
,
213 AtomInformationLength
,
218 Status
= STATUS_INVALID_INFO_CLASS
;
221 /* Return to caller */