ReactOS  0.4.13-dev-563-g0561610
console.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Win32k subsystem
4  * PURPOSE: Console support functions for CONSRV
5  * FILE: win32ss/user/ntuser/console.c
6  * PROGRAMMER: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7  */
8 
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserMisc);
11 
15  IN CONSOLECONTROL ConsoleCtrl,
16  IN PVOID ConsoleCtrlInfo,
17  IN ULONG ConsoleCtrlInfoLength)
18 {
20 
21  /* Allow only the Console Server to perform this operation (via CSRSS) */
23  return STATUS_ACCESS_DENIED;
24 
26 
27  switch (ConsoleCtrl)
28  {
30  {
31  DESKTOP_CONSOLE_THREAD DesktopConsoleThreadInfo;
33  ULONG_PTR OldThreadId;
34 
35  if (ConsoleCtrlInfoLength != sizeof(DesktopConsoleThreadInfo))
36  {
38  break;
39  }
40 
41  _SEH2_TRY
42  {
43  ProbeForWrite(ConsoleCtrlInfo, ConsoleCtrlInfoLength, sizeof(USHORT));
44  DesktopConsoleThreadInfo = *(PDESKTOP_CONSOLE_THREAD)ConsoleCtrlInfo;
45  }
47  {
49  _SEH2_YIELD(break);
50  }
51  _SEH2_END;
52 
53  /* Reference the desktop */
54  Status = ObReferenceObjectByHandle(DesktopConsoleThreadInfo.DesktopHandle,
55  0,
57  UserMode,
58  (PVOID*)&Desktop,
59  NULL);
60  if (!NT_SUCCESS(Status)) break;
61 
62  /* Save the old thread ID, it is always returned to the caller */
63  OldThreadId = Desktop->dwConsoleThreadId;
64 
65  /* Set the new console input thread ID for this desktop if required */
66  if (DesktopConsoleThreadInfo.ThreadId != (ULONG_PTR)INVALID_HANDLE_VALUE)
67  {
68  Desktop->dwConsoleThreadId = DesktopConsoleThreadInfo.ThreadId;
69  }
70 
71  /* Always return the old thread ID */
72  DesktopConsoleThreadInfo.ThreadId = OldThreadId;
73 
74  /* Dereference the desktop */
76 
77  /* Return the information back to the caller */
78  _SEH2_TRY
79  {
80  *(PDESKTOP_CONSOLE_THREAD)ConsoleCtrlInfo = DesktopConsoleThreadInfo;
81  }
83  {
85  }
86  _SEH2_END;
87 
88  break;
89  }
90 
92  {
93  if (ConsoleCtrlInfoLength != sizeof(ATOM))
94  {
96  break;
97  }
98 
99  _SEH2_TRY
100  {
101  ProbeForRead(ConsoleCtrlInfo, ConsoleCtrlInfoLength, sizeof(USHORT));
102  gaGuiConsoleWndClass = *(ATOM*)ConsoleCtrlInfo;
103  }
105  {
107  }
108  _SEH2_END;
109 
110  break;
111  }
112 
114  {
115  HPALETTE hPalette;
116 
117  if (ConsoleCtrlInfoLength != sizeof(hPalette))
118  {
120  break;
121  }
122 
123  _SEH2_TRY
124  {
125  ProbeForRead(ConsoleCtrlInfo, ConsoleCtrlInfoLength, sizeof(USHORT));
126  hPalette = *(HPALETTE*)ConsoleCtrlInfo;
127  }
129  {
131  _SEH2_YIELD(break);
132  }
133  _SEH2_END;
134 
135  /* Make the palette handle public */
136  GreSetObjectOwnerEx(hPalette,
139  break;
140  }
141 
143  {
144  ERR("NtUserConsoleControl - ConsoleAcquireDisplayOwnership is UNIMPLEMENTED\n");
146  break;
147  }
148 
149  default:
150  ERR("Calling invalid control %d in NtUserConsoleControl\n", ConsoleCtrl);
152  break;
153  }
154 
155  UserLeave();
156 
157  return Status;
158 }
159 
160 /* EOF */
#define IN
Definition: typedefs.h:38
NTSTATUS APIENTRY NtUserConsoleControl(IN CONSOLECONTROL ConsoleCtrl, IN PVOID ConsoleCtrlInfo, IN ULONG ConsoleCtrlInfoLength)
Definition: console.c:14
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
enum _CONSOLECONTROL CONSOLECONTROL
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
WORD ATOM
Definition: dimm.idl:113
PEPROCESS gpepCSRSS
Definition: csr.c:15
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
DBG_DEFAULT_CHANNEL(UserMisc)
ATOM gaGuiConsoleWndClass
Definition: ntuser.c:27
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
struct _DESKTOP_CONSOLE_THREAD * PDESKTOP_CONSOLE_THREAD
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
_SEH2_END
Definition: create.c:4424
unsigned short USHORT
Definition: pedump.c:61
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
BOOL NTAPI GreSetObjectOwnerEx(HGDIOBJ hobj, ULONG ulOwner, ULONG Flags)
Definition: gdiobj.c:1219
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define APIENTRY
Definition: api.h:79