explorer starts but crash due to missing/lost winsta (ref/deref problem?)
Modified: branches/hardons1stbranch/win32k/include/keyboard.h
Added: branches/hardons1stbranch/win32k/include/userfuncs.h
Modified: branches/hardons1stbranch/win32k/include/win32k.h
Modified: branches/hardons1stbranch/win32k/main/dllmain.c
Modified: branches/hardons1stbranch/win32k/ntuser/accelerator.c
Modified: branches/hardons1stbranch/win32k/ntuser/caret.c
Modified: branches/hardons1stbranch/win32k/ntuser/class.c
Modified: branches/hardons1stbranch/win32k/ntuser/cursoricon.c
Modified: branches/hardons1stbranch/win32k/ntuser/desktop.c
Modified: branches/hardons1stbranch/win32k/ntuser/handle.c
Modified: branches/hardons1stbranch/win32k/ntuser/hook.c
Modified: branches/hardons1stbranch/win32k/ntuser/hotkey.c
Modified: branches/hardons1stbranch/win32k/ntuser/keyboard.c
Modified: branches/hardons1stbranch/win32k/ntuser/message.c
Modified: branches/hardons1stbranch/win32k/ntuser/msgqueue.c
Modified: branches/hardons1stbranch/win32k/ntuser/useratom.c
Modified: branches/hardons1stbranch/win32k/ntuser/window.c
Modified: branches/hardons1stbranch/win32k/ntuser/winsta.c

Modified: branches/hardons1stbranch/win32k/include/keyboard.h
--- branches/hardons1stbranch/win32k/include/keyboard.h	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/include/keyboard.h	2005-07-27 13:18:11 UTC (rev 16799)
@@ -1,231 +0,0 @@
-#ifndef _WIN32K_KEYBOARD_H
-#define _WIN32K_KEYBOARD_H
-
-DWORD FASTCALL 
-UserGetKeyState(DWORD key);
-
-/* handle.h */
-
-VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes);
-HANDLE UserAllocHandle(PUSER_HANDLE_TABLE ht, PVOID object, USER_OBJECT_TYPE type );
-PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type );
-PVOID UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle );
-PVOID UserGetNextHandle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type );
-
-
-/************* DESKTOP.C *****************/
-
-inline PDESKTOP_OBJECT FASTCALL UserGetCurrentDesktop();
-
-
-
-
-/************************* ACCELERATOR.C ***********************/
-
-inline PACCELERATOR_TABLE FASTCALL UserGetAccelObject(HACCEL hCursor);
-
-PACCELERATOR_TABLE UserGetAcceleratorTable(HACCEL hAccel);
-PACCELERATOR_TABLE UserAllocAcceleratorTable(HACCEL* h);
-
-PACCELERATOR_TABLE UserCreateAcceleratorTableObject(HACCEL* h);
-
-
-/* metric.c */
-ULONG FASTCALL 
-UserGetSystemMetrics(ULONG Index);
-
-/* input.h */
-NTSTATUS FASTCALL 
-UserAcquireOrReleaseInputOwnership(BOOLEAN Release);
-
-/* focus.c */
-PWINDOW_OBJECT FASTCALL
-UserSetFocus(PWINDOW_OBJECT Wnd OPTIONAL);
-
-
-/* painting.c */
-DWORD FASTCALL 
-UserInvalidateRect(PWINDOW_OBJECT Wnd, CONST RECT *Rect, BOOL Erase);
-
-DWORD FASTCALL
-UserScrollDC(HDC hDC, INT dx, INT dy, const RECT *lprcScroll,
-   const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate);
-
-INT FASTCALL
-UserGetUpdateRgn(PWINDOW_OBJECT Window, HRGN hRgn, BOOL bErase);
-
-/* message.c */
-BOOL FASTCALL 
-UserPostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-
-/************************ WINDOW.C *****************************/
-
-inline VOID FASTCALL UserFreeWindowObject(PWINDOW_OBJECT Wnd);
-
-PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd);
-
-PWINDOW_OBJECT FASTCALL UserCreateWindowObject(HWND* h, ULONG bytes);
-
-PWINDOW_OBJECT FASTCALL 
-UserGetWindow(PWINDOW_OBJECT Wnd, UINT Relationship);
-
-LONG FASTCALL 
-UserGetWindowLong(PWINDOW_OBJECT Wnd, DWORD Index, BOOL Ansi);
-
-LONG FASTCALL
-UserSetWindowLong(PWINDOW_OBJECT Wnd, DWORD Index, LONG NewValue, BOOL Ansi);
-
-BOOLEAN FASTCALL
-UserDestroyWindow(PWINDOW_OBJECT Wnd);
-
-HWND FASTCALL
-GetHwnd(PWINDOW_OBJECT Wnd);
-
-/************************* WINSTA.C ****************************/
-
-inline PWINSTATION_OBJECT FASTCALL UserGetCurrentWinSta();
-
-/************************* MENU.C ****************************/
-
-inline PMENU_OBJECT FASTCALL UserGetMenuObject(HMENU hMenu);
-
-HMENU FASTCALL
-UserCreateMenu(BOOL PopupMenu);
-
-PMENU_OBJECT FASTCALL 
-UserCreateMenuObject(HANDLE* h);
-
-
-/* caret.c */
-BOOL FASTCALL
-UserShowCaret(PWINDOW_OBJECT Wnd);
-
-BOOL FASTCALL
-UserSetCaretPos(int X, int Y);
-
-BOOL FASTCALL
-UserHideCaret(PWINDOW_OBJECT Wnd);
-
-/* winpos.c */
-
-BOOL FASTCALL
-UserGetClientOrigin(PWINDOW_OBJECT hWnd, LPPOINT Point);
-
-/* scrollbar.c */
-DWORD FASTCALL
-UserShowScrollBar(PWINDOW_OBJECT Wnd, int wBar, DWORD bShow);
-
-/* timer.c */
-
-inline VOID FASTCALL 
-UserFreeTimer(PTIMER_ENTRY Timer);
-
-VOID FASTCALL
-UserRemoveTimersWindow(PWINDOW_OBJECT Wnd);
-
-VOID FASTCALL
-UserInsertTimer(PTIMER_ENTRY NewTimer);
-
-VOID FASTCALL 
-UserSetNextPendingTimer();
-
-VOID FASTCALL
-UserRemoveTimersQueue(PUSER_MESSAGE_QUEUE Queue);
-
-/* hook.c*/
-PHOOK FASTCALL
-HookCreate(HHOOK* hHook);
-
-PHOOK FASTCALL HookGet(HHOOK hHook);
-
-/* class.c */
-
-VOID FASTCALL
-ClassReferenceClass(PWNDCLASS_OBJECT Class);
-
-VOID FASTCALL
-ClassDereferenceClass(PWNDCLASS_OBJECT Class);
-
-PWNDCLASS_OBJECT FASTCALL 
-ClassCreateClass(DWORD bytes);
-
-
-/********************* CURSORI(ICON).C *****************/
-
-inline PCURICON_OBJECT FASTCALL 
-UserGetCursorObject(HCURSOR hCursor);
-
-VOID FASTCALL
-CurIconReferenceCurIcon(PCURICON_OBJECT CurIcon);
-
-PCURICON_OBJECT UserAllocCursorIcon(HCURSOR* h);
-PCURICON_OBJECT UserGetCursorIcon(HCURSOR hCursor);
-
-VOID FASTCALL
-UserDereferenceCurIcon(PCURICON_OBJECT CurIcon);
-
-VOID FASTCALL 
-CursorDereference(PCURICON_OBJECT Cursor);
-
-PCURICON_OBJECT FASTCALL 
-UserCreateCursorObject(HCURSOR* hCursor, ULONG extraBytes);
-
-PCURICON_OBJECT FASTCALL 
-CursorGet(HCURSOR hCursor);
-
-inline PCURICON_OBJECT FASTCALL 
-UserGetCursorIconObject(HCURSOR hCursor);
-
-/* monitor.c */
-
-PMONITOR_OBJECT FASTCALL UserCreateMonitorObject(HANDLE* h);
-
-PMONITOR_OBJECT UserGetMonitorObject(HANDLE hCursor);
-
-
-/* msgqueue.c */
-
-VOID FASTCALL 
-MsqRemoveWindowMessagesFromQueue(PWINDOW_OBJECT pWindow);
-
-inline BOOL FASTCALL
-UserMessageFilter(UINT Message, UINT FilterMin, UINT FilterMax);
-
-VOID FASTCALL
-MsqRemoveTimersWindow(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Wnd);
-
-VOID FASTCALL
-MsqInsertExpiredTimer(PTIMER_ENTRY Timer);
-
-PTIMER_ENTRY FASTCALL
-UserFindExpiredTimer(   
-   PUSER_MESSAGE_QUEUE Queue,
-   PWINDOW_OBJECT Wnd OPTIONAL, 
-   UINT MsgFilterMin, 
-   UINT MsgFilterMax,
-   BOOL Remove
-   );
-
-PTIMER_ENTRY FASTCALL
-MsqRemoveTimer(
-   PWINDOW_OBJECT Wnd, 
-   UINT_PTR IDEvent, 
-   UINT Message
-   );
-
-/* windc.c */
-
-HDC FASTCALL
-UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL, HANDLE ClipRegion, ULONG Flags);
-
-INT FASTCALL
-UserReleaseDC(PWINDOW_OBJECT Wnd, HDC hDc);
-
-DWORD FASTCALL
-UserGetWindowDC(PWINDOW_OBJECT Wnd);
-
-/* div */
-#define UserGetCurrentQueue() \
-((PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue)
-
-#endif /* _WIN32K_KEYBOARD_H */

Added: branches/hardons1stbranch/win32k/include/userfuncs.h
--- branches/hardons1stbranch/win32k/include/userfuncs.h	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/include/userfuncs.h	2005-07-27 13:18:11 UTC (rev 16799)
@@ -0,0 +1,231 @@
+#ifndef _WIN32K_USERFUNCS_H
+#define _WIN32K_USERFUNCS_H
+
+/*************** KEYBOARD.C ******************/
+
+DWORD FASTCALL 
+UserGetKeyState(DWORD key);
+
+/******************** HANDLE.C ***************/
+
+VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes);
+HANDLE UserAllocHandle(PUSER_HANDLE_TABLE ht, PVOID object, USER_OBJECT_TYPE type );
+PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type );
+PVOID UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle );
+PVOID UserGetNextHandle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type );
+
+
+/************* DESKTOP.C *****************/
+
+inline PDESKTOP_OBJECT FASTCALL UserGetCurrentDesktop();
+
+
+
+
+/************************* ACCELERATOR.C ***********************/
+
+inline PACCELERATOR_TABLE FASTCALL UserGetAccelObject(HACCEL hCursor);
+
+PACCELERATOR_TABLE FASTCALL UserCreateAccelObject(HACCEL* h);
+
+
+
+/* metric.c */
+ULONG FASTCALL 
+UserGetSystemMetrics(ULONG Index);
+
+/* input.h */
+NTSTATUS FASTCALL 
+UserAcquireOrReleaseInputOwnership(BOOLEAN Release);
+
+/* focus.c */
+PWINDOW_OBJECT FASTCALL
+UserSetFocus(PWINDOW_OBJECT Wnd OPTIONAL);
+
+
+/* painting.c */
+DWORD FASTCALL 
+UserInvalidateRect(PWINDOW_OBJECT Wnd, CONST RECT *Rect, BOOL Erase);
+
+DWORD FASTCALL
+UserScrollDC(HDC hDC, INT dx, INT dy, const RECT *lprcScroll,
+   const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate);
+
+INT FASTCALL
+UserGetUpdateRgn(PWINDOW_OBJECT Window, HRGN hRgn, BOOL bErase);
+
+/* message.c */
+BOOL FASTCALL 
+UserPostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+
+/************************ WINDOW.C *****************************/
+
+inline VOID FASTCALL UserFreeWindowObject(PWINDOW_OBJECT Wnd);
+
+PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd);
+
+PWINDOW_OBJECT FASTCALL UserCreateWindowObject(HWND* h, ULONG bytes);
+
+PWINDOW_OBJECT FASTCALL 
+UserGetWindow(PWINDOW_OBJECT Wnd, UINT Relationship);
+
+LONG FASTCALL 
+UserGetWindowLong(PWINDOW_OBJECT Wnd, DWORD Index, BOOL Ansi);
+
+LONG FASTCALL
+UserSetWindowLong(PWINDOW_OBJECT Wnd, DWORD Index, LONG NewValue, BOOL Ansi);
+
+BOOLEAN FASTCALL
+UserDestroyWindow(PWINDOW_OBJECT Wnd);
+
+HWND FASTCALL
+GetHwnd(PWINDOW_OBJECT Wnd);
+
+/************************* WINSTA.C ****************************/
+
+inline PWINSTATION_OBJECT FASTCALL UserGetCurrentWinSta();
+
+/************************* MENU.C ****************************/
+
+inline PMENU_OBJECT FASTCALL UserGetMenuObject(HMENU hMenu);
+
+HMENU FASTCALL
+UserCreateMenu(BOOL PopupMenu);
+
+PMENU_OBJECT FASTCALL 
+UserCreateMenuObject(HANDLE* h);
+
+
+/* caret.c */
+BOOL FASTCALL
+UserShowCaret(PWINDOW_OBJECT Wnd);
+
+BOOL FASTCALL
+UserSetCaretPos(int X, int Y);
+
+BOOL FASTCALL
+UserHideCaret(PWINDOW_OBJECT Wnd);
+
+/* winpos.c */
+
+BOOL FASTCALL
+UserGetClientOrigin(PWINDOW_OBJECT hWnd, LPPOINT Point);
+
+/* scrollbar.c */
+DWORD FASTCALL
+UserShowScrollBar(PWINDOW_OBJECT Wnd, int wBar, DWORD bShow);
+
+/* timer.c */
+
+inline VOID FASTCALL 
+UserFreeTimer(PTIMER_ENTRY Timer);
+
+VOID FASTCALL
+UserRemoveTimersWindow(PWINDOW_OBJECT Wnd);
+
+VOID FASTCALL
+UserInsertTimer(PTIMER_ENTRY NewTimer);
+
+VOID FASTCALL 
+UserSetNextPendingTimer();
+
+VOID FASTCALL
+UserRemoveTimersQueue(PUSER_MESSAGE_QUEUE Queue);
+
+/* hook.c*/
+PHOOK FASTCALL
+HookCreate(HHOOK* hHook);
+
+PHOOK FASTCALL HookGet(HHOOK hHook);
+
+/* class.c */
+
+VOID FASTCALL
+ClassReferenceClass(PWNDCLASS_OBJECT Class);
+
+VOID FASTCALL
+ClassDereferenceClass(PWNDCLASS_OBJECT Class);
+
+PWNDCLASS_OBJECT FASTCALL 
+ClassCreateClass(DWORD bytes);
+
+
+/********************* CURSORIICON.C *****************/
+
+inline PCURICON_OBJECT FASTCALL 
+UserGetCursorObject(HCURSOR hCursor);
+
+VOID FASTCALL
+CurIconReferenceCurIcon(PCURICON_OBJECT CurIcon);
+
+PCURICON_OBJECT UserAllocCursorIcon(HCURSOR* h);
+PCURICON_OBJECT UserGetCursorIcon(HCURSOR hCursor);
+
+VOID FASTCALL
+UserDereferenceCurIcon(PCURICON_OBJECT CurIcon);
+
+VOID FASTCALL 
+CursorDereference(PCURICON_OBJECT Cursor);
+
+PCURICON_OBJECT FASTCALL 
+UserCreateCursorObject(HCURSOR* hCursor, ULONG extraBytes);
+
+PCURICON_OBJECT FASTCALL 
+CursorGet(HCURSOR hCursor);
+
+
+/* monitor.c */
+
+PMONITOR_OBJECT FASTCALL UserCreateMonitorObject(HANDLE* h);
+
+PMONITOR_OBJECT UserGetMonitorObject(HANDLE hCursor);
+
+
+/* msgqueue.c */
+
+VOID FASTCALL 
+MsqRemoveWindowMessagesFromQueue(PWINDOW_OBJECT pWindow);
+
+inline BOOL FASTCALL
+UserMessageFilter(UINT Message, UINT FilterMin, UINT FilterMax);
+
+VOID FASTCALL
+MsqRemoveTimersWindow(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Wnd);
+
+VOID FASTCALL
+MsqInsertExpiredTimer(PTIMER_ENTRY Timer);
+
+PTIMER_ENTRY FASTCALL
+UserFindExpiredTimer(   
+   PUSER_MESSAGE_QUEUE Queue,
+   PWINDOW_OBJECT Wnd OPTIONAL, 
+   UINT MsgFilterMin, 
+   UINT MsgFilterMax,
+   BOOL Remove
+   );
+
+PTIMER_ENTRY FASTCALL
+MsqRemoveTimer(
+   PWINDOW_OBJECT Wnd, 
+   UINT_PTR IDEvent, 
+   UINT Message
+   );
+
+/* windc.c */
+
+HDC FASTCALL
+UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL, HANDLE ClipRegion, ULONG Flags);
+
+INT FASTCALL
+UserReleaseDC(PWINDOW_OBJECT Wnd, HDC hDc);
+
+DWORD FASTCALL
+UserGetWindowDC(PWINDOW_OBJECT Wnd);
+
+/* div */
+#define UserGetCurrentQueue() \
+((PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue)
+
+
+
+#endif /* _WIN32K_USERFUNCS_H */

Modified: branches/hardons1stbranch/win32k/include/win32k.h
--- branches/hardons1stbranch/win32k/include/win32k.h	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/include/win32k.h	2005-07-27 13:18:11 UTC (rev 16799)
@@ -59,5 +59,6 @@
 #include <eng/misc.h>
 #include <dib/dib.h>
 #include <include/ntuser.h>
+#include <include/userfuncs.h>
 
 /* EOF */

Modified: branches/hardons1stbranch/win32k/main/dllmain.c
--- branches/hardons1stbranch/win32k/main/dllmain.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/main/dllmain.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -144,6 +144,8 @@
     /* Get the Win32 Thread */
     Win32Thread = PsGetThreadWin32Thread(Thread);
     
+    //FIXME: imo, its an error if it already exist. Gunnar
+    
     /* Allocate one if needed */
     if (!Win32Thread)
     {
@@ -178,6 +180,9 @@
                                    DesktopPath,
                                    &hWinSta,
                                    &hDesk);
+
+/*----      this code i dont get ------*/
+/* imo, a thread REQUIRE a desktop!!! */
       if(NT_SUCCESS(Status))
       {
         if(hWinSta != NULL)
@@ -213,6 +218,8 @@
           }
         }
       }
+/*----      this code i dont get ------*/
+
       Win32Thread->IsExiting = FALSE;
       UserDestroyCaret(Win32Thread);
       Win32Thread->MessageQueue = MsqCreateMessageQueue(Thread);

Modified: branches/hardons1stbranch/win32k/ntuser/accelerator.c
--- branches/hardons1stbranch/win32k/ntuser/accelerator.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/accelerator.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -115,17 +115,11 @@
 }
 
 
-PACCELERATOR_TABLE UserCreateAcceleratorTableObject(HACCEL* h)
+PACCELERATOR_TABLE FASTCALL UserCreateAccelObject(HACCEL* h)
 {
    PVOID mem;
-   PWINSTATION_OBJECT WinSta;
+   PWINSTATION_OBJECT WinSta = UserGetCurrentWinSta();
    
-   /*
-   Get process winsta? Or thread->desk->winsta? 
-   can a process threads be assigned to different winstas (via desktops?)   
-   */
-   WinSta = IntGetWinStaObj();
-   
    mem = ExAllocatePool(PagedPool, sizeof(ACCELERATOR_TABLE));
    if (!mem) return NULL;
    RtlZeroMemory(mem, sizeof(ACCELERATOR_TABLE));
@@ -161,7 +155,7 @@
       RETURN(FALSE);
    }
 
-   AcceleratorTable = UserCreateAcceleratorTableObject(&Handle);
+   AcceleratorTable = UserCreateAccelObject(&Handle);
    if (AcceleratorTable == NULL)
    {
 
@@ -227,7 +221,6 @@
    if (!AcceleratorTable)
    {
       SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE);
-//      ObDereferenceObject(WindowStation);
       DPRINT1("E2\n");
       RETURN(FALSE);
    }
@@ -437,8 +430,8 @@
 
 inline PACCELERATOR_TABLE FASTCALL UserGetAccelObject(HACCEL hCursor)
 {
-   PWINSTATION_OBJECT WinSta;
-   WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   PWINSTATION_OBJECT WinSta = UserGetCurrentWinSta();
+
    return (PACCELERATOR_TABLE)UserGetObject(&WinSta->HandleTable, hCursor, USER_CURSOR_ICON );   
 }
 

Modified: branches/hardons1stbranch/win32k/ntuser/caret.c
--- branches/hardons1stbranch/win32k/ntuser/caret.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/caret.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -55,7 +55,7 @@
 UserSetCaretBlinkTime(UINT uMSeconds)
 {
    /* Don't save the new value to the registry! */
-   PWINSTATION_OBJECT WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   PWINSTATION_OBJECT WinStaObject = UserGetCurrentWinSta();
 
    /* windows doesn't do this check */
    if((uMSeconds < MIN_CARETBLINKRATE) || (uMSeconds > MAX_CARETBLINKRATE))
@@ -141,7 +141,7 @@
    PWINSTATION_OBJECT WinStaObject;
    UINT Ret;
 
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
 
    Ret = WinStaObject->CaretBlinkRate;
    if(!Ret)

Modified: branches/hardons1stbranch/win32k/ntuser/class.c
--- branches/hardons1stbranch/win32k/ntuser/class.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/class.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -116,7 +116,7 @@
    if (!ClassName || !PsGetWin32Thread()->Desktop)
       return FALSE;
 
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
 
    Status = RtlLookupAtomInAtomTable(
                WinStaObject->AtomTable,
@@ -225,7 +225,7 @@
       return 0;
    }
 
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
 
    Length = 0;
    Status = RtlQueryAtomInAtomTable(WinStaObject->AtomTable,
@@ -457,7 +457,7 @@
       RETURN((RTL_ATOM)0);
    }
 
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
 
    if (ClassName->Length > 0)
    {
@@ -729,7 +729,7 @@
       RETURN(FALSE);
    }
 
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
 
    if (!ClassReferenceClassByNameOrAtom(&Class, ClassNameOrAtom, hInstance))
    {

Modified: branches/hardons1stbranch/win32k/ntuser/cursoricon.c
--- branches/hardons1stbranch/win32k/ntuser/cursoricon.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/cursoricon.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -90,7 +90,7 @@
    XLATEOBJ *XlateObj = NULL;
    HDC Screen;
 
-   CurInfo = UserGetSysCursorInfo(PsGetWin32Thread()->Desktop->WindowStation);
+   CurInfo = UserGetSysCursorInfo(UserGetCurrentWinSta());
    
    OldCursor = CurInfo->CurrentCursorObject;
    if (OldCursor)
@@ -401,39 +401,8 @@
    //FIXME
 }
 
-PCURICON_OBJECT FASTCALL
-UserCreateCurIconHandle(PWINSTATION_OBJECT WinStaObject)
-{
-   PCURICON_OBJECT Cursor;
-   HCURSOR hCursor;
 
-   Cursor = UserCreateCursorObject(&hCursor, 0);
-   if(!Cursor)
-   {
-      SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-      return FALSE;
-   }
 
-   Cursor->Self = hCursor;
-
-   InitializeListHead(&Cursor->ProcessList);
-
-   if (! UserReferenceCurIconByProcess(Cursor))
-   {
-      DPRINT1("Failed to add process\n");
-//      ObmCloseHandle(WinStaObject->HandleTable, Handle);
-      //ObmDereferenceObject(Object);
-      UserReferenceCurIcon(Cursor);
-      return NULL;
-   }
-
-   InsertHeadList(&CurIconList, &Cursor->ListEntry);
-
-   CursorDereference(Cursor);
-
-   return Cursor;
-}
-
 BOOLEAN FASTCALL
 UserDestroyCurIconObject(PCURICON_OBJECT Cursor, BOOL ProcessCleanup)
 {
@@ -488,7 +457,7 @@
       RemoveEntryList(&Cursor->ListEntry);
    }
 
-   CurInfo = UserGetSysCursorInfo(PsGetWin32Thread()->Desktop->WindowStation);
+   CurInfo = UserGetSysCursorInfo(UserGetCurrentWinSta());
 
    if (CurInfo->CurrentCursorObject == Cursor)
    {
@@ -555,6 +524,8 @@
 }
 
 
+
+
 PCURICON_OBJECT FASTCALL UserCreateCursorObject(HCURSOR* hCursor, ULONG extraBytes)
 {
    PVOID mem;
@@ -562,10 +533,10 @@
    
    mem = ExAllocatePool(PagedPool, sizeof(CURICON_OBJECT)+extraBytes);
    if (!mem) return NULL;
+   
    RtlZeroMemory(mem, sizeof(CURICON_OBJECT)+extraBytes);
    
-   /* FIX: kan desk->winsta vµre forskjellig fra proc->winsta? */
-   WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   WinSta = UserGetCurrentWinSta();
    
    *hCursor = UserAllocHandle(&WinSta->HandleTable, mem, USER_CURSOR_ICON);
    if (!*hCursor){
@@ -596,7 +567,20 @@
       RETURN(NULL);
       
    Cursor->Self = hCursor;
+   InitializeListHead(&Cursor->ProcessList);
 
+   if (! UserReferenceCurIconByProcess(Cursor))
+   {
+      DPRINT1("Failed to add process\n");
+//      ObmCloseHandle(WinStaObject->HandleTable, Handle);
+      UserReferenceCurIcon(Cursor);
+      RETURN( NULL);
+   }
+
+   InsertHeadList(&CurIconList, &Cursor->ListEntry);
+
+
+
    if(IconInfo)
    {
       Status = MmCopyFromCaller(&Cursor->IconInfo, IconInfo, sizeof(ICONINFO));
@@ -643,11 +627,11 @@
 
 inline PCURICON_OBJECT FASTCALL UserGetCursorObject(HCURSOR hCursor)
 {
-   PWINSTATION_OBJECT WinSta;
-   WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   PWINSTATION_OBJECT WinSta = UserGetCurrentWinSta();
    return (PCURICON_OBJECT)UserGetObject(&WinSta->HandleTable, hCursor, USER_CURSOR_ICON );   
 }
 
+
 /*
  * @implemented
  */
@@ -819,13 +803,13 @@
       RETURN( FALSE);
    }
 
-   CurInfo = UserGetSysCursorInfo(PsGetWin32Thread()->Desktop->WindowStation);
+   CurInfo = UserGetSysCursorInfo(UserGetCurrentWinSta());
    CursorObject = (PCURICON_OBJECT)CurInfo->CurrentCursorObject;
 
    SafeCi.flags = ((CurInfo->ShowingCursor && CursorObject) ? CURSOR_SHOWING : 0);
    SafeCi.hCursor = (CursorObject ? (HCURSOR)CursorObject->Self : (HCURSOR)0);
 
-   UserGetCursorLocation(PsGetWin32Thread()->Desktop->WindowStation, &SafeCi.ptScreenPos);
+   UserGetCursorLocation(UserGetCurrentWinSta(), &SafeCi.ptScreenPos);
 
    Status = MmCopyToCaller(pci, &SafeCi, sizeof(CURSORINFO));
    if(!NT_SUCCESS(Status))
@@ -867,8 +851,8 @@
       RETURN( FALSE);
    }
 
-   CurInfo = UserGetSysCursorInfo(PsGetWin32Thread()->Desktop->WindowStation);
-   UserGetCursorLocation(PsGetWin32Thread()->Desktop->WindowStation, &MousePos);
+   CurInfo = UserGetSysCursorInfo(UserGetCurrentWinSta());
+   UserGetCursorLocation(UserGetCurrentWinSta(), &MousePos);
 
 //   if(WinStaObject->ActiveDesktop)
 //      DesktopWindow = IntGetWindowObject(WinStaObject->ActiveDesktop->DesktopWindow);
@@ -911,11 +895,6 @@
 }
 
 
-inline PCURICON_OBJECT FASTCALL UserGetCursorIconObject(HCURSOR hCursor)
-{
-   PWINSTATION_OBJECT WinSta = PsGetWin32Thread()->Desktop->WindowStation;
-   return (PCURICON_OBJECT)UserGetObject(&WinSta->HandleTable, hCursor, USER_CURSOR_ICON);
-}
 
 
 /*
@@ -937,7 +916,7 @@
    DPRINT("Enter NtUserDestroyCursorIcon\n");
    UserEnterExclusive();
 
-   Cursor = UserGetCursorIconObject(hCursor);
+   Cursor = UserGetCursorObject(hCursor);
    if(!Cursor)
    {
       RETURN(FALSE);
@@ -1027,7 +1006,7 @@
    if(!lpRect)
       RETURN( FALSE);
 
-   CurInfo = UserGetSysCursorInfo(PsGetWin32Thread()->Desktop->WindowStation);
+   CurInfo = UserGetSysCursorInfo(UserGetCurrentWinSta());
    if(CurInfo->CursorClipInfo.IsClipped)
    {
       Rect.left = CurInfo->CursorClipInfo.Left;

Modified: branches/hardons1stbranch/win32k/ntuser/desktop.c
--- branches/hardons1stbranch/win32k/ntuser/desktop.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/desktop.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -1188,7 +1188,7 @@
    BOOL doPatBlt = TRUE;
    int len;
 
-   PWINSTATION_OBJECT WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   PWINSTATION_OBJECT WinSta = UserGetCurrentWinSta();
 
    IntGdiGetClipBox(hDC, &Rect);
 

Modified: branches/hardons1stbranch/win32k/ntuser/handle.c
--- branches/hardons1stbranch/win32k/ntuser/handle.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/handle.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -118,6 +118,8 @@
 {
     PUSER_HANDLE_ENTRY entry;
 
+    ASSERT(ht);
+
     if (!(entry = handle_to_entry(ht, handle )) || entry->type != type) return NULL;
     return entry->ptr;
 }

Modified: branches/hardons1stbranch/win32k/ntuser/hook.c
--- branches/hardons1stbranch/win32k/ntuser/hook.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/hook.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -406,7 +406,7 @@
    mem = ExAllocatePool(PagedPool, sizeof(HOOK));
    if (!mem) return NULL;
 
-   WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   WinSta = UserGetCurrentWinSta();
    *hHook = UserAllocHandle(&WinSta->HandleTable, mem, USER_HOOK_PROC);
    if (!*hHook){
       ExFreePool(mem);
@@ -419,7 +419,7 @@
 PHOOK FASTCALL HookGet(HHOOK hHook)
 {
    PWINSTATION_OBJECT WinSta;
-   WinSta = PsGetWin32Thread()->Desktop->WindowStation;
+   WinSta = UserGetCurrentWinSta();
    return (PHOOK)UserGetObject(&WinSta->HandleTable, hHook, USER_HOOK_PROC );
 }
 

Modified: branches/hardons1stbranch/win32k/ntuser/hotkey.c
--- branches/hardons1stbranch/win32k/ntuser/hotkey.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/hotkey.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -113,8 +113,11 @@
   PHOT_KEY_ITEM HotKeyItem;
   PWINSTATION_OBJECT WinStaObject = NULL;
 
-  if(Window->OwnerThread && Window->OwnerThread->ThreadsProcess)
+  if(Window->OwnerThread && Window->OwnerThread->ThreadsProcess){
+     
+     //FIXME: hmm...this winsta path look fishy
     WinStaObject = Window->OwnerThread->Tcb.Win32Thread->Desktop->WindowStation;
+ }
 
   if(!WinStaObject)
     return;

Modified: branches/hardons1stbranch/win32k/ntuser/keyboard.c
--- branches/hardons1stbranch/win32k/ntuser/keyboard.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/keyboard.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -665,8 +665,7 @@
   IntLockQueueState;
 
   /* All messages have to contain the cursor point. */
-  UserGetCursorLocation(PsGetWin32Thread()->Desktop->WindowStation,
-                       &NewMsg.pt);
+  UserGetCursorLocation(UserGetCurrentWinSta(), &NewMsg.pt);
 
   UState = ToUnicodeInner(lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff,
 			  QueueKeyStateTable, wp, 2, 0,

Modified: branches/hardons1stbranch/win32k/ntuser/message.c
--- branches/hardons1stbranch/win32k/ntuser/message.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/message.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -1272,8 +1272,7 @@
          SetLastWin32Error(ERROR_INVALID_PARAMETER);
          return(FALSE);
       }
-      UserGetCursorLocation(PsGetWin32Thread()->Desktop->WindowStation,
-                            &KernelModeMsg.pt);
+      UserGetCursorLocation(UserGetCurrentWinSta(), &KernelModeMsg.pt);
       KeQueryTickCount(&LargeTickCount);
       KernelModeMsg.time = LargeTickCount.u.LowPart;
       MsqPostMessage(Window->MessageQueue, &KernelModeMsg,

Modified: branches/hardons1stbranch/win32k/ntuser/msgqueue.c
--- branches/hardons1stbranch/win32k/ntuser/msgqueue.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/msgqueue.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -234,9 +234,9 @@
    {
       return FALSE;
    }
-   //FIXME: UserGetCurrentWinSta()
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
 
+   WinStaObject = UserGetCurrentWinSta();
+
    CurInfo = UserGetSysCursorInfo(WinStaObject);
    Res = (Msg->hwnd == (HWND)CurInfo->LastClkWnd) &&
          ((Msg->time - CurInfo->LastBtnDown) < CurInfo->DblClickSpeed);

Modified: branches/hardons1stbranch/win32k/ntuser/useratom.c
--- branches/hardons1stbranch/win32k/ntuser/useratom.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/useratom.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -41,7 +41,7 @@
       SetLastNtError(Status);
       return (RTL_ATOM)0;
    }
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
    Status = RtlAddAtomToAtomTable(WinStaObject->AtomTable,
 				  AtomName, &Atom);
    if (!NT_SUCCESS(Status))
@@ -64,7 +64,7 @@
       SetLastNtError(Status);
       return 0;
    }
-   WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+   WinStaObject = UserGetCurrentWinSta();
    Status = RtlQueryAtomInAtomTable(WinStaObject->AtomTable,
       nAtom, NULL, NULL, lpBuffer, &Size);
    if (Size < nSize)

Modified: branches/hardons1stbranch/win32k/ntuser/window.c
--- branches/hardons1stbranch/win32k/ntuser/window.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/window.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -107,6 +107,7 @@
 {
    PWINSTATION_OBJECT WinSta;
    WinSta = UserGetCurrentWinSta();
+   ASSERT(WinSta);
    return (PWINDOW_OBJECT)UserGetObject(&WinSta->HandleTable, hWnd, USER_WINDOW );
 }
 
@@ -1497,7 +1498,7 @@
       DPRINT("Thread is not attached to a desktop! Cannot create window!\n");
       return (HWND)0;
     }
-  WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+  WinStaObject = UserGetCurrentWinSta();
   ObReferenceObjectByPointer(WinStaObject, KernelMode, ExWindowStationObjectType, 0);
 
   /* Create the window object. */
@@ -2461,7 +2462,7 @@
           goto Cleanup;
         }
 
-      WinStaObject = PsGetWin32Thread()->Desktop->WindowStation;
+      WinStaObject = UserGetCurrentWinSta();
 
       Status = RtlLookupAtomInAtomTable(
          WinStaObject->AtomTable,

Modified: branches/hardons1stbranch/win32k/ntuser/winsta.c
--- branches/hardons1stbranch/win32k/ntuser/winsta.c	2005-07-27 12:01:05 UTC (rev 16798)
+++ branches/hardons1stbranch/win32k/ntuser/winsta.c	2005-07-27 13:18:11 UTC (rev 16799)
@@ -976,21 +976,38 @@
 
 inline PWINSTATION_OBJECT FASTCALL UserGetCurrentWinSta()
 {
+   //ASSERT(PsGetWin32Thread());
+   //ASSERT(PsGetWin32Thread()->Desktop);
+   //ASSERT(PsGetWin32Thread()->Desktop->WindowStation);
+
+#if 0
+   if (!PsGetWin32Thread()->Desktop)
+   {
+      DPRINT1("FIXME: PsGetWin32Thread()->Desktop is NULL!!!\n");
+      return NULL;
+   }
+   
    return PsGetWin32Thread()->Desktop->WindowStation;
+#endif
+
+   return IntGetWinStaObj();
 }
 
+
 PWINSTATION_OBJECT FASTCALL
 IntGetWinStaObj(VOID)
 {
   PWINSTATION_OBJECT WinStaObj;
 
   /*
-   * just a temporary hack, this will be gone soon
+   * just a temporary hack, this will be gone soon. I HOPE SO!
[truncated at 1000 lines; 25 more skipped]