From 038af33480450d3092adb520ce0974cb23efde9c Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 27 Jul 2008 22:31:48 +0000 Subject: [PATCH] * dcrt0.cc (dll_crt0_0): Remove calling malloc_init and user_shared_initialize_1 from here. (dll_crt0_1): Remove dynamically_loaded check. Just call malloc_init and user_shared_initialize unconditionally. * shared.cc (user_shared_create): Rename from user_shared_initialize. (user_shared_initialize): Rename from user_shared_initialize_1. Move complete user_shared content initialization code here from user_shared_create. * syscalls.cc (seteuid32): Remove call to user_shared_initialize_1. That is implied by the "true" argument to user_shared_create(). --- winsup/cygwin/ChangeLog | 14 ++++++++++++ winsup/cygwin/dcrt0.cc | 25 ++++++--------------- winsup/cygwin/shared.cc | 43 ++++++++++++++++++------------------- winsup/cygwin/shared_info.h | 5 +++-- winsup/cygwin/syscalls.cc | 6 ++---- 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 6bc80e9bf..5d2dd3ede 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2008-07-27 Corinna Vinschen + Christopher Faylor + + * dcrt0.cc (dll_crt0_0): Remove calling malloc_init and + user_shared_initialize_1 from here. + (dll_crt0_1): Remove dynamically_loaded check. Just call malloc_init + and user_shared_initialize unconditionally. + * shared.cc (user_shared_create): Rename from user_shared_initialize. + (user_shared_initialize): Rename from user_shared_initialize_1. Move + complete user_shared content initialization code here from + user_shared_create. + * syscalls.cc (seteuid32): Remove call to user_shared_initialize_1. + That is implied by the "true" argument to user_shared_create(). + 2008-07-27 Christopher Faylor * mount.cc (mount_info::init): Add location where we're looking for diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 5c85eb834..6b2d283fd 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -752,20 +752,6 @@ dll_crt0_0 () events_init (); tty_list::init_session (); - if (dynamically_loaded) - { - /* When dynamically loaded. we must initialize the user shared memory - entirely here since dll_crt0_1 will not be called. Stuff in - user_shared_initialize_1 relies on malloc and cygtls being available - and the initialization isn't finished without calling it. In the - non-dynamical case this is called in dll_crt0_1, because malloc_init - has to test for overloaded malloc functionality in the application. - That's not an issue when cygwin is loaded dynamically. It will just - use its own malloc area. */ - malloc_init (); - user_shared_initialize_1 (); - } - debug_printf ("finished dll_crt0_0 initialization"); } @@ -778,11 +764,12 @@ dll_crt0_1 (void *) { check_sanity_and_sync (user_data); - if (!dynamically_loaded) - { - malloc_init (); - user_shared_initialize_1 (); - } + /* Initialize malloc and then call user_shared_initialize since it relies + on a functioning malloc and it's possible that the user's program may + have overridden malloc. We only know about that at this stage, + unfortunately. */ + malloc_init (); + user_shared_initialize (); #ifdef CGF int i = 0; diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 23a8d992d..5989dbd1a 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -198,12 +198,13 @@ open_shared (const char *name, int n, HANDLE& shared_h, DWORD size, return shared; } -/* User shared initialization which requires malloc and cygtls stuff has to - go here. */ +/* Second half of user shared initialization: Initialize content. */ void -user_shared_initialize_1 () +user_shared_initialize () { - if (!user_shared->cb) + DWORD sversion = (DWORD) InterlockedExchange ((LONG *) &user_shared->version, USER_VERSION_MAGIC); + /* Wait for initialization of the Cygwin per-user shared, if necessary */ + if (!sversion) { cygpsid sid (cygheap->user.sid ()); struct passwd *pw = internal_getpwsid (sid); @@ -214,10 +215,20 @@ user_shared_initialize_1 () user_shared->mountinfo.init (); /* Initialize the mount table. */ user_shared->cb = sizeof (*user_shared); } + else + { + while (!user_shared->cb) + low_priority_sleep (0); // Should be hit only very very rarely + if (user_shared->version != sversion) + multiple_cygwin_problem ("user shared memory version", user_shared->version, sversion); + else if (user_shared->cb != sizeof (*user_shared)) + multiple_cygwin_problem ("user shared memory size", user_shared->cb, sizeof (*user_shared)); + } } +/* First half of user shared initialization: Create shared mem region. */ void -user_shared_initialize (bool reinit) +user_shared_create (bool reinit) { char name[UNLEN + 1] = ""; /* Large enough for SID */ @@ -240,18 +251,8 @@ user_shared_initialize (bool reinit) debug_printf ("opening user shared for '%s' at %p", name, user_shared); ProtectHandleINH (cygwin_user_h); debug_printf ("user shared version %x", user_shared->version); - - DWORD sversion = (DWORD) InterlockedExchange ((LONG *) &user_shared->version, USER_VERSION_MAGIC); - /* Wait for initialization of the Cygwin per-user shared, if necessary */ - if (sversion) - { - while (!user_shared->cb) - low_priority_sleep (0); // Should be hit only very very rarely - if (user_shared->version != sversion) - multiple_cygwin_problem ("user shared memory version", user_shared->version, sversion); - else if (user_shared->cb != sizeof (*user_shared)) - multiple_cygwin_problem ("user shared memory size", user_shared->cb, sizeof (*user_shared)); - } + if (reinit) + user_shared_initialize (); } void __stdcall @@ -367,16 +368,14 @@ memory_init () } /* Initialize general shared memory */ - shared_locations sh_cygwin_shared = SH_CYGWIN_SHARED; + shared_locations sh_cygwin_shared; cygwin_shared = (shared_info *) open_shared ("shared", CYGWIN_VERSION_SHARED_DATA, cygwin_shared_h, sizeof (*cygwin_shared), - sh_cygwin_shared); - + sh_cygwin_shared = SH_CYGWIN_SHARED); cygwin_shared->initialize (); - - user_shared_initialize (false); + user_shared_create (false); } unsigned diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h index 45b347014..91aca2a52 100644 --- a/winsup/cygwin/shared_info.h +++ b/winsup/cygwin/shared_info.h @@ -163,6 +163,7 @@ enum shared_locations SH_JUSTOPEN }; + void __stdcall memory_init (); void __stdcall shared_destroy (); @@ -185,6 +186,6 @@ char *__stdcall shared_name (char *, const char *, int); void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all, DWORD access = FILE_MAP_READ | FILE_MAP_WRITE); -extern void user_shared_initialize (bool reinit); -extern void user_shared_initialize_1 (); +extern void user_shared_create (bool reinit); +extern void user_shared_initialize (); diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index a5bca574d..bb74dff26 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2612,10 +2612,8 @@ seteuid32 (__uid32_t uid) myself->uid = uid; groups.ischanged = FALSE; if (!issamesid) - { - user_shared_initialize (true); - user_shared_initialize_1 (); - } + /* Recreate and fill out the user shared region for a new user. */ + user_shared_create (true); return 0; }