ReactOS  0.4.14-dev-358-gbef841c
atom.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for atom.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TAG_ATOM   'motA'
 

Functions

PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable (VOID)
 
NTSTATUS NTAPI NtAddAtom (IN PWSTR AtomName, IN ULONG AtomNameLength, OUT PRTL_ATOM Atom)
 
NTSTATUS NTAPI NtDeleteAtom (IN RTL_ATOM Atom)
 
NTSTATUS NTAPI NtFindAtom (IN PWSTR AtomName, IN ULONG AtomNameLength, OUT PRTL_ATOM Atom)
 
NTSTATUS NTAPI NtQueryInformationAtom (RTL_ATOM Atom, ATOM_INFORMATION_CLASS AtomInformationClass, PVOID AtomInformation, ULONG AtomInformationLength, PULONG ReturnLength)
 

Variables

PRTL_ATOM_TABLE GlobalAtomTable
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file atom.c.

◆ TAG_ATOM

#define TAG_ATOM   'motA'

Definition at line 16 of file atom.c.

Function Documentation

◆ ExpGetGlobalAtomTable()

PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable ( VOID  )

Definition at line 44 of file atom.c.

45 {
47 
48  /* Return it if we have one */
49  if (GlobalAtomTable) return GlobalAtomTable;
50 
51  /* Create it */
53 
54  /* If we couldn't create it, return NULL */
55  if (!NT_SUCCESS(Status)) return NULL;
56 
57  /* Return the newly created one */
58  return GlobalAtomTable;
59 }
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI RtlCreateAtomTable(IN ULONG TableSize, IN OUT PRTL_ATOM_TABLE *AtomTable)
Definition: atom.c:150
Status
Definition: gdiplustypes.h:24
PRTL_ATOM_TABLE GlobalAtomTable
Definition: atom.c:27

Referenced by NtAddAtom(), NtDeleteAtom(), NtFindAtom(), and NtQueryInformationAtom().

◆ NtAddAtom()

NTSTATUS NTAPI NtAddAtom ( IN PWSTR  AtomName,
IN ULONG  AtomNameLength,
OUT PRTL_ATOM  Atom 
)

Definition at line 88 of file atom.c.

91 {
95  LPWSTR CapturedName;
96  ULONG CapturedSize;
97  RTL_ATOM SafeAtom;
98  PAGED_CODE();
99 
100  /* Check for the table */
101  if (AtomTable == NULL) return STATUS_ACCESS_DENIED;
102 
103  /* Check for valid name */
104  if (AtomNameLength > (RTL_MAXIMUM_ATOM_LENGTH * sizeof(WCHAR)))
105  {
106  /* Fail */
107  DPRINT1("Atom name too long\n");
109  }
110 
111  /* Check if we're called from user-mode or kernel-mode */
112  if (PreviousMode == KernelMode)
113  {
114  /* Re-use the given name if kernel mode */
115  CapturedName = AtomName;
116  }
117  else
118  {
119  /* Check if we have a name */
120  if (AtomName)
121  {
122  /* Allocate an aligned buffer + the null char */
123  CapturedSize = ((AtomNameLength + sizeof(WCHAR)) &
124  ~(sizeof(WCHAR) -1));
125  CapturedName = ExAllocatePoolWithTag(PagedPool,
126  CapturedSize,
127  TAG_ATOM);
128 
129  if (!CapturedName)
130  {
131  /* Fail the call */
133  }
134 
135  /* Enter SEH */
136  _SEH2_TRY
137  {
138  /* Probe the atom */
139  ProbeForRead(AtomName, AtomNameLength, sizeof(WCHAR));
140 
141  /* Copy the name and null-terminate it */
142  RtlCopyMemory(CapturedName, AtomName, AtomNameLength);
143  CapturedName[AtomNameLength / sizeof(WCHAR)] = UNICODE_NULL;
144 
145  /* Probe the atom too */
147  }
149  {
150  /* Return the exception code */
152  }
153  _SEH2_END;
154  }
155  else
156  {
157  /* No name */
158  CapturedName = NULL;
159  }
160  }
161 
162  /* Call the runtime function */
163  Status = RtlAddAtomToAtomTable(AtomTable, CapturedName, &SafeAtom);
164  if (NT_SUCCESS(Status) && (Atom))
165  {
166  /* Success and caller wants the atom back.. .enter SEH */
167  _SEH2_TRY
168  {
169  /* Return the atom */
170  *Atom = SafeAtom;
171  }
173  {
174  /* Get the exception code */
176  }
177  _SEH2_END;
178  }
179 
180  /* If we captured anything, free it */
181  if ((CapturedName != NULL) && (CapturedName != AtomName))
182  ExFreePoolWithTag(CapturedName, TAG_ATOM);
183 
184  /* Return to caller */
185  return Status;
186 }
#define TAG_ATOM
Definition: atom.c:16
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned short RTL_ATOM
Definition: atom.c:42
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ProbeForWriteUshort(Ptr)
Definition: probe.h:34
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define UNICODE_NULL
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RTL_MAXIMUM_ATOM_LENGTH
Definition: rtltypes.h:36
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable(VOID)
Definition: atom.c:44
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSTATUS NTAPI RtlAddAtomToAtomTable(IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM Atom)
Definition: atom.c:308

Referenced by InitUserAtoms(), and InternalAddAtom().

◆ NtDeleteAtom()

NTSTATUS NTAPI NtDeleteAtom ( IN RTL_ATOM  Atom)

Definition at line 208 of file atom.c.

209 {
211  PAGED_CODE();
212 
213  /* Check for valid table */
214  if (AtomTable == NULL) return STATUS_ACCESS_DENIED;
215 
216  /* Call worker function */
217  return RtlDeleteAtomFromAtomTable(AtomTable, Atom);
218 }
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI RtlDeleteAtomFromAtomTable(IN PRTL_ATOM_TABLE AtomTable, IN RTL_ATOM Atom)
Definition: atom.c:426
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable(VOID)
Definition: atom.c:44

Referenced by InternalDeleteAtom().

◆ NtFindAtom()

NTSTATUS NTAPI NtFindAtom ( IN PWSTR  AtomName,
IN ULONG  AtomNameLength,
OUT PRTL_ATOM  Atom 
)

Definition at line 245 of file atom.c.

248 {
252  LPWSTR CapturedName = NULL;
253  ULONG CapturedSize;
254  RTL_ATOM SafeAtom;
255  PAGED_CODE();
256 
257  /* Check for the table */
258  if (AtomTable == NULL) return STATUS_ACCESS_DENIED;
259 
260  /* Check for valid name */
261  if (AtomNameLength > (RTL_MAXIMUM_ATOM_LENGTH * sizeof(WCHAR)))
262  {
263  /* Fail */
264  DPRINT1("Atom name too long\n");
266  }
267 
268  /* Re-use the given name if kernel mode or no atom name */
269  CapturedName = AtomName;
270 
271  /* Check if we're called from user-mode*/
272  if (PreviousMode != KernelMode)
273  {
274  /* Enter SEH */
275  _SEH2_TRY
276  {
277  /* Check if we have a name */
278  if (AtomName)
279  {
280  /* Probe the atom */
281  ProbeForRead(AtomName, AtomNameLength, sizeof(WCHAR));
282 
283  /* Allocate an aligned buffer + the null char */
284  CapturedSize = ((AtomNameLength + sizeof(WCHAR)) &~
285  (sizeof(WCHAR) -1));
286  CapturedName = ExAllocatePoolWithTag(PagedPool,
287  CapturedSize,
288  TAG_ATOM);
289  if (!CapturedName)
290  {
291  /* Fail the call */
293  }
294  else
295  {
296  /* Copy the name and null-terminate it */
297  RtlCopyMemory(CapturedName, AtomName, AtomNameLength);
298  CapturedName[AtomNameLength / sizeof(WCHAR)] = UNICODE_NULL;
299  }
300 
301  /* Probe the atom too */
303  }
304  }
306  {
307  /* Return the exception code */
309  }
310  _SEH2_END;
311  }
312 
313  /* Call the runtime function */
314  Status = RtlLookupAtomInAtomTable(AtomTable, CapturedName, &SafeAtom);
315  if (NT_SUCCESS(Status) && (Atom))
316  {
317  /* Success and caller wants the atom back.. .enter SEH */
318  _SEH2_TRY
319  {
320  /* Return the atom */
321  *Atom = SafeAtom;
322  }
324  {
326  }
327  _SEH2_END;
328  }
329 
330  /* If we captured anything, free it */
331  if ((CapturedName) && (CapturedName != AtomName))
332  ExFreePoolWithTag(CapturedName, TAG_ATOM);
333 
334  /* Return to caller */
335  return Status;
336 }
#define TAG_ATOM
Definition: atom.c:16
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned short RTL_ATOM
Definition: atom.c:42
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ProbeForWriteUshort(Ptr)
Definition: probe.h:34
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define UNICODE_NULL
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RTL_MAXIMUM_ATOM_LENGTH
Definition: rtltypes.h:36
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable(VOID)
Definition: atom.c:44
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSTATUS NTAPI RtlLookupAtomInAtomTable(IN PRTL_ATOM_TABLE AtomTable, IN PWSTR AtomName, OUT PRTL_ATOM Atom)
Definition: atom.c:495

Referenced by InternalFindAtom().

◆ NtQueryInformationAtom()

NTSTATUS NTAPI NtQueryInformationAtom ( RTL_ATOM  Atom,
ATOM_INFORMATION_CLASS  AtomInformationClass,
PVOID  AtomInformation,
ULONG  AtomInformationLength,
PULONG  ReturnLength 
)

Definition at line 370 of file atom.c.

375 {
377  PATOM_BASIC_INFORMATION BasicInformation = AtomInformation;
378  PATOM_TABLE_INFORMATION TableInformation = AtomInformation;
380  ULONG Flags, UsageCount, NameLength, RequiredLength = 0;
382 
383  PAGED_CODE();
384 
385  /* Check for valid table */
386  if (AtomTable == NULL) return STATUS_ACCESS_DENIED;
387 
389 
390  _SEH2_TRY
391  {
392  /* Probe the parameters */
393  if (PreviousMode != KernelMode)
394  {
395  ProbeForWrite(AtomInformation,
396  AtomInformationLength,
397  sizeof(ULONG));
398 
399  if (ReturnLength != NULL)
400  {
402  }
403  }
404 
405  /* Choose class */
406  switch (AtomInformationClass)
407  {
408  /* Caller requested info about an atom */
410 
411  /* Size check */
413  if (RequiredLength > AtomInformationLength)
414  {
415  /* Fail */
416  DPRINT1("Buffer too small\n");
418  _SEH2_LEAVE;
419  }
420 
421  /* Prepare query */
422  UsageCount = 0;
423  NameLength = AtomInformationLength - RequiredLength;
424  BasicInformation->Name[0] = UNICODE_NULL;
425 
426  /* Query the data */
427  Status = RtlQueryAtomInAtomTable(AtomTable,
428  Atom,
429  &UsageCount,
430  &Flags,
431  BasicInformation->Name,
432  &NameLength);
433  if (NT_SUCCESS(Status))
434  {
435  /* Return data */
436  BasicInformation->UsageCount = (USHORT)UsageCount;
437  BasicInformation->Flags = (USHORT)Flags;
438  BasicInformation->NameLength = (USHORT)NameLength;
439  RequiredLength += NameLength + sizeof(WCHAR);
440  }
441  break;
442 
443  /* Caller requested info about an Atom Table */
445 
446  /* Size check */
448  if (RequiredLength > AtomInformationLength)
449  {
450  /* Fail */
451  DPRINT1("Buffer too small\n");
453  _SEH2_LEAVE;
454  }
455 
456  /* Query the data */
458  (AtomInformationLength - RequiredLength) /
459  sizeof(RTL_ATOM),
460  &TableInformation->NumberOfAtoms,
461  TableInformation->Atoms);
462  if (NT_SUCCESS(Status))
463  {
464  /* Update the return length */
465  RequiredLength += TableInformation->NumberOfAtoms * sizeof(RTL_ATOM);
466  }
467  break;
468 
469  /* Caller was on crack */
470  default:
471 
472  /* Unrecognized class */
474  break;
475  }
476 
477  /* Return the required size */
478  if (ReturnLength != NULL)
479  {
481  }
482  }
484  {
486  }
487  _SEH2_END;
488 
489  /* Return to caller */
490  return Status;
491 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
unsigned short RTL_ATOM
Definition: atom.c:42
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_Out_ RTL_ATOM * Atom
Definition: class.h:54
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define UNICODE_NULL
NTSTATUS NTAPI RtlQueryAtomInAtomTable(PRTL_ATOM_TABLE AtomTable, RTL_ATOM Atom, PULONG RefCount, PULONG PinCount, PWSTR AtomName, PULONG NameLength)
Definition: atom.c:600
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
unsigned short USHORT
Definition: pedump.c:61
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
PRTL_ATOM_TABLE NTAPI ExpGetGlobalAtomTable(VOID)
Definition: atom.c:44
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
NTSTATUS NTAPI RtlQueryAtomListInAtomTable(IN PRTL_ATOM_TABLE AtomTable, IN ULONG MaxAtomCount, OUT ULONG *AtomCount, OUT RTL_ATOM *AtomList)
Definition: atom.c:704
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define _SEH2_LEAVE
Definition: filesup.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by InternalGetAtomName().

Variable Documentation

◆ GlobalAtomTable

PRTL_ATOM_TABLE GlobalAtomTable

Definition at line 27 of file atom.c.

Referenced by ExpGetGlobalAtomTable().