[UMPNPMGR]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 25 Sep 2014 23:44:28 +0000 (23:44 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 25 Sep 2014 23:44:28 +0000 (23:44 +0000)
- Turn the user-mode PnP Manager into a dll, as it is in Windows. However, on Windows 2k/XP/2k3, the dll is managed by services.exe (the SC Manager) (and its entry point name hardcoded in it), whereas on Vista/7+ it is managed by svchost.exe . Since we do not support external dll hardcoded services management in services.exe, make it svchost-compatible instead.
- In the .spec file, we mention that a few API set is exported (in stdcall), but we use it also for RPC, and therefore one has to fix somewhere the calling conventions.
- Add/modify the registry entries accordingly.

svn path=/trunk/; revision=64292

reactos/base/services/umpnpmgr/CMakeLists.txt
reactos/base/services/umpnpmgr/umpnpmgr.c
reactos/base/services/umpnpmgr/umpnpmgr.rc
reactos/base/services/umpnpmgr/umpnpmgr.spec [new file with mode: 0644]
reactos/boot/bootdata/hivesft.inf
reactos/boot/bootdata/hivesys.inf

index 9667d98..5987acf 100644 (file)
@@ -3,16 +3,19 @@ include_directories(${REACTOS_SOURCE_DIR}/include/reactos/idl)
 
 add_rpc_files(server ${REACTOS_SOURCE_DIR}/include/reactos/idl/pnp.idl)
 
+spec2def(umpnpmgr.dll umpnpmgr.spec ADD_IMPORTLIB)
 
-add_executable(umpnpmgr
+add_library(umpnpmgr SHARED
     umpnpmgr.c
     umpnpmgr.rc
-    ${CMAKE_CURRENT_BINARY_DIR}/pnp_s.c)
+    ${CMAKE_CURRENT_BINARY_DIR}/pnp_s.c
+    ${CMAKE_CURRENT_BINARY_DIR}/umpnpmgr_stubs.c
+    ${CMAKE_CURRENT_BINARY_DIR}/umpnpmgr.def)
 
 target_link_libraries(umpnpmgr
     wdmguid
     ${PSEH_LIB})
 
-set_module_type(umpnpmgr win32cui UNICODE)
+set_module_type(umpnpmgr win32dll UNICODE)
 add_importlibs(umpnpmgr advapi32 rpcrt4 userenv shlwapi msvcrt kernel32 ntdll)
 add_cd_file(TARGET umpnpmgr DESTINATION reactos/system32 FOR all)
index d8fbfa7..86da35e 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 /* INCLUDES *****************************************************************/
+
 //#define HAVE_SLIST_ENTRY_IMPLEMENTED
 #define WIN32_NO_STATUS
 #define _INC_WINDOWS
 
 /* GLOBALS ******************************************************************/
 
-static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
 static WCHAR ServiceName[] = L"PlugPlay";
-static SERVICE_TABLE_ENTRYW ServiceTable[] =
-{
-    {ServiceName, ServiceMain},
-    {NULL, NULL}
-};
 
 static SERVICE_STATUS_HANDLE ServiceStatusHandle;
 static SERVICE_STATUS ServiceStatus;
@@ -102,7 +97,7 @@ RpcServerThread(LPVOID lpParameter)
     DPRINT("RpcServerThread() called\n");
 
 #if 0
-    /* XP-compatible protocol sequence/endpoint */
+    /* 2k/XP/2k3-compatible protocol sequence/endpoint */
     Status = RpcServerUseProtseqEpW(L"ncacn_np",
                                     20,
                                     L"\\pipe\\ntsvcs",
@@ -113,7 +108,7 @@ RpcServerThread(LPVOID lpParameter)
         DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
 #endif
 
-    /* Vista-compatible protocol sequence/endpoint */
+    /* Vista/7-compatible protocol sequence/endpoint */
     Status = RpcServerUseProtseqEpW(L"ncacn_np",
                                     20,
                                     L"\\pipe\\plugplay",
@@ -1333,7 +1328,7 @@ DWORD PNP_GetClassRegProp(
         }
     }
 
-done:;
+done:
     if (ret == CR_SUCCESS)
         *pulTransferLen = *pulLength;
 
@@ -1438,7 +1433,7 @@ DWORD PNP_SetClassRegProp(
             ret = CR_REGISTRY_ERROR;
     }
 
-done:;
+done:
     if (hPropKey != NULL)
         RegCloseKey(hPropKey);
 
@@ -2642,7 +2637,7 @@ DWORD PNP_GetCustomDevProp(
         }
     }
 
-done:;
+done:
     if (ret == CR_SUCCESS)
         *pulTransferLen = *pulLength;
 
@@ -2792,7 +2787,9 @@ DWORD PNP_RegisterServiceNotification(
 
 /* Function 73 */
 DWORD PNP_SetActiveService(
-    handle_t hBinding)
+    handle_t hBinding,
+    LPWSTR pszFilter,
+    DWORD ulFlags)
 {
     UNIMPLEMENTED;
     return CR_CALL_NOT_IMPLEMENTED;
@@ -3309,7 +3306,7 @@ ServiceControlHandler(DWORD dwControl,
 }
 
 
-static VOID CALLBACK
+VOID WINAPI
 ServiceMain(DWORD argc, LPTSTR *argv)
 {
     HANDLE hThread;
@@ -3363,22 +3360,18 @@ ServiceMain(DWORD argc, LPTSTR *argv)
     DPRINT("ServiceMain() done\n");
 }
 
-
-int
-wmain(int argc, WCHAR *argv[])
+static DWORD
+InitializePnPManager(VOID)
 {
     BOOLEAN OldValue;
     DWORD dwError;
 
-    UNREFERENCED_PARAMETER(argc);
-    UNREFERENCED_PARAMETER(argv);
-
-    DPRINT("Umpnpmgr: main() started\n");
+    DPRINT("UMPNPMGR: InitializePnPManager() started\n");
 
     /* We need this privilege for using CreateProcessAsUserW */
     RtlAdjustPrivilege(SE_ASSIGNPRIMARYTOKEN_PRIVILEGE, TRUE, FALSE, &OldValue);
 
-    hInstallEvent = CreateEvent(NULL, TRUE, SetupIsActive()/*FALSE*/, NULL);
+    hInstallEvent = CreateEventW(NULL, TRUE, SetupIsActive()/*FALSE*/, NULL);
     if (hInstallEvent == NULL)
     {
         dwError = GetLastError();
@@ -3386,7 +3379,7 @@ wmain(int argc, WCHAR *argv[])
         return dwError;
     }
 
-    hDeviceInstallListNotEmpty = CreateEvent(NULL, FALSE, FALSE, NULL);
+    hDeviceInstallListNotEmpty = CreateEventW(NULL, FALSE, FALSE, NULL);
     if (hDeviceInstallListNotEmpty == NULL)
     {
         dwError = GetLastError();
@@ -3433,13 +3426,28 @@ wmain(int argc, WCHAR *argv[])
         return dwError;
     }
 
-    StartServiceCtrlDispatcher(ServiceTable);
+    DPRINT("UMPNPMGR: InitializePnPManager() done\n");
 
-    DPRINT("Umpnpmgr: main() done\n");
+    return 0;
+}
 
-    ExitThread(0);
+BOOL WINAPI
+DllMain(HINSTANCE hinstDLL,
+        DWORD fdwReason,
+        LPVOID lpvReserved)
+{
+    switch (fdwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            DisableThreadLibraryCalls(hinstDLL);
+            InitializePnPManager();
+            break;
 
-    return 0;
+        case DLL_PROCESS_DETACH:
+            break;
+    }
+
+    return TRUE;
 }
 
 /* EOF */
index 617c0c3..c884011 100644 (file)
@@ -1,4 +1,5 @@
-#define REACTOS_STR_FILE_DESCRIPTION  "User-Mode Plug and Play manager"
+#define REACTOS_VERSION_DLL
+#define REACTOS_STR_FILE_DESCRIPTION  "User-Mode Plug and Play Manager"
 #define REACTOS_STR_INTERNAL_NAME     "Umpnpmgr"
-#define REACTOS_STR_ORIGINAL_FILENAME "Umpnpmgr.exe"
+#define REACTOS_STR_ORIGINAL_FILENAME "umpnpmgr.dll"
 #include <reactos/version.rc>
diff --git a/reactos/base/services/umpnpmgr/umpnpmgr.spec b/reactos/base/services/umpnpmgr/umpnpmgr.spec
new file mode 100644 (file)
index 0000000..ba4214e
--- /dev/null
@@ -0,0 +1,15 @@
+@ stub DeleteServicePlugPlayRegKeys
+
+;;; FIXME: Windows UMPNPMGR exports those APIs.
+;;; Fix their calling convention before enabling these exports!!
+
+;@ stdcall PNP_GetDeviceList(long ptr ptr ptr long)
+;@ stdcall PNP_GetDeviceListSize(long ptr ptr long)
+;@ stdcall PNP_GetDeviceRegProp(long ptr long ptr ptr ptr ptr long)
+;@ stdcall PNP_HwProfFlags(long long ptr long ptr ptr ptr long long)
+;@ stdcall PNP_SetActiveService(long ptr long)
+
+@ stub RegisterScmCallback
+@ stub RegisterServiceNotification
+@ stdcall ServiceMain(long ptr) ;; If using SvcHost.exe (Vista+)
+;@ stdcall SvcEntry_PlugPlay(long long long long) ;; If using services.exe (<= 2k3)
index e98ac4d..6b6f473 100644 (file)
@@ -1588,7 +1588,8 @@ HKLM,"SOFTWARE\Microsoft\Ole","EnableRemoteConnect",0x00000000,"N"
 
 ; SvcHost services
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SvcHost",,0x00000012
-HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SvcHost", "netsvcs",0x00010000,"DHCP","BITS"
+HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SvcHost","DcomLaunch",0x00010000,"PlugPlay"
+HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SvcHost","netsvcs",0x00010000,"DHCP","BITS"
 
 ; Win32 config
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows",,0x00000012
index 17bbb36..23c775a 100644 (file)
@@ -1841,12 +1841,13 @@ HKLM,"SYSTEM\CurrentControlSet\Services\Pci\Parameters","101300D6101880D6",0x000
 ; Plug and Play manager
 HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","DisplayName",0x00000000,"Plug and Play"
 HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Description",0x00000000,"Detects hardware changes and installs needed software if possible"
-HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ErrorControl",0x00010001,0x00000000
+HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ErrorControl",0x00010001,0x00000001
 HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Group",0x00000000,"PlugPlay"
-HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ImagePath",0x00020000,"%SystemRoot%\system32\umpnpmgr.exe"
+HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ImagePath",0x00020000,"%SystemRoot%\system32\svchost.exe -k DcomLaunch"
 HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ObjectName",0x00000000,"LocalSystem"
-HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Start",0x00010001,0x00000004
-HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Type",0x00010001,0x00000010
+HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Start",0x00010001,0x00000002
+HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Type",0x00010001,0x00000020
+HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay\Parameters","ServiceDll",0x00020000,"%SystemRoot%\system32\umpnpmgr.dll"
 
 ; RPC service
 HKLM,"SYSTEM\CurrentControlSet\Services\Rpcss","DisplayName",0x00000000,"Remote Procedure Call"