Author: tkreuzer Date: Sat Aug 13 16:27:30 2011 New Revision: 53206
URL: http://svn.reactos.org/svn/reactos?rev=53206&view=rev Log: [WIN32K] - use the correct pool tags for PROCESSINFO and THREADINFO - get rid of RETURN macro usage - misc code cleanup
Modified: trunk/reactos/subsystems/win32/win32k/main/dllmain.c
Modified: trunk/reactos/subsystems/win32/win32k/main/dllmain.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/mai... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/main/dllmain.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/main/dllmain.c [iso-8859-1] Sat Aug 13 16:27:30 2011 @@ -49,7 +49,7 @@ /* FIXME - lock the process */ Win32Process = ExAllocatePoolWithTag(NonPagedPool, sizeof(PROCESSINFO), - 'p23W'); + USERTAG_PROCESSINFO);
if (Win32Process == NULL) RETURN( STATUS_NO_MEMORY);
@@ -157,9 +157,9 @@
DPRINT1("Shell process is exiting (%d)\n", ExitCode);
- UserPostMessage(hwndSAS, - WM_LOGONNOTIFY, - LN_SHELL_EXITED, + UserPostMessage(hwndSAS, + WM_LOGONNOTIFY, + LN_SHELL_EXITED, ExitCode); } } @@ -220,9 +220,9 @@ PSW32THREADCALLOUTTYPE Type) { struct _EPROCESS *Process; - PTHREADINFO Win32Thread; + PTHREADINFO ptiCurrent; int i; - DECLARE_RETURN(NTSTATUS); + NTSTATUS Status;
DPRINT("Enter Win32kThreadCallback\n"); UserEnterExclusive(); @@ -230,59 +230,63 @@ Process = Thread->ThreadsProcess;
/* Get the Win32 Thread */ - Win32Thread = PsGetThreadWin32Thread(Thread); + ptiCurrent = PsGetThreadWin32Thread(Thread);
/* Allocate one if needed */ - if (!Win32Thread) + if (!ptiCurrent) { /* FIXME - lock the process */ - Win32Thread = ExAllocatePoolWithTag(NonPagedPool, - sizeof(THREADINFO), - 't23W'); - - if (Win32Thread == NULL) RETURN( STATUS_NO_MEMORY); - - RtlZeroMemory(Win32Thread, sizeof(THREADINFO)); - - PsSetThreadWin32Thread(Thread, Win32Thread); + ptiCurrent = ExAllocatePoolWithTag(NonPagedPool, + sizeof(THREADINFO), + USERTAG_THREADINFO); + + if (ptiCurrent == NULL) + { + Status = STATUS_NO_MEMORY; + goto leave; + } + + RtlZeroMemory(ptiCurrent, sizeof(THREADINFO)); + + PsSetThreadWin32Thread(Thread, ptiCurrent); /* FIXME - unlock the process */ } + if (Type == PsW32ThreadCalloutInitialize) { HWINSTA hWinSta = NULL; PTEB pTeb; HDESK hDesk = NULL; - NTSTATUS Status; PUNICODE_STRING DesktopPath; PDESKTOP pdesk; PRTL_USER_PROCESS_PARAMETERS ProcessParams = (Process->Peb ? Process->Peb->ProcessParameters : NULL);
DPRINT("Creating W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql());
- InitializeListHead(&Win32Thread->WindowListHead); - InitializeListHead(&Win32Thread->W32CallbackListHead); - InitializeListHead(&Win32Thread->PtiLink); + InitializeListHead(&ptiCurrent->WindowListHead); + InitializeListHead(&ptiCurrent->W32CallbackListHead); + InitializeListHead(&ptiCurrent->PtiLink); for (i = 0; i < NB_HOOKS; i++) { - InitializeListHead(&Win32Thread->aphkStart[i]); - } - - Win32Thread->TIF_flags &= ~TIF_INCLEANUP; - co_IntDestroyCaret(Win32Thread); - Win32Thread->ppi = PsGetCurrentProcessWin32Process(); - Win32Thread->ptiSibling = Win32Thread->ppi->ptiList; - Win32Thread->ppi->ptiList = Win32Thread; - Win32Thread->ppi->cThreads++; - if (Win32Thread->rpdesk && !Win32Thread->pDeskInfo) - { - Win32Thread->pDeskInfo = Win32Thread->rpdesk->pDeskInfo; - } - Win32Thread->MessageQueue = MsqCreateMessageQueue(Thread); - Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout(); - Win32Thread->pEThread = Thread; + InitializeListHead(&ptiCurrent->aphkStart[i]); + } + + ptiCurrent->TIF_flags &= ~TIF_INCLEANUP; + co_IntDestroyCaret(ptiCurrent); + ptiCurrent->ppi = PsGetCurrentProcessWin32Process(); + ptiCurrent->ptiSibling = ptiCurrent->ppi->ptiList; + ptiCurrent->ppi->ptiList = ptiCurrent; + ptiCurrent->ppi->cThreads++; + if (ptiCurrent->rpdesk && !ptiCurrent->pDeskInfo) + { + ptiCurrent->pDeskInfo = ptiCurrent->rpdesk->pDeskInfo; + } + ptiCurrent->MessageQueue = MsqCreateMessageQueue(Thread); + ptiCurrent->KeyboardLayout = W32kGetDefaultKeyLayout(); + ptiCurrent->pEThread = Thread;
/* HAAAAAAAACK! This should go to Win32kProcessCallback */ - if(Win32Thread->ppi->hdeskStartup == NULL) + if(ptiCurrent->ppi->hdeskStartup == NULL) { /* * inherit the thread desktop and process window station (if not yet inherited) from the process startup @@ -313,8 +317,8 @@
if(NT_SUCCESS(Status)) { - Win32Thread->ppi->hdeskStartup = hDesk; - Win32Thread->ppi->rpdeskStartup = pdesk; + ptiCurrent->ppi->hdeskStartup = hDesk; + ptiCurrent->ppi->rpdeskStartup = pdesk; } } } @@ -324,9 +328,9 @@ } }
- if (Win32Thread->ppi->hdeskStartup != NULL) - { - if (!IntSetThreadDesktop(Win32Thread->ppi->hdeskStartup, FALSE)) + if (ptiCurrent->ppi->hdeskStartup != NULL) + { + if (!IntSetThreadDesktop(ptiCurrent->ppi->hdeskStartup, FALSE)) { DPRINT1("Unable to set thread desktop\n"); } @@ -336,20 +340,21 @@ if (pTeb) { /* Attempt to startup client support which should have been initialized in IntSetThreadDesktop. */ PCLIENTINFO pci = (PCLIENTINFO)pTeb->Win32ClientInfo; - Win32Thread->pClientInfo = pci; - pci->ppi = Win32Thread->ppi; - pci->fsHooks = Win32Thread->fsHooks; - if (Win32Thread->KeyboardLayout) pci->hKL = Win32Thread->KeyboardLayout->hkl; - pci->dwTIFlags = Win32Thread->TIF_flags; + ptiCurrent->pClientInfo = pci; + pci->ppi = ptiCurrent->ppi; + pci->fsHooks = ptiCurrent->fsHooks; + if (ptiCurrent->KeyboardLayout) pci->hKL = ptiCurrent->KeyboardLayout->hkl; + pci->dwTIFlags = ptiCurrent->TIF_flags; + /* CI may not have been initialized. */ - if (!pci->pDeskInfo && Win32Thread->pDeskInfo) + if (!pci->pDeskInfo && ptiCurrent->pDeskInfo) { if (!pci->ulClientDelta) pci->ulClientDelta = DesktopHeapGetUserDelta();
- pci->pDeskInfo = (PVOID)((ULONG_PTR)Win32Thread->pDeskInfo - pci->ulClientDelta); + pci->pDeskInfo = (PVOID)((ULONG_PTR)ptiCurrent->pDeskInfo - pci->ulClientDelta); } - if (Win32Thread->pcti && pci->pDeskInfo) - pci->pClientThreadInfo = (PVOID)((ULONG_PTR)Win32Thread->pcti - pci->ulClientDelta); + if (ptiCurrent->pcti && pci->pDeskInfo) + pci->pClientThreadInfo = (PVOID)((ULONG_PTR)ptiCurrent->pcti - pci->ulClientDelta); else pci->pClientThreadInfo = NULL; } @@ -357,60 +362,62 @@ { DPRINT1("No TEB for this Thread!\n"); // System thread running! Now SendMessage should be okay. - Win32Thread->pcti = &Win32Thread->cti; + ptiCurrent->pcti = &ptiCurrent->cti; } GetW32ThreadInfo(); } else { PTHREADINFO pti; - PSINGLE_LIST_ENTRY e; + PSINGLE_LIST_ENTRY psle;
DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql());
- Win32Thread->TIF_flags |= TIF_INCLEANUP; - pti = Win32Thread->ppi->ptiList; - if (pti == Win32Thread) - { - Win32Thread->ppi->ptiList = Win32Thread->ptiSibling; - Win32Thread->ppi->cThreads--; + ptiCurrent->TIF_flags |= TIF_INCLEANUP; + pti = ptiCurrent->ppi->ptiList; + if (pti == ptiCurrent) + { + ptiCurrent->ppi->ptiList = ptiCurrent->ptiSibling; + ptiCurrent->ppi->cThreads--; } else { do { - if (pti->ptiSibling == Win32Thread) + if (pti->ptiSibling == ptiCurrent) { - pti->ptiSibling = Win32Thread->ptiSibling; - Win32Thread->ppi->cThreads--; + pti->ptiSibling = ptiCurrent->ptiSibling; + ptiCurrent->ppi->cThreads--; break; } pti = pti->ptiSibling; } while (pti); } - DceFreeThreadDCE(Win32Thread); + DceFreeThreadDCE(ptiCurrent); HOOK_DestroyThreadHooks(Thread); EVENT_DestroyThreadEvents(Thread); + /* Cleanup timers */ - DestroyTimersForThread(Win32Thread); - KeSetEvent(Win32Thread->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE); + DestroyTimersForThread(ptiCurrent); + KeSetEvent(ptiCurrent->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE); UnregisterThreadHotKeys(Thread); + /* what if this co_ func crash in umode? what will clean us up then? */ co_DestroyThreadWindows(Thread); - IntBlockInput(Win32Thread, FALSE); - MsqDestroyMessageQueue(Win32Thread->MessageQueue); - IntCleanupThreadCallbacks(Win32Thread); + IntBlockInput(ptiCurrent, FALSE); + MsqDestroyMessageQueue(ptiCurrent->MessageQueue); + IntCleanupThreadCallbacks(ptiCurrent);
/* cleanup user object references stack */ - e = PopEntryList(&Win32Thread->ReferencesList); - while (e) - { - PUSER_REFERENCE_ENTRY ref = CONTAINING_RECORD(e, USER_REFERENCE_ENTRY, Entry); + psle = PopEntryList(&ptiCurrent->ReferencesList); + while (psle) + { + PUSER_REFERENCE_ENTRY ref = CONTAINING_RECORD(psle, USER_REFERENCE_ENTRY, Entry); DPRINT("thread clean: remove reference obj 0x%x\n",ref->obj); UserDereferenceObject(ref->obj);
- e = PopEntryList(&Win32Thread->ReferencesList); + psle = PopEntryList(&ptiCurrent->ReferencesList); }
IntSetThreadDesktop(NULL, TRUE); @@ -418,12 +425,13 @@ PsSetThreadWin32Thread(Thread, NULL); }
- RETURN( STATUS_SUCCESS); - -CLEANUP: + Status = STATUS_SUCCESS; + +leave: UserLeave(); - DPRINT("Leave Win32kThreadCallback, ret=%i\n",_ret_); - END_CLEANUP; + DPRINT("Leave Win32kThreadCallback, Status=0x%lx\n",Status); + + return Status; }
NTSTATUS