ReactOS 0.4.16-dev-336-gb667d82
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
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! */
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}
110
112NTAPI
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
134NTAPI
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
155VOID
156NTAPI
158{
160
161 /* Fill out the callback structure */
162 Parameters.Object = DeletedObject;
163
164 ExpWin32SessionCallout(DeletedObject,
166 &Parameters);
167}
168
170NTAPI
176 IN OUT PUNICODE_STRING CompleteName,
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}
200VOID
201NTAPI
203{
205
206 /* Fill out the callback structure */
207 Parameters.Object = DeletedObject;
208
209 ExpWin32SessionCallout(DeletedObject,
211 &Parameters);
212}
213
215NTAPI
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
235VOID
236NTAPI
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
256CODE_SEG("INIT")
258NTAPI
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}
302
303/* EOF */
#define CODE_SEG(...)
unsigned char BOOLEAN
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:802
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
NTSTATUS(NTAPI * PKWIN32_SESSION_CALLOUT)(_In_ PVOID Parameter)
Definition: pstypes.h:599
#define OBJ_OPENLINK
Definition: winternl.h:230
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define OBJ_PERMANENT
Definition: winternl.h:226
@ ProcessHandleCount
Definition: winternl.h:876
#define ASSERT(a)
Definition: mode.c:44
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
ObjectType
Definition: metafile.c:81
enum _OB_OPEN_REASON OB_OPEN_REASON
#define _Inout_opt_
Definition: no_sal2.h:216
#define _In_
Definition: no_sal2.h:158
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#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
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
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 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 STATUS_NOT_FOUND
Definition: shellext.h:72
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
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 NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
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 ExpWin32SessionCallout(_In_ PVOID Object, _In_ PKWIN32_SESSION_CALLOUT CalloutProcedure, _Inout_opt_ PVOID Parameter)
Definition: win32k.c:52
struct _WIN32_KERNEL_OBJECT_HEADER * PWIN32_KERNEL_OBJECT_HEADER
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete
Definition: win32k.c:41
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
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse
Definition: win32k.c:40
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete
Definition: win32k.c:44
VOID NTAPI ExpWinStaObjectDelete(PVOID DeletedObject)
Definition: win32k.c:157
BOOLEAN NTAPI ExpWin32kInit(VOID)
Definition: win32k.c:259
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose
Definition: win32k.c:46
BOOLEAN NTAPI ExpDesktopOkToClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: win32k.c:113
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose
Definition: win32k.c:42
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen
Definition: win32k.c:45
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose
Definition: win32k.c:43
VOID NTAPI ExpDesktopClose(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: win32k.c:237
struct _WIN32_KERNEL_OBJECT_HEADER WIN32_KERNEL_OBJECT_HEADER
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
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
KAPC_STATE
Definition: ketypes.h:1409
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:417
_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