* dcrt0.cc (dll_crt0_0): Call malloc_init and user_shared_initialize_1
here in case we're dynamically loaded. Explain why. (dll_crt0_1): Call user_shared_initialize_1 from here. * mount.cc (is_native_path): New inline function testing for native and long Win32 path prefix. (is_unc_share): Remove long WIn32 path prefix test. (mount_info::create_root_entry): Use PATH_MAX buffer. (mount_info::init): Ditto. (mount_info::add_item): Test for is_native_path as well. * path.cc (normalize_win32_path): Simplify native path prefix code. * shared.cc (user_shared_initialize_1): New function taking user shared initialization code relying on malloc and cygtls. (user_shared_initialize): Move mountinfo initialization to user_shared_initialize_1. * shared_info.h (user_shared_initialize_1): Declare. * syscalls.cc (seteuid32): Call user_shared_initialize_1 after user changed.
This commit is contained in:
parent
5f853b3fc5
commit
1d011c0a68
|
@ -1,3 +1,23 @@
|
||||||
|
2008-07-25 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* dcrt0.cc (dll_crt0_0): Call malloc_init and user_shared_initialize_1
|
||||||
|
here in case we're dynamically loaded. Explain why.
|
||||||
|
(dll_crt0_1): Call user_shared_initialize_1 from here.
|
||||||
|
* mount.cc (is_native_path): New inline function testing for native
|
||||||
|
and long Win32 path prefix.
|
||||||
|
(is_unc_share): Remove long WIn32 path prefix test.
|
||||||
|
(mount_info::create_root_entry): Use PATH_MAX buffer.
|
||||||
|
(mount_info::init): Ditto.
|
||||||
|
(mount_info::add_item): Test for is_native_path as well.
|
||||||
|
* path.cc (normalize_win32_path): Simplify native path prefix code.
|
||||||
|
* shared.cc (user_shared_initialize_1): New function taking user
|
||||||
|
shared initialization code relying on malloc and cygtls.
|
||||||
|
(user_shared_initialize): Move mountinfo initialization to
|
||||||
|
user_shared_initialize_1.
|
||||||
|
* shared_info.h (user_shared_initialize_1): Declare.
|
||||||
|
* syscalls.cc (seteuid32): Call user_shared_initialize_1 after user
|
||||||
|
changed.
|
||||||
|
|
||||||
2008-07-24 Corinna Vinschen <corinna@vinschen.de>
|
2008-07-24 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* mount.cc (mount_info::from_fstab): Change system_printf to
|
* mount.cc (mount_info::from_fstab): Change system_printf to
|
||||||
|
|
|
@ -752,6 +752,20 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,6 +788,8 @@ dll_crt0_1 (void *)
|
||||||
ProtectHandle (hMainProc);
|
ProtectHandle (hMainProc);
|
||||||
ProtectHandle (hMainThread);
|
ProtectHandle (hMainThread);
|
||||||
|
|
||||||
|
user_shared_initialize_1 ();
|
||||||
|
|
||||||
cygheap->cwd.init ();
|
cygheap->cwd.init ();
|
||||||
|
|
||||||
/* Initialize pthread mainthread when not forked and it is safe to call new,
|
/* Initialize pthread mainthread when not forked and it is safe to call new,
|
||||||
|
|
|
@ -47,13 +47,23 @@ details. */
|
||||||
This function is only used to test for valid input strings.
|
This function is only used to test for valid input strings.
|
||||||
The later normalization drops the native prefixes. */
|
The later normalization drops the native prefixes. */
|
||||||
|
|
||||||
|
static inline bool __stdcall
|
||||||
|
is_native_path (const char *path)
|
||||||
|
{
|
||||||
|
return isdirsep (path[0])
|
||||||
|
&& (isdirsep (path[1]) || path[1] == '?')
|
||||||
|
&& (path[2] == '?' || path[2] == '.')
|
||||||
|
&& isdirsep (path[3])
|
||||||
|
&& isalpha (path[4]);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool __stdcall
|
static inline bool __stdcall
|
||||||
is_unc_share (const char *path)
|
is_unc_share (const char *path)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
return (isdirsep (path[0])
|
return (isdirsep (path[0])
|
||||||
&& isdirsep (path[1])
|
&& isdirsep (path[1])
|
||||||
&& (isalnum (path[2]) || path[2] == '.' || path[2] == '?')
|
&& isalnum (path[2])
|
||||||
&& ((p = strpbrk (path + 3, "\\/")) != NULL)
|
&& ((p = strpbrk (path + 3, "\\/")) != NULL)
|
||||||
&& isalnum (p[1]));
|
&& isalnum (p[1]));
|
||||||
}
|
}
|
||||||
|
@ -76,8 +86,8 @@ inline void
|
||||||
mount_info::create_root_entry (const PWCHAR root)
|
mount_info::create_root_entry (const PWCHAR root)
|
||||||
{
|
{
|
||||||
/* Create a default root dir from the path the Cygwin DLL is in. */
|
/* Create a default root dir from the path the Cygwin DLL is in. */
|
||||||
char native_root[NT_MAX_PATH];
|
char native_root[PATH_MAX];
|
||||||
sys_wcstombs (native_root, NT_MAX_PATH, root);
|
sys_wcstombs (native_root, PATH_MAX, root);
|
||||||
mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY);
|
mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY);
|
||||||
/* Create a default cygdrive entry. Note that this is a user entry.
|
/* Create a default cygdrive entry. Note that this is a user entry.
|
||||||
This allows to override it with mount, unless the sysadmin created
|
This allows to override it with mount, unless the sysadmin created
|
||||||
|
@ -94,7 +104,7 @@ mount_info::init ()
|
||||||
{
|
{
|
||||||
nmounts = 0;
|
nmounts = 0;
|
||||||
PWCHAR pathend;
|
PWCHAR pathend;
|
||||||
WCHAR path[NT_MAX_PATH];
|
WCHAR path[PATH_MAX];
|
||||||
|
|
||||||
pathend = wcpcpy (path, cygwin_shared->installation_root);
|
pathend = wcpcpy (path, cygwin_shared->installation_root);
|
||||||
create_root_entry (path);
|
create_root_entry (path);
|
||||||
|
@ -972,7 +982,7 @@ mount_info::add_item (const char *native, const char *posix,
|
||||||
not a UNC or absolute path. */
|
not a UNC or absolute path. */
|
||||||
|
|
||||||
if (native == NULL || !isabspath (native) ||
|
if (native == NULL || !isabspath (native) ||
|
||||||
!(is_unc_share (native) || isdrive (native)))
|
!(is_native_path (native) || is_unc_share (native) || isdrive (native)))
|
||||||
nativeerr = EINVAL;
|
nativeerr = EINVAL;
|
||||||
else
|
else
|
||||||
nativeerr = normalize_win32_path (native, nativetmp, nativetail);
|
nativeerr = normalize_win32_path (native, nativetmp, nativetail);
|
||||||
|
|
|
@ -1311,12 +1311,9 @@ normalize_win32_path (const char *src, char *dst, char *&tail)
|
||||||
{
|
{
|
||||||
src += 4;
|
src += 4;
|
||||||
if (src[1] != ':') /* native UNC path */
|
if (src[1] != ':') /* native UNC path */
|
||||||
{
|
|
||||||
src += 2; /* Fortunately the first char is not copied... */
|
src += 2; /* Fortunately the first char is not copied... */
|
||||||
beg_src_slash = true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
beg_src_slash = isdirsep (src[0]);
|
beg_src_slash = false;
|
||||||
}
|
}
|
||||||
if (beg_src_slash && isdirsep (src[1]))
|
if (beg_src_slash && isdirsep (src[1]))
|
||||||
{
|
{
|
||||||
|
|
|
@ -198,6 +198,24 @@ 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
|
||||||
|
go here. */
|
||||||
|
void
|
||||||
|
user_shared_initialize_1 ()
|
||||||
|
{
|
||||||
|
if (!user_shared->cb)
|
||||||
|
{
|
||||||
|
cygpsid sid (cygheap->user.sid ());
|
||||||
|
struct passwd *pw = internal_getpwsid (sid);
|
||||||
|
/* Correct the user name with what's defined in /etc/passwd before
|
||||||
|
loading the user fstab file. */
|
||||||
|
if (pw)
|
||||||
|
cygheap->user.set_name (pw->pw_name);
|
||||||
|
user_shared->mountinfo.init (); /* Initialize the mount table. */
|
||||||
|
user_shared->cb = sizeof (*user_shared);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
user_shared_initialize (bool reinit)
|
user_shared_initialize (bool reinit)
|
||||||
{
|
{
|
||||||
|
@ -224,19 +242,8 @@ user_shared_initialize (bool reinit)
|
||||||
debug_printf ("user shared version %x", user_shared->version);
|
debug_printf ("user shared version %x", user_shared->version);
|
||||||
|
|
||||||
DWORD sversion = (DWORD) InterlockedExchange ((LONG *) &user_shared->version, USER_VERSION_MAGIC);
|
DWORD sversion = (DWORD) InterlockedExchange ((LONG *) &user_shared->version, USER_VERSION_MAGIC);
|
||||||
/* Initialize the Cygwin per-user shared, if necessary */
|
/* Wait for initialization of the Cygwin per-user shared, if necessary */
|
||||||
if (!sversion)
|
if (sversion)
|
||||||
{
|
|
||||||
cygpsid sid (cygheap->user.sid ());
|
|
||||||
struct passwd *pw = internal_getpwsid (sid);
|
|
||||||
/* Correct the user name with what's defined in /etc/passwd before
|
|
||||||
loading the user fstab file. */
|
|
||||||
if (pw)
|
|
||||||
cygheap->user.set_name (pw->pw_name);
|
|
||||||
user_shared->mountinfo.init (); /* Initialize the mount table. */
|
|
||||||
user_shared->cb = sizeof (*user_shared);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
while (!user_shared->cb)
|
while (!user_shared->cb)
|
||||||
low_priority_sleep (0); // Should be hit only very very rarely
|
low_priority_sleep (0); // Should be hit only very very rarely
|
||||||
|
|
|
@ -185,3 +185,5 @@ void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD si
|
||||||
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_initialize (bool reinit);
|
||||||
|
extern void user_shared_initialize_1 ();
|
||||||
|
|
||||||
|
|
|
@ -2612,7 +2612,10 @@ seteuid32 (__uid32_t uid)
|
||||||
myself->uid = uid;
|
myself->uid = uid;
|
||||||
groups.ischanged = FALSE;
|
groups.ischanged = FALSE;
|
||||||
if (!issamesid)
|
if (!issamesid)
|
||||||
|
{
|
||||||
user_shared_initialize (true);
|
user_shared_initialize (true);
|
||||||
|
user_shared_initialize_1 ();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue