[win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / callback.c
index deb75a0..e536d4c 100644 (file)
@@ -1,23 +1,4 @@
 /*
- *  ReactOS W32 Subsystem
- *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * PURPOSE:          Window classes
@@ -33,7 +14,7 @@
 
 /* INCLUDES ******************************************************************/
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -112,26 +93,26 @@ IntCleanupThreadCallbacks(PTHREADINFO W32Thread)
 // This will help user space programs speed up read access with the window object.
 //
 static VOID
-IntSetTebWndCallback (HWND * hWnd, PVOID * pWnd)
+IntSetTebWndCallback (HWND * hWnd, PWND * pWnd)
 {
   HWND hWndS = *hWnd;
-  PWINDOW_OBJECT Window = UserGetWindowObject(*hWnd);
+  PWND Window = UserGetWindowObject(*hWnd);
   PCLIENTINFO ClientInfo = GetWin32ClientInfo();
 
   *hWnd = ClientInfo->CallbackWnd.hWnd;
-  *pWnd = ClientInfo->CallbackWnd.pvWnd;
+  *pWnd = ClientInfo->CallbackWnd.pWnd;
 
   ClientInfo->CallbackWnd.hWnd  = hWndS;
-  ClientInfo->CallbackWnd.pvWnd = DesktopHeapAddressToUser(Window->Wnd);
+  ClientInfo->CallbackWnd.pWnd = DesktopHeapAddressToUser(Window);
 }
 
 static VOID
-IntRestoreTebWndCallback (HWND hWnd, PVOID pWnd)
+IntRestoreTebWndCallback (HWND hWnd, PWND pWnd)
 {
   PCLIENTINFO ClientInfo = GetWin32ClientInfo();
 
   ClientInfo->CallbackWnd.hWnd = hWnd;
-  ClientInfo->CallbackWnd.pvWnd = pWnd;
+  ClientInfo->CallbackWnd.pWnd = pWnd;
 }
 
 /* FUNCTIONS *****************************************************************/
@@ -144,7 +125,8 @@ co_IntCallSentMessageCallback(SENDASYNCPROC CompletionCallback,
                               LRESULT Result)
 {
    SENDASYNCPROC_CALLBACK_ARGUMENTS Arguments;
-   PVOID ResultPointer, pWnd;
+   PVOID ResultPointer;
+   PWND pWnd;
    ULONG ResultLength;
    NTSTATUS Status;
 
@@ -187,7 +169,8 @@ co_IntCallWindowProc(WNDPROC Proc,
    WINDOWPROC_CALLBACK_ARGUMENTS StackArguments;
    PWINDOWPROC_CALLBACK_ARGUMENTS Arguments;
    NTSTATUS Status;
-   PVOID ResultPointer, pWnd;
+   PVOID ResultPointer;
+   PWND pWnd;
    ULONG ResultLength;
    ULONG ArgumentLength;
    LRESULT Result;
@@ -268,7 +251,7 @@ co_IntCallWindowProc(WNDPROC Proc,
 HMENU APIENTRY
 co_IntLoadSysMenuTemplate()
 {
-   LRESULT Result;
+   LRESULT Result = 0;
    NTSTATUS Status;
    PVOID ResultPointer;
    ULONG ResultLength;
@@ -283,23 +266,29 @@ co_IntLoadSysMenuTemplate()
                                0,
                                &ResultPointer,
                                &ResultLength);
-
-   /* Simulate old behaviour: copy into our local buffer */
-   Result = *(LRESULT*)ResultPointer;
+   if (NT_SUCCESS(Status))
+   {
+      /* Simulate old behaviour: copy into our local buffer */
+      _SEH2_TRY
+      {
+        ProbeForRead(ResultPointer, sizeof(LRESULT), 1);
+        Result = *(LRESULT*)ResultPointer;
+      }
+      _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+      {
+        Result = 0;
+      }
+      _SEH2_END
+   }
 
    UserEnterCo();
 
-   if (!NT_SUCCESS(Status))
-   {
-      return(0);
-   }
    return (HMENU)Result;
 }
 
 BOOL APIENTRY
 co_IntLoadDefaultCursors(VOID)
 {
-   LRESULT Result;
    NTSTATUS Status;
    PVOID ResultPointer;
    ULONG ResultLength;
@@ -316,9 +305,6 @@ co_IntLoadDefaultCursors(VOID)
                                &ResultPointer,
                                &ResultLength);
 
-   /* Simulate old behaviour: copy into our local buffer */
-   Result = *(LRESULT*)ResultPointer;
-
    UserEnterCo();
 
    if (!NT_SUCCESS(Status))
@@ -351,6 +337,16 @@ co_IntCallHookProc(INT HookId,
    UNICODE_STRING ClassName;
    PANSI_STRING asWindowName;
    PANSI_STRING asClassName;
+   PTHREADINFO pti;
+
+   ASSERT(Proc);
+
+   pti = PsGetCurrentThreadWin32Thread();
+   if (pti->TIF_flags & TIF_INCLEANUP)
+   {
+      DPRINT1("Thread is in cleanup and trying to call hook %d\n", Code);
+      return 0;
+   }
 
    ArgumentLength = sizeof(HOOKPROC_CALLBACK_ARGUMENTS) - sizeof(WCHAR)
                     + ModuleName->Length;
@@ -491,7 +487,7 @@ co_IntCallHookProc(INT HookId,
                {
                   RtlCopyMemory(Extra, ClassName.Buffer, ClassName.Length);
                   CbtCreatewndExtra->Cs.lpszClass =
-                     (LPCWSTR) MAKELONG(Extra - (PCHAR) CbtCreatewndExtra, 1);
+                     (LPCWSTR)(ULONG_PTR) MAKELONG(Extra - (PCHAR) CbtCreatewndExtra, 1);
                   Extra += ClassName.Length;
 
                   if (Ansi)
@@ -687,14 +683,19 @@ co_IntCallLoadMenu( HINSTANCE hModule,
    Argument = IntCbAllocateMemory(ArgumentLength);
    if (NULL == Argument)
    {
-      DPRINT1("EventProc callback failed: out of memory\n");
+      DPRINT1("LoadMenu callback failed: out of memory\n");
       return 0;
    }
    Common = (PLOADMENU_CALLBACK_ARGUMENTS) Argument;
 
+   // Help Intersource check and MenuName is now 4 bytes + so zero it.
+   RtlZeroMemory(Common, ArgumentLength); 
 
    Common->hModule = hModule;
-   RtlCopyMemory(&Common->MenuName, pMenuName->Buffer, pMenuName->Length);
+   if (pMenuName->Length)
+      RtlCopyMemory(&Common->MenuName, pMenuName->Buffer, pMenuName->Length);
+   else
+      RtlCopyMemory(&Common->MenuName, &pMenuName->Buffer, sizeof(WCHAR));
 
    ResultPointer = NULL;
    ResultLength = sizeof(LRESULT);
@@ -709,8 +710,10 @@ co_IntCallLoadMenu( HINSTANCE hModule,
 
    UserEnterCo();
 
+   Result = *(LRESULT*)ResultPointer;
+
    IntCbFreeMemory(Argument);
-  
+
    if (!NT_SUCCESS(Status))
    {
       return 0;
@@ -719,4 +722,29 @@ co_IntCallLoadMenu( HINSTANCE hModule,
    return (HMENU)Result;
 }
 
+NTSTATUS
+APIENTRY
+co_IntClientThreadSetup(VOID)
+{
+   NTSTATUS Status;
+   ULONG ArgumentLength, ResultLength;
+   PVOID Argument, ResultPointer;
+
+   ArgumentLength = ResultLength = 0;
+   Argument = ResultPointer = NULL;
+
+   UserLeaveCo();
+
+   Status = KeUserModeCallback(USER32_CALLBACK_CLIENTTHREADSTARTUP,
+                               Argument,
+                               ArgumentLength,
+                               &ResultPointer,
+                               &ResultLength);
+
+   UserEnterCo();
+
+   return Status;
+}
+
+
 /* EOF */