Index: ntoskrnl/ex/win32k.c =================================================================== --- ntoskrnl/ex/win32k.c (revision 57484) +++ ntoskrnl/ex/win32k.c (working copy) @@ -40,6 +40,8 @@ PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExpWindowStationObjectOkToClose = NULL; PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExpDesktopObjectOkToClose = NULL; PKWIN32_DELETEMETHOD_CALLOUT ExpDesktopObjectDelete = NULL; +PKWIN32_OPENMETHOD_CALLOUT ExpDesktopObjectOpen = NULL; +PKWIN32_CLOSEMETHOD_CALLOUT ExpDesktopObjectClose = NULL; /* FUNCTIONS ****************************************************************/ @@ -133,6 +135,44 @@ ExpDesktopObjectDelete(&Parameters); } +NTSTATUS +NTAPI +ExpDesktopOpen(IN OB_OPEN_REASON Reason, + IN PEPROCESS Process OPTIONAL, + IN PVOID ObjectBody, + IN ACCESS_MASK GrantedAccess, + IN ULONG HandleCount) +{ + WIN32_OPENMETHOD_PARAMETERS Parameters; + + Parameters.OpenReason = Reason; + Parameters.Process = Process; + Parameters.Object = ObjectBody; + Parameters.GrantedAccess = GrantedAccess; + Parameters.HandleCount = HandleCount; + + return ExpDesktopObjectOpen(&Parameters); +} + +VOID +NTAPI +ExpDesktopClose(IN PEPROCESS Process OPTIONAL, + IN PVOID Object, + IN ACCESS_MASK GrantedAccess, + IN ULONG ProcessHandleCount, + IN ULONG SystemHandleCount) +{ + WIN32_CLOSEMETHOD_PARAMETERS Parameters; + + Parameters.Process = Process; + Parameters.Object = Object; + Parameters.AccessMask = GrantedAccess; + Parameters.ProcessHandleCount = ProcessHandleCount; + Parameters.SystemHandleCount = SystemHandleCount; + + ExpDesktopObjectClose(&Parameters); +} + BOOLEAN INIT_FUNCTION NTAPI @@ -169,6 +209,8 @@ ObjectTypeInitializer.DeleteProcedure = ExpDesktopDelete; ObjectTypeInitializer.ParseProcedure = NULL; ObjectTypeInitializer.OkayToCloseProcedure = ExpDesktopOkToClose; + ObjectTypeInitializer.OpenProcedure = ExpDesktopOpen; + ObjectTypeInitializer.CloseProcedure = ExpDesktopClose; ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, Index: ntoskrnl/ps/win32.c =================================================================== --- ntoskrnl/ps/win32.c (revision 57484) +++ ntoskrnl/ps/win32.c (working copy) @@ -23,6 +23,8 @@ extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExpWindowStationObjectOkToClose; extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExpDesktopObjectOkToClose; extern PKWIN32_DELETEMETHOD_CALLOUT ExpDesktopObjectDelete; +extern PKWIN32_OPENMETHOD_CALLOUT ExpDesktopObjectOpen; +extern PKWIN32_CLOSEMETHOD_CALLOUT ExpDesktopObjectClose; extern PKWIN32_POWEREVENT_CALLOUT PopEventCallout; /* PRIVATE FUNCTIONS *********************************************************/ @@ -121,6 +123,8 @@ ExpWindowStationObjectOkToClose = CalloutData->WindowStationOkToCloseProcedure; ExpDesktopObjectOkToClose = CalloutData->DesktopOkToCloseProcedure; ExpDesktopObjectDelete = CalloutData->DesktopDeleteProcedure; + ExpDesktopObjectOpen = CalloutData->DesktopOpenProcedure; + ExpDesktopObjectClose = CalloutData->DesktopCloseProcedure; PopEventCallout = CalloutData->PowerEventCallout; KeGdiFlushUserBatch = CalloutData->BatchFlushRoutine; } Index: win32ss/gdi/ntgdi/device.c =================================================================== --- win32ss/gdi/ntgdi/device.c (revision 57484) +++ win32ss/gdi/ntgdi/device.c (working copy) @@ -32,16 +32,16 @@ SURFOBJ *pso; PDESKTOP rpDesk; + /* Create surface */ + pso = &PDEVOBJ_pSurface(gppdevPrimary)->SurfObj; + SurfSize = pso->sizlBitmap; + /* Attach monitor */ UserAttachMonitor((HDEV)gppdevPrimary); DPRINT("IntCreatePrimarySurface, gppdevPrimary=%p, gppdevPrimary->pSurface = %p\n", gppdevPrimary, gppdevPrimary->pSurface); - /* Create surface */ - pso = &PDEVOBJ_pSurface(gppdevPrimary)->SurfObj; - SurfSize = pso->sizlBitmap; - /* Put the pointer in the center of the screen */ gpsi->ptCursor.x = pso->sizlBitmap.cx / 2; gpsi->ptCursor.y = pso->sizlBitmap.cy / 2; Index: win32ss/user/ntuser/accelerator.c =================================================================== --- win32ss/user/ntuser/accelerator.c (revision 57484) +++ win32ss/user/ntuser/accelerator.c (working copy) @@ -257,7 +257,7 @@ RETURN( (HACCEL) NULL ); } - Accel = UserCreateObject(gHandleTable, NULL, (PHANDLE)&hAccel, otAccel, sizeof(ACCELERATOR_TABLE)); + Accel = UserCreateObject(gHandleTable, NULL, NULL, (PHANDLE)&hAccel, otAccel, sizeof(ACCELERATOR_TABLE)); if (Accel == NULL) { Index: win32ss/user/ntuser/callback.c =================================================================== --- win32ss/user/ntuser/callback.c (revision 57484) +++ win32ss/user/ntuser/callback.c (working copy) @@ -129,6 +129,9 @@ HMODULE Result; ULONG_PTR pLibNameBuffer = 0, pInitFuncBuffer = 0; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + TRACE("co_IntClientLoadLibrary: %S, %S, %d, %d\n", pstrLibName->Buffer, pstrLibName->Buffer, Unload, ApiHook); /* Calculate the size of the argument */ @@ -235,6 +238,9 @@ ULONG ResultLength; NTSTATUS Status; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + Arguments.Callback = CompletionCallback; Arguments.Wnd = hWnd; Arguments.Msg = Msg; @@ -280,6 +286,9 @@ ULONG ArgumentLength; LRESULT Result; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + if (0 < lParamBufferSize) { ArgumentLength = sizeof(WINDOWPROC_CALLBACK_ARGUMENTS) + lParamBufferSize; @@ -363,6 +372,9 @@ PVOID ResultPointer; ULONG ResultLength; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + ResultPointer = NULL; ResultLength = sizeof(LRESULT); @@ -401,6 +413,9 @@ ULONG ResultLength; BOOL DefaultCursor = TRUE; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + ResultPointer = NULL; ResultLength = sizeof(LRESULT); @@ -447,6 +462,8 @@ UINT lParamSize = 0; ASSERT(Proc); + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); pti = PsGetCurrentThreadWin32Thread(); if (pti->TIF_flags & TIF_INCLEANUP) @@ -833,6 +850,9 @@ ULONG ArgumentLength, ResultLength; PVOID Argument, ResultPointer; + /* Do not allow the desktop thread to do callback to user mode */ + ASSERT(PsGetCurrentThreadWin32Thread() != ptiDesktopThread); + ArgumentLength = ResultLength = 0; Argument = ResultPointer = NULL; Index: win32ss/user/ntuser/callproc.c =================================================================== --- win32ss/user/ntuser/callproc.c (revision 57484) +++ win32ss/user/ntuser/callproc.c (working copy) @@ -34,7 +34,7 @@ HANDLE Handle; NewCallProc = (PCALLPROCDATA)UserCreateObject(gHandleTable, - Desktop, + Desktop, NULL, &Handle, otCallProc, sizeof(CALLPROCDATA)); Index: win32ss/user/ntuser/class.c =================================================================== --- win32ss/user/ntuser/class.c (revision 57484) +++ win32ss/user/ntuser/class.c (working copy) @@ -638,12 +638,16 @@ IN OUT PCLS *ClassLink, IN PDESKTOP Desktop) { - PCLS Class; + PCLS Class = BaseClass; ASSERT(BaseClass->pclsBase == BaseClass); - Class = IntGetClassForDesktop(BaseClass, - ClassLink, - Desktop); + if(Desktop != NULL) + { + Class = IntGetClassForDesktop(BaseClass, + ClassLink, + Desktop); + } + if (Class != NULL) { Class->cWndReferenceCount++; @@ -1286,13 +1290,16 @@ } PCLS -IntGetAndReferenceClass(PUNICODE_STRING ClassName, HINSTANCE hInstance) +IntGetAndReferenceClass(PUNICODE_STRING ClassName, HINSTANCE hInstance, BOOL bDesktopThread) { PCLS *ClassLink, Class = NULL; RTL_ATOM ClassAtom; PTHREADINFO pti; - pti = PsGetCurrentThreadWin32Thread(); + if(bDesktopThread) + pti = ptiDesktopThread; + else + pti = PsGetCurrentThreadWin32Thread(); if ( !(pti->ppi->W32PF_flags & W32PF_CLASSESREGISTERED )) { Index: win32ss/user/ntuser/class.h =================================================================== --- win32ss/user/ntuser/class.h (revision 57484) +++ win32ss/user/ntuser/class.h (working copy) @@ -39,7 +39,7 @@ IN PPROCESSINFO pi); PCLS -IntGetAndReferenceClass(PUNICODE_STRING ClassName, HINSTANCE hInstance); +IntGetAndReferenceClass(PUNICODE_STRING ClassName, HINSTANCE hInstance, BOOL bDesktopThread); BOOL FASTCALL UserRegisterSystemClasses(VOID); Index: win32ss/user/ntuser/clipboard.c =================================================================== --- win32ss/user/ntuser/clipboard.c (revision 57484) +++ win32ss/user/ntuser/clipboard.c (working copy) @@ -182,6 +182,7 @@ /* Create the clipboard data */ pClipboardData = (PCLIPBOARDDATA)UserCreateObject(gHandleTable, NULL, + NULL, &hMem, otClipBoardData, cjDataSize); @@ -293,7 +294,7 @@ PCLIPBOARDDATA pMemObj; HANDLE hMem; - pMemObj = (PCLIPBOARDDATA)UserCreateObject(gHandleTable, NULL, &hMem, otClipBoardData, + pMemObj = (PCLIPBOARDDATA)UserCreateObject(gHandleTable, NULL, NULL, &hMem, otClipBoardData, sizeof(CLIPBOARDDATA) + sizeof(LCID)); if (pMemObj) { @@ -1080,7 +1081,7 @@ UserEnterExclusive(); /* Create Clipboard data object */ - pMemObj = UserCreateObject(gHandleTable, NULL, &hMem, otClipBoardData, sizeof(CLIPBOARDDATA) + cbData); + pMemObj = UserCreateObject(gHandleTable, NULL, NULL, &hMem, otClipBoardData, sizeof(CLIPBOARDDATA) + cbData); if (!pMemObj) goto cleanup; Index: win32ss/user/ntuser/csr.c =================================================================== --- win32ss/user/ntuser/csr.c (revision 57484) +++ win32ss/user/ntuser/csr.c (working copy) @@ -88,74 +88,4 @@ return Status; } - -NTSTATUS -APIENTRY -CsrInsertObject(HANDLE ObjectHandle, - ACCESS_MASK DesiredAccess, - PHANDLE Handle) -{ - NTSTATUS Status; - HANDLE CsrProcessHandle; - OBJECT_ATTRIBUTES ObjectAttributes; - CLIENT_ID Cid; - - /* Put CSR'S CID */ - Cid.UniqueProcess = CsrProcess->UniqueProcessId; - Cid.UniqueThread = 0; - - /* Empty Attributes */ - InitializeObjectAttributes(&ObjectAttributes, - NULL, - 0, - NULL, - NULL); - - /* Get a Handle to Csrss */ - Status = ZwOpenProcess(&CsrProcessHandle, - PROCESS_DUP_HANDLE, - &ObjectAttributes, - &Cid); - - if ((NT_SUCCESS(Status))) - { - /* Duplicate the Handle */ - Status = ZwDuplicateObject(NtCurrentProcess(), - ObjectHandle, - CsrProcessHandle, - Handle, - DesiredAccess, - OBJ_INHERIT, - 0); - - /* Close our handle to CSRSS */ - ZwClose(CsrProcessHandle); - } - - return Status; -} - -NTSTATUS FASTCALL -CsrCloseHandle(HANDLE Handle) -{ - NTSTATUS Status; - PEPROCESS OldProcess; - - /* Switch to the process in which the handle is valid */ - OldProcess = PsGetCurrentProcess(); - if (CsrProcess != OldProcess) - { - KeAttachProcess(&CsrProcess->Pcb); - } - - Status = ZwClose(Handle); - - if (CsrProcess != OldProcess) - { - KeDetachProcess(); - } - - return Status; -} - /* EOF */ Index: win32ss/user/ntuser/cursoricon.c =================================================================== --- win32ss/user/ntuser/cursoricon.c (revision 57484) +++ win32ss/user/ntuser/cursoricon.c (working copy) @@ -209,7 +209,7 @@ PCURICON_OBJECT CurIcon; HANDLE hCurIcon; - CurIcon = UserCreateObject(gHandleTable, NULL, &hCurIcon, otCursorIcon, sizeof(CURICON_OBJECT)); + CurIcon = UserCreateObject(gHandleTable, NULL, NULL, &hCurIcon, otCursorIcon, sizeof(CURICON_OBJECT)); if (!CurIcon) { Index: win32ss/user/ntuser/desktop.c =================================================================== --- win32ss/user/ntuser/desktop.c (revision 57484) +++ win32ss/user/ntuser/desktop.c (working copy) @@ -11,7 +11,6 @@ #include DBG_DEFAULT_CHANNEL(UserDesktop); -static VOID IntFreeDesktopHeap( IN OUT PDESKTOP Desktop @@ -23,7 +22,17 @@ PDESKTOP InputDesktop = NULL; HDESK InputDesktopHandle = NULL; HDC ScreenDeviceContext = NULL; +PTHREADINFO ptiDesktopThread; +static NTSTATUS +UserInitializeDesktop(PDESKTOP pdesk, PUNICODE_STRING DesktopName, PWINSTATION_OBJECT pwinsta); + +static NTSTATUS +IntMapDesktopView(IN PDESKTOP pdesk); + +static NTSTATUS +IntUnmapDesktopView(IN PDESKTOP pdesk); + /* OBJECT CALLBACKS **********************************************************/ NTSTATUS @@ -115,19 +124,13 @@ (PVOID)&Desktop); if (!NT_SUCCESS(Status)) return Status; - /* Initialize shell hook window list and set the parent */ - RtlZeroMemory(Desktop, sizeof(DESKTOP)); - InitializeListHead(&Desktop->ShellHookWindows); - Desktop->rpwinstaParent = (PWINSTATION_OBJECT)ParseObject; + /* Initialize the desktop */ + Status = UserInitializeDesktop(Desktop, RemainingName, WinStaObject); - /* Put the desktop on the window station's list of associated desktops */ - InsertTailList(&Desktop->rpwinstaParent->DesktopListHead, - &Desktop->ListEntry); - /* Set the desktop object and return success */ *Object = Desktop; *pContext = TRUE; - return STATUS_SUCCESS; + return Status; } VOID APIENTRY @@ -140,7 +143,7 @@ /* Remove the desktop from the window station's list of associcated desktops */ RemoveEntryList(&Desktop->ListEntry); - IntFreeDesktopHeap(Desktop); + //IntFreeDesktopHeap(Desktop); } NTSTATUS NTAPI @@ -166,6 +169,25 @@ return STATUS_SUCCESS; } +NTSTATUS NTAPI IntDesktopObjectOpen(PWIN32_OPENMETHOD_PARAMETERS Parameters) +{ + PPROCESSINFO ppi = PsGetProcessWin32Process(Parameters->Process); + if(ppi == NULL) + return STATUS_SUCCESS; + + return IntMapDesktopView((PDESKTOP)Parameters->Object); +} + +NTSTATUS NTAPI IntDesktopObjectClose(PWIN32_CLOSEMETHOD_PARAMETERS Parameters) +{ + PPROCESSINFO ppi = PsGetProcessWin32Process(Parameters->Process); + if(ppi == NULL) + return STATUS_SUCCESS; + + return IntUnmapDesktopView((PDESKTOP)Parameters->Object); +} + + /* PRIVATE FUNCTIONS **********************************************************/ INIT_FUNCTION @@ -597,9 +619,53 @@ co_UserRedrawWindow(Wnd, NULL, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN); return TRUE; } - return FALSE; // Not processed so go with callback. + return TRUE; // Not processed so go with callback. } +BOOL FASTCALL +UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) +{ + *lResult = 0; + + switch(Msg) + { + case WM_NCCREATE: + pwnd->fnid |= FNID_MESSAGEWND; + *lResult = (LRESULT)TRUE; + break; + case WM_DESTROY: + pwnd->fnid |= FNID_DESTROY; + break; + } + + return TRUE; +} + +VOID NTAPI DesktopThreadMain() +{ + BOOL Ret; + MSG Msg; + + ptiDesktopThread = PsGetCurrentThreadWin32Thread(); + + UserEnterExclusive(); + + /* Register system classes. This thread does not belong to any desktop so the + classes will be allocated from the shared heap */ + UserRegisterSystemClasses(); + + while(TRUE) + { + Ret = co_IntGetPeekMessage(&Msg, 0, 0, 0, PM_REMOVE, TRUE); + if(Ret) + { + IntDispatchMessage(&Msg); + } + } + + UserLeave(); +} + HDC FASTCALL UserGetDesktopDC(ULONG DcType, BOOL EmptyDC, BOOL ValidatehWnd) { @@ -810,7 +876,7 @@ return FALSE; } -static VOID +VOID IntFreeDesktopHeap(IN OUT PDESKTOP Desktop) { if (Desktop->pheapDesktop != NULL) @@ -1030,6 +1096,63 @@ return TRUE; } +static NTSTATUS +UserInitializeDesktop(PDESKTOP pdesk, PUNICODE_STRING DesktopName, PWINSTATION_OBJECT pwinsta) +{ + PVOID DesktopHeapSystemBase = NULL; + ULONG_PTR HeapSize = 400 * 1024; + SIZE_T DesktopInfoSize; + INT i; + + TRACE("UserInitializeDesktop desktop 0x%p with name %wZ\n", pdesk, DesktopName); + + RtlZeroMemory(pdesk, sizeof(DESKTOP)); + + /* Link the desktop with the parent window station */ + pdesk->rpwinstaParent = pwinsta; + InsertTailList(&pwinsta->DesktopListHead, &pdesk->ListEntry); + + /* Create the desktop heap */ + pdesk->hsectionDesktop = NULL; + pdesk->pheapDesktop = UserCreateHeap(&pdesk->hsectionDesktop, + &DesktopHeapSystemBase, + HeapSize); + if (pdesk->pheapDesktop == NULL) + { + ObDereferenceObject(pdesk); + ERR("Failed to create desktop heap!\n"); + return STATUS_NO_MEMORY; + } + + /* Create DESKTOPINFO */ + DesktopInfoSize = sizeof(DESKTOPINFO) + DesktopName->Length + sizeof(WCHAR); + pdesk->pDeskInfo = RtlAllocateHeap(pdesk->pheapDesktop, + HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, + DesktopInfoSize); + if (pdesk->pDeskInfo == NULL) + { + ObDereferenceObject(pdesk); + ERR("Failed to create the DESKTOP structure!\n"); + return STATUS_NO_MEMORY; + } + + /* Initialize the DESKTOPINFO */ + pdesk->pDeskInfo->pvDesktopBase = DesktopHeapSystemBase; + pdesk->pDeskInfo->pvDesktopLimit = (PVOID)((ULONG_PTR)DesktopHeapSystemBase + HeapSize); + RtlCopyMemory(pdesk->pDeskInfo->szDesktopName, + DesktopName->Buffer, + DesktopName->Length + sizeof(WCHAR)); + for (i = 0; i < NB_HOOKS; i++) + { + InitializeListHead(&pdesk->pDeskInfo->aphkStart[i]); + } + + InitializeListHead(&pdesk->ShellHookWindows); + InitializeListHead(&pdesk->PtiList); + + return STATUS_SUCCESS; +} + /* SYSCALLS *******************************************************************/ /* @@ -1074,42 +1197,34 @@ ACCESS_MASK dwDesiredAccess) { PDESKTOP DesktopObject; - UNICODE_STRING DesktopName; NTSTATUS Status = STATUS_SUCCESS; HDESK Desktop; - CSR_API_MESSAGE Request; - PVOID DesktopHeapSystemBase = NULL; - SIZE_T DesktopInfoSize; BOOLEAN Context; - ULONG_PTR HeapSize = 400 * 1024; /* FIXME: Windows uses 200KB by default */ UNICODE_STRING ClassName; LARGE_STRING WindowName; BOOL NoHooks = FALSE; PWND pWnd = NULL; CREATESTRUCTW Cs; - INT i; PTHREADINFO ptiCurrent; + PCLS pcls; + DECLARE_RETURN(HDESK); TRACE("Enter NtUserCreateDesktop\n"); UserEnterExclusive(); ptiCurrent = PsGetCurrentThreadWin32Thread(); - if (ptiCurrent) - { + ASSERT(ptiCurrent); + ASSERT(ptiDesktopThread); + /* Turn off hooks when calling any CreateWindowEx from inside win32k. */ - NoHooks = (ptiCurrent->TIF_flags & TIF_DISABLEHOOKS); - ptiCurrent->TIF_flags |= TIF_DISABLEHOOKS; - ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags; - } - /*else - {ERR("NtUserCreateDesktop: No ptiCurrent\n");}*/ - DesktopName.Buffer = NULL; - + NoHooks = (ptiCurrent->TIF_flags & TIF_DISABLEHOOKS); + ptiCurrent->TIF_flags |= TIF_DISABLEHOOKS; + ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags; + /* * Try to open already existing desktop */ - Status = ObOpenObjectByName( ObjectAttributes, ExDesktopObjectType, @@ -1127,26 +1242,6 @@ RETURN( Desktop); } - /* Capture desktop name */ - _SEH2_TRY - { - ProbeForRead( ObjectAttributes, sizeof(OBJECT_ATTRIBUTES), 1); - - Status = IntSafeCopyUnicodeStringTerminateNULL(&DesktopName, ObjectAttributes->ObjectName); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END - - if (! NT_SUCCESS(Status)) - { - ERR("Failed reading Object Attributes from user space.\n"); - SetLastNtError(Status); - RETURN( NULL); - } - /* Reference the desktop */ Status = ObReferenceObjectByHandle(Desktop, 0, @@ -1160,78 +1255,41 @@ RETURN(NULL); } - TRACE("NtUserCreateDesktop created desktop 0x%p with name %wZ\n", DesktopObject, &DesktopName); + + if (ptiCurrent && !ptiCurrent->rpdesk) IntSetThreadDesktop(Desktop,FALSE); - DesktopObject->hsectionDesktop = NULL; - DesktopObject->pheapDesktop = UserCreateHeap(&DesktopObject->hsectionDesktop, - &DesktopHeapSystemBase, - HeapSize); - if (DesktopObject->pheapDesktop == NULL) - { - ObDereferenceObject(DesktopObject); - ERR("Failed to create desktop heap!\n"); - RETURN(NULL); - } - DesktopInfoSize = sizeof(DESKTOPINFO) + DesktopName.Length + sizeof(WCHAR); + /* Get the desktop window class. The thread desktop does not belong to any desktop + so the classes created there (including the desktop class) are allocated in the shared heap + It would cause problems if we used a class that belongs to the caller */ + ClassName.Buffer = ((PWSTR)((ULONG_PTR)(WORD)(gpsi->atomSysClass[ICLS_DESKTOP]))); + ClassName.Length = 0; + pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE); + + RtlZeroMemory(&WindowName, sizeof(WindowName)); + RtlZeroMemory(&Cs, sizeof(Cs)); + Cs.x = UserGetSystemMetrics(SM_XVIRTUALSCREEN), + Cs.y = UserGetSystemMetrics(SM_YVIRTUALSCREEN), + Cs.cx = UserGetSystemMetrics(SM_CXVIRTUALSCREEN), + Cs.cy = UserGetSystemMetrics(SM_CYVIRTUALSCREEN), + Cs.style = WS_POPUP|WS_CLIPCHILDREN; + Cs.hInstance = hModClient; // hModuleWin; // Server side winproc! Leave it to Timo to not pass on notes! + Cs.lpszName = (LPCWSTR) &WindowName; + Cs.lpszClass = (LPCWSTR) &ClassName; - DesktopObject->pDeskInfo = RtlAllocateHeap(DesktopObject->pheapDesktop, - HEAP_NO_SERIALIZE, - DesktopInfoSize); - - if (DesktopObject->pDeskInfo == NULL) + /* Use IntCreateWindow instead of co_UserCreateWindowEx cause the later expects a thread with a desktop */ + pWnd = IntCreateWindow(&Cs, &WindowName, pcls, NULL, NULL, NULL, DesktopObject); + if (!pWnd) { - ObDereferenceObject(DesktopObject); - ERR("Failed to create the DESKTOP structure!\n"); - RETURN(NULL); + ERR("Failed to create Message window handle\n"); } - - RtlZeroMemory(DesktopObject->pDeskInfo, - DesktopInfoSize); - - DesktopObject->pDeskInfo->pvDesktopBase = DesktopHeapSystemBase; - DesktopObject->pDeskInfo->pvDesktopLimit = (PVOID)((ULONG_PTR)DesktopHeapSystemBase + HeapSize); - RtlCopyMemory(DesktopObject->pDeskInfo->szDesktopName, - DesktopName.Buffer, - DesktopName.Length + sizeof(WCHAR)); - - /* Initialize some local (to win32k) desktop state. */ - InitializeListHead(&DesktopObject->PtiList); - DesktopObject->ActiveMessageQueue = NULL; - - /* Setup Global Hooks. */ - for (i = 0; i < NB_HOOKS; i++) + else { - InitializeListHead(&DesktopObject->pDeskInfo->aphkStart[i]); + DesktopObject->DesktopWindow = pWnd->head.h; + DesktopObject->pDeskInfo->spwnd = pWnd; + pWnd->fnid = FNID_DESKTOP; } - - /* - * Create a handle for CSRSS and notify CSRSS for Creating Desktop Background Windows and Threads. - */ - Request.Type = MAKE_CSR_API(CREATE_DESKTOP, CSR_GUI); - Status = CsrInsertObject(Desktop, - GENERIC_ALL, - (HANDLE*)&Request.Data.CreateDesktopRequest.DesktopHandle); - if (! NT_SUCCESS(Status)) - { - ERR("Failed to create desktop handle for CSRSS\n"); - ZwClose(Desktop); - SetLastNtError(Status); - RETURN( NULL); - } - - Status = co_CsrNotify(&Request); - if (! NT_SUCCESS(Status)) - { - CsrCloseHandle(Request.Data.CreateDesktopRequest.DesktopHandle); - ERR("Failed to notify CSRSS about new desktop\n"); - ZwClose(Desktop); - SetLastNtError(Status); - RETURN( NULL); - } - - if (ptiCurrent && !ptiCurrent->rpdesk) IntSetThreadDesktop(Desktop,FALSE); - + ClassName.Buffer = ((PWSTR)((ULONG_PTR)(WORD)(gpsi->atomSysClass[ICLS_HWNDMESSAGE]))); ClassName.Length = 0; RtlZeroMemory(&WindowName, sizeof(WindowName)); @@ -1243,7 +1301,9 @@ Cs.lpszName = (LPCWSTR) &WindowName; Cs.lpszClass = (LPCWSTR) &ClassName; - pWnd = co_UserCreateWindowEx(&Cs, &ClassName, &WindowName, NULL); + pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE); + + pWnd = IntCreateWindow(&Cs, &WindowName, pcls, NULL, NULL, NULL, DesktopObject); if (!pWnd) { ERR("Failed to create Message window handle\n"); @@ -1251,6 +1311,7 @@ else { DesktopObject->spwndMessage = pWnd; + pWnd->fnid = FNID_MESSAGEWND; } /* Now,,, @@ -1264,9 +1325,9 @@ RETURN( Desktop); CLEANUP: - if(DesktopName.Buffer != NULL) + if(DesktopObject!= NULL) { - ExFreePoolWithTag(DesktopName.Buffer, TAG_STRING); + ObDereferenceObject(DesktopObject); } if (!NoHooks && ptiCurrent) { Index: win32ss/user/ntuser/desktop.h =================================================================== --- win32ss/user/ntuser/desktop.h (revision 57484) +++ win32ss/user/ntuser/desktop.h (working copy) @@ -73,6 +73,7 @@ extern HDESK InputDesktopHandle; extern PCLS DesktopWindowClass; extern HDC ScreenDeviceContext; +extern PTHREADINFO ptiDesktopThread; typedef struct _SHELL_HOOK_WINDOW { @@ -104,6 +105,12 @@ NTSTATUS NTAPI IntDesktopOkToClose(PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters); +NTSTATUS NTAPI +IntDesktopObjectOpen(PWIN32_OPENMETHOD_PARAMETERS Parameters); + +NTSTATUS NTAPI +IntDesktopObjectClose(PWIN32_CLOSEMETHOD_PARAMETERS Parameters); + HDC FASTCALL IntGetScreenDC(VOID); @@ -283,4 +290,6 @@ PWND FASTCALL co_GetDesktopWindow(PWND); BOOL FASTCALL IntPaintDesktop(HDC); BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *); +BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); +VOID NTAPI DesktopThreadMain(); /* EOF */ Index: win32ss/user/ntuser/event.c =================================================================== --- win32ss/user/ntuser/event.c (revision 57484) +++ win32ss/user/ntuser/event.c (working copy) @@ -378,7 +378,7 @@ } } // Creator, pti is set here. - pEH = UserCreateObject(gHandleTable, NULL, &Handle, otEvent, sizeof(EVENTHOOK)); + pEH = UserCreateObject(gHandleTable, NULL, NULL, &Handle, otEvent, sizeof(EVENTHOOK)); if (pEH) { InsertTailList(&GlobalEvents->Events, &pEH->Chain); Index: win32ss/user/ntuser/hook.c =================================================================== --- win32ss/user/ntuser/hook.c (revision 57484) +++ win32ss/user/ntuser/hook.c (working copy) @@ -1571,7 +1571,7 @@ } ObDereferenceObject(WinStaObj); - Hook = UserCreateObject(gHandleTable, NULL, (PHANDLE)&Handle, otHook, sizeof(HOOK)); + Hook = UserCreateObject(gHandleTable, NULL, NULL, (PHANDLE)&Handle, otHook, sizeof(HOOK)); if (!Hook) { Index: win32ss/user/ntuser/input.c =================================================================== --- win32ss/user/ntuser/input.c (revision 57484) +++ win32ss/user/ntuser/input.c (working copy) @@ -304,6 +304,7 @@ switch (Type) { case 0: RawInputThreadMain(); break; + case 1: DesktopThreadMain(); break; default: ERR("Wrong type: %x\n", Type); } Index: win32ss/user/ntuser/kbdlayout.c =================================================================== --- win32ss/user/ntuser/kbdlayout.c (revision 57484) +++ win32ss/user/ntuser/kbdlayout.c (working copy) @@ -131,7 +131,7 @@ L"Control\\Keyboard Layouts\\"; /* Create keyboard layout file object */ - pkf = UserCreateObject(gHandleTable, NULL, NULL, otKBDfile, sizeof(KBDFILE)); + pkf = UserCreateObject(gHandleTable, NULL, NULL, NULL, otKBDfile, sizeof(KBDFILE)); if (!pkf) { ERR("Failed to create object!\n"); @@ -206,7 +206,7 @@ PKL pKl; /* Create keyboard layout object */ - pKl = UserCreateObject(gHandleTable, NULL, NULL, otKBDlayout, sizeof(KL)); + pKl = UserCreateObject(gHandleTable, NULL, NULL, NULL, otKBDlayout, sizeof(KL)); if (!pKl) { ERR("Failed to create object!\n"); Index: win32ss/user/ntuser/main.c =================================================================== --- win32ss/user/ntuser/main.c (revision 57484) +++ win32ss/user/ntuser/main.c (working copy) @@ -285,6 +285,7 @@ if (ptiCurrent->KeyboardLayout) UserReferenceObject(ptiCurrent->KeyboardLayout); ptiCurrent->TIF_flags &= ~TIF_INCLEANUP; + ptiCurrent->pcti = &ptiCurrent->cti; /* Initialize the CLIENTINFO */ pci = (PCLIENTINFO)pTeb->Win32ClientInfo; @@ -605,14 +606,16 @@ DPRINT("Win32k hInstance 0x%p!\n",hModuleWin); /* Register Object Manager Callbacks */ + CalloutData.ProcessCallout = Win32kProcessCallback; + CalloutData.ThreadCallout = Win32kThreadCallback; CalloutData.WindowStationParseProcedure = IntWinStaObjectParse; CalloutData.WindowStationDeleteProcedure = IntWinStaObjectDelete; + CalloutData.WindowStationOkToCloseProcedure = IntWinstaOkToClose; + CalloutData.DesktopOkToCloseProcedure = IntDesktopOkToClose; CalloutData.DesktopDeleteProcedure = IntDesktopObjectDelete; - CalloutData.ProcessCallout = Win32kProcessCallback; - CalloutData.ThreadCallout = Win32kThreadCallback; + CalloutData.DesktopCloseProcedure = IntDesktopObjectClose; + CalloutData.DesktopOpenProcedure = IntDesktopObjectOpen; CalloutData.BatchFlushRoutine = NtGdiFlushUserBatch; - CalloutData.DesktopOkToCloseProcedure = IntDesktopOkToClose; - CalloutData.WindowStationOkToCloseProcedure = IntWinstaOkToClose; /* Register our per-process and per-thread structures. */ PsEstablishWin32Callouts((PWIN32_CALLOUTS_FPNS)&CalloutData); Index: win32ss/user/ntuser/menu.c =================================================================== --- win32ss/user/ntuser/menu.c (revision 57484) +++ win32ss/user/ntuser/menu.c (working copy) @@ -249,7 +249,7 @@ PPROCESSINFO CurrentWin32Process; Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable, - NULL, + NULL, NULL, Handle, otMenu, sizeof(MENU_OBJECT)); @@ -360,7 +360,7 @@ return NULL; Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable, - NULL, + NULL, NULL, &hMenu, otMenu, sizeof(MENU_OBJECT)); Index: win32ss/user/ntuser/message.c =================================================================== --- win32ss/user/ntuser/message.c (revision 57484) +++ win32ss/user/ntuser/message.c (working copy) @@ -714,6 +714,13 @@ pMsg->lParam, &retval); break; + case FNID_MESSAGEWND: + DoCallBack = !UserMessageWindowProc( Window, + pMsg->message, + pMsg->wParam, + pMsg->lParam, + &retval); + break; } } @@ -1307,6 +1314,9 @@ case FNID_DESKTOP: DoCallBack = !DesktopWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result); break; + case FNID_MESSAGEWND: + DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result); + break; } if (!DoCallBack) { @@ -1590,6 +1600,9 @@ case FNID_DESKTOP: DoCallBack = !DesktopWindowProc(Window, Msg, wParam, lParamPacked, (LRESULT*)&Result); break; + case FNID_MESSAGEWND: + DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result); + break; } } @@ -2233,6 +2246,16 @@ } break; } + + case FNID_MESSAGEWND: + { + Window = UserGetWindowObject(hWnd); + if (Window) + { + Ret = !UserMessageWindowProc(Window, Msg, wParam, lParam,&lResult); + } + break; + } case FNID_DEFWINDOWPROC: /* Validate input */ if (hWnd) Index: win32ss/user/ntuser/monitor.c =================================================================== --- win32ss/user/ntuser/monitor.c (revision 57484) +++ win32ss/user/ntuser/monitor.c (working copy) @@ -32,7 +32,7 @@ PMONITOR IntCreateMonitorObject() { - return UserCreateObject(gHandleTable, NULL, NULL, otMonitor, sizeof(MONITOR)); + return UserCreateObject(gHandleTable, NULL, NULL, NULL, otMonitor, sizeof(MONITOR)); } /* IntDestroyMonitorObject Index: win32ss/user/ntuser/msgqueue.h =================================================================== --- win32ss/user/ntuser/msgqueue.h (revision 57484) +++ win32ss/user/ntuser/msgqueue.h (working copy) @@ -298,4 +298,13 @@ DWORD APIENTRY IntGetQueueStatus(DWORD); UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam); + +BOOL FASTCALL +co_IntGetPeekMessage( PMSG pMsg, + HWND hWnd, + UINT MsgFilterMin, + UINT MsgFilterMax, + UINT RemoveMsg, + BOOL bGMSG ); + /* EOF */ Index: win32ss/user/ntuser/object.c =================================================================== --- win32ss/user/ntuser/object.c (revision 57484) +++ win32ss/user/ntuser/object.c (working copy) @@ -293,20 +293,20 @@ FASTCALL UserCreateObject( PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, + PTHREADINFO pti, HANDLE* h, USER_OBJECT_TYPE type, ULONG size) { HANDLE hi; PVOID Object; - PTHREADINFO pti; PPROCESSINFO ppi; BOOL dt; PDESKTOP rpdesk = pDesktop; - pti = GetW32ThreadInfo(); + if(!pti) pti = GetW32ThreadInfo(); + if (!pDesktop) rpdesk = pti->rpdesk; ppi = pti->ppi; - if (!pDesktop) rpdesk = pti->rpdesk; switch (type) { Index: win32ss/user/ntuser/object.h =================================================================== --- win32ss/user/ntuser/object.h (revision 57484) +++ win32ss/user/ntuser/object.h (working copy) @@ -33,7 +33,7 @@ VOID FASTCALL UserReferenceObject(PVOID obj); PVOID FASTCALL UserReferenceObjectByHandle(HANDLE handle, USER_OBJECT_TYPE type); BOOL FASTCALL UserDereferenceObject(PVOID obj); -PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, struct _DESKTOP* pDesktop, HANDLE* h,USER_OBJECT_TYPE type , ULONG size); +PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, struct _DESKTOP* pDesktop, PTHREADINFO pti, HANDLE* h,USER_OBJECT_TYPE type , ULONG size); BOOL FASTCALL UserDeleteObject(HANDLE h, USER_OBJECT_TYPE type ); PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type ); PVOID UserGetObjectNoErr(PUSER_HANDLE_TABLE, HANDLE, USER_OBJECT_TYPE); Index: win32ss/user/ntuser/simplecall.c =================================================================== --- win32ss/user/ntuser/simplecall.c (revision 57484) +++ win32ss/user/ntuser/simplecall.c (working copy) @@ -183,7 +183,7 @@ if (count == 0) count = 8; psmwp = (PSMWP) UserCreateObject( gHandleTable, - NULL, + NULL, NULL, (PHANDLE)&hDwp, otSMWP, sizeof(SMWP)); Index: win32ss/user/ntuser/timer.c =================================================================== --- win32ss/user/ntuser/timer.c (revision 57484) +++ win32ss/user/ntuser/timer.c (working copy) @@ -56,7 +56,7 @@ HANDLE Handle; PTIMER Ret = NULL; - Ret = UserCreateObject(gHandleTable, NULL, &Handle, otTimer, sizeof(TIMER)); + Ret = UserCreateObject(gHandleTable, NULL, NULL, &Handle, otTimer, sizeof(TIMER)); if (Ret) { Ret->head.h = Handle; Index: win32ss/user/ntuser/window.c =================================================================== --- win32ss/user/ntuser/window.c (revision 57484) +++ win32ss/user/ntuser/window.c (working copy) @@ -1661,7 +1661,8 @@ PCLS Class, PWND ParentWindow, PWND OwnerWindow, - PVOID acbiBuffer) + PVOID acbiBuffer, + PDESKTOP pdeskCreated) { PWND pWnd = NULL; HWND hWnd; @@ -1670,7 +1671,7 @@ BOOL MenuChanged; BOOL bUnicodeWindow; - pti = PsGetCurrentThreadWin32Thread(); + pti = pdeskCreated ? ptiDesktopThread : GetW32ThreadInfo(); if (!(Cs->dwExStyle & WS_EX_LAYOUTRTL)) { @@ -1690,8 +1691,7 @@ */ if ( Class->fnid != FNID_DIALOG ) { - PPROCESSINFO ppi = PsGetCurrentProcessWin32Process(); - if (ppi->dwLayout & LAYOUT_RTL) + if (pti->ppi->dwLayout & LAYOUT_RTL) { Cs->dwExStyle |= WS_EX_LAYOUTRTL; } @@ -1713,7 +1713,8 @@ /* Allocate the new window */ pWnd = (PWND) UserCreateObject( gHandleTable, - pti->rpdesk, + pdeskCreated ? pdeskCreated : pti->rpdesk, + pti, (PHANDLE)&hWnd, otWindow, sizeof(WND) + Class->cbwndExtra); @@ -1723,14 +1724,14 @@ goto AllocError; } - TRACE("Created object with handle %X\n", hWnd); + TRACE("Created window object with handle %X\n", hWnd); - if (NULL == pti->rpdesk->DesktopWindow) + if (pdeskCreated && pdeskCreated->DesktopWindow == NULL ) { /* HACK: Helper for win32csr/desktopbg.c */ /* If there is no desktop window yet, we must be creating it */ TRACE("CreateWindow setting desktop.\n"); - pti->rpdesk->DesktopWindow = hWnd; - pti->rpdesk->pDeskInfo->spwnd = pWnd; + pdeskCreated->DesktopWindow = hWnd; + pdeskCreated->pDeskInfo->spwnd = pWnd; } /* @@ -2010,7 +2011,7 @@ pCbtCreate = NULL; /* Get the class and reference it */ - Class = IntGetAndReferenceClass(ClassName, Cs->hInstance); + Class = IntGetAndReferenceClass(ClassName, Cs->hInstance, FALSE); if(!Class) { ERR("Failed to find class %wZ\n", ClassName); @@ -2059,7 +2060,8 @@ Class, ParentWindow, OwnerWindow, - acbiBuffer); + acbiBuffer, + NULL); if(!Window) { ERR("IntCreateWindow failed!\n"); Index: win32ss/user/ntuser/window.h =================================================================== --- win32ss/user/ntuser/window.h (revision 57484) +++ win32ss/user/ntuser/window.h (working copy) @@ -47,7 +47,13 @@ BOOL FASTCALL IntShowOwnedPopups( PWND owner, BOOL fShow ); LRESULT FASTCALL IntDefWindowProc( PWND Window, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL Ansi); VOID FASTCALL IntNotifyWinEvent(DWORD, PWND, LONG, LONG, DWORD); -PWND FASTCALL co_UserCreateWindowEx(CREATESTRUCTW*, PUNICODE_STRING, PLARGE_STRING, PVOID); +PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs, + PLARGE_STRING WindowName, + PCLS Class, + PWND ParentWindow, + PWND OwnerWindow, + PVOID acbiBuffer, + PDESKTOP pdeskCreated); BOOL FASTCALL IntEnableWindow(HWND,BOOL); BOOL FASTCALL IntIsWindowVisible(PWND); DWORD FASTCALL GetNCHitEx(PWND,POINT); Index: win32ss/user/ntuser/winsta.c =================================================================== --- win32ss/user/ntuser/winsta.c (revision 57484) +++ win32ss/user/ntuser/winsta.c (working copy) @@ -229,10 +229,7 @@ { TEXTMETRICW tmw; UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY"); - if (! IntCreatePrimarySurface()) - { - return FALSE; - } + ScreenDeviceContext = IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE); if (NULL == ScreenDeviceContext) { @@ -241,6 +238,11 @@ } GreSetDCOwner(ScreenDeviceContext, GDI_OBJ_HMGR_PUBLIC); + if (! IntCreatePrimarySurface()) + { + return FALSE; + } + /* Setup the cursor */ co_IntLoadDefaultCursors(); Index: win32ss/user/win32csr/desktopbg.c =================================================================== --- win32ss/user/win32csr/desktopbg.c (revision 57484) +++ win32ss/user/win32csr/desktopbg.c (working copy) @@ -1,341 +1,27 @@ -/* - * win32ss/user/win32csr/desktopbg.c - * - * Desktop background window functions - * - * ReactOS Operating System - * - * Looks as a hax fix to a problem of not having a proper class window proc support - * which ReactOS has now. - * - * Notes on reason why this is here: - * http://www.reactos.org/archives/public/ros-kernel/2003-November/000538.html - * http://www.reactos.org/archives/public/ros-kernel/2003-November/000545.html - * http://www.reactos.org/archives/public/ros-kernel/2003-November/000586.html - * http://www.reactos.org/archives/public/ros-kernel/2003-November/000674.html - * Revision 6908 Move desktop window proc from WIN32K to CSRSS - * Bugs 42, 48 and 57. - * - * http://www.reactos.org/archives/public/ros-kernel/2003-December/001186.html - * - - Now this is used to start Desktops Threads with TEB support. - These first three are Application, Winlogon and ScreenSaver desktops. - - */ - #define NDEBUG #include "w32csr.h" #include -#define DESKTOP_WINDOW_ATOM 32769 - -#define PM_SHOW_DESKTOP 1 -#define PM_HIDE_DESKTOP 2 - -typedef struct tagDTBG_THREAD_DATA -{ - HDESK Desktop; - HANDLE Event; - NTSTATUS Status; -} DTBG_THREAD_DATA, *PDTBG_THREAD_DATA; - -typedef struct tagPRIVATE_NOTIFY_DESKTOP -{ - NMHDR hdr; - struct /* PM_SHOW_DESKTOP */ - { - int Width; - int Height; - } ShowDesktop; -} PRIVATE_NOTIFY_DESKTOP, *PPRIVATE_NOTIFY_DESKTOP; - -static BOOL BgInitialized = FALSE; -static HWND VisibleDesktopWindow = NULL; -#if 0 -static -LRESULT -CALLBACK -DtbgWindowProc(HWND Wnd, - UINT Msg, - WPARAM wParam, - LPARAM lParam) -{ - PAINTSTRUCT PS; - - switch (Msg) - { - case WM_ERASEBKGND: - PaintDesktop((HDC)wParam); - return 1; - - case WM_PAINT: - if (BeginPaint(Wnd, &PS)) - EndPaint(Wnd, &PS); - return 0; - - case WM_SETCURSOR: - return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW)); - - case WM_NCCREATE: - return (LRESULT)TRUE; - - case WM_CREATE: - NtUserSetWindowFNID(Wnd, FNID_DESKTOP); // Anti-ReactOS hack! - case WM_CLOSE: - return 0; - - case WM_DISPLAYCHANGE: - MoveWindow(Wnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); - break; - - case WM_NOTIFY: - { - PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam; - - /* Use WM_NOTIFY for private messages since - * it can't be sent between processes! - */ - switch (nmh->hdr.code) - { - case PM_SHOW_DESKTOP: - { - LRESULT Result; - - Result = !SetWindowPos(Wnd, NULL, 0, 0, - nmh->ShowDesktop.Width, - nmh->ShowDesktop.Height, - SWP_NOACTIVATE | SWP_NOZORDER | - SWP_SHOWWINDOW); - - UpdateWindow(Wnd); - VisibleDesktopWindow = Wnd; - return Result; - } - - case PM_HIDE_DESKTOP: - { - LRESULT Result; - - Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0, - SWP_NOACTIVATE | SWP_NOZORDER | - SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); - - UpdateWindow(Wnd); - VisibleDesktopWindow = NULL; - return Result; - } - - default: - DPRINT("Unknown notification code 0x%x sent to the desktop window!\n", - nmh->hdr.code); - return 0; - } - } - - default: - return DefWindowProcW(Wnd, Msg, wParam, lParam); - } - - return 0; -} - -static -BOOL -FASTCALL -DtbgInit(VOID) -{ - WNDCLASSEXW Class; - ATOM ClassAtom; - - /* - * Create the desktop window class - */ - Class.cbSize = sizeof(WNDCLASSEXW); - Class.style = 0; // Local Class - Class.lpfnWndProc = DtbgWindowProc; - Class.cbClsExtra = 0; - Class.cbWndExtra = 0; - Class.hInstance = (HINSTANCE)GetModuleHandleW(NULL); - Class.hIcon = NULL; - Class.hCursor = NULL; - Class.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND); - Class.lpszMenuName = NULL; - Class.lpszClassName = (LPCWSTR)DESKTOP_WINDOW_ATOM; - ClassAtom = RegisterClassExW(&Class); - - if (ClassAtom == INVALID_ATOM) - { - DPRINT1("Unable to register desktop background class (error %d)\n", - GetLastError()); - - return FALSE; - } - - VisibleDesktopWindow = NULL; - - return TRUE; -} -#endif -static -DWORD -WINAPI -DtbgDesktopThread(PVOID Data) -{ - HWND BackgroundWnd; - MSG msg; - PDTBG_THREAD_DATA ThreadData = (PDTBG_THREAD_DATA)Data; - - DPRINT("DtbgDesktopThread\n"); - - if (!SetThreadDesktop(ThreadData->Desktop)) - { - DPRINT1("Failed to set thread desktop\n"); - ThreadData->Status = STATUS_UNSUCCESSFUL; - SetEvent(ThreadData->Event); - return 1; - } - - BackgroundWnd = CreateWindowW((LPCWSTR)DESKTOP_WINDOW_ATOM, - L"", - WS_POPUP | WS_CLIPCHILDREN, - GetSystemMetrics(SM_XVIRTUALSCREEN), - GetSystemMetrics(SM_YVIRTUALSCREEN), - GetSystemMetrics(SM_CXVIRTUALSCREEN), - GetSystemMetrics(SM_CYVIRTUALSCREEN), - NULL, NULL, - (HINSTANCE)GetModuleHandleW(L"user32.dll"), // Run in win32k/user32. - NULL); - - if (NULL == BackgroundWnd) - { - DPRINT1("Failed to create desktop background window\n"); - ThreadData->Status = STATUS_UNSUCCESSFUL; - SetEvent(ThreadData->Event); - return 1; - } - - DPRINT("BackgroundWnd 0x%p\n",BackgroundWnd); - - ThreadData->Status = STATUS_SUCCESS; - SetEvent(ThreadData->Event); - - while (GetMessageW(&msg, NULL, 0, 0)) - { - if (msg.message == WM_QUIT) - { - DPRINT1("DtbgDesktopThread WM_QUIT\n"); - } - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - - DPRINT1("DtbgDesktopThread Exit\n"); - return 1; -} - CSR_API(CsrCreateDesktop) { - DTBG_THREAD_DATA ThreadData; - HANDLE ThreadHandle; - - DPRINT("CsrCreateDesktop\n"); - - if (!BgInitialized) - { - BgInitialized = TRUE; - - // if (!DtbgInit()) - // return STATUS_UNSUCCESSFUL; - } - - /* - * The desktop handle we got from win32k is in - * the scope of CSRSS so we can just use it. - */ - ThreadData.Desktop = Request->Data.CreateDesktopRequest.DesktopHandle; - - ThreadData.Event = CreateEventW(NULL, FALSE, FALSE, NULL); - - if (NULL == ThreadData.Event) - { - DPRINT1("Failed to create event (error %d)\n", GetLastError()); - return STATUS_UNSUCCESSFUL; - } - - ThreadHandle = CreateThread(NULL, - 0, - DtbgDesktopThread, - (PVOID)&ThreadData, - 0, - NULL); - - if (NULL == ThreadHandle) - { - CloseHandle(ThreadData.Event); - DPRINT1("Failed to create desktop window thread.\n"); - return STATUS_UNSUCCESSFUL; - } - - CloseHandle(ThreadHandle); - - WaitForSingleObject(ThreadData.Event, INFINITE); - CloseHandle(ThreadData.Event); - - return ThreadData.Status; + return STATUS_SUCCESS; } CSR_API(CsrShowDesktop) { -#if 0 - PRIVATE_NOTIFY_DESKTOP nmh; - DPRINT("CsrShowDesktop\n"); - - nmh.hdr.hwndFrom = Request->Data.ShowDesktopRequest.DesktopWindow; - nmh.hdr.idFrom = 0; - nmh.hdr.code = PM_SHOW_DESKTOP; - - nmh.ShowDesktop.Width = (int)Request->Data.ShowDesktopRequest.Width; - nmh.ShowDesktop.Height = (int)Request->Data.ShowDesktopRequest.Height; - - if (SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow, - WM_NOTIFY, - (WPARAM)nmh.hdr.hwndFrom, - (LPARAM)&nmh)) - { - return STATUS_UNSUCCESSFUL; - } -#endif return STATUS_SUCCESS; } CSR_API(CsrHideDesktop) { -#if 0 - PRIVATE_NOTIFY_DESKTOP nmh; - DPRINT("CsrHideDesktop\n"); - - nmh.hdr.hwndFrom = Request->Data.ShowDesktopRequest.DesktopWindow; - nmh.hdr.idFrom = 0; - nmh.hdr.code = PM_HIDE_DESKTOP; - - if (SendMessageW(Request->Data.ShowDesktopRequest.DesktopWindow, - WM_NOTIFY, - (WPARAM)nmh.hdr.hwndFrom, - (LPARAM)&nmh)) - { - return STATUS_UNSUCCESSFUL; - } -#endif return STATUS_SUCCESS; } BOOL -FASTCALL -DtbgIsDesktopVisible(VOID) +FASTCALL DtbgIsDesktopVisible(VOID) { - VisibleDesktopWindow = GetDesktopWindow(); // DESKTOPWNDPROC + HWND VisibleDesktopWindow = GetDesktopWindow(); // DESKTOPWNDPROC if (VisibleDesktopWindow != NULL && !IsWindowVisible(VisibleDesktopWindow)) Index: win32ss/user/win32csr/dllmain.c =================================================================== --- win32ss/user/win32csr/dllmain.c (revision 57484) +++ win32ss/user/win32csr/dllmain.c (working copy) @@ -331,6 +331,7 @@ HANDLE ServerThread; CLIENT_ID ClientId; NTSTATUS Status; + UINT i; Win32CsrApiHeap = RtlGetProcessHeap(); @@ -353,14 +354,17 @@ InitializeListHead(&DosDeviceHistory); /* Start Raw Input Threads */ - Status = RtlCreateUserThread(NtCurrentProcess(), NULL, TRUE, 0, 0, 0, (PTHREAD_START_ROUTINE)CreateSystemThreads, (PVOID)0, &ServerThread, &ClientId); - if (NT_SUCCESS(Status)) + for (i = 0; i < 2; ++i) { - NtResumeThread(ServerThread, NULL); - NtClose(ServerThread); + Status = RtlCreateUserThread(NtCurrentProcess(), NULL, TRUE, 0, 0, 0, (PTHREAD_START_ROUTINE)CreateSystemThreads, (PVOID)i, &ServerThread, &ClientId); + if (NT_SUCCESS(Status)) + { + NtResumeThread(ServerThread, NULL); + NtClose(ServerThread); + } + else + DPRINT1("Cannot start Raw Input Thread!\n"); } - else - DPRINT1("Cannot start Raw Input Thread!\n"); return STATUS_SUCCESS; }