ReactOS  0.4.15-dev-5109-g2469ce2
ntuser.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: ntuser init. and main funcs.
5  * FILE: win32ss/user/ntuser/ntuser.c
6  */
7 
8 #include <win32k.h>
9 DBG_DEFAULT_CHANNEL(UserMisc);
10 
12 
13 /* GLOBALS ********************************************************************/
14 
19 ATOM AtomMessage; // Window Message atom.
20 ATOM AtomWndObj; // Window Object atom.
21 ATOM AtomLayer; // Window Layer atom.
22 ATOM AtomFlashWndState; // Window Flash State atom.
23 ATOM AtomDDETrack; // Window DDE Tracking atom.
24 ATOM AtomQOS; // Window DDE Quality of Service atom.
29 
30 /* PRIVATE FUNCTIONS **********************************************************/
31 
32 static
35 {
37 
38  gpsi->atomSysClass[ICLS_MENU] = 32768;
39  gpsi->atomSysClass[ICLS_DESKTOP] = 32769;
40  gpsi->atomSysClass[ICLS_DIALOG] = 32770;
41  gpsi->atomSysClass[ICLS_SWITCH] = 32771;
44 
45  /* System Message Atom */
46  AtomMessage = IntAddGlobalAtom(L"Message", TRUE);
47  gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage;
48 
49  /* System Context Help Id Atom */
51 
54 
55  gpsi->atomFrostedWindowProp = IntAddGlobalAtom(L"SysFrostedWindow", TRUE);
56 
58  AtomQOS = IntAddGlobalAtom(L"SysQOS", TRUE);
59  AtomImeLevel = IntAddGlobalAtom(L"SysIMEL", TRUE);
60 
61  /*
62  * FIXME: AddPropW uses the global kernel atom table, thus leading to conflicts if we use
63  * the win32k atom table for this one. What is the right thing to do ?
64  */
65  // AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE);
66  NtAddAtom(L"SysWNDO", 14, &AtomWndObj);
67 
68  AtomLayer = IntAddGlobalAtom(L"SysLayer", TRUE);
69  AtomFlashWndState = IntAddGlobalAtom(L"FlashWState", TRUE);
70 
71  return STATUS_SUCCESS;
72 }
73 
74 /* FUNCTIONS ******************************************************************/
75 
76 CODE_SEG("INIT")
78 NTAPI
80 {
82  HKEY hKey;
83 
84  if (!UserCreateHandleTable())
85  {
86  ERR("Failed creating handle table\n");
88  }
89 
91  if (!NT_SUCCESS(Status))
92  {
93  ERR("Error init session impl.\n");
94  return Status;
95  }
96 
97  InitUserAtoms();
98 
99  Status = RegOpenKey(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
100  &hKey);
101  if (NT_SUCCESS(Status))
102  {
103  DWORD dwValue = 0;
104  RegReadDWORD(hKey, L"DisplayVersion", &dwValue);
105  g_AlwaysDisplayVersion = !!dwValue;
106  ZwClose(hKey);
107  }
108 
109  InitSysParams();
110 
111  return STATUS_SUCCESS;
112 }
113 
114 NTSTATUS
115 NTAPI
116 InitVideo(VOID);
117 
118 NTSTATUS
119 NTAPI
121 {
122  static const DWORD wPattern55AA[] = /* 32 bit aligned */
123  { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
124  0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa };
125  HBITMAP hPattern55AABitmap = NULL;
127 
129 
130 // Create Event for Disconnect Desktop.
131 
133  if (!NT_SUCCESS(Status)) return Status;
134 
135  /* Initialize the Video */
136  Status = InitVideo();
137  if (!NT_SUCCESS(Status))
138  {
139  /* We failed, bugcheck */
140  KeBugCheckEx(VIDEO_DRIVER_INIT_FAILURE, Status, 0, 0, USER_VERSION);
141  }
142 
143 // {
144 // DrvInitConsole.
145 // DrvChangeDisplaySettings.
146 // Update Shared Device Caps.
147 // Initialize User Screen.
148 // }
149 
150 // Set Global SERVERINFO Error flags.
151 // Load Resources.
152 
154 
155  if (gpsi->hbrGray == NULL)
156  {
157  hPattern55AABitmap = GreCreateBitmap(8, 8, 1, 1, (LPBYTE)wPattern55AA);
158  if (hPattern55AABitmap == NULL)
160 
161  gpsi->hbrGray = IntGdiCreatePatternBrush(hPattern55AABitmap);
162 
163  if (gpsi->hbrGray == NULL)
165  }
166 
167  return STATUS_SUCCESS;
168 }
169 
170 /*
171  * Called from usersrv.
172  */
173 NTSTATUS
174 APIENTRY
176  DWORD dwWinVersion,
177  HANDLE hPowerRequestEvent,
178  HANDLE hMediaRequestEvent)
179 {
181 
182  TRACE("Enter NtUserInitialize(%lx, %p, %p)\n",
183  dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
184 
185  /* Check if we are already initialized */
186  if (gpepCSRSS)
187  return STATUS_UNSUCCESSFUL;
188 
189  /* Check Windows USER subsystem version */
190  if (dwWinVersion != USER_VERSION)
191  {
192  /* No match, bugcheck */
193  KeBugCheckEx(WIN32K_INIT_OR_RIT_FAILURE, 0, 0, dwWinVersion, USER_VERSION);
194  }
195 
196  /* Acquire exclusive lock */
198 
199  /* Save the EPROCESS of CSRSS */
200  InitCsrProcess(/*PsGetCurrentProcess()*/);
201 
202 // Initialize Power Request List (use hPowerRequestEvent).
203 // Initialize Media Change (use hMediaRequestEvent).
204 
205 // InitializeGreCSRSS();
206 // {
207 // Startup DxGraphics.
208 // calls ** UserGetLanguageID() and sets it **.
209 // Enables Fonts drivers, Initialize Font table & Stock Fonts.
210 // }
211 
212  /* Initialize USER */
214 
215  /* Return */
216  UserLeave();
217  return Status;
218 }
219 
220 
221 /*
222 RETURN
223  True if current thread owns the lock (possibly shared)
224 */
226 {
229 }
230 
232 {
234 }
235 
237 {
239 }
240 
241 // Win: EnterSharedCrit
243 {
246 }
247 
248 // Win: EnterCrit
250 {
255 }
256 
257 // Win: LeaveCrit
259 {
264 }
265 
266 /* EOF */
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:242
#define ICLS_ICONTITLE
Definition: ntuser.h:912
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOL FASTCALL UserIsEntered(VOID)
Definition: ntuser.c:225
WORD ATOM
Definition: dimm.idl:113
ATOM atomFrostedWindowProp
Definition: ntuser.h:1039
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
PEPROCESS gpepCSRSS
Definition: csr.c:15
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
LONG NTSTATUS
Definition: precomp.h:26
PSERVERINFO gpsi
Definition: imm.c:17
#define ICLS_DESKTOP
Definition: ntuser.h:908
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
ERESOURCE UserLock
Definition: ntuser.c:18
#define USER_VERSION
Definition: ntuser.h:1116
ATOM gaGuiConsoleWndClass
Definition: ntuser.c:27
ATOM atomContextHelpIdProp
Definition: ntuser.h:1038
#define FASTCALL
Definition: nt_native.h:50
BOOL ClientPfnInit
Definition: ntuser.c:26
#define ICLS_DIALOG
Definition: ntuser.h:909
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define L(x)
Definition: ntvdm.h:50
HBRUSH NTAPI IntGdiCreatePatternBrush(HBITMAP hbmPattern)
Definition: brush.cpp:303
unsigned char * LPBYTE
Definition: typedefs.h:53
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS APIENTRY NtUserInitialize(DWORD dwWinVersion, HANDLE hPowerRequestEvent, HANDLE hMediaRequestEvent)
Definition: ntuser.c:175
NTSTATUS NTAPI UserCreateWinstaDirectory(VOID)
Definition: winsta.c:51
BOOL g_AlwaysDisplayVersion
Definition: ntuser.c:17
PPROCESSINFO gppiInputProvider
Definition: ntuser.c:16
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1619
BOOL InitSysParams(VOID)
Definition: sysparams.c:350
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:249
Status
Definition: gdiplustypes.h:24
#define ICLS_TOOLTIPS
Definition: ntuser.h:913
DBG_DEFAULT_CHANNEL(UserMisc)
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
static NTSTATUS FASTCALL InitUserAtoms(VOID)
Definition: ntuser.c:34
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOL FASTCALL RegisterControlAtoms(VOID)
Definition: class.c:396
BOOL NTAPI RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:150
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define ICLS_SWITCH
Definition: ntuser.h:911
ATOM AtomDDETrack
Definition: ntuser.c:23
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS NTAPI NtAddAtom(IN PWSTR AtomName, IN ULONG AtomNameLength, OUT PRTL_ATOM Atom)
Definition: atom.c:86
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
ATOM AtomImeLevel
Definition: ntuser.c:28
ATOM atomIconProp
Definition: ntuser.h:1037
BOOL NTAPI NtUserUpdatePerUserSystemParameters(DWORD dwReserved, BOOL bEnable)
Definition: sysparams.c:360
ATOM AtomWndObj
Definition: ntuser.c:20
VOID InitCsrProcess(VOID)
Definition: csr.c:20
#define ERR(fmt,...)
Definition: debug.h:110
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
ATOM AtomMessage
Definition: ntuser.c:19
BOOL FASTCALL UserCreateHandleTable(VOID)
Definition: object.c:536
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
ATOM atomIconSmProp
Definition: ntuser.h:1036
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
NTSTATUS FASTCALL InitSessionImpl(VOID)
Definition: session.c:18
ATOM AtomLayer
Definition: ntuser.c:21
ATOM AtomQOS
Definition: ntuser.c:24
NTSTATUS NTAPI InitUserImpl(VOID)
Definition: ntuser.c:79
ULONG ERESOURCE
Definition: env_spec_w32.h:594
NTSTATUS NTAPI UserInitialize(VOID)
Definition: ntuser.c:120
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
HINSTANCE hModClient
Definition: ntuser.c:25
static HBITMAP
Definition: button.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ICLS_MENU
Definition: ntuser.h:910
NTSTATUS NTAPI InitVideo(VOID)
Definition: display.c:151
#define ASSERT_NOGDILOCKS()
Definition: gdidebug.h:10
#define RegOpenKey
Definition: winreg.h:519
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
ATOM AtomFlashWndState
Definition: ntuser.c:22
static const WORD wPattern55AA[]
Definition: commctrl.c:86
VOID FASTCALL CleanupUserImpl(VOID)
Definition: ntuser.c:236
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
RTL_ATOM FASTCALL IntAddGlobalAtom(LPWSTR lpBuffer, BOOL PinAtom)
Definition: useratom.c:62
#define APIENTRY
Definition: api.h:79
ATOM atomSysClass[ICLS_NOTUSED+1]
Definition: ntuser.h:1031
#define NT_ASSERT
Definition: rtlfuncs.h:3310
HBITMAP NTAPI GreCreateBitmap(_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cPlanes, _In_ ULONG cBitsPixel, _In_opt_ PVOID pvBits)
Definition: bitmaps.c:172