Alexandre Julliard : ntdll: Move mapping of the user shared data to the Unix library.
Alexandre Julliard
julliard at winehq.org
Thu Jun 4 16:08:01 CDT 2020
Module: wine
Branch: master
Commit: 4ffe39573b537d638e4b39c9b5990c6566d62b09
URL: https://source.winehq.org/git/wine.git/?a=commit;h=4ffe39573b537d638e4b39c9b5990c6566d62b09
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Jun 4 19:48:26 2020 +0200
ntdll: Move mapping of the user shared data to the Unix library.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/loader.c | 1 -
dlls/ntdll/ntdll_misc.h | 1 -
dlls/ntdll/thread.c | 47 +-----------------------------------------
dlls/ntdll/unix/thread.c | 2 ++
dlls/ntdll/unix/unix_private.h | 1 +
dlls/ntdll/unix/virtual.c | 44 +++++++++++++++++++++++++++++++++++++++
6 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 1dbb073963..45d32399ad 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -4392,7 +4392,6 @@ void __wine_process_init(void)
FILE_umask = umask(0777);
umask( FILE_umask );
- map_user_shared_data();
load_global_options();
version_init();
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index f2a1baf17f..65c65cc02d 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -176,7 +176,6 @@ extern NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_S
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 map_user_shared_data(void) DECLSPEC_HIDDEN;
/* completion */
extern NTSTATUS NTDLL_AddCompletion( HANDLE hFile, ULONG_PTR CompletionValue,
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 2d4fbe6cbe..8918b39a9c 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -49,7 +49,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(thread);
WINE_DECLARE_DEBUG_CHANNEL(relay);
-struct _KUSER_SHARED_DATA *user_shared_data = NULL;
+struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) = NULL;
@@ -173,33 +173,6 @@ int __cdecl __wine_dbg_output( const char *str )
return unix_funcs->dbg_output( str );
}
-void map_user_shared_data(void)
-{
- static const WCHAR wine_usdW[] = {'\\','K','e','r','n','e','l','O','b','j','e','c','t','s',
- '\\','_','_','w','i','n','e','_','u','s','e','r','_','s','h','a','r','e','d','_','d','a','t','a',0};
- OBJECT_ATTRIBUTES attr = {sizeof(attr)};
- UNICODE_STRING wine_usd_str;
- NTSTATUS status;
- HANDLE section;
- int res, fd, needs_close;
-
- RtlInitUnicodeString( &wine_usd_str, wine_usdW );
- InitializeObjectAttributes( &attr, &wine_usd_str, OBJ_OPENIF, NULL, NULL );
- if ((status = NtOpenSection( §ion, SECTION_ALL_ACCESS, &attr )))
- {
- MESSAGE( "wine: failed to open the USD section: %08x\n", status );
- exit(1);
- }
- if ((res = unix_funcs->server_get_unix_fd( section, 0, &fd, &needs_close, NULL, NULL )) ||
- (user_shared_data != mmap( user_shared_data, sizeof(*user_shared_data),
- PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0 )))
- {
- MESSAGE( "wine: failed to remap the process USD: %d\n", res );
- exit(1);
- }
- if (needs_close) close( fd );
- NtClose( section );
-}
/***********************************************************************
* thread_init
@@ -211,27 +184,9 @@ void map_user_shared_data(void)
TEB *thread_init( SIZE_T *info_size, BOOL *suspend )
{
TEB *teb;
- void *addr;
- SIZE_T size;
- NTSTATUS status;
virtual_init();
- /* reserve space for shared user data */
-
- addr = (void *)0x7ffe0000;
- size = 0x1000;
- status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size,
- MEM_RESERVE|MEM_COMMIT, PAGE_READONLY );
- if (status)
- {
- MESSAGE( "wine: failed to map the shared user data: %08x\n", status );
- exit(1);
- }
- user_shared_data = addr;
-
- /* allocate and initialize the PEB and initial TEB */
-
teb = unix_funcs->init_threading( &nb_threads, &__wine_ldt_copy, info_size, suspend, &server_cpus,
&is_wow64, &server_start_time );
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c
index 3c69dfbd64..1d84c7173a 100644
--- a/dlls/ntdll/unix/thread.c
+++ b/dlls/ntdll/unix/thread.c
@@ -107,6 +107,8 @@ TEB * CDECL init_threading( int *nb_threads_ptr, struct ldt_copy **ldt_copy, SIZ
dbg_init();
server_init_process();
info_size = server_init_thread( teb->Peb, suspend );
+ virtual_map_user_shared_data();
+
if (size) *size = info_size;
if (cpus) *cpus = server_cpus;
if (wow64) *wow64 = is_wow64;
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index 962774f8c1..ce751c9030 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -134,6 +134,7 @@ extern void virtual_init(void) DECLSPEC_HIDDEN;
extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_alloc_teb( TEB **ret_teb ) DECLSPEC_HIDDEN;
extern void virtual_free_teb( TEB *teb ) DECLSPEC_HIDDEN;
+extern void virtual_map_user_shared_data(void) DECLSPEC_HIDDEN;
extern void signal_init_threading(void) DECLSPEC_HIDDEN;
extern NTSTATUS signal_alloc_thread( TEB *teb ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index d768f32f12..7c5b5d5cf1 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -161,6 +161,8 @@ static void *user_space_limit = (void *)0x7fff0000;
static void *working_set_limit = (void *)0x7fff0000;
#endif
+static struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
+
SIZE_T signal_stack_size = 0;
SIZE_T signal_stack_mask = 0;
static SIZE_T signal_stack_align;
@@ -2543,10 +2545,21 @@ TEB *virtual_alloc_first_teb(void)
{
TEB *teb;
PEB *peb;
+ NTSTATUS status;
+ SIZE_T data_size = page_size;
SIZE_T peb_size = page_size;
SIZE_T teb_size = signal_stack_mask + 1;
SIZE_T total = 32 * teb_size;
+ /* reserve space for shared user data */
+ status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&user_shared_data, 0, &data_size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_READONLY );
+ if (status)
+ {
+ ERR( "wine: failed to map the shared user data: %08x\n", status );
+ exit(1);
+ }
+
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&teb_block, 0, &total,
MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE );
teb_block_pos = 30;
@@ -2733,6 +2746,37 @@ void virtual_clear_thread_stack( void *stack_end )
}
+/***********************************************************************
+ * virtual_map_user_shared_data
+ */
+void virtual_map_user_shared_data(void)
+{
+ static const WCHAR wine_usdW[] = {'\\','K','e','r','n','e','l','O','b','j','e','c','t','s',
+ '\\','_','_','w','i','n','e','_','u','s','e','r','_','s','h','a','r','e','d','_','d','a','t','a',0};
+ OBJECT_ATTRIBUTES attr = {sizeof(attr)};
+ UNICODE_STRING wine_usd_str;
+ NTSTATUS status;
+ HANDLE section;
+ int res, fd, needs_close;
+
+ RtlInitUnicodeString( &wine_usd_str, wine_usdW );
+ InitializeObjectAttributes( &attr, &wine_usd_str, OBJ_OPENIF, NULL, NULL );
+ if ((status = NtOpenSection( §ion, SECTION_ALL_ACCESS, &attr )))
+ {
+ ERR( "failed to open the USD section: %08x\n", status );
+ exit(1);
+ }
+ if ((res = server_get_unix_fd( section, 0, &fd, &needs_close, NULL, NULL )) ||
+ (user_shared_data != mmap( user_shared_data, page_size, PROT_READ, MAP_SHARED|MAP_FIXED, fd, 0 )))
+ {
+ ERR( "failed to remap the process USD: %d\n", res );
+ exit(1);
+ }
+ if (needs_close) close( fd );
+ NtClose( section );
+}
+
+
/***********************************************************************
* virtual_handle_fault
*/
More information about the wine-cvs
mailing list