Hello Timo,<br>
Let's make a deal: while I fix this in win32k, you may try to find a way to fix 
that one too in the SAC driver line 1192:<br>
I used the object macros because I didn't want to have the (huge) overhead of 
calling ObQueryNameString() together with allocating memory buffers just to 
retrieve the necessary names that already exist somewhere. (Also we note that 
WinStation objects, by their nature, really wrap closely around the NT objects 
and that's why I didn't see any inconvenience in using the helper macros for 
retrieving said information).<br>
Hermes<span style="font-family:arial,helvetica,sans-serif; 

<div class="gl_quote" style="margin-top: 20px; padding-top: 5px;">De : "Timo 
A : ros-dev@reactos.org,"Hermès Bélusca-Maïto"<br>
Envoyé: lundi 10 décembre 2018 01:44<br>
Objet : Re: [ros-diffs] 07/18: [WIN32K:NTUSER] Get rid of the cached window 
station Name member, and instead just use the name stored in the NT Object's 
header. CORE-11933 and PR #621.<br>
<div class="gl_quoted"><br>
Why did you remove an abstraction and create additional dependencies on<br>
internal implementation details?<br>
Win32k is not supposed to directly access internal kernel structures!<br>
The headers and macros shouldn't even be in NDK.<br>
Please revert or fix this. And while you are at it, put an "#ifdef<br>
_NTOSKRNL_" around the stuff in NDK to prevent people from using it.<br>
Am 19.08.2018 um 22:16 schrieb Hermès Bélusca-Maïto:<br>
&gt; commit 43e2ab208a2d3d50b12b4689347f57ca83568dd9<br>
&gt; Author: Hermès Bélusca-Maïto<br>
&gt; AuthorDate: Sun Jun 17 19:40:32 2018 +0200<br>
&gt; Commit: Hermès Bélusca-Maïto<br>
&gt; CommitDate: Sun Aug 19 22:18:32 2018 +0200<br>
&gt; [WIN32K:NTUSER] Get rid of the cached window station Name member, and 
instead just use the name stored in the NT Object's header.<br>
&gt; CORE-11933 and PR #621.<br>
&gt; - Remove the related hack-FIXMEs;<br>
&gt; - Adjust NtUserGetObjectInformation() in accordance.<br>
&gt; - Retrieve the window-station/desktop object type string in 
&gt; also from the NT Object's header.<br>
&gt; Also simplify the UOI_FLAGS case of NtUserGetObjectInformation() by 
&gt; the handle inheritance information directly from the 
&gt; structure returned by ObReferenceObjectByHandle().<br>
&gt; ---<br>
&gt; win32ss/user/ntuser/sysparams.c | 3 +-<br>
&gt; win32ss/user/ntuser/winsta.c | 106 
&gt; win32ss/user/ntuser/winsta.h | 1 -<br>
&gt; 3 files changed, 51 insertions(+), 59 deletions(-)<br>
&gt; diff --git a/win32ss/user/ntuser/sysparams.c 
&gt; index 7eedc028de..d0badba00e 100644<br>
&gt; --- a/win32ss/user/ntuser/sysparams.c<br>
&gt; +++ b/win32ss/user/ntuser/sysparams.c<br>
&gt; @@ -33,7 +33,8 @@ BOOL g_PaintDesktopVersion = FALSE;<br>
&gt; } \<br>
&gt; else \<br>
&gt; { \<br>
&gt; - ERR("NtUserSystemParametersInfo requires interactive window station 
(current is %wZ)\n", &amp;GetW32ProcessInfo()-&gt;prpwinsta-&gt;Name); \<br>
&gt; + ERR("NtUserSystemParametersInfo requires interactive window station 
(current is %wZ)\n", \<br>
&gt; + 
&gt; } \<br>
&gt; EngSetLastError(err); \<br>
&gt; return 0; \<br>
&gt; diff --git a/win32ss/user/ntuser/winsta.c 
&gt; index f373b1cedf..ba1b1eb57d 100644<br>
&gt; --- a/win32ss/user/ntuser/winsta.c<br>
&gt; +++ b/win32ss/user/ntuser/winsta.c<br>
&gt; @@ -114,8 +114,6 @@ IntWinStaObjectDelete(<br>
&gt; RtlDestroyAtomTable(WinSta-&gt;AtomTable);<br>
&gt; - RtlFreeUnicodeString(&amp;WinSta-&gt;Name);<br>
&gt; -<br>
&gt; return STATUS_SUCCESS;<br>
&gt; }<br>
&gt; @@ -449,8 +447,6 @@ IntCreateWindowStation(<br>
&gt; RtlZeroMemory(WindowStationObject, sizeof(WINSTATION_OBJECT));<br>
&gt; InitializeListHead(&amp;WindowStationObject-&gt;DesktopListHead);<br>
&gt; - WindowStationObject-&gt;Name = *ObjectAttributes-&gt;ObjectName;<br>
&gt; - ObjectAttributes-&gt;ObjectName = NULL; // FIXME! (see 
&gt; WindowStationObject-&gt;dwSessionId = NtCurrentPeb()-&gt;SessionId;<br>
&gt; Status = RtlCreateAtomTable(37, 
&gt; if (!NT_SUCCESS(Status))<br>
&gt; @@ -491,7 +487,7 @@ IntCreateWindowStation(<br>
&gt; }<br>
&gt; TRACE("IntCreateWindowStation created object 0x%p with name %wZ handle 
&gt; - WindowStationObject, &amp;WindowStationObject-&gt;Name, 
&gt; + WindowStationObject, ObjectAttributes-&gt;ObjectName, WindowStation);<br>
&gt; *phWinSta = WindowStation;<br>
&gt; return STATUS_SUCCESS;<br>
&gt; @@ -582,23 +578,7 @@ NtUserCreateWindowStation(<br>
&gt; return NULL;<br>
&gt; }<br>
&gt; - WindowStationName.Length = wcslen(ServiceWinStaName) * sizeof(WCHAR);<br>
&gt; - WindowStationName.MaximumLength =<br>
&gt; - WindowStationName.Length + sizeof(UNICODE_NULL);<br>
&gt; - WindowStationName.Buffer =<br>
&gt; - ExAllocatePoolWithTag(PagedPool,<br>
&gt; - WindowStationName.MaximumLength,<br>
&gt; - TAG_STRING);<br>
&gt; - if (!WindowStationName.Buffer)<br>
&gt; - {<br>
&gt; - Status = STATUS_NO_MEMORY;<br>
&gt; - ERR("Impossible to build a valid window station name, Status 0x%08lx\n", 
&gt; - SetLastNtError(Status);<br>
&gt; - return NULL;<br>
&gt; - }<br>
&gt; - RtlStringCbCopyW(WindowStationName.Buffer,<br>
&gt; - WindowStationName.MaximumLength,<br>
&gt; - ServiceWinStaName);<br>
&gt; + RtlInitUnicodeString(&amp;WindowStationName, ServiceWinStaName);<br>
&gt; LocalObjectAttributes.ObjectName = &amp;WindowStationName;<br>
&gt; AccessMode = KernelMode;<br>
&gt; }<br>
&gt; @@ -615,12 +595,7 @@ NtUserCreateWindowStation(<br>
&gt; Unknown5,<br>
&gt; Unknown6);<br>
&gt; - // FIXME! Because in some situations we store the allocated window 
station name<br>
&gt; - // inside the window station, we must not free it now! We know this fact 
&gt; - // IntCreateWindowStation() sets LocalObjectAttributes.ObjectName to 
&gt; - // This hack must be removed once we just use the stored Ob name 
&gt; - // (in which case we will always free the allocated name here).<br>
&gt; - if (LocalObjectAttributes.ObjectName)<br>
&gt; + if ((AccessMode == UserMode) &amp;&amp; 
&gt; ExFreePoolWithTag(LocalObjectAttributes.ObjectName-&gt;Buffer, 
&gt; if (NT_SUCCESS(Status))<br>
&gt; @@ -802,7 +777,11 @@ NtUserGetObjectInformation(<br>
&gt; NTSTATUS Status;<br>
&gt; PWINSTATION_OBJECT WinStaObject = NULL;<br>
&gt; PDESKTOP DesktopObject = NULL;<br>
&gt; + POBJECT_HEADER ObjectHeader;<br>
&gt; USEROBJECTFLAGS ObjectFlags;<br>
&gt; + PUNICODE_STRING pStrNameU = NULL;<br>
&gt; PVOID pvData = NULL;<br>
&gt; SIZE_T nDataSize = 0;<br>
&gt; @@ -820,13 +799,13 @@ NtUserGetObjectInformation(<br>
&gt; _SEH2_END;<br>
&gt; /* Try window station */<br>
&gt; - TRACE("Trying to open window station %p\n", hObject);<br>
&gt; + TRACE("Trying to open window station 0x%p\n", hObject);<br>
&gt; Status = ObReferenceObjectByHandle(hObject,<br>
&gt; 0,<br>
&gt; ExWindowStationObjectType,<br>
&gt; UserMode,<br>
&gt; (PVOID*)&amp;WinStaObject,<br>
&gt; - NULL);<br>
&gt; + &amp;HandleInfo);<br>
&gt; if (Status == STATUS_OBJECT_TYPE_MISMATCH)<br>
&gt; {<br>
&gt; @@ -852,23 +831,8 @@ NtUserGetObjectInformation(<br>
&gt; {<br>
&gt; case UOI_FLAGS:<br>
&gt; {<br>
&gt; - ULONG BytesWritten;<br>
&gt; -<br>
&gt; ObjectFlags.fReserved = FALSE;<br>
&gt; -<br>
&gt; - /* Check whether this handle is inheritable */<br>
&gt; - Status = ZwQueryObject(hObject,<br>
&gt; - ObjectHandleFlagInformation,<br>
&gt; - &amp;HandleInfo,<br>
&gt; - &amp;BytesWritten);<br>
&gt; - if (!NT_SUCCESS(Status))<br>
&gt; - {<br>
&gt; - ERR("ZwQueryObject failed, Status 0x%08lx\n", Status);<br>
&gt; - break;<br>
&gt; - }<br>
&gt; - ObjectFlags.fInherit = HandleInfo.Inherit;<br>
&gt; + ObjectFlags.fInherit = !!(HandleInfo.HandleAttributes &amp; 
&gt; ObjectFlags.dwFlags = 0;<br>
&gt; if (WinStaObject != NULL)<br>
&gt; @@ -893,11 +857,24 @@ NtUserGetObjectInformation(<br>
&gt; case UOI_NAME:<br>
&gt; {<br>
&gt; - // FIXME: Use either ObQueryNameString() or read directly that name 
inside the Object section!<br>
&gt; if (WinStaObject != NULL)<br>
&gt; {<br>
&gt; - pvData = WinStaObject-&gt;Name.Buffer;<br>
&gt; - nDataSize = WinStaObject-&gt;Name.Length + sizeof(WCHAR);<br>
&gt; + ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);<br>
&gt; + NameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);<br>
&gt; +<br>
&gt; + if (NameInfo &amp;&amp; (NameInfo-&gt;Name.Length &gt; 0))<br>
&gt; + {<br>
&gt; + /* Named window station */<br>
&gt; + pStrNameU = &amp;NameInfo-&gt;Name;<br>
&gt; + nDataSize = pStrNameU-&gt;Length + sizeof(UNICODE_NULL);<br>
&gt; + }<br>
&gt; + else<br>
&gt; + {<br>
&gt; + /* Unnamed window station (should never happen!) */<br>
&gt; + ASSERT(FALSE);<br>
&gt; + pStrNameU = NULL;<br>
&gt; + nDataSize = sizeof(UNICODE_NULL);<br>
&gt; + }<br>
&gt; Status = STATUS_SUCCESS;<br>
&gt; }<br>
&gt; else if (DesktopObject != NULL)<br>
&gt; @@ -917,14 +894,16 @@ NtUserGetObjectInformation(<br>
&gt; {<br>
&gt; if (WinStaObject != NULL)<br>
&gt; {<br>
&gt; - pvData = L"WindowStation";<br>
&gt; - nDataSize = sizeof(L"WindowStation");<br>
&gt; + ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);<br>
&gt; + pStrNameU = &amp;ObjectHeader-&gt;Type-&gt;Name;<br>
&gt; + nDataSize = pStrNameU-&gt;Length + sizeof(UNICODE_NULL);<br>
&gt; Status = STATUS_SUCCESS;<br>
&gt; }<br>
&gt; else if (DesktopObject != NULL)<br>
&gt; {<br>
&gt; - pvData = L"Desktop";<br>
&gt; - nDataSize = sizeof(L"Desktop");<br>
&gt; + ObjectHeader = OBJECT_TO_OBJECT_HEADER(DesktopObject);<br>
&gt; + pStrNameU = &amp;ObjectHeader-&gt;Type-&gt;Name;<br>
&gt; + nDataSize = pStrNameU-&gt;Length + sizeof(UNICODE_NULL);<br>
&gt; Status = STATUS_SUCCESS;<br>
&gt; }<br>
&gt; else<br>
&gt; @@ -954,10 +933,25 @@ Exit:<br>
&gt; *nLengthNeeded = nDataSize;<br>
&gt; /* Try to copy data to caller */<br>
&gt; - if (Status == STATUS_SUCCESS)<br>
&gt; + if (Status == STATUS_SUCCESS &amp;&amp; (nDataSize &gt; 0))<br>
&gt; {<br>
&gt; TRACE("Trying to copy data to caller (len = %lu, len needed = %lu)\n", 
nLength, nDataSize);<br>
&gt; - RtlCopyMemory(pvInformation, pvData, nDataSize);<br>
&gt; + if (pvData)<br>
&gt; + {<br>
&gt; + /* Copy the data */<br>
&gt; + RtlCopyMemory(pvInformation, pvData, nDataSize);<br>
&gt; + }<br>
&gt; + else if (pStrNameU)<br>
&gt; + {<br>
&gt; + /* Copy and NULL-terminate the string */<br>
&gt; + RtlCopyMemory(pvInformation, pStrNameU-&gt;Buffer, 
&gt; + ((PWCHAR)pvInformation)[pStrNameU-&gt;Length / sizeof(WCHAR)] = 
&gt; + }<br>
&gt; + else<br>
&gt; + {<br>
&gt; + /* Zero the memory */<br>
&gt; + RtlZeroMemory(pvInformation, nDataSize);<br>
&gt; + }<br>
&gt; }<br>
&gt; }<br>
&gt; @@ -1026,8 +1020,6 @@ NtUserSetObjectInformation(<br>
&gt; }<br>
&gt; -<br>
&gt; -<br>
&gt; UserGetProcessWindowStation(VOID)<br>
&gt; {<br>
&gt; diff --git a/win32ss/user/ntuser/winsta.h 
&gt; index 085f3bcb26..19b1479ec0 100644<br>
&gt; --- a/win32ss/user/ntuser/winsta.h<br>
&gt; +++ b/win32ss/user/ntuser/winsta.h<br>
&gt; @@ -15,7 +15,6 @@ typedef struct _WINSTATION_OBJECT<br>
&gt; {<br>
&gt; DWORD dwSessionId;<br>
&gt; - UNICODE_STRING Name;<br>
&gt; LIST_ENTRY DesktopListHead;<br>
&gt; PRTL_ATOM_TABLE AtomTable;<br>
&gt; HANDLE ShellWindow;<br>

<div class="gl_quoted">&nbsp;</div>
Ros-dev mailing list

Reply via email to