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>
10 DBG_DEFAULT_CHANNEL(UserMisc
);
13 IntAddAtom(LPWSTR AtomName
)
15 NTSTATUS Status
= STATUS_SUCCESS
;
19 pti
= PsGetCurrentThreadWin32Thread();
20 if (pti
->rpdesk
== NULL
)
22 SetLastNtError(Status
);
26 Status
= RtlAddAtomToAtomTable(gAtomTable
, AtomName
, &Atom
);
28 if (!NT_SUCCESS(Status
))
30 SetLastNtError(Status
);
37 IntGetAtomName(RTL_ATOM nAtom
, LPWSTR lpBuffer
, ULONG cjBufSize
)
39 NTSTATUS Status
= STATUS_SUCCESS
;
41 ULONG Size
= cjBufSize
;
43 pti
= PsGetCurrentThreadWin32Thread();
44 if (pti
->rpdesk
== NULL
)
46 SetLastNtError(Status
);
50 Status
= RtlQueryAtomInAtomTable(gAtomTable
, nAtom
, NULL
, NULL
, lpBuffer
, &Size
);
52 if (!NT_SUCCESS(Status
))
54 SetLastNtError(Status
);
62 IntAddGlobalAtom(LPWSTR lpBuffer
, BOOL PinAtom
)
65 NTSTATUS Status
= STATUS_SUCCESS
;
67 Status
= RtlAddAtomToAtomTable(gAtomTable
, lpBuffer
, &Atom
);
69 if (!NT_SUCCESS(Status
))
71 ERR("Error init Global Atom.\n");
76 RtlPinAtomInAtomTable(gAtomTable
, Atom
);
82 * \brief Returns the name of an atom.
84 * \param atom - The atom to be queried.
85 * \param pustrName - Pointer to an initialized UNICODE_STRING that receives
86 * the name of the atom. The function does not update the
87 Length member. The string is always NULL-terminated.
89 * \return The length of the name in characters, or 0 if the function fails.
91 * \note The function does not aquire any global lock, since synchronisation is
92 * handled by the RtlAtom function.
94 _Success_(return != 0)
95 _At_(pustrName
->Buffer
, _Out_z_bytecap_post_bytecount_(pustrName
->MaximumLength
, return * 2 + 2))
100 _Inout_ PUNICODE_STRING pustrName
)
102 WCHAR awcBuffer
[256];
105 /* Retrieve the atom name into a local buffer (max length is 255 chars) */
106 cjLength
= IntGetAtomName((RTL_ATOM
)atom
, awcBuffer
, sizeof(awcBuffer
));
111 /* Probe the unicode string and the buffer */
112 ProbeForRead(pustrName
, sizeof(*pustrName
), 1);
113 ProbeForWrite(pustrName
->Buffer
, pustrName
->MaximumLength
, 1);
115 /* Check if we have enough space to write the NULL termination */
116 if (pustrName
->MaximumLength
>= sizeof(UNICODE_NULL
))
118 /* Limit the length to the buffer size */
119 cjLength
= min(pustrName
->MaximumLength
- sizeof(UNICODE_NULL
),
122 /* Copy the string and NULL terminate it */
123 RtlCopyMemory(pustrName
->Buffer
, awcBuffer
, cjLength
);
124 pustrName
->Buffer
[cjLength
/ sizeof(WCHAR
)] = L
'\0';
131 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
133 /* On exception, set last error and fail */
134 SetLastNtError(_SEH2_GetExceptionCode());
140 /* Return the length in characters */
141 return cjLength
/ sizeof(WCHAR
);