2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: User Atom helper routines
5 * FILE: subsys/win32k/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");
75 if ( Atom
&& PinAtom
) RtlPinAtomInAtomTable(gAtomTable
, Atom
);
81 * \brief Returns the name of an atom.
83 * \param atom - The atom to be queried.
84 * \param pustrName - Pointer to an initialized UNICODE_STRING that receives
85 * the name of the atom. The function does not update the
86 Length member. The string is always NULL-terminated.
88 * \return The length of the name in characters, or 0 if the function fails.
90 * \note The function does not aquire any global lock, since synchronisation is
91 * handled by the RtlAtom function.
94 _At_(pustrName
->Buffer
, _Out_z_bytecap_post_bytecount_(pustrName
->MaximumLength
, return*2+2))
99 _Inout_ PUNICODE_STRING pustrName
)
101 WCHAR awcBuffer
[256];
104 /* Retrieve the atom name into a local buffer (max length is 255 chars) */
105 cjLength
= IntGetAtomName((RTL_ATOM
)atom
, awcBuffer
, sizeof(awcBuffer
));
110 /* Probe the unicode string and the buffer */
111 ProbeForRead(pustrName
, sizeof(*pustrName
), 1);
112 ProbeForWrite(pustrName
->Buffer
, pustrName
->MaximumLength
, 1);
114 /* Check if we have enough space to write the NULL termination */
115 if (pustrName
->MaximumLength
>= sizeof(UNICODE_NULL
))
117 /* Limit the length to the buffer size */
118 cjLength
= min(pustrName
->MaximumLength
- sizeof(UNICODE_NULL
),
121 /* Copy the string and NULL terminate it */
122 RtlCopyMemory(pustrName
->Buffer
, awcBuffer
, cjLength
);
123 pustrName
->Buffer
[cjLength
/ sizeof(WCHAR
)] = L
'\0';
130 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
132 /* On exception, set last error and fail */
133 SetLastNtError(_SEH2_GetExceptionCode());
139 /* Return the length in characters */
140 return cjLength
/ sizeof(WCHAR
);