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 11 BOOL FASTCALL RegisterControlAtoms(VOID); 12 13 /* GLOBALS ********************************************************************/ 14 15 PTHREADINFO gptiCurrent = NULL; 16 PPROCESSINFO gppiInputProvider = NULL; 17 BOOL g_AlwaysDisplayVersion = FALSE; 18 ERESOURCE UserLock; 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. 25 HINSTANCE hModClient = NULL; 26 BOOL ClientPfnInit = FALSE; 27 ATOM gaGuiConsoleWndClass; 28 29 /* PRIVATE FUNCTIONS **********************************************************/ 30 31 static 32 NTSTATUS FASTCALL 33 InitUserAtoms(VOID) 34 { 35 RegisterControlAtoms(); 36 37 gpsi->atomSysClass[ICLS_MENU] = 32768; 38 gpsi->atomSysClass[ICLS_DESKTOP] = 32769; 39 gpsi->atomSysClass[ICLS_DIALOG] = 32770; 40 gpsi->atomSysClass[ICLS_SWITCH] = 32771; 41 gpsi->atomSysClass[ICLS_ICONTITLE] = 32772; 42 gpsi->atomSysClass[ICLS_TOOLTIPS] = 32774; 43 44 /* System Message Atom */ 45 AtomMessage = IntAddGlobalAtom(L"Message", TRUE); 46 gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage; 47 48 /* System Context Help Id Atom */ 49 gpsi->atomContextHelpIdProp = IntAddGlobalAtom(L"SysCH", TRUE); 50 51 gpsi->atomIconSmProp = IntAddGlobalAtom(L"SysICS", TRUE); 52 gpsi->atomIconProp = IntAddGlobalAtom(L"SysIC", TRUE); 53 54 gpsi->atomFrostedWindowProp = IntAddGlobalAtom(L"SysFrostedWindow", TRUE); 55 56 AtomDDETrack = IntAddGlobalAtom(L"SysDT", TRUE); 57 AtomQOS = IntAddGlobalAtom(L"SysQOS", TRUE); 58 59 /* 60 * FIXME: AddPropW uses the global kernel atom table, thus leading to conflicts if we use 61 * the win32k atom table for this one. What is the right thing to do ? 62 */ 63 // AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE); 64 NtAddAtom(L"SysWNDO", 14, &AtomWndObj); 65 66 AtomLayer = IntAddGlobalAtom(L"SysLayer", TRUE); 67 AtomFlashWndState = IntAddGlobalAtom(L"FlashWState", TRUE); 68 69 return STATUS_SUCCESS; 70 } 71 72 /* FUNCTIONS ******************************************************************/ 73 74 INIT_FUNCTION 75 NTSTATUS 76 NTAPI 77 InitUserImpl(VOID) 78 { 79 NTSTATUS Status; 80 HKEY hKey; 81 82 ExInitializeResourceLite(&UserLock); 83 84 if (!UserCreateHandleTable()) 85 { 86 ERR("Failed creating handle table\n"); 87 return STATUS_INSUFFICIENT_RESOURCES; 88 } 89 90 Status = InitSessionImpl(); 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 120 UserInitialize(VOID) 121 { 122 static const DWORD wPattern55AA[] = /* 32 bit aligned */ 123 { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa, 124 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa }; 125 HBITMAP hPattern55AABitmap = NULL; 126 NTSTATUS Status; 127 128 NT_ASSERT(PsGetCurrentThreadWin32Thread() != NULL); 129 130 // Create Event for Disconnect Desktop. 131 132 Status = UserCreateWinstaDirectory(); 133 if (!NT_SUCCESS(Status)) return Status; 134 135 /* Initialize Video */ 136 Status = InitVideo(); 137 if (!NT_SUCCESS(Status)) return Status; 138 139 // { 140 // DrvInitConsole. 141 // DrvChangeDisplaySettings. 142 // Update Shared Device Caps. 143 // Initialize User Screen. 144 // } 145 146 // Set Global SERVERINFO Error flags. 147 // Load Resources. 148 149 NtUserUpdatePerUserSystemParameters(0, TRUE); 150 151 if (gpsi->hbrGray == NULL) 152 { 153 hPattern55AABitmap = GreCreateBitmap(8, 8, 1, 1, (LPBYTE)wPattern55AA); 154 if (hPattern55AABitmap == NULL) 155 return STATUS_INSUFFICIENT_RESOURCES; 156 157 gpsi->hbrGray = IntGdiCreatePatternBrush(hPattern55AABitmap); 158 159 if (gpsi->hbrGray == NULL) 160 return STATUS_INSUFFICIENT_RESOURCES; 161 } 162 163 return STATUS_SUCCESS; 164 } 165 166 /* 167 * Called from usersrv. 168 */ 169 NTSTATUS 170 APIENTRY 171 NtUserInitialize( 172 DWORD dwWinVersion, 173 HANDLE hPowerRequestEvent, 174 HANDLE hMediaRequestEvent) 175 { 176 NTSTATUS Status; 177 178 TRACE("Enter NtUserInitialize(%lx, %p, %p)\n", 179 dwWinVersion, hPowerRequestEvent, hMediaRequestEvent); 180 181 /* Check if we are already initialized */ 182 if (gpepCSRSS) 183 return STATUS_UNSUCCESSFUL; 184 185 /* Check Windows USER subsystem version */ 186 if (dwWinVersion != USER_VERSION) 187 { 188 // FIXME: Should bugcheck! 189 return STATUS_UNSUCCESSFUL; 190 } 191 192 /* Acquire exclusive lock */ 193 UserEnterExclusive(); 194 195 /* Save the EPROCESS of CSRSS */ 196 InitCsrProcess(/*PsGetCurrentProcess()*/); 197 198 // Initialize Power Request List (use hPowerRequestEvent). 199 // Initialize Media Change (use hMediaRequestEvent). 200 201 // InitializeGreCSRSS(); 202 // { 203 // Startup DxGraphics. 204 // calls ** UserGetLanguageID() and sets it **. 205 // Enables Fonts drivers, Initialize Font table & Stock Fonts. 206 // } 207 208 /* Initialize USER */ 209 Status = UserInitialize(); 210 211 /* Return */ 212 UserLeave(); 213 return Status; 214 } 215 216 217 /* 218 RETURN 219 True if current thread owns the lock (possibly shared) 220 */ 221 BOOL FASTCALL UserIsEntered(VOID) 222 { 223 return ExIsResourceAcquiredExclusiveLite(&UserLock) || 224 ExIsResourceAcquiredSharedLite(&UserLock); 225 } 226 227 BOOL FASTCALL UserIsEnteredExclusive(VOID) 228 { 229 return ExIsResourceAcquiredExclusiveLite(&UserLock); 230 } 231 232 VOID FASTCALL CleanupUserImpl(VOID) 233 { 234 ExDeleteResourceLite(&UserLock); 235 } 236 237 VOID FASTCALL UserEnterShared(VOID) 238 { 239 KeEnterCriticalRegion(); 240 ExAcquireResourceSharedLite(&UserLock, TRUE); 241 } 242 243 VOID FASTCALL UserEnterExclusive(VOID) 244 { 245 ASSERT_NOGDILOCKS(); 246 KeEnterCriticalRegion(); 247 ExAcquireResourceExclusiveLite(&UserLock, TRUE); 248 gptiCurrent = PsGetCurrentThreadWin32Thread(); 249 } 250 251 VOID FASTCALL UserLeave(VOID) 252 { 253 ASSERT_NOGDILOCKS(); 254 ASSERT(UserIsEntered()); 255 ExReleaseResourceLite(&UserLock); 256 KeLeaveCriticalRegion(); 257 } 258 259 /* EOF */ 260