ReactOS  0.4.14-dev-593-g1793dcc
useratom.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: User Atom helper routines
5  * FILE: win32ss/user/ntuser/useratom.c
6  * PROGRAMER: Filip Navara <xnavara@volny.cz>
7  */
8 
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserMisc);
11 
13 IntAddAtom(LPWSTR AtomName)
14 {
16  PTHREADINFO pti;
17  RTL_ATOM Atom;
18 
20  if (pti->rpdesk == NULL)
21  {
23  return (RTL_ATOM)0;
24  }
25 
27 
28  if (!NT_SUCCESS(Status))
29  {
31  return (RTL_ATOM)0;
32  }
33  return Atom;
34 }
35 
38 {
40  PTHREADINFO pti;
41  ULONG Size = cjBufSize;
42 
44  if (pti->rpdesk == NULL)
45  {
47  return 0;
48  }
49 
51 
52  if (!NT_SUCCESS(Status))
53  {
55  return 0;
56  }
57 
58  return Size;
59 }
60 
63 {
64  RTL_ATOM Atom;
66 
68 
69  if (!NT_SUCCESS(Status))
70  {
71  ERR("Error init Global Atom.\n");
72  return 0;
73  }
74 
75  if (Atom && PinAtom)
77 
78  return Atom;
79 }
80 
94 _Success_(return != 0)
95 _At_(pustrName->Buffer, _Out_z_bytecap_post_bytecount_(pustrName->MaximumLength, return * 2 + 2))
96 ULONG
98 NtUserGetAtomName(
99  _In_ ATOM atom,
100  _Inout_ PUNICODE_STRING pustrName)
101 {
102  WCHAR awcBuffer[256];
103  ULONG cjLength;
104 
105  /* Retrieve the atom name into a local buffer (max length is 255 chars) */
106  cjLength = IntGetAtomName((RTL_ATOM)atom, awcBuffer, sizeof(awcBuffer));
107  if (cjLength != 0)
108  {
109  _SEH2_TRY
110  {
111  /* Probe the unicode string and the buffer */
112  ProbeForRead(pustrName, sizeof(*pustrName), 1);
113  ProbeForWrite(pustrName->Buffer, pustrName->MaximumLength, 1);
114 
115  /* Check if we have enough space to write the NULL termination */
116  if (pustrName->MaximumLength >= sizeof(UNICODE_NULL))
117  {
118  /* Limit the length to the buffer size */
119  cjLength = min(pustrName->MaximumLength - sizeof(UNICODE_NULL),
120  cjLength);
121 
122  /* Copy the string and NULL terminate it */
123  RtlCopyMemory(pustrName->Buffer, awcBuffer, cjLength);
124  pustrName->Buffer[cjLength / sizeof(WCHAR)] = L'\0';
125  }
126  else
127  {
128  cjLength = 0;
129  }
130  }
132  {
133  /* On exception, set last error and fail */
135  cjLength = 0;
136  }
137  _SEH2_END
138  }
139 
140  /* Return the length in characters */
141  return cjLength / sizeof(WCHAR);
142 }
143 
144 /* EOF */
return
Definition: dirsup.c:529
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned short RTL_ATOM
Definition: atom.c:42
_Success_(return !=0)
Returns the name of an atom.
Definition: useratom.c:94
WORD ATOM
Definition: dimm.idl:113
NTSYSAPI NTSTATUS NTAPI RtlAddAtomToAtomTable(_In_ PRTL_ATOM_TABLE AtomTable, _In_ PWSTR AtomName, _Out_ PRTL_ATOM Atom)
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
LONG NTSTATUS
Definition: precomp.h:26
PRTL_ATOM_TABLE gAtomTable
Definition: session.c:13
NTSYSAPI NTSTATUS NTAPI RtlPinAtomInAtomTable(_In_ PRTL_ATOM_TABLE AtomTable, _In_ RTL_ATOM Atom)
_Out_ RTL_ATOM * Atom
Definition: class.h:54
#define FASTCALL
Definition: nt_native.h:50
struct _DESKTOP * rpdesk
Definition: win32.h:91
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
DBG_DEFAULT_CHANNEL(UserMisc)
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define _At_(target, annos)
Definition: no_sal2.h:11
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define _Out_z_bytecap_post_bytecount_(cap, count)
Definition: no_sal2.h:387
#define _Inout_
Definition: no_sal2.h:244
NTSYSAPI NTSTATUS NTAPI RtlQueryAtomInAtomTable(_In_ PRTL_ATOM_TABLE AtomTable, _In_ RTL_ATOM Atom, _Out_opt_ PULONG RefCount, _Out_opt_ PULONG PinCount, _Out_opt_z_bytecap_(*NameLength) PWSTR AtomName, _Inout_opt_ PULONG NameLength)
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
static const WCHAR L[]
Definition: oid.c:1250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
_SEH2_END
Definition: create.c:4424
#define min(a, b)
Definition: monoChain.cc:55
ULONG FASTCALL IntGetAtomName(RTL_ATOM nAtom, LPWSTR lpBuffer, ULONG cjBufSize)
Definition: useratom.c:37
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2938
RTL_ATOM FASTCALL IntAddAtom(LPWSTR AtomName)
Definition: useratom.c:13
RTL_ATOM FASTCALL IntAddGlobalAtom(LPWSTR lpBuffer, BOOL PinAtom)
Definition: useratom.c:62
#define APIENTRY
Definition: api.h:79