2006-07-17 17:32:58 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2005-01-26 13:58:37 +00:00
|
|
|
* FILE: ntoskrnl/ps/win32.c
|
2006-07-17 17:32:58 +00:00
|
|
|
* PURPOSE: Process Manager: Win32K Initialization and Support
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2002-01-04 13:09:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2006-09-07 22:38:06 +00:00
|
|
|
#include <winerror.h>
|
2005-03-19 20:26:46 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2002-01-04 13:09:37 +00:00
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout = NULL;
|
|
|
|
PKWIN32_THREAD_CALLOUT PspW32ThreadCallout = NULL;
|
2007-11-05 17:27:25 +00:00
|
|
|
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch = NULL;
|
2006-05-25 20:03:13 +00:00
|
|
|
extern PKWIN32_PARSEMETHOD_CALLOUT ExpWindowStationObjectParse;
|
|
|
|
extern PKWIN32_DELETEMETHOD_CALLOUT ExpWindowStationObjectDelete;
|
|
|
|
extern PKWIN32_DELETEMETHOD_CALLOUT ExpDesktopObjectDelete;
|
2007-05-09 00:29:38 +00:00
|
|
|
extern PKWIN32_POWEREVENT_CALLOUT PopEventCallout;
|
2005-03-12 14:15:49 +00:00
|
|
|
|
2006-07-17 17:32:58 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2002-01-04 13:09:37 +00:00
|
|
|
|
2003-06-20 16:26:53 +00:00
|
|
|
NTSTATUS
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2006-01-11 05:42:32 +00:00
|
|
|
PsConvertToGuiThread(VOID)
|
2003-06-20 16:26:53 +00:00
|
|
|
{
|
2006-01-13 21:56:51 +00:00
|
|
|
ULONG_PTR NewStack;
|
|
|
|
PVOID OldStack;
|
2006-01-11 05:42:32 +00:00
|
|
|
PETHREAD Thread = PsGetCurrentThread();
|
|
|
|
PEPROCESS Process = PsGetCurrentProcess();
|
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Validate the previous mode */
|
2006-07-15 20:10:13 +00:00
|
|
|
if (KeGetPreviousMode() == KernelMode) return STATUS_INVALID_PARAMETER;
|
2006-01-11 05:42:32 +00:00
|
|
|
|
2009-08-16 22:52:05 +00:00
|
|
|
/* If no win32k, crashes later */
|
|
|
|
ASSERT(PspW32ProcessCallout != NULL);
|
|
|
|
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Make sure win32k is here */
|
2006-07-15 20:10:13 +00:00
|
|
|
if (!PspW32ProcessCallout) return STATUS_ACCESS_DENIED;
|
2003-06-20 16:26:53 +00:00
|
|
|
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Make sure it's not already win32 */
|
|
|
|
if (Thread->Tcb.ServiceTable != KeServiceDescriptorTable)
|
|
|
|
{
|
2006-07-15 20:10:13 +00:00
|
|
|
/* We're already a win32 thread */
|
2006-01-11 05:42:32 +00:00
|
|
|
return STATUS_ALREADY_WIN32;
|
|
|
|
}
|
2003-06-20 16:26:53 +00:00
|
|
|
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Check if we don't already have a kernel-mode stack */
|
|
|
|
if (!Thread->Tcb.LargeStack)
|
2003-06-20 16:26:53 +00:00
|
|
|
{
|
2006-01-11 05:42:32 +00:00
|
|
|
/* We don't create one */
|
2007-09-27 13:07:43 +00:00
|
|
|
NewStack = (ULONG_PTR)MmCreateKernelStack(TRUE, 0);
|
2006-01-11 05:42:32 +00:00
|
|
|
if (!NewStack)
|
2005-06-26 16:06:32 +00:00
|
|
|
{
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Panic in user-mode */
|
|
|
|
NtCurrentTeb()->LastErrorValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
return STATUS_NO_MEMORY;
|
2005-06-26 16:06:32 +00:00
|
|
|
}
|
2006-01-11 05:42:32 +00:00
|
|
|
|
2007-09-27 13:07:43 +00:00
|
|
|
/* We're about to switch stacks. Enter a guarded region */
|
|
|
|
KeEnterGuardedRegion();
|
2006-01-11 05:42:32 +00:00
|
|
|
|
|
|
|
/* Switch stacks */
|
2006-01-13 21:56:51 +00:00
|
|
|
OldStack = KeSwitchKernelStack((PVOID)NewStack,
|
|
|
|
(PVOID)(NewStack - KERNEL_STACK_SIZE));
|
2006-01-11 05:42:32 +00:00
|
|
|
|
2007-09-27 13:07:43 +00:00
|
|
|
/* Leave the guarded region */
|
|
|
|
KeLeaveGuardedRegion();
|
2006-01-11 05:42:32 +00:00
|
|
|
|
|
|
|
/* Delete the old stack */
|
2006-01-13 22:23:31 +00:00
|
|
|
MmDeleteKernelStack(OldStack, FALSE);
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 05:42:32 +00:00
|
|
|
/* This check is bizare. Check out win32k later */
|
|
|
|
if (!Process->Win32Process)
|
2003-06-20 16:26:53 +00:00
|
|
|
{
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Now tell win32k about us */
|
2006-07-09 18:54:13 +00:00
|
|
|
Status = PspW32ProcessCallout(Process, TRUE);
|
2006-07-15 20:10:13 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 05:42:32 +00:00
|
|
|
/* Set the new service table */
|
|
|
|
Thread->Tcb.ServiceTable = KeServiceDescriptorTableShadow;
|
|
|
|
ASSERT(Thread->Tcb.Win32Thread == 0);
|
|
|
|
|
|
|
|
/* Tell Win32k about our thread */
|
2006-07-09 18:54:13 +00:00
|
|
|
Status = PspW32ThreadCallout(Thread, PsW32ThreadCalloutInitialize);
|
2006-01-11 05:42:32 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Revert our table */
|
|
|
|
Thread->Tcb.ServiceTable = KeServiceDescriptorTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
2005-06-26 16:06:32 +00:00
|
|
|
return Status;
|
2003-06-20 16:26:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-17 17:32:58 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PsEstablishWin32Callouts(IN PWIN32_CALLOUTS_FPNS CalloutData)
|
|
|
|
{
|
|
|
|
/* Setup the callback pointers */
|
|
|
|
PspW32ProcessCallout = CalloutData->ProcessCallout;
|
|
|
|
PspW32ThreadCallout = CalloutData->ThreadCallout;
|
|
|
|
ExpWindowStationObjectParse = CalloutData->WindowStationParseProcedure;
|
|
|
|
ExpWindowStationObjectDelete = CalloutData->WindowStationDeleteProcedure;
|
|
|
|
ExpDesktopObjectDelete = CalloutData->DesktopDeleteProcedure;
|
2007-05-09 00:29:38 +00:00
|
|
|
PopEventCallout = CalloutData->PowerEventCallout;
|
2007-11-05 17:27:25 +00:00
|
|
|
KeGdiFlushUserBatch = CalloutData->BatchFlushRoutine;
|
2006-07-17 17:32:58 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-27 18:28:26 +00:00
|
|
|
NTAPI
|
2005-03-19 20:26:46 +00:00
|
|
|
NtW32Call(IN ULONG RoutineIndex,
|
|
|
|
IN PVOID Argument,
|
|
|
|
IN ULONG ArgumentLength,
|
2006-01-22 20:34:47 +00:00
|
|
|
OUT PVOID* Result,
|
|
|
|
OUT PULONG ResultLength)
|
2005-03-19 20:26:46 +00:00
|
|
|
{
|
2006-01-22 20:34:47 +00:00
|
|
|
PVOID RetResult;
|
|
|
|
ULONG RetResultLength;
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2006-01-22 20:34:47 +00:00
|
|
|
ASSERT(KeGetPreviousMode() != KernelMode);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-17 17:32:58 +00:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2006-01-22 20:34:47 +00:00
|
|
|
{
|
2006-07-17 17:32:58 +00:00
|
|
|
/* Probe arguments */
|
2006-01-22 20:34:47 +00:00
|
|
|
ProbeForWritePointer(Result);
|
|
|
|
ProbeForWriteUlong(ResultLength);
|
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-01-22 20:34:47 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-01-22 20:34:47 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2006-01-22 20:34:47 +00:00
|
|
|
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Call kernel function */
|
|
|
|
Status = KeUserModeCallback(RoutineIndex,
|
|
|
|
Argument,
|
|
|
|
ArgumentLength,
|
|
|
|
&RetResult,
|
|
|
|
&RetResultLength);
|
2006-01-22 20:34:47 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Enter SEH for write back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Return results to user mode */
|
|
|
|
*Result = RetResult;
|
|
|
|
*ResultLength = RetResultLength;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-01-22 20:34:47 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-01-22 20:34:47 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_END;
|
2006-01-22 20:34:47 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-19 20:26:46 +00:00
|
|
|
/* Return the result */
|
2006-01-22 20:34:47 +00:00
|
|
|
return Status;
|
2005-05-09 01:38:29 +00:00
|
|
|
}
|
2005-03-19 20:26:46 +00:00
|
|
|
|
2002-01-04 13:09:37 +00:00
|
|
|
/* EOF */
|