* 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().
This commit is contained in:
Christopher Faylor 2008-07-27 22:31:48 +00:00
parent b58e5f427a
commit 038af33480
5 changed files with 46 additions and 47 deletions

View File

@ -1,3 +1,17 @@
2008-07-27 Corinna Vinschen <corinna@vinschen.de>
Christopher Faylor <me+cygwin@cgf.cx>
* 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 <me+cygwin@cgf.cx> 2008-07-27 Christopher Faylor <me+cygwin@cgf.cx>
* mount.cc (mount_info::init): Add location where we're looking for * mount.cc (mount_info::init): Add location where we're looking for

View File

@ -752,20 +752,6 @@ dll_crt0_0 ()
events_init (); events_init ();
tty_list::init_session (); 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"); debug_printf ("finished dll_crt0_0 initialization");
} }
@ -778,11 +764,12 @@ dll_crt0_1 (void *)
{ {
check_sanity_and_sync (user_data); check_sanity_and_sync (user_data);
if (!dynamically_loaded) /* 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
malloc_init (); have overridden malloc. We only know about that at this stage,
user_shared_initialize_1 (); unfortunately. */
} malloc_init ();
user_shared_initialize ();
#ifdef CGF #ifdef CGF
int i = 0; int i = 0;

View File

@ -198,12 +198,13 @@ open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
return shared; return shared;
} }
/* User shared initialization which requires malloc and cygtls stuff has to /* Second half of user shared initialization: Initialize content. */
go here. */
void 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 ()); cygpsid sid (cygheap->user.sid ());
struct passwd *pw = internal_getpwsid (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->mountinfo.init (); /* Initialize the mount table. */
user_shared->cb = sizeof (*user_shared); 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 void
user_shared_initialize (bool reinit) user_shared_create (bool reinit)
{ {
char name[UNLEN + 1] = ""; /* Large enough for SID */ 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); debug_printf ("opening user shared for '%s' at %p", name, user_shared);
ProtectHandleINH (cygwin_user_h); ProtectHandleINH (cygwin_user_h);
debug_printf ("user shared version %x", user_shared->version); debug_printf ("user shared version %x", user_shared->version);
if (reinit)
DWORD sversion = (DWORD) InterlockedExchange ((LONG *) &user_shared->version, USER_VERSION_MAGIC); user_shared_initialize ();
/* 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));
}
} }
void __stdcall void __stdcall
@ -367,16 +368,14 @@ memory_init ()
} }
/* Initialize general shared memory */ /* 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_shared = (shared_info *) open_shared ("shared",
CYGWIN_VERSION_SHARED_DATA, CYGWIN_VERSION_SHARED_DATA,
cygwin_shared_h, cygwin_shared_h,
sizeof (*cygwin_shared), sizeof (*cygwin_shared),
sh_cygwin_shared); sh_cygwin_shared = SH_CYGWIN_SHARED);
cygwin_shared->initialize (); cygwin_shared->initialize ();
user_shared_create (false);
user_shared_initialize (false);
} }
unsigned unsigned

View File

@ -163,6 +163,7 @@ enum shared_locations
SH_JUSTOPEN SH_JUSTOPEN
}; };
void __stdcall memory_init (); void __stdcall memory_init ();
void __stdcall shared_destroy (); 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, void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size,
shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all, shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all,
DWORD access = FILE_MAP_READ | FILE_MAP_WRITE); DWORD access = FILE_MAP_READ | FILE_MAP_WRITE);
extern void user_shared_initialize (bool reinit); extern void user_shared_create (bool reinit);
extern void user_shared_initialize_1 (); extern void user_shared_initialize ();

View File

@ -2612,10 +2612,8 @@ seteuid32 (__uid32_t uid)
myself->uid = uid; myself->uid = uid;
groups.ischanged = FALSE; groups.ischanged = FALSE;
if (!issamesid) if (!issamesid)
{ /* Recreate and fill out the user shared region for a new user. */
user_shared_initialize (true); user_shared_create (true);
user_shared_initialize_1 ();
}
return 0; return 0;
} }