ReactOS  0.4.13-dev-257-gfabbd7c
win32.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/ps/win32.c
5  * PURPOSE: Process Manager: Win32K Initialization and Support
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ****************************************************************/
10 
11 #include <ntoskrnl.h>
12 #include <winerror.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* GLOBALS ******************************************************************/
17 
18 PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout = NULL;
29 
30 /* PRIVATE FUNCTIONS *********************************************************/
31 
33 NTAPI
35 {
36  ULONG_PTR NewStack;
37  PVOID OldStack;
41  PAGED_CODE();
42 
43  /* Validate the previous mode */
45 
46  /* If no win32k, crashes later */
48 
49  /* Make sure win32k is here */
51 
52  /* Make sure it's not already win32 */
54  {
55  /* We're already a win32 thread */
56  return STATUS_ALREADY_WIN32;
57  }
58 
59  /* Check if we don't already have a kernel-mode stack */
60  if (!Thread->Tcb.LargeStack)
61  {
62  /* We don't create one */
63  NewStack = (ULONG_PTR)MmCreateKernelStack(TRUE, 0);
64  if (!NewStack)
65  {
66  /* Panic in user-mode */
67  NtCurrentTeb()->LastErrorValue = ERROR_NOT_ENOUGH_MEMORY;
68  return STATUS_NO_MEMORY;
69  }
70 
71  /* We're about to switch stacks. Enter a guarded region */
73 
74  /* Switch stacks */
75  OldStack = KeSwitchKernelStack((PVOID)NewStack,
76  (PVOID)(NewStack - KERNEL_STACK_SIZE));
77 
78  /* Leave the guarded region */
80 
81  /* Delete the old stack */
82  MmDeleteKernelStack(OldStack, FALSE);
83  }
84 
85  /* Always do the process callout! */
87  if (!NT_SUCCESS(Status)) return Status;
88 
89  /* Set the new service table */
92 
93  /* Tell Win32k about our thread */
95  if (!NT_SUCCESS(Status))
96  {
97  /* Revert our table */
99  }
100 
101  /* Return status */
102  return Status;
103 }
104 
105 /* PUBLIC FUNCTIONS **********************************************************/
106 
107 /*
108  * @implemented
109  */
110 VOID
111 NTAPI
113 {
114  /* Setup the callback pointers */
115  PspW32ProcessCallout = CalloutData->ProcessCallout;
116  PspW32ThreadCallout = CalloutData->ThreadCallout;
117  ExpWindowStationObjectParse = CalloutData->WindowStationParseProcedure;
118  ExpWindowStationObjectDelete = CalloutData->WindowStationDeleteProcedure;
119  ExpWindowStationObjectOkToClose = CalloutData->WindowStationOkToCloseProcedure;
120  ExpDesktopObjectOkToClose = CalloutData->DesktopOkToCloseProcedure;
121  ExpDesktopObjectDelete = CalloutData->DesktopDeleteProcedure;
122  ExpDesktopObjectOpen = CalloutData->DesktopOpenProcedure;
123  ExpDesktopObjectClose = CalloutData->DesktopCloseProcedure;
124  PopEventCallout = CalloutData->PowerEventCallout;
125  KeGdiFlushUserBatch = CalloutData->BatchFlushRoutine;
126 }
127 
128 /* EOF */
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
Definition: win32.c:20
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose
Definition: win32k.c:46
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
PKWIN32_POWEREVENT_CALLOUT PopEventCallout
Definition: events.c:32
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID ServiceTable
Definition: ketypes.h:1561
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
PVOID NTAPI KeSwitchKernelStack(IN PVOID StackBase, IN PVOID StackLimit)
#define KeGetPreviousMode()
Definition: ketypes.h:1081
LONG NTSTATUS
Definition: precomp.h:26
KTHREAD Tcb
Definition: pstypes.h:1034
NTSTATUS(NTAPI * PKWIN32_THREAD_CALLOUT)(_In_ struct _ETHREAD *Thread, _In_ PSW32THREADCALLOUTTYPE Type)
Definition: pstypes.h:515
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
NTSTATUS(NTAPI * PKWIN32_SESSION_CALLOUT)(_In_ PVOID Parameter)
Definition: pstypes.h:582
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete
Definition: win32k.c:48
NTSTATUS NTAPI PsConvertToGuiThread(VOID)
Definition: win32.c:34
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout
Definition: win32.c:18
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
smooth NULL
Definition: ftsmooth.c:416
#define KeLeaveGuardedRegion()
Definition: ke_x.h:63
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose
Definition: win32k.c:50
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define KERNEL_STACK_SIZE
NTSTATUS(NTAPI * PKWIN32_POWEREVENT_CALLOUT)(_In_ struct _WIN32_POWEREVENT_PARAMETERS *Parameters)
Definition: pstypes.h:528
#define KeEnterGuardedRegion()
Definition: ke_x.h:34
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete
Definition: win32k.c:45
NTSTATUS(NTAPI * PGDI_BATCHFLUSH_ROUTINE)(VOID)
Definition: pstypes.h:546
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define STATUS_ALREADY_WIN32
Definition: ntstatus.h:141
PKWIN32_THREAD_CALLOUT PspW32ThreadCallout
Definition: win32.c:19
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse
Definition: win32k.c:44
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID NTAPI PsEstablishWin32Callouts(IN PWIN32_CALLOUTS_FPNS CalloutData)
Definition: win32.c:112
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
PVOID Win32Thread
Definition: ketypes.h:1756
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen
Definition: win32k.c:49
#define ULONG_PTR
Definition: config.h:101
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose
Definition: win32k.c:47