ReactOS  0.4.15-dev-1629-g9aa73da
win32k.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel
4  * FILE: ntoskrnl/ex/win32k.c
5  * PURPOSE: Executive Win32 Object Support (Desktop/WinStation)
6  * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7  */
8 
9 #include <ntoskrnl.h>
10 #define NDEBUG
11 #include <debug.h>
12 
14 {
17 
18 
19 /* DATA **********************************************************************/
20 
23 
25 {
30 };
31 
33 {
38 };
39 
47 
48 /* FUNCTIONS ****************************************************************/
49 
51 NTAPI
54  _In_ PKWIN32_SESSION_CALLOUT CalloutProcedure,
56 {
57  PWIN32_KERNEL_OBJECT_HEADER Win32ObjectHeader;
58  PVOID SessionEntry = NULL;
61 
62  /* The objects have a common header. And the kernel accesses it!
63  Thanks MS for this kind of retarded "design"! */
64  Win32ObjectHeader = Object;
65 
66  /* Check if we are not already in the correct session */
67  if (!PsGetCurrentProcess()->ProcessInSession ||
68  (PsGetCurrentProcessSessionId() != Win32ObjectHeader->SessionId))
69  {
70  /* Get the session from the objects session Id */
71  DPRINT("SessionId == %d\n", Win32ObjectHeader->SessionId);
72  SessionEntry = MmGetSessionById(Win32ObjectHeader->SessionId);
73  if (SessionEntry == NULL)
74  {
75  /* The requested session does not even exist! */
76  ASSERT(FALSE);
77  return STATUS_NOT_FOUND;
78  }
79 
80  /* Attach to the session */
81  Status = MmAttachSession(SessionEntry, &ApcState);
82  if (!NT_SUCCESS(Status))
83  {
84  DPRINT1("Could not attach to 0x%p, object %p, callout 0x%p\n",
85  SessionEntry,
86  Win32ObjectHeader,
87  CalloutProcedure);
88 
89  /* Cleanup and return */
90  MmQuitNextSession(SessionEntry);
91  ASSERT(FALSE);
92  return Status;
93  }
94  }
95 
96  /* Call the callout routine */
97  Status = CalloutProcedure(Parameter);
98 
99  /* Check if we have a session */
100  if (SessionEntry != NULL)
101  {
102  /* Detach from the session and quit using it */
103  MmDetachSession(SessionEntry, &ApcState);
104  MmQuitNextSession(SessionEntry);
105  }
106 
107  /* Return the callback status */
108  return Status;
109 }
110 
111 BOOLEAN
112 NTAPI
114  IN PVOID Object,
115  IN HANDLE Handle,
117 {
120 
121  Parameters.Process = Process;
122  Parameters.Object = Object;
123  Parameters.Handle = Handle;
124  Parameters.PreviousMode = AccessMode;
125 
128  &Parameters);
129 
130  return NT_SUCCESS(Status);
131 }
132 
133 BOOLEAN
134 NTAPI
136  IN PVOID Object,
137  IN HANDLE Handle,
139 {
142 
143  Parameters.Process = Process;
144  Parameters.Object = Object;
145  Parameters.Handle = Handle;
146  Parameters.PreviousMode = AccessMode;
147 
150  &Parameters);
151 
152  return NT_SUCCESS(Status);
153 }
154 
155 VOID
156 NTAPI
158 {
160 
161  /* Fill out the callback structure */
162  Parameters.Object = DeletedObject;
163 
164  ExpWin32SessionCallout(DeletedObject,
166  &Parameters);
167 }
168 
169 NTSTATUS
170 NTAPI
176  IN OUT PUNICODE_STRING CompleteName,
180  OUT PVOID *Object)
181 {
183 
184  /* Fill out the callback structure */
185  Parameters.ParseObject = ParseObject;
186  Parameters.ObjectType = ObjectType;
187  Parameters.AccessState = AccessState;
188  Parameters.AccessMode = AccessMode;
189  Parameters.Attributes = Attributes;
190  Parameters.CompleteName = CompleteName;
191  Parameters.RemainingName = RemainingName;
192  Parameters.Context = Context;
193  Parameters.SecurityQos = SecurityQos;
194  Parameters.Object = Object;
195 
196  return ExpWin32SessionCallout(ParseObject,
198  &Parameters);
199 }
200 VOID
201 NTAPI
202 ExpDesktopDelete(PVOID DeletedObject)
203 {
205 
206  /* Fill out the callback structure */
207  Parameters.Object = DeletedObject;
208 
209  ExpWin32SessionCallout(DeletedObject,
211  &Parameters);
212 }
213 
214 NTSTATUS
215 NTAPI
218  IN PVOID ObjectBody,
220  IN ULONG HandleCount)
221 {
223 
224  Parameters.OpenReason = Reason;
225  Parameters.Process = Process;
226  Parameters.Object = ObjectBody;
227  Parameters.GrantedAccess = GrantedAccess;
228  Parameters.HandleCount = HandleCount;
229 
230  return ExpWin32SessionCallout(ObjectBody,
232  &Parameters);
233 }
234 
235 VOID
236 NTAPI
238  IN PVOID Object,
241  IN ULONG SystemHandleCount)
242 {
244 
245  Parameters.Process = Process;
246  Parameters.Object = Object;
247  Parameters.AccessMask = GrantedAccess;
248  Parameters.ProcessHandleCount = ProcessHandleCount;
249  Parameters.SystemHandleCount = SystemHandleCount;
250 
253  &Parameters);
254 }
255 
256 CODE_SEG("INIT")
257 BOOLEAN
258 NTAPI
260 {
261  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
264  DPRINT("Creating Win32 Object Types\n");
265 
266  /* Create the window station Object Type */
267  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
268  RtlInitUnicodeString(&Name, L"WindowStation");
269  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
270  ObjectTypeInitializer.GenericMapping = ExpWindowStationMapping;
271  ObjectTypeInitializer.PoolType = NonPagedPool;
272  ObjectTypeInitializer.DeleteProcedure = ExpWinStaObjectDelete;
273  ObjectTypeInitializer.ParseProcedure = ExpWinStaObjectParse;
274  ObjectTypeInitializer.OkayToCloseProcedure = ExpWindowStationOkToClose;
275  ObjectTypeInitializer.SecurityRequired = TRUE;
276  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK |
277  OBJ_PERMANENT |
279  ObjectTypeInitializer.ValidAccessMask = STANDARD_RIGHTS_REQUIRED;
281  &ObjectTypeInitializer,
282  NULL,
284  if (!NT_SUCCESS(Status)) return FALSE;
285 
286  /* Create desktop object type */
287  RtlInitUnicodeString(&Name, L"Desktop");
288  ObjectTypeInitializer.GenericMapping = ExpDesktopMapping;
289  ObjectTypeInitializer.DeleteProcedure = ExpDesktopDelete;
290  ObjectTypeInitializer.ParseProcedure = NULL;
291  ObjectTypeInitializer.OkayToCloseProcedure = ExpDesktopOkToClose;
292  ObjectTypeInitializer.OpenProcedure = ExpDesktopOpen;
293  ObjectTypeInitializer.CloseProcedure = ExpDesktopClose;
295  &ObjectTypeInitializer,
296  NULL,
298  if (!NT_SUCCESS(Status)) return FALSE;
299 
300  return TRUE;
301 }
302 
303 /* EOF */
#define OBJ_OPENLINK
Definition: winternl.h:230
NTSTATUS NTAPI 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)
Definition: win32k.c:171
ObjectType
Definition: metafile.c:80
#define IN
Definition: typedefs.h:39
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
KAPC_STATE
Definition: ketypes.h:1280
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure
Definition: obtypes.h:373
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI MmGetSessionById(_In_ ULONG SessionId)
Definition: session.c:1054
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
NTSTATUS NTAPI ExpWin32SessionCallout(_In_ PVOID Object, _In_ PKWIN32_SESSION_CALLOUT CalloutProcedure, _Inout_opt_ PVOID Parameter)
Definition: win32k.c:52
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose
Definition: win32k.c:42
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
NTSTATUS(NTAPI * PKWIN32_SESSION_CALLOUT)(_In_ PVOID Parameter)
Definition: pstypes.h:590
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
VOID NTAPI ExpDesktopClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: win32k.c:237
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:395
struct NameRec_ * Name
Definition: cdprocs.h:459
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN NTAPI ExpWin32kInit(VOID)
Definition: win32k.c:259
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
VOID NTAPI MmQuitNextSession(_Inout_ PVOID SessionEntry)
Definition: session.c:1034
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete
Definition: win32k.c:41
Status
Definition: gdiplustypes.h:24
struct _WIN32_KERNEL_OBJECT_HEADER WIN32_KERNEL_OBJECT_HEADER
#define STATUS_NOT_FOUND
Definition: shellext.h:72
ULONG NTAPI PsGetCurrentProcessSessionId(VOID)
Definition: process.c:1133
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen
Definition: win32k.c:45
GENERIC_MAPPING ExpWindowStationMapping
Definition: win32k.c:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
OB_PARSE_METHOD ParseProcedure
Definition: obtypes.h:370
CODE_SEG("INIT")
Definition: fsrtlpc.c:19
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
struct _WIN32_KERNEL_OBJECT_HEADER * PWIN32_KERNEL_OBJECT_HEADER
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
BOOLEAN NTAPI ExpDesktopOkToClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: win32k.c:113
VOID NTAPI ExpDesktopDelete(PVOID DeletedObject)
Definition: win32k.c:202
OB_OPEN_METHOD OpenProcedure
Definition: obtypes.h:367
static const WCHAR L[]
Definition: oid.c:1250
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose
Definition: win32k.c:46
#define OBJ_PERMANENT
Definition: winternl.h:226
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
GENERIC_MAPPING ExpDesktopMapping
Definition: win32k.c:32
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete
Definition: win32k.c:44
enum _OB_OPEN_REASON OB_OPEN_REASON
#define _In_
Definition: no_sal2.h:158
VOID NTAPI ExpWinStaObjectDelete(PVOID DeletedObject)
Definition: win32k.c:157
BOOLEAN NTAPI ExpWindowStationOkToClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: win32k.c:135
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1488
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse
Definition: win32k.c:40
#define NULL
Definition: types.h:112
NTSTATUS NTAPI ExpDesktopOpen(IN OB_OPEN_REASON Reason, IN PEPROCESS Process OPTIONAL, IN PVOID ObjectBody, IN ACCESS_MASK GrantedAccess, IN ULONG HandleCount)
Definition: win32k.c:216
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
_In_ HANDLE Handle
Definition: extypes.h:390
struct tagContext Context
Definition: acpixf.h:1034
#define OUT
Definition: typedefs.h:40
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:45
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose
Definition: win32k.c:43
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define _Inout_opt_
Definition: no_sal2.h:216
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:801
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68