2003-05-18 17:16:18 +00:00
|
|
|
/*
|
|
|
|
* ReactOS W32 Subsystem
|
2005-01-06 23:12:59 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 ReactOS Team
|
2003-05-18 17:16:18 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-01-03 00:46:42 +00:00
|
|
|
/* $Id$
|
2002-07-13 21:37:27 +00:00
|
|
|
*
|
1999-05-22 23:55:56 +00:00
|
|
|
* Entry Point for win32k.sys
|
|
|
|
*/
|
2004-05-10 17:07:20 +00:00
|
|
|
#include <w32k.h>
|
2004-11-20 16:46:06 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <win32k/debug1.h>
|
|
|
|
#include <debug.h>
|
2002-07-13 21:37:27 +00:00
|
|
|
|
2004-04-09 20:03:21 +00:00
|
|
|
#ifdef __USE_W32API
|
|
|
|
typedef NTSTATUS (STDCALL *PW32_PROCESS_CALLBACK)(
|
|
|
|
struct _EPROCESS *Process,
|
|
|
|
BOOLEAN Create);
|
|
|
|
|
|
|
|
typedef NTSTATUS (STDCALL *PW32_THREAD_CALLBACK)(
|
|
|
|
struct _ETHREAD *Thread,
|
|
|
|
BOOLEAN Create);
|
|
|
|
|
|
|
|
VOID STDCALL
|
|
|
|
PsEstablishWin32Callouts(
|
|
|
|
PW32_PROCESS_CALLBACK W32ProcessCallback,
|
|
|
|
PW32_THREAD_CALLBACK W32ThreadCallback,
|
|
|
|
PVOID Param3,
|
|
|
|
PVOID Param4,
|
|
|
|
ULONG W32ThreadSize,
|
|
|
|
ULONG W32ProcessSize);
|
|
|
|
#endif
|
|
|
|
|
2004-12-12 01:40:39 +00:00
|
|
|
BOOL INTERNAL_CALL GDI_CleanupForProcess (struct _EPROCESS *Process);
|
|
|
|
|
2002-07-04 19:56:38 +00:00
|
|
|
extern SSDT Win32kSSDT[];
|
|
|
|
extern SSPT Win32kSSPT[];
|
|
|
|
extern ULONG Win32kNumberOfSysCalls;
|
1999-07-12 23:26:57 +00:00
|
|
|
|
2003-06-20 16:26:53 +00:00
|
|
|
NTSTATUS STDCALL
|
2003-08-19 11:48:50 +00:00
|
|
|
Win32kProcessCallback (struct _EPROCESS *Process,
|
2003-06-20 16:26:53 +00:00
|
|
|
BOOLEAN Create)
|
|
|
|
{
|
|
|
|
PW32PROCESS Win32Process;
|
2004-11-20 16:46:06 +00:00
|
|
|
|
2003-06-20 16:26:53 +00:00
|
|
|
Win32Process = Process->Win32Process;
|
|
|
|
if (Create)
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT("Creating W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql());
|
2003-06-20 16:26:53 +00:00
|
|
|
|
|
|
|
InitializeListHead(&Win32Process->ClassListHead);
|
|
|
|
ExInitializeFastMutex(&Win32Process->ClassListLock);
|
2003-07-31 23:11:38 +00:00
|
|
|
|
|
|
|
InitializeListHead(&Win32Process->MenuListHead);
|
|
|
|
ExInitializeFastMutex(&Win32Process->MenuListLock);
|
2003-06-20 16:26:53 +00:00
|
|
|
|
2003-12-12 23:49:48 +00:00
|
|
|
InitializeListHead(&Win32Process->PrivateFontListHead);
|
|
|
|
ExInitializeFastMutex(&Win32Process->PrivateFontListLock);
|
2003-12-13 22:38:29 +00:00
|
|
|
|
2005-01-06 23:12:59 +00:00
|
|
|
InitializeListHead(&Win32Process->DriverObjListHead);
|
|
|
|
ExInitializeFastMutex(&Win32Process->DriverObjListLock);
|
|
|
|
|
2003-10-09 06:13:05 +00:00
|
|
|
Win32Process->KeyboardLayout = W32kGetDefaultKeyLayout();
|
2004-05-21 10:09:31 +00:00
|
|
|
|
|
|
|
/* setup process flags */
|
|
|
|
Win32Process->Flags = 0;
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT("Destroying W32 process PID:%d at IRQ level: %lu\n", Process->UniqueProcessId, KeGetCurrentIrql());
|
|
|
|
IntRemoveProcessWndProcHandles((HANDLE)Process->UniqueProcessId);
|
2003-08-19 11:48:50 +00:00
|
|
|
IntCleanupMenus(Process, Win32Process);
|
2003-12-13 22:38:29 +00:00
|
|
|
IntCleanupCurIcons(Process, Win32Process);
|
2005-01-06 23:12:59 +00:00
|
|
|
IntEngCleanupDriverObjs(Process, Win32Process);
|
2004-11-16 16:29:21 +00:00
|
|
|
CleanupMonitorImpl();
|
2003-08-18 13:37:54 +00:00
|
|
|
|
2005-01-06 23:12:59 +00:00
|
|
|
|
2004-12-12 01:40:39 +00:00
|
|
|
GDI_CleanupForProcess(Process);
|
2004-12-24 17:45:59 +00:00
|
|
|
|
|
|
|
IntGraphicsCheck(FALSE);
|
2004-05-01 16:43:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister logon application automatically
|
|
|
|
*/
|
|
|
|
if(LogonProcess == Win32Process)
|
|
|
|
{
|
|
|
|
LogonProcess = NULL;
|
|
|
|
}
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS STDCALL
|
2003-08-19 11:48:50 +00:00
|
|
|
Win32kThreadCallback (struct _ETHREAD *Thread,
|
2003-06-20 16:26:53 +00:00
|
|
|
BOOLEAN Create)
|
|
|
|
{
|
|
|
|
struct _EPROCESS *Process;
|
|
|
|
PW32THREAD Win32Thread;
|
|
|
|
|
|
|
|
Process = Thread->ThreadsProcess;
|
2004-09-28 15:02:31 +00:00
|
|
|
Win32Thread = Thread->Tcb.Win32Thread;
|
2003-06-20 16:26:53 +00:00
|
|
|
if (Create)
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
HWINSTA hWinSta = NULL;
|
|
|
|
HDESK hDesk = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PUNICODE_STRING DesktopPath;
|
|
|
|
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());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* inherit the thread desktop and process window station (if not yet inherited) from the process startup
|
|
|
|
* info structure. See documentation of CreateProcess()
|
|
|
|
*/
|
|
|
|
DesktopPath = (ProcessParams ? ((ProcessParams->DesktopInfo.Length > 0) ? &ProcessParams->DesktopInfo : NULL) : NULL);
|
|
|
|
Status = IntParseDesktopPath(Process,
|
|
|
|
DesktopPath,
|
|
|
|
&hWinSta,
|
|
|
|
&hDesk);
|
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
if(hWinSta != NULL)
|
|
|
|
{
|
|
|
|
if(Process != CsrProcess)
|
|
|
|
{
|
|
|
|
HWINSTA hProcessWinSta = (HWINSTA)InterlockedCompareExchangePointer((PVOID)&Process->Win32WindowStation, (PVOID)hWinSta, NULL);
|
|
|
|
if(hProcessWinSta != NULL)
|
|
|
|
{
|
|
|
|
/* our process is already assigned to a different window station, we don't need the handle anymore */
|
|
|
|
NtClose(hWinSta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NtClose(hWinSta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Win32Thread->hDesktop = hDesk;
|
|
|
|
|
|
|
|
Status = ObReferenceObjectByHandle(hDesk,
|
|
|
|
0,
|
|
|
|
ExDesktopObjectType,
|
|
|
|
KernelMode,
|
|
|
|
(PVOID*)&Win32Thread->Desktop,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Unable to reference thread desktop handle 0x%x\n", hDesk);
|
|
|
|
Win32Thread->Desktop = NULL;
|
|
|
|
NtClose(hDesk);
|
|
|
|
}
|
|
|
|
}
|
2003-06-20 16:26:53 +00:00
|
|
|
|
2004-02-05 20:09:10 +00:00
|
|
|
Win32Thread->IsExiting = FALSE;
|
2003-10-16 22:07:37 +00:00
|
|
|
IntDestroyCaret(Win32Thread);
|
2003-11-18 23:33:31 +00:00
|
|
|
Win32Thread->MessageQueue = MsqCreateMessageQueue(Thread);
|
2003-10-09 06:13:05 +00:00
|
|
|
Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout();
|
2003-11-19 13:19:40 +00:00
|
|
|
Win32Thread->MessagePumpHookValue = 0;
|
2003-06-20 16:26:53 +00:00
|
|
|
InitializeListHead(&Win32Thread->WindowListHead);
|
|
|
|
ExInitializeFastMutex(&Win32Thread->WindowListLock);
|
2004-05-22 21:12:15 +00:00
|
|
|
InitializeListHead(&Win32Thread->W32CallbackListHead);
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Cid.UniqueThread, KeGetCurrentIrql());
|
2003-06-20 16:26:53 +00:00
|
|
|
|
2004-02-05 20:09:10 +00:00
|
|
|
Win32Thread->IsExiting = TRUE;
|
2003-12-12 14:22:37 +00:00
|
|
|
HOOK_DestroyThreadHooks(Thread);
|
2003-11-03 18:52:21 +00:00
|
|
|
UnregisterThreadHotKeys(Thread);
|
2003-06-25 22:37:07 +00:00
|
|
|
DestroyThreadWindows(Thread);
|
2004-04-29 20:26:35 +00:00
|
|
|
IntBlockInput(Win32Thread, FALSE);
|
2004-05-22 16:48:50 +00:00
|
|
|
MsqDestroyMessageQueue(Win32Thread->MessageQueue);
|
2004-05-22 21:12:15 +00:00
|
|
|
IntCleanupThreadCallbacks(Win32Thread);
|
2004-11-20 16:46:06 +00:00
|
|
|
if(Win32Thread->Desktop != NULL)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(Win32Thread->Desktop);
|
|
|
|
}
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-02 08:55:45 +00:00
|
|
|
/*
|
|
|
|
* This definition doesn't work
|
|
|
|
*/
|
2004-01-24 08:27:40 +00:00
|
|
|
// BOOL STDCALL DllMain(VOID)
|
2003-11-03 18:52:21 +00:00
|
|
|
NTSTATUS STDCALL
|
2000-02-20 22:52:50 +00:00
|
|
|
DllMain (
|
2001-03-31 15:35:08 +00:00
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
1999-07-12 23:26:57 +00:00
|
|
|
{
|
2001-06-12 17:51:51 +00:00
|
|
|
NTSTATUS Status;
|
2001-03-31 15:35:08 +00:00
|
|
|
BOOLEAN Result;
|
2000-02-21 22:44:37 +00:00
|
|
|
|
2001-03-31 15:35:08 +00:00
|
|
|
/*
|
|
|
|
* Register user mode call interface
|
|
|
|
* (system service table index = 1)
|
|
|
|
*/
|
2003-06-20 16:26:53 +00:00
|
|
|
Result = KeAddSystemServiceTable (Win32kSSDT,
|
|
|
|
NULL,
|
|
|
|
Win32kNumberOfSysCalls,
|
|
|
|
Win32kSSPT,
|
|
|
|
1);
|
2001-03-31 15:35:08 +00:00
|
|
|
if (Result == FALSE)
|
2003-06-20 16:26:53 +00:00
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Adding system services failed!\n");
|
2003-06-20 16:26:53 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
1999-05-27 23:08:26 +00:00
|
|
|
|
2002-01-27 01:11:24 +00:00
|
|
|
/*
|
|
|
|
* Register our per-process and per-thread structures.
|
|
|
|
*/
|
2003-08-19 11:48:50 +00:00
|
|
|
PsEstablishWin32Callouts (Win32kProcessCallback,
|
|
|
|
Win32kThreadCallback,
|
2003-06-20 16:26:53 +00:00
|
|
|
0,
|
|
|
|
0,
|
2003-12-20 15:42:47 +00:00
|
|
|
sizeof(W32THREAD),
|
2003-06-20 16:26:53 +00:00
|
|
|
sizeof(W32PROCESS));
|
2003-12-21 10:19:40 +00:00
|
|
|
|
2001-06-12 17:51:51 +00:00
|
|
|
Status = InitWindowStationImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize window station implementation!\n");
|
2001-06-12 17:51:51 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = InitClassImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize window class implementation!\n");
|
2001-06-12 17:51:51 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2003-11-23 11:39:48 +00:00
|
|
|
Status = InitDesktopImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize desktop implementation!\n");
|
2003-11-23 11:39:48 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2001-06-12 17:51:51 +00:00
|
|
|
Status = InitWindowImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize window implementation!\n");
|
2001-06-12 17:51:51 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2003-07-31 23:11:38 +00:00
|
|
|
Status = InitMenuImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize menu implementation!\n");
|
2003-07-31 23:11:38 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2003-11-03 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2002-01-27 01:11:24 +00:00
|
|
|
Status = InitInputImpl();
|
2002-01-13 22:52:08 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize input implementation.\n");
|
2002-01-13 22:52:08 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2003-11-24 00:22:53 +00:00
|
|
|
Status = InitKeyboardImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize keyboard implementation.\n");
|
2003-11-24 00:22:53 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2004-11-16 16:29:21 +00:00
|
|
|
Status = InitMonitorImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DbgPrint("Failed to initialize monitor implementation!\n");
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2002-01-13 22:52:08 +00:00
|
|
|
Status = MsqInitializeImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize message queue implementation.\n");
|
2002-01-13 22:52:08 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2003-04-02 23:19:28 +00:00
|
|
|
Status = InitTimerImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize timer implementation.\n");
|
2003-04-02 23:19:28 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2003-12-07 12:59:34 +00:00
|
|
|
Status = InitAcceleratorImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize accelerator implementation.\n");
|
2003-12-07 12:59:34 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2004-08-08 17:57:34 +00:00
|
|
|
Status = InitGuiCheckImpl();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2004-11-20 16:46:06 +00:00
|
|
|
DPRINT1("Failed to initialize GUI check implementation.\n");
|
2004-08-08 17:57:34 +00:00
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2003-12-03 21:50:50 +00:00
|
|
|
InitGdiObjectHandleTable ();
|
|
|
|
|
|
|
|
/* Initialize FreeType library */
|
|
|
|
if (! InitFontSupport())
|
|
|
|
{
|
|
|
|
DPRINT1("Unable to initialize font support\n");
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create stock objects, ie. precreated objects commonly
|
|
|
|
used by win32 applications */
|
|
|
|
CreateStockObjects();
|
2004-12-12 01:40:39 +00:00
|
|
|
CreateSysColorObjects();
|
2004-05-13 19:31:09 +00:00
|
|
|
|
|
|
|
PREPARE_TESTS
|
2003-12-03 21:50:50 +00:00
|
|
|
|
2001-03-31 15:35:08 +00:00
|
|
|
return STATUS_SUCCESS;
|
2000-02-21 22:44:37 +00:00
|
|
|
}
|
2000-02-20 22:52:50 +00:00
|
|
|
|
2000-02-22 20:53:11 +00:00
|
|
|
|
2003-11-03 18:52:21 +00:00
|
|
|
BOOLEAN STDCALL
|
2003-08-19 11:48:50 +00:00
|
|
|
Win32kInitialize (VOID)
|
2000-02-22 20:53:11 +00:00
|
|
|
{
|
2001-03-31 15:35:08 +00:00
|
|
|
return TRUE;
|
2000-02-22 20:53:11 +00:00
|
|
|
}
|
|
|
|
|
2000-02-20 22:52:50 +00:00
|
|
|
/* EOF */
|