[PATCH resend 3/3] ntdll: Use the new WineUsd service to map user shared data.

Rémi Bernon rbernon at codeweavers.com
Mon Feb 10 05:37:36 CST 2020


If the device cannot be opened, then the service may not be started yet,
or the current process is the service itself. In which case, we can
ignore the error and continue as before without timestamp updates.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

Notes:
    When submitting the patch on testbot, the service was not started
    and the test failed. It may be the same there and I think the
    wine.inf update requires a server restart to be accounted for. I'm
    not sure how to force the new service to start right away.

 dlls/ntdll/ntdll_misc.h |  1 +
 dlls/ntdll/server.c     |  2 ++
 dlls/ntdll/tests/time.c |  1 -
 dlls/ntdll/thread.c     | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index e1fb1e9eba7..3ef4bf5a88a 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -197,6 +197,7 @@ extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
 extern void virtual_fill_image_information( const pe_image_info_t *pe_info,
                                             SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
 extern struct _KUSER_SHARED_DATA *user_shared_data DECLSPEC_HIDDEN;
+extern void user_shared_data_init(void);
 
 /* completion */
 extern NTSTATUS NTDLL_AddCompletion( HANDLE hFile, ULONG_PTR CompletionValue,
diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index 089eb3b89aa..1fc902b1f29 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -1471,6 +1471,8 @@ void server_init_process_done(void)
     }
     SERVER_END_REQ;
 
+    user_shared_data_init();
+
     assert( !status );
     signal_start_process( entry, suspend );
 }
diff --git a/dlls/ntdll/tests/time.c b/dlls/ntdll/tests/time.c
index be6859fe3e1..3c5fbbb857d 100644
--- a/dlls/ntdll/tests/time.c
+++ b/dlls/ntdll/tests/time.c
@@ -172,7 +172,6 @@ static void test_NtGetTickCount(void)
     {
         diff = (user_shared_data->u.TickCountQuad * user_shared_data->TickCountMultiplier) >> 24;
         diff = pNtGetTickCount() - diff;
-        todo_wine
         ok(diff < 100, "NtGetTickCount - TickCountQuad too high, expected < 100 got %d\n", diff);
         Sleep(50);
     }
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index f993dd314c3..8895d4f790e 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -46,10 +46,12 @@
 #include "wine/server.h"
 #include "wine/debug.h"
 #include "ntdll_misc.h"
+#include "wine/usd.h"
 #include "ddk/wdm.h"
 #include "wine/exception.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(thread);
+WINE_DECLARE_DEBUG_CHANNEL(wineusd);
 
 #ifndef PTHREAD_STACK_MIN
 #define PTHREAD_STACK_MIN 16384
@@ -212,6 +214,38 @@ static void set_process_name( int argc, char *argv[] )
 #endif  /* HAVE_PRCTL */
 }
 
+void user_shared_data_init(void)
+{
+    static const WCHAR device_nameW[] = {'\\','D','e','v','i','c','e','\\','W','i','n','e','U','s','d',0};
+    struct _KUSER_SHARED_DATA data = *user_shared_data;
+    OBJECT_ATTRIBUTES attr = {sizeof(attr)};
+    UNICODE_STRING string;
+    IO_STATUS_BLOCK io;
+    NTSTATUS status;
+    HANDLE device;
+    void *addr = user_shared_data;
+    SIZE_T size = 0;
+
+    RtlInitUnicodeString( &string, device_nameW );
+    attr.ObjectName = &string;
+    if ((status = NtCreateFile( &device, 0, &attr, &io, NULL,
+                                FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN,
+                                FILE_NON_DIRECTORY_FILE, NULL, 0 )))
+    {
+        WARN_(wineusd)( "Failed to open user shared data device, status: %x.\n", status );
+        return;
+    }
+
+    NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
+
+    if ((status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &io,
+                                         IOCTL_WINEUSD_INITIALIZE,
+                                         &data, sizeof(data), NULL, 0 )))
+    {
+        MESSAGE( "wine: failed to map the shared user data: %08x\n", status );
+        exit(1);
+    }
+}
 
 /***********************************************************************
  *           thread_init
-- 
2.25.0




More information about the wine-devel mailing list