=?UTF-8?Q?Michael=20M=C3=BCller=20?=: winedevice: Call DriverUnload function when unloading a driver.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Feb 24 10:33:23 CST 2015


Module: wine
Branch: master
Commit: a8b000c54d57e21e80c30b0e8faf0196a2e09541
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a8b000c54d57e21e80c30b0e8faf0196a2e09541

Author: Michael Müller <michael at fds-team.de>
Date:   Mon Jan 26 04:31:10 2015 +0100

winedevice: Call DriverUnload function when unloading a driver.

Based on a patch by Alexander Morozov.

---

 programs/winedevice/device.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/programs/winedevice/device.c b/programs/winedevice/device.c
index 72bc124..9677a82 100644
--- a/programs/winedevice/device.c
+++ b/programs/winedevice/device.c
@@ -167,8 +167,26 @@ static NTSTATUS init_driver( HMODULE module, UNICODE_STRING *keyname )
     return status;
 }
 
+/* call the driver unload function */
+static void unload_driver( HMODULE module, DRIVER_OBJECT *driver_obj )
+{
+    if (driver_obj->DriverUnload)
+    {
+        if (WINE_TRACE_ON(relay))
+            WINE_DPRINTF( "%04x:Call driver unload %p (obj=%p)\n", GetCurrentThreadId(),
+                          driver_obj->DriverUnload, driver_obj );
+
+        driver_obj->DriverUnload( driver_obj );
+
+        if (WINE_TRACE_ON(relay))
+            WINE_DPRINTF( "%04x:Ret  driver unload %p (obj=%p)\n", GetCurrentThreadId(),
+                          driver_obj->DriverUnload, driver_obj );
+    }
+    FreeLibrary( module );
+}
+
 /* load the .sys module for a device driver */
-static BOOL load_driver(void)
+static HMODULE load_driver(void)
 {
     static const WCHAR driversW[] = {'\\','d','r','i','v','e','r','s','\\',0};
     static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t','\\',0};
@@ -249,10 +267,10 @@ static BOOL load_driver(void)
 
     module = load_driver_module( str );
     HeapFree( GetProcessHeap(), 0, path );
-    if (!module) return FALSE;
+    if (!module) return NULL;
 
     init_driver( module, &keypath );
-    return TRUE;
+    return module;
 }
 
 static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
@@ -287,6 +305,7 @@ static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_
 static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
 {
     SERVICE_STATUS status;
+    HMODULE driver_module;
 
     WINE_TRACE( "starting service %s\n", wine_dbgstr_w(driver_name) );
 
@@ -305,13 +324,15 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
     status.dwWaitHint                = 10000;
     SetServiceStatus( service_handle, &status );
 
-    if (load_driver())
+    driver_module = load_driver();
+    if (driver_module)
     {
         status.dwCurrentState     = SERVICE_RUNNING;
         status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
         SetServiceStatus( service_handle, &status );
 
         wine_ntoskrnl_main_loop( stop_event );
+        unload_driver( driver_module, &driver_obj );
     }
     else WINE_ERR( "driver %s failed to load\n", wine_dbgstr_w(driver_name) );
 




More information about the wine-cvs mailing list