2005-12-29 17:57:11 +00:00
|
|
|
/*
|
2005-01-26 13:58:37 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2005-12-29 17:57:11 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
2005-01-26 13:58:37 +00:00
|
|
|
* FILE: ntoskrnl/ex/win32k.c
|
2005-12-29 17:57:11 +00:00
|
|
|
* PURPOSE: Executive Win32 Object Support (Desktop/WinStation)
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
2001-06-12 17:51:51 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2001-06-12 17:51:51 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
typedef struct _WIN32_KERNEL_OBJECT_HEADER
|
|
|
|
{
|
|
|
|
ULONG SessionId;
|
|
|
|
} WIN32_KERNEL_OBJECT_HEADER, *PWIN32_KERNEL_OBJECT_HEADER;
|
|
|
|
|
|
|
|
|
2001-06-12 17:51:51 +00:00
|
|
|
/* DATA **********************************************************************/
|
|
|
|
|
2005-11-22 02:30:18 +00:00
|
|
|
POBJECT_TYPE ExWindowStationObjectType = NULL;
|
|
|
|
POBJECT_TYPE ExDesktopObjectType = NULL;
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
GENERIC_MAPPING ExpWindowStationMapping =
|
2005-06-25 14:04:56 +00:00
|
|
|
{
|
|
|
|
STANDARD_RIGHTS_READ,
|
|
|
|
STANDARD_RIGHTS_WRITE,
|
|
|
|
STANDARD_RIGHTS_EXECUTE,
|
|
|
|
STANDARD_RIGHTS_REQUIRED
|
2004-11-20 16:46:06 +00:00
|
|
|
};
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2006-05-25 20:03:13 +00:00
|
|
|
GENERIC_MAPPING ExpDesktopMapping =
|
2005-06-25 14:04:56 +00:00
|
|
|
{
|
|
|
|
STANDARD_RIGHTS_READ,
|
|
|
|
STANDARD_RIGHTS_WRITE,
|
|
|
|
STANDARD_RIGHTS_EXECUTE,
|
|
|
|
STANDARD_RIGHTS_REQUIRED
|
2004-11-20 16:46:06 +00:00
|
|
|
};
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen = NULL;
|
|
|
|
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose = NULL;
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2005-03-12 14:15:49 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
ExpWin32SessionCallout(
|
|
|
|
_In_ PVOID Object,
|
|
|
|
_In_ PKWIN32_SESSION_CALLOUT CalloutProcedure,
|
|
|
|
_Inout_opt_ PVOID Parameter)
|
|
|
|
{
|
|
|
|
PWIN32_KERNEL_OBJECT_HEADER Win32ObjectHeader;
|
|
|
|
PVOID SessionEntry = NULL;
|
|
|
|
KAPC_STATE ApcState;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* The objects have a common header. And the kernel accesses it!
|
|
|
|
Thanks MS for this kind of retarded "design"! */
|
|
|
|
Win32ObjectHeader = Object;
|
|
|
|
|
|
|
|
/* Check if we are not already in the correct session */
|
|
|
|
if (!PsGetCurrentProcess()->ProcessInSession ||
|
|
|
|
(PsGetCurrentProcessSessionId() != Win32ObjectHeader->SessionId))
|
|
|
|
{
|
|
|
|
/* Get the session from the objects session Id */
|
2013-11-20 23:50:42 +00:00
|
|
|
DPRINT("SessionId == %d\n", Win32ObjectHeader->SessionId);
|
2013-11-19 23:09:13 +00:00
|
|
|
SessionEntry = MmGetSessionById(Win32ObjectHeader->SessionId);
|
|
|
|
if (SessionEntry == NULL)
|
|
|
|
{
|
|
|
|
/* The requested session does not even exist! */
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(FALSE);
|
2013-11-19 23:09:13 +00:00
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach to the session */
|
|
|
|
Status = MmAttachSession(SessionEntry, &ApcState);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Could not attach to 0x%p, object %p, callout 0x%p\n",
|
|
|
|
SessionEntry,
|
|
|
|
Win32ObjectHeader,
|
|
|
|
CalloutProcedure);
|
|
|
|
|
|
|
|
/* Cleanup and return */
|
|
|
|
MmQuitNextSession(SessionEntry);
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(FALSE);
|
2013-11-19 23:09:13 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the callout routine */
|
|
|
|
Status = CalloutProcedure(Parameter);
|
|
|
|
|
|
|
|
/* Check if we have a session */
|
|
|
|
if (SessionEntry != NULL)
|
|
|
|
{
|
|
|
|
/* Detach from the session and quit using it */
|
|
|
|
MmDetachSession(SessionEntry, &ApcState);
|
|
|
|
MmQuitNextSession(SessionEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the callback status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-08-13 20:10:40 +00:00
|
|
|
BOOLEAN
|
2011-03-22 09:19:26 +00:00
|
|
|
NTAPI
|
|
|
|
ExpDesktopOkToClose( IN PEPROCESS Process OPTIONAL,
|
|
|
|
IN PVOID Object,
|
|
|
|
IN HANDLE Handle,
|
|
|
|
IN KPROCESSOR_MODE AccessMode)
|
|
|
|
{
|
|
|
|
WIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters;
|
2013-11-19 23:09:13 +00:00
|
|
|
NTSTATUS Status;
|
2011-03-22 09:19:26 +00:00
|
|
|
|
|
|
|
Parameters.Process = Process;
|
|
|
|
Parameters.Object = Object;
|
|
|
|
Parameters.Handle = Handle;
|
|
|
|
Parameters.PreviousMode = AccessMode;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
Status = ExpWin32SessionCallout(Object,
|
|
|
|
ExpDesktopObjectOkToClose,
|
|
|
|
&Parameters);
|
|
|
|
|
|
|
|
return NT_SUCCESS(Status);
|
2011-03-22 09:19:26 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 20:10:40 +00:00
|
|
|
BOOLEAN
|
2011-03-22 09:19:26 +00:00
|
|
|
NTAPI
|
|
|
|
ExpWindowStationOkToClose( IN PEPROCESS Process OPTIONAL,
|
|
|
|
IN PVOID Object,
|
|
|
|
IN HANDLE Handle,
|
|
|
|
IN KPROCESSOR_MODE AccessMode)
|
|
|
|
{
|
|
|
|
WIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters;
|
2013-11-19 23:09:13 +00:00
|
|
|
NTSTATUS Status;
|
2011-03-22 09:19:26 +00:00
|
|
|
|
|
|
|
Parameters.Process = Process;
|
|
|
|
Parameters.Object = Object;
|
|
|
|
Parameters.Handle = Handle;
|
|
|
|
Parameters.PreviousMode = AccessMode;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
Status = ExpWin32SessionCallout(Object,
|
|
|
|
ExpWindowStationObjectOkToClose,
|
|
|
|
&Parameters);
|
|
|
|
|
|
|
|
return NT_SUCCESS(Status);
|
2011-03-22 09:19:26 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2001-08-26 17:30:21 +00:00
|
|
|
ExpWinStaObjectDelete(PVOID DeletedObject)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2006-05-25 20:03:13 +00:00
|
|
|
WIN32_DELETEMETHOD_PARAMETERS Parameters;
|
|
|
|
|
|
|
|
/* Fill out the callback structure */
|
|
|
|
Parameters.Object = DeletedObject;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
ExpWin32SessionCallout(DeletedObject,
|
|
|
|
ExpWindowStationObjectDelete,
|
|
|
|
&Parameters);
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2006-05-25 01:18:31 +00:00
|
|
|
ExpWinStaObjectParse(IN PVOID ParseObject,
|
|
|
|
IN PVOID ObjectType,
|
|
|
|
IN OUT PACCESS_STATE AccessState,
|
|
|
|
IN KPROCESSOR_MODE AccessMode,
|
|
|
|
IN ULONG Attributes,
|
|
|
|
IN OUT PUNICODE_STRING CompleteName,
|
|
|
|
IN OUT PUNICODE_STRING RemainingName,
|
|
|
|
IN OUT PVOID Context OPTIONAL,
|
|
|
|
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
|
|
|
|
OUT PVOID *Object)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2006-05-25 20:03:13 +00:00
|
|
|
WIN32_PARSEMETHOD_PARAMETERS Parameters;
|
|
|
|
|
|
|
|
/* Fill out the callback structure */
|
|
|
|
Parameters.ParseObject = ParseObject;
|
|
|
|
Parameters.ObjectType = ObjectType;
|
|
|
|
Parameters.AccessState = AccessState;
|
|
|
|
Parameters.AccessMode = AccessMode;
|
|
|
|
Parameters.Attributes = Attributes;
|
|
|
|
Parameters.CompleteName = CompleteName;
|
|
|
|
Parameters.RemainingName = RemainingName;
|
|
|
|
Parameters.Context = Context;
|
|
|
|
Parameters.SecurityQos = SecurityQos;
|
|
|
|
Parameters.Object = Object;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
return ExpWin32SessionCallout(ParseObject,
|
|
|
|
ExpWindowStationObjectParse,
|
|
|
|
&Parameters);
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-03-12 14:15:49 +00:00
|
|
|
ExpDesktopDelete(PVOID DeletedObject)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2006-05-25 20:03:13 +00:00
|
|
|
WIN32_DELETEMETHOD_PARAMETERS Parameters;
|
|
|
|
|
|
|
|
/* Fill out the callback structure */
|
|
|
|
Parameters.Object = DeletedObject;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
ExpWin32SessionCallout(DeletedObject,
|
|
|
|
ExpDesktopObjectDelete,
|
|
|
|
&Parameters);
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 10:34:41 +00:00
|
|
|
NTSTATUS
|
2013-11-19 23:09:13 +00:00
|
|
|
NTAPI
|
2012-10-28 10:34:41 +00:00
|
|
|
ExpDesktopOpen(IN OB_OPEN_REASON Reason,
|
|
|
|
IN PEPROCESS Process OPTIONAL,
|
|
|
|
IN PVOID ObjectBody,
|
|
|
|
IN ACCESS_MASK GrantedAccess,
|
|
|
|
IN ULONG HandleCount)
|
|
|
|
{
|
|
|
|
WIN32_OPENMETHOD_PARAMETERS Parameters;
|
|
|
|
|
|
|
|
Parameters.OpenReason = Reason;
|
|
|
|
Parameters.Process = Process;
|
|
|
|
Parameters.Object = ObjectBody;
|
|
|
|
Parameters.GrantedAccess = GrantedAccess;
|
|
|
|
Parameters.HandleCount = HandleCount;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
return ExpWin32SessionCallout(ObjectBody,
|
|
|
|
ExpDesktopObjectOpen,
|
|
|
|
&Parameters);
|
2012-10-28 10:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2013-11-19 23:09:13 +00:00
|
|
|
NTAPI
|
2012-10-28 10:34:41 +00:00
|
|
|
ExpDesktopClose(IN PEPROCESS Process OPTIONAL,
|
|
|
|
IN PVOID Object,
|
|
|
|
IN ACCESS_MASK GrantedAccess,
|
|
|
|
IN ULONG ProcessHandleCount,
|
|
|
|
IN ULONG SystemHandleCount)
|
|
|
|
{
|
|
|
|
WIN32_CLOSEMETHOD_PARAMETERS Parameters;
|
|
|
|
|
|
|
|
Parameters.Process = Process;
|
|
|
|
Parameters.Object = Object;
|
|
|
|
Parameters.AccessMask = GrantedAccess;
|
|
|
|
Parameters.ProcessHandleCount = ProcessHandleCount;
|
|
|
|
Parameters.SystemHandleCount = SystemHandleCount;
|
|
|
|
|
2013-11-19 23:09:13 +00:00
|
|
|
ExpWin32SessionCallout(Object,
|
|
|
|
ExpDesktopObjectClose,
|
|
|
|
&Parameters);
|
2012-10-28 10:34:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2020-05-23 13:56:10 +00:00
|
|
|
BOOLEAN
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2001-06-12 17:51:51 +00:00
|
|
|
ExpWin32kInit(VOID)
|
|
|
|
{
|
2005-05-15 17:59:33 +00:00
|
|
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
|
|
|
UNICODE_STRING Name;
|
2012-09-03 01:12:58 +00:00
|
|
|
NTSTATUS Status;
|
2005-12-29 17:57:11 +00:00
|
|
|
DPRINT("Creating Win32 Object Types\n");
|
2005-05-15 17:59:33 +00:00
|
|
|
|
|
|
|
/* Create the window station Object Type */
|
|
|
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
|
|
|
RtlInitUnicodeString(&Name, L"WindowStation");
|
|
|
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
|
|
|
ObjectTypeInitializer.GenericMapping = ExpWindowStationMapping;
|
|
|
|
ObjectTypeInitializer.PoolType = NonPagedPool;
|
|
|
|
ObjectTypeInitializer.DeleteProcedure = ExpWinStaObjectDelete;
|
2006-05-25 19:30:09 +00:00
|
|
|
ObjectTypeInitializer.ParseProcedure = ExpWinStaObjectParse;
|
2011-03-22 09:19:26 +00:00
|
|
|
ObjectTypeInitializer.OkayToCloseProcedure = ExpWindowStationOkToClose;
|
2012-09-02 22:06:42 +00:00
|
|
|
ObjectTypeInitializer.SecurityRequired = TRUE;
|
|
|
|
ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK |
|
|
|
|
OBJ_PERMANENT |
|
|
|
|
OBJ_EXCLUSIVE;
|
2012-09-03 01:12:58 +00:00
|
|
|
ObjectTypeInitializer.ValidAccessMask = STANDARD_RIGHTS_REQUIRED;
|
|
|
|
Status = ObCreateObjectType(&Name,
|
|
|
|
&ObjectTypeInitializer,
|
|
|
|
NULL,
|
|
|
|
&ExWindowStationObjectType);
|
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
2013-11-19 23:09:13 +00:00
|
|
|
|
2005-03-12 14:15:49 +00:00
|
|
|
/* Create desktop object type */
|
2005-05-15 17:59:33 +00:00
|
|
|
RtlInitUnicodeString(&Name, L"Desktop");
|
|
|
|
ObjectTypeInitializer.GenericMapping = ExpDesktopMapping;
|
|
|
|
ObjectTypeInitializer.DeleteProcedure = ExpDesktopDelete;
|
|
|
|
ObjectTypeInitializer.ParseProcedure = NULL;
|
2011-03-22 09:19:26 +00:00
|
|
|
ObjectTypeInitializer.OkayToCloseProcedure = ExpDesktopOkToClose;
|
2012-10-28 10:34:41 +00:00
|
|
|
ObjectTypeInitializer.OpenProcedure = ExpDesktopOpen;
|
|
|
|
ObjectTypeInitializer.CloseProcedure = ExpDesktopClose;
|
2013-10-11 13:15:20 +00:00
|
|
|
Status = ObCreateObjectType(&Name,
|
|
|
|
&ObjectTypeInitializer,
|
|
|
|
NULL,
|
|
|
|
&ExDesktopObjectType);
|
2012-09-03 01:12:58 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
2013-11-19 23:09:13 +00:00
|
|
|
|
2012-09-03 01:12:58 +00:00
|
|
|
return TRUE;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|