ReactOS 0.4.16-dev-117-g38f21f9
win32k.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for win32k.c:

Go to the source code of this file.

Classes

struct  _WIN32_KERNEL_OBJECT_HEADER
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _WIN32_KERNEL_OBJECT_HEADER WIN32_KERNEL_OBJECT_HEADER
 
typedef struct _WIN32_KERNEL_OBJECT_HEADERPWIN32_KERNEL_OBJECT_HEADER
 

Functions

NTSTATUS NTAPI ExpWin32SessionCallout (_In_ PVOID Object, _In_ PKWIN32_SESSION_CALLOUT CalloutProcedure, _Inout_opt_ PVOID Parameter)
 
BOOLEAN NTAPI ExpDesktopOkToClose (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
 
BOOLEAN NTAPI ExpWindowStationOkToClose (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
 
VOID NTAPI ExpWinStaObjectDelete (PVOID DeletedObject)
 
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)
 
VOID NTAPI ExpDesktopDelete (PVOID DeletedObject)
 
NTSTATUS NTAPI ExpDesktopOpen (IN OB_OPEN_REASON Reason, IN PEPROCESS Process OPTIONAL, IN PVOID ObjectBody, IN ACCESS_MASK GrantedAccess, IN ULONG HandleCount)
 
VOID NTAPI ExpDesktopClose (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
BOOLEAN NTAPI ExpWin32kInit (VOID)
 

Variables

POBJECT_TYPE ExWindowStationObjectType = NULL
 
POBJECT_TYPE ExDesktopObjectType = NULL
 
GENERIC_MAPPING ExpWindowStationMapping
 
GENERIC_MAPPING ExpDesktopMapping
 
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
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file win32k.c.

Typedef Documentation

◆ PWIN32_KERNEL_OBJECT_HEADER

◆ WIN32_KERNEL_OBJECT_HEADER

Function Documentation

◆ ExpDesktopClose()

VOID NTAPI ExpDesktopClose ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  ProcessHandleCount,
IN ULONG  SystemHandleCount 
)

Definition at line 237 of file win32k.c.

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}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
@ ProcessHandleCount
Definition: winternl.h:876
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
NTSTATUS NTAPI ExpWin32SessionCallout(_In_ PVOID Object, _In_ PKWIN32_SESSION_CALLOUT CalloutProcedure, _Inout_opt_ PVOID Parameter)
Definition: win32k.c:52
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose
Definition: win32k.c:46
_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:20

Referenced by ExpWin32kInit().

◆ ExpDesktopDelete()

VOID NTAPI ExpDesktopDelete ( PVOID  DeletedObject)

Definition at line 202 of file win32k.c.

203{
205
206 /* Fill out the callback structure */
207 Parameters.Object = DeletedObject;
208
209 ExpWin32SessionCallout(DeletedObject,
211 &Parameters);
212}
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete
Definition: win32k.c:44

Referenced by ExpWin32kInit().

◆ ExpDesktopOkToClose()

BOOLEAN NTAPI ExpDesktopOkToClose ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN HANDLE  Handle,
IN KPROCESSOR_MODE  AccessMode 
)

Definition at line 113 of file win32k.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose
Definition: win32k.c:43
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396

Referenced by ExpWin32kInit().

◆ ExpDesktopOpen()

NTSTATUS NTAPI ExpDesktopOpen ( IN OB_OPEN_REASON  Reason,
IN PEPROCESS Process  OPTIONAL,
IN PVOID  ObjectBody,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  HandleCount 
)

Definition at line 216 of file win32k.c.

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}
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen
Definition: win32k.c:45

Referenced by ExpWin32kInit().

◆ ExpWin32kInit()

BOOLEAN NTAPI ExpWin32kInit ( VOID  )

Definition at line 259 of file win32k.c.

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 |
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}
struct NameRec_ * Name
Definition: cdprocs.h:460
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NonPagedPool
Definition: env_spec_w32.h:307
#define OBJ_OPENLINK
Definition: winternl.h:230
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define OBJ_PERMANENT
Definition: winternl.h:226
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1136
#define DPRINT
Definition: sndvol32.h:73
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
OB_OPEN_METHOD OpenProcedure
Definition: obtypes.h:367
OB_PARSE_METHOD ParseProcedure
Definition: obtypes.h:370
OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure
Definition: obtypes.h:373
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
GENERIC_MAPPING ExpWindowStationMapping
Definition: win32k.c:24
BOOLEAN NTAPI ExpWindowStationOkToClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: win32k.c:135
GENERIC_MAPPING ExpDesktopMapping
Definition: win32k.c:32
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
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
VOID NTAPI ExpWinStaObjectDelete(PVOID DeletedObject)
Definition: win32k.c:157
BOOLEAN NTAPI ExpDesktopOkToClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: win32k.c:113
VOID NTAPI ExpDesktopClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: win32k.c:237
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
VOID NTAPI ExpDesktopDelete(PVOID DeletedObject)
Definition: win32k.c:202
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21

Referenced by ExpInitSystemPhase1().

◆ ExpWin32SessionCallout()

NTSTATUS NTAPI ExpWin32SessionCallout ( _In_ PVOID  Object,
_In_ PKWIN32_SESSION_CALLOUT  CalloutProcedure,
_Inout_opt_ PVOID  Parameter 
)

Definition at line 52 of file win32k.c.

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! */
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);
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}
#define DPRINT1
Definition: precomp.h:8
#define ASSERT(a)
Definition: mode.c:44
VOID NTAPI MmQuitNextSession(_Inout_ PVOID SessionEntry)
Definition: session.c:1030
PVOID NTAPI MmGetSessionById(_In_ ULONG SessionId)
Definition: session.c:1050
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1765
ULONG NTAPI PsGetCurrentProcessSessionId(VOID)
Definition: process.c:1133
#define STATUS_NOT_FOUND
Definition: shellext.h:72
KAPC_STATE
Definition: ketypes.h:1409
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by ExpDesktopClose(), ExpDesktopDelete(), ExpDesktopOkToClose(), ExpDesktopOpen(), ExpWindowStationOkToClose(), ExpWinStaObjectDelete(), and ExpWinStaObjectParse().

◆ ExpWindowStationOkToClose()

BOOLEAN NTAPI ExpWindowStationOkToClose ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN HANDLE  Handle,
IN KPROCESSOR_MODE  AccessMode 
)

Definition at line 135 of file win32k.c.

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}
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose
Definition: win32k.c:42

Referenced by ExpWin32kInit().

◆ ExpWinStaObjectDelete()

VOID NTAPI ExpWinStaObjectDelete ( PVOID  DeletedObject)

Definition at line 157 of file win32k.c.

158{
160
161 /* Fill out the callback structure */
162 Parameters.Object = DeletedObject;
163
164 ExpWin32SessionCallout(DeletedObject,
166 &Parameters);
167}
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete
Definition: win32k.c:41

Referenced by ExpWin32kInit().

◆ ExpWinStaObjectParse()

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 at line 171 of file win32k.c.

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}
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:802
ObjectType
Definition: metafile.c:81
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse
Definition: win32k.c:40
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:417

Referenced by ExpWin32kInit().

Variable Documentation

◆ ExDesktopObjectType

◆ ExpDesktopMapping

GENERIC_MAPPING ExpDesktopMapping
Initial value:
=
{
}
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67

Definition at line 32 of file win32k.c.

Referenced by ExpWin32kInit().

◆ ExpDesktopObjectClose

PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose = NULL

Definition at line 46 of file win32k.c.

Referenced by ExpDesktopClose(), and PsEstablishWin32Callouts().

◆ ExpDesktopObjectDelete

PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete = NULL

Definition at line 44 of file win32k.c.

Referenced by ExpDesktopDelete(), and PsEstablishWin32Callouts().

◆ ExpDesktopObjectOkToClose

PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose = NULL

Definition at line 43 of file win32k.c.

Referenced by ExpDesktopOkToClose(), and PsEstablishWin32Callouts().

◆ ExpDesktopObjectOpen

PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen = NULL

Definition at line 45 of file win32k.c.

Referenced by ExpDesktopOpen(), and PsEstablishWin32Callouts().

◆ ExpWindowStationMapping

GENERIC_MAPPING ExpWindowStationMapping

◆ ExpWindowStationObjectDelete

PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete = NULL

Definition at line 41 of file win32k.c.

Referenced by ExpWinStaObjectDelete(), and PsEstablishWin32Callouts().

◆ ExpWindowStationObjectOkToClose

PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose = NULL

Definition at line 42 of file win32k.c.

Referenced by ExpWindowStationOkToClose(), and PsEstablishWin32Callouts().

◆ ExpWindowStationObjectParse

PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse = NULL

Definition at line 40 of file win32k.c.

Referenced by ExpWinStaObjectParse(), and PsEstablishWin32Callouts().

◆ ExWindowStationObjectType