From: "Rémi Bernon" Subject: [PATCH v2 3/3] ntdll: Use the new WineUsd service to map user shared data. Message-Id: <20191202133218.459945-4-rbernon@codeweavers.com> Date: Mon, 2 Dec 2019 14:32:18 +0100 In-Reply-To: <20191202133218.459945-1-rbernon@codeweavers.com> References: <20191202133218.459945-1-rbernon@codeweavers.com> 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 --- 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 ac146941236..e4e2de86a42 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -195,6 +195,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 204370a1b77..58d23e3e27e 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 621aaddfe34..f52cc2599b1 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.24.0