ReactOS 0.4.15-dev-5664-g3bf4ef6
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
29
30/* PRIVATE FUNCTIONS *********************************************************/
31
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 */
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 */
110VOID
111NTAPI
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 */
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#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:32
#define ULONG_PTR
Definition: config.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
NTSTATUS(NTAPI * PKWIN32_SESSION_CALLOUT)(_In_ PVOID Parameter)
Definition: pstypes.h:598
NTSTATUS(NTAPI * PKWIN32_PROCESS_CALLOUT)(_In_ struct _EPROCESS *Process, _In_ BOOLEAN Create)
Definition: pstypes.h:524
@ PsW32ThreadCalloutInitialize
Definition: pstypes.h:499
NTSTATUS(NTAPI * PKWIN32_POWEREVENT_CALLOUT)(_In_ struct _WIN32_POWEREVENT_PARAMETERS *Parameters)
Definition: pstypes.h:544
NTSTATUS(NTAPI * PGDI_BATCHFLUSH_ROUTINE)(VOID)
Definition: pstypes.h:562
NTSTATUS(NTAPI * PKWIN32_THREAD_CALLOUT)(_In_ struct _ETHREAD *Thread, _In_ PSW32THREADCALLOUTTYPE Type)
Definition: pstypes.h:531
#define NtCurrentTeb
#define KeLeaveGuardedRegion()
Definition: ke_x.h:68
#define KeEnterGuardedRegion()
Definition: ke_x.h:39
#define ASSERT(a)
Definition: mode.c:44
#define KernelMode
Definition: asm.h:34
#define KeGetPreviousMode()
Definition: ketypes.h:1108
PVOID NTAPI KeSwitchKernelStack(IN PVOID StackBase, IN PVOID StackLimit)
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
PVOID NTAPI MmCreateKernelStack(BOOLEAN GuiStack, UCHAR Node)
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectDelete
Definition: win32k.c:41
NTSTATUS NTAPI PsConvertToGuiThread(VOID)
Definition: win32.c:34
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectParse
Definition: win32k.c:40
PKWIN32_THREAD_CALLOUT PspW32ThreadCallout
Definition: win32.c:19
PKWIN32_SESSION_CALLOUT ExpDesktopObjectDelete
Definition: win32k.c:44
PKWIN32_SESSION_CALLOUT ExpDesktopObjectClose
Definition: win32k.c:46
PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout
Definition: win32.c:18
PKWIN32_SESSION_CALLOUT ExpWindowStationObjectOkToClose
Definition: win32k.c:42
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOpen
Definition: win32k.c:45
PKWIN32_SESSION_CALLOUT ExpDesktopObjectOkToClose
Definition: win32k.c:43
PKWIN32_POWEREVENT_CALLOUT PopEventCallout
Definition: events.c:32
VOID NTAPI PsEstablishWin32Callouts(IN PWIN32_CALLOUTS_FPNS CalloutData)
Definition: win32.c:112
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
Definition: win32.c:20
#define STATUS_ALREADY_WIN32
Definition: ntstatus.h:141
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
#define KERNEL_STACK_SIZE
KTHREAD Tcb
Definition: pstypes.h:1103
PVOID Win32Thread
Definition: ketypes.h:1806
PVOID ServiceTable
Definition: ketypes.h:1611
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define PsGetCurrentProcess
Definition: psfuncs.h:17