mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[win32k]
- Improve the definition and simplify NtUserCreateDesktop, NtUserOpenDesktop, NtUserCreateWindowStation, NtUserOpenWindowStation svn path=/trunk/; revision=51082
This commit is contained in:
parent
bfb74cd0bc
commit
71201dea2c
5 changed files with 184 additions and 299 deletions
|
@ -564,13 +564,22 @@ OpenDesktopW(
|
|||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
UNICODE_STRING DesktopName;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
|
||||
RtlInitUnicodeString(&DesktopName, lpszDesktop);
|
||||
|
||||
return NtUserOpenDesktop(
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&DesktopName,
|
||||
dwFlags,
|
||||
dwDesiredAccess);
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
GetProcessWindowStation(),
|
||||
0);
|
||||
|
||||
if( fInherit == TRUE )
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
return NtUserOpenDesktop(&ObjectAttributes, dwFlags, dwDesiredAccess);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <user32.h>
|
||||
|
||||
#include <wine/debug.h>
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(winsta);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -58,12 +59,50 @@ CreateWindowStationW(LPCWSTR lpwinsta,
|
|||
LPSECURITY_ATTRIBUTES lpsa)
|
||||
{
|
||||
UNICODE_STRING WindowStationName;
|
||||
UNICODE_STRING WindowStationsDir = RTL_CONSTANT_STRING(L"\\Windows\\WindowStations");
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
HANDLE hWindowStationsDir;
|
||||
NTSTATUS Status;
|
||||
HWINSTA hwinsta;
|
||||
|
||||
/* Open WindowStations directory */
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&WindowStationsDir,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
0,
|
||||
0);
|
||||
|
||||
Status = NtOpenDirectoryObject(&hWindowStationsDir,
|
||||
DIRECTORY_CREATE_OBJECT,
|
||||
&ObjectAttributes);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
ERR("Failed to open WindowStations directory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&WindowStationName, lpwinsta);
|
||||
|
||||
return NtUserCreateWindowStation(&WindowStationName,
|
||||
/* Create the window station object */
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&WindowStationName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
hWindowStationsDir,
|
||||
0);
|
||||
|
||||
/* Check if the handle should be inheritable */
|
||||
if (lpsa && lpsa->bInheritHandle)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
hwinsta = NtUserCreateWindowStation(&ObjectAttributes,
|
||||
dwDesiredAccess,
|
||||
lpsa, 0, 0, 0, 0);
|
||||
0, 0, 0, 0, 0);
|
||||
|
||||
NtClose(hWindowStationsDir);
|
||||
|
||||
return hwinsta;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -303,10 +342,47 @@ OpenWindowStationW(LPCWSTR lpszWinSta,
|
|||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
UNICODE_STRING WindowStationName;
|
||||
UNICODE_STRING WindowStationsDir = RTL_CONSTANT_STRING(L"\\Windows\\WindowStations");
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
HANDLE hWindowStationsDir;
|
||||
NTSTATUS Status;
|
||||
HWINSTA hwinsta;
|
||||
|
||||
/* Open WindowStations directory */
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&WindowStationsDir,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
0,
|
||||
0);
|
||||
|
||||
Status = NtOpenDirectoryObject(&hWindowStationsDir,
|
||||
DIRECTORY_TRAVERSE,
|
||||
&ObjectAttributes);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
ERR("Failed to open WindowStations directory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Open the window station object */
|
||||
RtlInitUnicodeString(&WindowStationName, lpszWinSta);
|
||||
|
||||
return NtUserOpenWindowStation(&WindowStationName, dwDesiredAccess);
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&WindowStationName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
hWindowStationsDir,
|
||||
0);
|
||||
|
||||
if( fInherit == TRUE )
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
hwinsta = NtUserOpenWindowStation(&ObjectAttributes, dwDesiredAccess);
|
||||
|
||||
NtClose(hWindowStationsDir);
|
||||
|
||||
return hwinsta;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1462,7 +1462,7 @@ NtUserCreateLocalMemHandle(
|
|||
HWND
|
||||
NTAPI
|
||||
NtUserCreateWindowEx(
|
||||
DWORD dwExStyle, // |= 0x80000000 == Ansi used to set WNDS_ANSICREATOR
|
||||
DWORD dwExStyle,
|
||||
PLARGE_STRING plstrClassName,
|
||||
PLARGE_STRING plstrClsVersion,
|
||||
PLARGE_STRING plstrWindowName,
|
||||
|
@ -1481,9 +1481,9 @@ NtUserCreateWindowEx(
|
|||
HWINSTA
|
||||
NTAPI
|
||||
NtUserCreateWindowStation(
|
||||
PUNICODE_STRING lpszWindowStationName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
ACCESS_MASK dwDesiredAccess,
|
||||
LPSECURITY_ATTRIBUTES lpSecurity,
|
||||
DWORD Unknown2,
|
||||
DWORD Unknown3,
|
||||
DWORD Unknown4,
|
||||
DWORD Unknown5,
|
||||
|
@ -2301,7 +2301,7 @@ NtUserOpenClipboard(
|
|||
HDESK
|
||||
NTAPI
|
||||
NtUserOpenDesktop(
|
||||
PUNICODE_STRING lpszDesktopName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
DWORD dwFlags,
|
||||
ACCESS_MASK dwDesiredAccess);
|
||||
|
||||
|
@ -2315,7 +2315,7 @@ NtUserOpenInputDesktop(
|
|||
HWINSTA
|
||||
NTAPI
|
||||
NtUserOpenWindowStation(
|
||||
PUNICODE_STRING lpszWindowStationName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
ACCESS_MASK dwDesiredAccess);
|
||||
|
||||
BOOL
|
||||
|
|
|
@ -859,15 +859,12 @@ IntFreeDesktopHeap(IN OUT PDESKTOP Desktop)
|
|||
|
||||
HDESK APIENTRY
|
||||
NtUserCreateDesktop(
|
||||
POBJECT_ATTRIBUTES poa,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
PUNICODE_STRING lpszDesktopDevice,
|
||||
LPDEVMODEW lpdmw,
|
||||
DWORD dwFlags,
|
||||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
PTHREADINFO W32Thread;
|
||||
PWINSTATION_OBJECT WinStaObject;
|
||||
PDESKTOP DesktopObject;
|
||||
UNICODE_STRING DesktopName;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
@ -875,12 +872,9 @@ NtUserCreateDesktop(
|
|||
CSR_API_MESSAGE Request;
|
||||
PVOID DesktopHeapSystemBase = NULL;
|
||||
SIZE_T DesktopInfoSize;
|
||||
UNICODE_STRING SafeDesktopName;
|
||||
ULONG DummyContext;
|
||||
ULONG_PTR HeapSize = 4 * 1024 * 1024; /* FIXME */
|
||||
HWINSTA hWindowStation = NULL ;
|
||||
PUNICODE_STRING lpszDesktopName = NULL;
|
||||
UNICODE_STRING ClassName, MenuName;
|
||||
UNICODE_STRING ClassName;
|
||||
LARGE_STRING WindowName;
|
||||
BOOL NoHooks = FALSE;
|
||||
PWND pWnd = NULL;
|
||||
|
@ -889,7 +883,7 @@ NtUserCreateDesktop(
|
|||
PTHREADINFO ptiCurrent;
|
||||
DECLARE_RETURN(HDESK);
|
||||
|
||||
DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName);
|
||||
DPRINT("Enter NtUserCreateDesktop\n");
|
||||
UserEnterExclusive();
|
||||
|
||||
ptiCurrent = PsGetCurrentThreadWin32Thread();
|
||||
|
@ -899,19 +893,38 @@ NtUserCreateDesktop(
|
|||
NoHooks = (ptiCurrent->TIF_flags & TIF_DISABLEHOOKS);
|
||||
ptiCurrent->TIF_flags |= TIF_DISABLEHOOKS;
|
||||
}
|
||||
DesktopName.Buffer = NULL;
|
||||
|
||||
/*
|
||||
* Try to open already existing desktop
|
||||
*/
|
||||
|
||||
DPRINT("Trying to open desktop (%wZ)\n", &DesktopName);
|
||||
|
||||
Status = ObOpenObjectByName(
|
||||
ObjectAttributes,
|
||||
ExDesktopObjectType,
|
||||
UserMode,
|
||||
NULL,
|
||||
dwDesiredAccess,
|
||||
(PVOID)&DummyContext,
|
||||
(HANDLE*)&Desktop);
|
||||
if (!NT_SUCCESS(Status)) RETURN(NULL);
|
||||
if (Status == STATUS_OBJECT_NAME_EXISTS)
|
||||
{
|
||||
RETURN( Desktop);
|
||||
}
|
||||
|
||||
/* Capture desktop name */
|
||||
_SEH2_TRY
|
||||
{
|
||||
ProbeForRead( poa,
|
||||
sizeof(OBJECT_ATTRIBUTES),
|
||||
1);
|
||||
ProbeForRead( ObjectAttributes, sizeof(OBJECT_ATTRIBUTES), 1);
|
||||
|
||||
hWindowStation = poa->RootDirectory;
|
||||
lpszDesktopName = poa->ObjectName;
|
||||
Status = IntSafeCopyUnicodeString(&DesktopName, ObjectAttributes->ObjectName);
|
||||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
Status =_SEH2_GetExceptionCode();
|
||||
Status = _SEH2_GetExceptionCode();
|
||||
}
|
||||
_SEH2_END
|
||||
|
||||
|
@ -922,75 +935,6 @@ NtUserCreateDesktop(
|
|||
RETURN( NULL);
|
||||
}
|
||||
|
||||
Status = IntValidateWindowStationHandle(
|
||||
hWindowStation,
|
||||
KernelMode,
|
||||
0, /* FIXME - WINSTA_CREATEDESKTOP */
|
||||
&WinStaObject);
|
||||
|
||||
if (! NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
|
||||
hWindowStation, lpszDesktopName);
|
||||
SetLastNtError(Status);
|
||||
RETURN( NULL);
|
||||
}
|
||||
if(lpszDesktopName != NULL)
|
||||
{
|
||||
Status = IntSafeCopyUnicodeString(&SafeDesktopName, lpszDesktopName);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastNtError(Status);
|
||||
RETURN( NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&SafeDesktopName, NULL);
|
||||
}
|
||||
|
||||
if (! IntGetFullWindowStationName(&DesktopName, &WinStaObject->Name,
|
||||
&SafeDesktopName))
|
||||
{
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
ObDereferenceObject(WinStaObject);
|
||||
if (lpszDesktopName)
|
||||
ExFreePoolWithTag(SafeDesktopName.Buffer, TAG_STRING);
|
||||
RETURN( NULL);
|
||||
}
|
||||
if (lpszDesktopName)
|
||||
ExFreePoolWithTag(SafeDesktopName.Buffer, TAG_STRING);
|
||||
ObDereferenceObject(WinStaObject);
|
||||
|
||||
/*
|
||||
* Try to open already existing desktop
|
||||
*/
|
||||
|
||||
DPRINT("Trying to open desktop (%wZ)\n", &DesktopName);
|
||||
|
||||
/* Initialize ObjectAttributes for the desktop object */
|
||||
InitializeObjectAttributes(
|
||||
&ObjectAttributes,
|
||||
&DesktopName,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = ObOpenObjectByName(
|
||||
&ObjectAttributes,
|
||||
ExDesktopObjectType,
|
||||
KernelMode,
|
||||
NULL,
|
||||
dwDesiredAccess,
|
||||
(PVOID)&DummyContext,
|
||||
(HANDLE*)&Desktop);
|
||||
if (!NT_SUCCESS(Status)) RETURN(NULL);
|
||||
if (Status == STATUS_OBJECT_NAME_EXISTS)
|
||||
{
|
||||
ExFreePoolWithTag(DesktopName.Buffer, TAG_STRING);
|
||||
RETURN( Desktop);
|
||||
}
|
||||
|
||||
/* Reference the desktop */
|
||||
Status = ObReferenceObjectByHandle(Desktop,
|
||||
0,
|
||||
|
@ -1011,8 +955,7 @@ NtUserCreateDesktop(
|
|||
RETURN(NULL);
|
||||
}
|
||||
|
||||
DesktopInfoSize = FIELD_OFFSET(DESKTOPINFO,
|
||||
szDesktopName[(lpszDesktopName->Length / sizeof(WCHAR)) + 1]);
|
||||
DesktopInfoSize = sizeof(DESKTOPINFO) + DesktopName.Length;
|
||||
|
||||
DesktopObject->pDeskInfo = RtlAllocateHeap(DesktopObject->pheapDesktop,
|
||||
HEAP_NO_SERIALIZE,
|
||||
|
@ -1031,8 +974,8 @@ NtUserCreateDesktop(
|
|||
DesktopObject->pDeskInfo->pvDesktopBase = DesktopHeapSystemBase;
|
||||
DesktopObject->pDeskInfo->pvDesktopLimit = (PVOID)((ULONG_PTR)DesktopHeapSystemBase + HeapSize);
|
||||
RtlCopyMemory(DesktopObject->pDeskInfo->szDesktopName,
|
||||
lpszDesktopName->Buffer,
|
||||
lpszDesktopName->Length);
|
||||
DesktopName.Buffer,
|
||||
DesktopName.Length);
|
||||
|
||||
/* Initialize some local (to win32k) desktop state. */
|
||||
InitializeListHead(&DesktopObject->PtiList);
|
||||
|
@ -1042,7 +985,6 @@ NtUserCreateDesktop(
|
|||
{
|
||||
InitializeListHead(&DesktopObject->pDeskInfo->aphkStart[i]);
|
||||
}
|
||||
ExFreePoolWithTag(DesktopName.Buffer, TAG_STRING);
|
||||
|
||||
//// why is this here?
|
||||
#if 0
|
||||
|
@ -1090,7 +1032,6 @@ NtUserCreateDesktop(
|
|||
//
|
||||
ClassName.Buffer = ((PWSTR)((ULONG_PTR)(WORD)(gpsi->atomSysClass[ICLS_DESKTOP])));
|
||||
ClassName.Length = 0;
|
||||
RtlZeroMemory(&MenuName, sizeof(MenuName));
|
||||
RtlZeroMemory(&WindowName, sizeof(WindowName));
|
||||
|
||||
RtlZeroMemory(&Cs, sizeof(Cs));
|
||||
|
@ -1113,9 +1054,8 @@ NtUserCreateDesktop(
|
|||
DesktopObject->pDeskInfo->spwnd = pWndDesktop;
|
||||
}
|
||||
#endif
|
||||
W32Thread = PsGetCurrentThreadWin32Thread();
|
||||
|
||||
if (!W32Thread->rpdesk) IntSetThreadDesktop(DesktopObject,FALSE);
|
||||
if (!ptiCurrent->rpdesk) IntSetThreadDesktop(DesktopObject,FALSE);
|
||||
|
||||
/*
|
||||
Based on wine/server/window.c in get_desktop_window.
|
||||
|
@ -1123,7 +1063,6 @@ NtUserCreateDesktop(
|
|||
|
||||
ClassName.Buffer = ((PWSTR)((ULONG_PTR)(WORD)(gpsi->atomSysClass[ICLS_HWNDMESSAGE])));
|
||||
ClassName.Length = 0;
|
||||
RtlZeroMemory(&MenuName, sizeof(MenuName));
|
||||
RtlZeroMemory(&WindowName, sizeof(WindowName));
|
||||
|
||||
RtlZeroMemory(&Cs, sizeof(Cs));
|
||||
|
@ -1154,6 +1093,10 @@ NtUserCreateDesktop(
|
|||
RETURN( Desktop);
|
||||
|
||||
CLEANUP:
|
||||
if(DesktopName.Buffer != NULL)
|
||||
{
|
||||
ExFreePoolWithTag(DesktopName.Buffer, TAG_STRING);
|
||||
}
|
||||
if (!NoHooks && ptiCurrent) ptiCurrent->TIF_flags &= ~TIF_DISABLEHOOKS;
|
||||
DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_);
|
||||
UserLeave();
|
||||
|
@ -1184,85 +1127,17 @@ CLEANUP:
|
|||
|
||||
HDESK APIENTRY
|
||||
NtUserOpenDesktop(
|
||||
PUNICODE_STRING lpszDesktopName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
DWORD dwFlags,
|
||||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
HWINSTA WinSta;
|
||||
PWINSTATION_OBJECT WinStaObject;
|
||||
UNICODE_STRING DesktopName;
|
||||
UNICODE_STRING SafeDesktopName;
|
||||
NTSTATUS Status;
|
||||
HDESK Desktop;
|
||||
BOOL Result;
|
||||
DECLARE_RETURN(HDESK);
|
||||
|
||||
DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName);
|
||||
UserEnterExclusive();
|
||||
|
||||
/*
|
||||
* Validate the window station handle and compose the fully
|
||||
* qualified desktop name
|
||||
*/
|
||||
|
||||
WinSta = UserGetProcessWindowStation();
|
||||
Status = IntValidateWindowStationHandle(
|
||||
WinSta,
|
||||
KernelMode,
|
||||
0,
|
||||
&WinStaObject);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta);
|
||||
SetLastNtError(Status);
|
||||
RETURN( 0);
|
||||
}
|
||||
|
||||
if(lpszDesktopName != NULL)
|
||||
{
|
||||
Status = IntSafeCopyUnicodeString(&SafeDesktopName, lpszDesktopName);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastNtError(Status);
|
||||
RETURN( NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&SafeDesktopName, NULL);
|
||||
}
|
||||
|
||||
Result = IntGetFullWindowStationName(&DesktopName, &WinStaObject->Name,
|
||||
&SafeDesktopName);
|
||||
|
||||
if (lpszDesktopName)
|
||||
ExFreePoolWithTag(SafeDesktopName.Buffer, TAG_STRING);
|
||||
ObDereferenceObject(WinStaObject);
|
||||
|
||||
|
||||
if (!Result)
|
||||
{
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
RETURN( 0);
|
||||
}
|
||||
|
||||
|
||||
DPRINT("Trying to open desktop (%wZ)\n", &DesktopName);
|
||||
|
||||
/* Initialize ObjectAttributes for the desktop object */
|
||||
InitializeObjectAttributes(
|
||||
&ObjectAttributes,
|
||||
&DesktopName,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = ObOpenObjectByName(
|
||||
&ObjectAttributes,
|
||||
ObjectAttributes,
|
||||
ExDesktopObjectType,
|
||||
KernelMode,
|
||||
UserMode,
|
||||
NULL,
|
||||
dwDesiredAccess,
|
||||
NULL,
|
||||
|
@ -1271,19 +1146,10 @@ NtUserOpenDesktop(
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastNtError(Status);
|
||||
ExFreePool(DesktopName.Buffer);
|
||||
RETURN( 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName);
|
||||
ExFreePool(DesktopName.Buffer);
|
||||
|
||||
RETURN( Desktop);
|
||||
|
||||
CLEANUP:
|
||||
DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_);
|
||||
UserLeave();
|
||||
END_CLEANUP;
|
||||
return Desktop;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -392,61 +392,23 @@ IntGetScreenDC(VOID)
|
|||
|
||||
HWINSTA APIENTRY
|
||||
NtUserCreateWindowStation(
|
||||
PUNICODE_STRING lpszWindowStationName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
ACCESS_MASK dwDesiredAccess,
|
||||
LPSECURITY_ATTRIBUTES lpSecurity,
|
||||
DWORD Unknown2,
|
||||
DWORD Unknown3,
|
||||
DWORD Unknown4,
|
||||
DWORD Unknown5,
|
||||
DWORD Unknown6)
|
||||
{
|
||||
UNICODE_STRING WindowStationName;
|
||||
UNICODE_STRING FullWindowStationName;
|
||||
PWINSTATION_OBJECT WindowStationObject;
|
||||
HWINSTA WindowStation;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS Status;
|
||||
|
||||
/*
|
||||
* Generate full window station name
|
||||
*/
|
||||
Status = ProbeAndCaptureUnicodeString(&WindowStationName,
|
||||
UserMode,
|
||||
lpszWindowStationName);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to capture window station name (status 0x%08x)\n",
|
||||
Status);
|
||||
SetLastNtError(Status);
|
||||
return 0;
|
||||
}
|
||||
if (!IntGetFullWindowStationName(&FullWindowStationName,
|
||||
&WindowStationName,
|
||||
NULL))
|
||||
{
|
||||
ReleaseCapturedUnicodeString(&WindowStationName, UserMode);
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to open already existing window station
|
||||
*/
|
||||
|
||||
DPRINT("Trying to open window station (%wZ)\n", &FullWindowStationName);
|
||||
|
||||
/* Initialize ObjectAttributes for the window station object */
|
||||
InitializeObjectAttributes(
|
||||
&ObjectAttributes,
|
||||
&FullWindowStationName,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = ObOpenObjectByName(
|
||||
&ObjectAttributes,
|
||||
ObjectAttributes,
|
||||
ExWindowStationObjectType,
|
||||
KernelMode,
|
||||
UserMode,
|
||||
NULL,
|
||||
dwDesiredAccess,
|
||||
NULL,
|
||||
|
@ -454,24 +416,39 @@ NtUserCreateWindowStation(
|
|||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("Successfully opened window station (%wZ)\n",
|
||||
FullWindowStationName);
|
||||
ExFreePool(FullWindowStationName.Buffer);
|
||||
ReleaseCapturedUnicodeString(&WindowStationName, UserMode);
|
||||
return (HWINSTA)WindowStation;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* No existing window station found, try to create new one
|
||||
*/
|
||||
|
||||
DPRINT("Creating window station (%wZ)\n", &FullWindowStationName);
|
||||
/* Capture window station name */
|
||||
_SEH2_TRY
|
||||
{
|
||||
ProbeForRead( ObjectAttributes, sizeof(OBJECT_ATTRIBUTES), 1);
|
||||
Status = IntSafeCopyUnicodeString(&WindowStationName, ObjectAttributes->ObjectName);
|
||||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
Status =_SEH2_GetExceptionCode();
|
||||
}
|
||||
_SEH2_END
|
||||
|
||||
if (! NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed reading capturing window station name\n");
|
||||
SetLastNtError(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create the window station object */
|
||||
Status = ObCreateObject(
|
||||
KernelMode,
|
||||
UserMode,
|
||||
ExWindowStationObjectType,
|
||||
&ObjectAttributes,
|
||||
ExGetPreviousMode(),
|
||||
ObjectAttributes,
|
||||
UserMode,
|
||||
NULL,
|
||||
sizeof(WINSTATION_OBJECT),
|
||||
0,
|
||||
|
@ -480,26 +457,11 @@ NtUserCreateWindowStation(
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed creating window station (%wZ)\n", &FullWindowStationName);
|
||||
ExFreePool(FullWindowStationName.Buffer);
|
||||
ReleaseCapturedUnicodeString(&WindowStationName, UserMode);
|
||||
ExFreePoolWithTag(WindowStationName.Buffer, TAG_STRING);
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Zero out the buffer */
|
||||
RtlZeroMemory(WindowStationObject, sizeof(WINSTATION_OBJECT));
|
||||
|
||||
KeInitializeSpinLock(&WindowStationObject->Lock);
|
||||
|
||||
InitializeListHead(&WindowStationObject->DesktopListHead);
|
||||
|
||||
WindowStationObject->AtomTable = NULL;
|
||||
Status = RtlCreateAtomTable(37, &WindowStationObject->AtomTable);
|
||||
WindowStationObject->SystemMenuTemplate = (HANDLE)0;
|
||||
|
||||
WindowStationObject->Name = WindowStationName;
|
||||
|
||||
Status = ObInsertObject(
|
||||
(PVOID)WindowStationObject,
|
||||
NULL,
|
||||
|
@ -510,20 +472,21 @@ NtUserCreateWindowStation(
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed creating window station (%wZ)\n", &FullWindowStationName);
|
||||
ExFreePool(FullWindowStationName.Buffer);
|
||||
ExFreePool(WindowStationName.Buffer);
|
||||
ExFreePoolWithTag(WindowStationName.Buffer, TAG_STRING);
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
ObDereferenceObject(WindowStationObject);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the new window station object
|
||||
*/
|
||||
/* Initialize the window station */
|
||||
RtlZeroMemory(WindowStationObject, sizeof(WINSTATION_OBJECT));
|
||||
|
||||
KeInitializeSpinLock(&WindowStationObject->Lock);
|
||||
InitializeListHead(&WindowStationObject->DesktopListHead);
|
||||
Status = RtlCreateAtomTable(37, &WindowStationObject->AtomTable);
|
||||
WindowStationObject->SystemMenuTemplate = (HANDLE)0;
|
||||
WindowStationObject->Name = WindowStationName;
|
||||
WindowStationObject->ScreenSaverRunning = FALSE;
|
||||
|
||||
WindowStationObject->FlatMenu = FALSE;
|
||||
|
||||
if (!IntSetupClipboard(WindowStationObject))
|
||||
|
@ -538,8 +501,6 @@ NtUserCreateWindowStation(
|
|||
InitCursorImpl();
|
||||
}
|
||||
|
||||
DPRINT("Window station successfully created (%wZ)\n", &FullWindowStationName);
|
||||
ExFreePool(FullWindowStationName.Buffer);
|
||||
return WindowStation;
|
||||
}
|
||||
|
||||
|
@ -569,39 +530,16 @@ NtUserCreateWindowStation(
|
|||
|
||||
HWINSTA APIENTRY
|
||||
NtUserOpenWindowStation(
|
||||
PUNICODE_STRING lpszWindowStationName,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes,
|
||||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
UNICODE_STRING WindowStationName;
|
||||
HWINSTA WindowStation;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS Status;
|
||||
|
||||
/*
|
||||
* Generate full window station name
|
||||
*/
|
||||
|
||||
if (!IntGetFullWindowStationName(&WindowStationName, lpszWindowStationName,
|
||||
NULL))
|
||||
{
|
||||
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DPRINT("Trying to open window station (%wZ)\n", &WindowStationName);
|
||||
|
||||
/* Initialize ObjectAttributes for the window station object */
|
||||
InitializeObjectAttributes(
|
||||
&ObjectAttributes,
|
||||
&WindowStationName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = ObOpenObjectByName(
|
||||
&ObjectAttributes,
|
||||
ObjectAttributes,
|
||||
ExWindowStationObjectType,
|
||||
KernelMode,
|
||||
UserMode,
|
||||
NULL,
|
||||
dwDesiredAccess,
|
||||
NULL,
|
||||
|
@ -610,13 +548,9 @@ NtUserOpenWindowStation(
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastNtError(Status);
|
||||
ExFreePool(WindowStationName.Buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DPRINT("Successfully opened window station (%wZ)\n", &WindowStationName);
|
||||
ExFreePool(WindowStationName.Buffer);
|
||||
|
||||
return WindowStation;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue