Author: hbelusca Date: Wed Dec 17 00:33:40 2014 New Revision: 65696
URL: http://svn.reactos.org/svn/reactos?rev=65696&view=rev Log: [WIN32K] - Simplify NtUserInitialize: we can check whether gpepCSRSS is != NULL to see if we are initialized or not (instead of using gbInitialized). - The UserInitialize helper doesn't need to take parameters. The two event handles (power and media, used when we receive a power event -- for sleep, etc... -- and a media event -- like USB key insertion and such --) just need to be used in the not-yet-implemented "Initialize Power Request List" and "Initialize Media Change" steps. - Something that should be done is to bugcheck if the USER version reported is != 5.0 (as windows does).
[WINSRV] - Collapse common inclusions from usersrv and consrv into the common header winsrv.h.
[USERSRV] - _UserSoundSentry is NTAPI - Stub UserClientConnect (Timo's patch contains more involved code. I will commit it later). - Our NtUserInitialize(0, NULL, NULL); call (that made Windows BSOD) is wrong. It should be done with its first parameter correctly set to the USER version (5.0) and the two other parameters are handles to power and media events (see above). We should create them before. This is part of patch by Timo Kreuzer. CORE-7505 #comment UserClientConnect stubbed (it should be better implemented, I will commit the code from the patch later on); power&media events initialized; NtUserInitialize corrected.
Modified: trunk/reactos/win32ss/include/ntuser.h trunk/reactos/win32ss/user/ntuser/misc.c trunk/reactos/win32ss/user/ntuser/ntstubs.c trunk/reactos/win32ss/user/ntuser/ntuser.c trunk/reactos/win32ss/user/ntuser/ntuser.h trunk/reactos/win32ss/user/winsrv/consrv/consrv.h trunk/reactos/win32ss/user/winsrv/usersrv/api.h trunk/reactos/win32ss/user/winsrv/usersrv/init.c trunk/reactos/win32ss/user/winsrv/usersrv/usersrv.h trunk/reactos/win32ss/user/winsrv/winsrv.h
Modified: trunk/reactos/win32ss/include/ntuser.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/include/ntuser.h?re... ============================================================================== --- trunk/reactos/win32ss/include/ntuser.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/include/ntuser.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -1029,6 +1029,9 @@ DWORD dwDispatchCount; SHAREDINFO siClient; } USERCONNECT, *PUSERCONNECT; + +// WinNT 5.0 compatible user32 / win32k +#define USER_VERSION MAKELONG(0x0000, 0x0005)
typedef struct tagGETCLIPBDATA {
Modified: trunk/reactos/win32ss/user/ntuser/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/misc.c?... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/misc.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/misc.c [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -697,7 +697,7 @@ { /* Make sure that the first syscall is NtUserInitialize */ /* too bad this fails */ - //ASSERT(gbInitialized); + // ASSERT(gpepCSRSS);
UserDbgAssertThreadInfo(TRUE);
Modified: trunk/reactos/win32ss/user/ntuser/ntstubs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/ntstubs... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -890,7 +890,6 @@ IN USERTHREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength) - { NTSTATUS Status = STATUS_SUCCESS; PETHREAD Thread;
Modified: trunk/reactos/win32ss/user/ntuser/ntuser.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/ntuser.... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/ntuser.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/ntuser.c [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -17,7 +17,6 @@ ATOM AtomWndObj; // Window Object atom. ATOM AtomLayer; // Window Layer atom. ATOM AtomFlashWndState; // Window Flash State atom. -BOOL gbInitialized; HINSTANCE hModClient = NULL; BOOL ClientPfnInit = FALSE; PEPROCESS gpepCSRSS = NULL; @@ -98,9 +97,7 @@
NTSTATUS NTAPI -UserInitialize( - HANDLE hPowerRequestEvent, - HANDLE hMediaRequestEvent) +UserInitialize(VOID) { static const DWORD wPattern55AA[] = /* 32 bit aligned */ { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa, @@ -153,7 +150,7 @@ }
/* - Called from win32csr. + * Called from usersrv. */ NTSTATUS APIENTRY @@ -167,27 +164,26 @@ TRACE("Enter NtUserInitialize(%lx, %p, %p)\n", dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
- /* Check the Windows version */ - if (dwWinVersion != 0) + /* Check if we are already initialized */ + if (gpepCSRSS) + return STATUS_UNSUCCESSFUL; + + /* Check Windows USER subsystem version */ + if (dwWinVersion != USER_VERSION) { + // FIXME: Should bugcheck! return STATUS_UNSUCCESSFUL; }
/* Acquire exclusive lock */ UserEnterExclusive();
- /* Check if we are already initialized */ - if (gbInitialized) - { - UserLeave(); - return STATUS_UNSUCCESSFUL; - } - - /* Save EPROCESS of CSRSS */ + /* Save the EPROCESS of CSRSS */ gpepCSRSS = PsGetCurrentProcess();
-// Initialize Power Request List. -// Initialize Media Change. +// Initialize Power Request List (use hPowerRequestEvent). +// Initialize Media Change (use hMediaRequestEvent). + // InitializeGreCSRSS(); // { // Startup DxGraphics. @@ -196,10 +192,7 @@ // }
/* Initialize USER */ - Status = UserInitialize(hPowerRequestEvent, hMediaRequestEvent); - - /* Set us as initialized */ - gbInitialized = TRUE; + Status = UserInitialize();
/* Return */ UserLeave();
Modified: trunk/reactos/win32ss/user/ntuser/ntuser.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/ntuser.... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/ntuser.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/ntuser.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -9,7 +9,6 @@ #define UserEnterCo UserEnterExclusive #define UserLeaveCo UserLeave
-extern BOOL gbInitialized; extern PSERVERINFO gpsi; extern PTHREADINFO gptiCurrent; extern PPROCESSINFO gppiList;
Modified: trunk/reactos/win32ss/user/winsrv/consrv/consrv.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv/... ============================================================================== --- trunk/reactos/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -22,7 +22,6 @@ #include <wincon.h>
#define NTOS_MODE_USER -#include <ndk/exfuncs.h> #include <ndk/mmfuncs.h>
/* CONSOLE Headers */
Modified: trunk/reactos/win32ss/user/winsrv/usersrv/api.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/usersrv... ============================================================================== --- trunk/reactos/win32ss/user/winsrv/usersrv/api.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/usersrv/api.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -9,7 +9,7 @@ #pragma once
/* init.c */ -BOOL WINAPI _UserSoundSentry(VOID); +BOOL NTAPI _UserSoundSentry(VOID); CSR_API(SrvCreateSystemThreads); CSR_API(SrvActivateDebugger); CSR_API(SrvGetThreadConsoleDesktop);
Modified: trunk/reactos/win32ss/user/winsrv/usersrv/init.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/usersrv... ============================================================================== --- trunk/reactos/win32ss/user/winsrv/usersrv/init.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/usersrv/init.c [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -19,6 +19,10 @@ /* GLOBALS ********************************************************************/
HINSTANCE UserServerDllInstance = NULL; + +/* Handles for Power and Media events. Used by both usersrv and win32k. */ +HANDLE ghPowerRequestEvent; +HANDLE ghMediaRequestEvent;
/* Memory */ HANDLE UserServerHeap = NULL; // Our own heap. @@ -84,7 +88,7 @@ /* FUNCTIONS ******************************************************************/
// PUSER_SOUND_SENTRY. Used in basesrv.dll -BOOL WINAPI _UserSoundSentry(VOID) +BOOL NTAPI _UserSoundSentry(VOID) { // TODO: Do something. return TRUE; @@ -128,6 +132,35 @@ { DPRINT1("%s not yet implemented\n", __FUNCTION__); return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS +NTAPI +UserClientConnect(IN PCSR_PROCESS CsrProcess, + IN OUT PVOID ConnectionInfo, + IN OUT PULONG ConnectionInfoLength) +{ + DPRINT1("UserClientConnect\n"); + +#if 0 + // NTSTATUS Status = STATUS_SUCCESS; + PBASESRV_API_CONNECTINFO ConnectInfo = (PBASESRV_API_CONNECTINFO)ConnectionInfo; + + if ( ConnectionInfo == NULL || + ConnectionInfoLength == NULL || + *ConnectionInfoLength != sizeof(*ConnectInfo) ) + { + DPRINT1("BASESRV: Connection failed - ConnectionInfo = 0x%p ; ConnectionInfoLength = 0x%p (%lu), expected %lu\n", + ConnectionInfo, + ConnectionInfoLength, + ConnectionInfoLength ? *ConnectionInfoLength : (ULONG)-1, + sizeof(*ConnectInfo)); + + return STATUS_INVALID_PARAMETER; + } +#else + return STATUS_SUCCESS; +#endif }
CSR_SERVER_DLL_INIT(UserServerDllInitialization) @@ -141,9 +174,6 @@
/* Initialize the memory */ UserServerHeap = RtlGetProcessHeap(); - - /* Initialize the video */ - NtUserInitialize(0, NULL, NULL);
/* Setup the DLL Object */ LoadedServerDll->ApiBase = USERSRV_FIRST_API_NUMBER; @@ -154,7 +184,7 @@ LoadedServerDll->NameTable = UserServerApiNameTable; #endif LoadedServerDll->SizeOfProcessData = 0; - LoadedServerDll->ConnectCallback = NULL; + LoadedServerDll->ConnectCallback = UserClientConnect; LoadedServerDll->DisconnectCallback = NULL; LoadedServerDll->HardErrorCallback = UserServerHardError; LoadedServerDll->ShutdownProcessCallback = UserClientShutdown; @@ -175,9 +205,45 @@ NtClose(ServerThread); } else + { DPRINT1("Cannot start Raw Input Thread!\n"); + } } /*** END - From win32csr... ***/ + + /* Create the power request event */ + Status = NtCreateEvent(&ghPowerRequestEvent, + EVENT_ALL_ACCESS, + NULL, + SynchronizationEvent, + FALSE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Power request event creation failed with Status 0x%08x\n", Status); + return Status; + } + + /* Create the media request event */ + Status = NtCreateEvent(&ghMediaRequestEvent, + EVENT_ALL_ACCESS, + NULL, + SynchronizationEvent, + FALSE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Media request event creation failed with Status 0x%08x\n", Status); + return Status; + } + + /* Initialize the kernel mode subsystem */ + Status = NtUserInitialize(USER_VERSION, + ghPowerRequestEvent, + ghMediaRequestEvent); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtUserInitialize failed with Status 0x%08x\n", Status); + return Status; + }
/* All done */ return STATUS_SUCCESS;
Modified: trunk/reactos/win32ss/user/winsrv/usersrv/usersrv.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/usersrv... ============================================================================== --- trunk/reactos/win32ss/user/winsrv/usersrv/usersrv.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/usersrv/usersrv.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -9,6 +9,9 @@ #ifndef __USERSRV_H__ #define __USERSRV_H__
+/* Main header */ +#include "../winsrv.h" + /* PSDK/NDK Headers */ #include <stdarg.h>
@@ -16,21 +19,7 @@ #define _INC_WINDOWS #define COM_NO_WINDOWS_H
-#include <windef.h> -#include <winbase.h> -#include <wingdi.h> -#include <winuser.h> - -#define NTOS_MODE_USER -#include <ndk/obfuncs.h> -#include <ndk/psfuncs.h> -#include <ndk/rtlfuncs.h> - -/* Public Win32K Headers */ -#include <ntuser.h> - -/* CSRSS Header */ -#include <csr/csrsrv.h> +// #define NTOS_MODE_USER
/* USER Headers */ #include <win/winmsg.h>
Modified: trunk/reactos/win32ss/user/winsrv/winsrv.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/winsrv.... ============================================================================== --- trunk/reactos/win32ss/user/winsrv/winsrv.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/winsrv.h [iso-8859-1] Wed Dec 17 00:33:40 2014 @@ -21,11 +21,13 @@ #include <winbase.h> #include <wingdi.h> #include <winuser.h> + /* Undocumented user definitions */ #include <undocuser.h>
#define NTOS_MODE_USER #include <ndk/cmfuncs.h> +#include <ndk/exfuncs.h> #include <ndk/obfuncs.h> #include <ndk/psfuncs.h> #include <ndk/rtlfuncs.h>