Throughout, change 'cygwin_shared.mount' to 'mount_table'.

* child_info.h (child_info): Move shared_h, console_h to cygheap.  Add mount_h.
* cygheap.h (init_cygheap): Add shared_h, console_h.
* cygheap.cc (init_cheap): Initialize heap at a fixed location after the shared
memory regions.  Initialize cygheap->user name here.
* dcrt0.cc (dll_crt0_1): Call getpagesize () to initialize constants.  Remove
cygheap_init since it is done in shared_init now.
(_dll_crt0): Initialize mount_h, remove shared_h and console_h initialization.
* fhandler_console.cc (console_shared_h): Eliminate.
(get_tty_stuff): Use cygheap->console_h rather than console_shared_h.
* heap.cc (heap_init): Use page size constant calculated earlier in
initialization.
* shared.cc: Eliminate cygwin_shared_h.  Add cygwin_mount_h.
(mount_table_init): New function for initializing a user mount table.
(open_shared_file_map): Use constant for shared memory region.  Initialize
cygheap and mount table here.
(open_shared): Improve debugging output.
(shared_info::initialize): Eliminate call to mount.init.
(shared_terminate): Use cygheap->shared_h.  Close cygwin_mount_h.
(open_shared_file_map): Eliminate.
* shared_info.h (mount_info): Add a version field.
(shared_align_past): New macro for calculating location for shared memory
regions.
* sigproc.cc (init_child_info): Eliminate shared_h, console_h.
* spawn.cc (spawn_guts): Pass on cygwin_mount_h iff not a different user.
* syscalls.cc (system_info): New global holding system memory defaults.
(getpagesize): Use system_info.
* uinfo.cc (internal_getlogin): Only fill in user name if nonexistent.
* winsup.h: Declare system_info.
* passwd.cc (read_etc_passwd): Use cygheap->user.name () rather than retrieving
the name again.
This commit is contained in:
Christopher Faylor 2001-01-28 05:51:15 +00:00
parent 022ce214de
commit 2a6fc028ba
21 changed files with 264 additions and 210 deletions

View File

@ -1,3 +1,36 @@
Sun Jan 28 00:28:30 2001 Christopher Faylor <cgf@cygnus.com>
Throughout, change 'cygwin_shared.mount' to 'mount_table'.
* child_info.h (child_info): Move shared_h, console_h to cygheap. Add
mount_h.
* cygheap.h (init_cygheap): Add shared_h, console_h.
* cygheap.cc (init_cheap): Initialize heap at a fixed location after
the shared memory regions. Initialize cygheap->user name here.
* dcrt0.cc (dll_crt0_1): Call getpagesize () to initialize constants.
Remove cygheap_init since it is done in shared_init now.
(_dll_crt0): Initialize mount_h, remove shared_h and console_h
initialization.
* fhandler_console.cc (console_shared_h): Eliminate.
(get_tty_stuff): Use cygheap->console_h rather than console_shared_h.
* heap.cc (heap_init): Use page size constant calculated earlier in initialization.
* shared.cc: Eliminate cygwin_shared_h. Add cygwin_mount_h.
(mount_table_init): New function for initializing a user mount table.
(open_shared_file_map): Use constant for shared memory region. Initialize cygheap and mount table here.
(open_shared): Improve debugging output.
(shared_info::initialize): Eliminate call to mount.init.
(shared_terminate): Use cygheap->shared_h. Close cygwin_mount_h.
(open_shared_file_map): Eliminate.
* shared_info.h (mount_info): Add a version field.
(shared_align_past): New macro for calculating location for shared memory regions.
* sigproc.cc (init_child_info): Eliminate shared_h, console_h.
* spawn.cc (spawn_guts): Pass on cygwin_mount_h iff not a different user.
* syscalls.cc (system_info): New global holding system memory defaults.
(getpagesize): Use system_info.
* uinfo.cc (internal_getlogin): Only fill in user name if nonexistent.
* winsup.h: Declare system_info.
* passwd.cc (read_etc_passwd): Use cygheap->user.name () rather than retrieving the name again.
Sat Jan 27 10:18:02 2001 Christopher Faylor <cgf@cygnus.com> Sat Jan 27 10:18:02 2001 Christopher Faylor <cgf@cygnus.com>
* path.cc (path_conv::check): Detect when path has symlinks. * path.cc (path_conv::check): Detect when path has symlinks.

View File

@ -12,7 +12,7 @@ details. */
enum enum
{ {
PROC_MAGIC = 0xaf0bf000, PROC_MAGIC = 0xaf0cf000,
PROC_FORK = PROC_MAGIC + 1, PROC_FORK = PROC_MAGIC + 1,
PROC_EXEC = PROC_MAGIC + 2, PROC_EXEC = PROC_MAGIC + 2,
PROC_SPAWN = PROC_MAGIC + 3, PROC_SPAWN = PROC_MAGIC + 3,
@ -34,8 +34,7 @@ public:
DWORD type; // type of record DWORD type; // type of record
int cygpid; // cygwin pid of child process int cygpid; // cygwin pid of child process
HANDLE subproc_ready; // used for synchronization with parent HANDLE subproc_ready; // used for synchronization with parent
HANDLE shared_h; HANDLE mount_h;
HANDLE console_h;
HANDLE parent; HANDLE parent;
HANDLE pppid_handle; HANDLE pppid_handle;
init_cygheap *cygheap; init_cygheap *cygheap;

View File

@ -17,6 +17,7 @@
#include "heap.h" #include "heap.h"
#include "cygerrno.h" #include "cygerrno.h"
#include "sync.h" #include "sync.h"
#include "shared_info.h"
init_cygheap NO_COPY *cygheap; init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max = NULL; void NO_COPY *cygheap_max = NULL;
@ -26,10 +27,19 @@ static NO_COPY muto *cygheap_protect = NULL;
inline static void inline static void
init_cheap () init_cheap ()
{ {
cygheap = (init_cygheap *) VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS); void *addr = cygheap_address;
cygheap = (init_cygheap *) VirtualAlloc (addr, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
if (!cygheap) if (!cygheap)
api_fatal ("Couldn't reserve space for cygwin's heap, %E"); api_fatal ("Couldn't reserve space for cygwin's heap, %E");
cygheap_max = cygheap + 1; cygheap_max = cygheap + 1;
char username[MAX_USER_NAME];
DWORD username_len = MAX_USER_NAME;
if (!GetUserName (username, &username_len))
cygheap->user.set_name ("unknown");
else
cygheap->user.set_name (username);
} }
#define pagetrunc(x) ((void *) (((DWORD) (x)) & ~(4096 - 1))) #define pagetrunc(x) ((void *) (((DWORD) (x)) & ~(4096 - 1)))

View File

@ -103,6 +103,8 @@ struct init_cygheap
cygheap_root root; cygheap_root root;
cygheap_user user; cygheap_user user;
mode_t umask; mode_t umask;
HANDLE shared_h;
HANDLE console_h;
}; };
extern init_cygheap *cygheap; extern init_cygheap *cygheap;

View File

@ -632,9 +632,7 @@ dll_crt0_1 ()
/* FIXME: Verify forked children get their exception handler set up ok. */ /* FIXME: Verify forked children get their exception handler set up ok. */
exception_list cygwin_except_entry; exception_list cygwin_except_entry;
/* Initialize SIGSEGV handling, etc... Because the exception handler /* Initialize SIGSEGV handling, etc. */
references data in the shared area, this must be done after
shared_init. */
init_exceptions (&cygwin_except_entry); init_exceptions (&cygwin_except_entry);
do_global_ctors (&__CTOR_LIST__, 1); do_global_ctors (&__CTOR_LIST__, 1);
@ -656,6 +654,7 @@ dll_crt0_1 ()
threadname_init (); threadname_init ();
debug_init (); debug_init ();
(void) getpagesize (); /* initialize page size constant */
regthread ("main", GetCurrentThreadId ()); regthread ("main", GetCurrentThreadId ());
mainthread.init ("mainthread"); // For use in determining if signals mainthread.init ("mainthread"); // For use in determining if signals
@ -735,9 +734,6 @@ dll_crt0_1 ()
/* Initialize events. */ /* Initialize events. */
events_init (); events_init ();
if (!child_proc_info)
cygheap_init ();
cygcwd.init (); cygcwd.init ();
cygbench ("pre-forkee"); cygbench ("pre-forkee");
@ -918,9 +914,8 @@ _dll_crt0 ()
case PROC_EXEC: case PROC_EXEC:
{ {
child_proc_info = fork_info; child_proc_info = fork_info;
cygwin_mount_h = child_proc_info->mount_h;
mypid = child_proc_info->cygpid; mypid = child_proc_info->cygpid;
cygwin_shared_h = child_proc_info->shared_h;
console_shared_h = child_proc_info->console_h;
break; break;
} }
default: default:

View File

@ -299,7 +299,7 @@ static int NO_COPY keep_looping = 0;
extern "C" int extern "C" int
try_to_debug () try_to_debug ()
{ {
debug_printf ("debugger_command %s", debugger_command); debug_printf ("debugger_command '%s'", debugger_command);
if (*debugger_command == '\0') if (*debugger_command == '\0')
return 0; return 0;

View File

@ -91,8 +91,7 @@ static DWORD
get_cygdrive_info (char *user, char *system, char *user_flags, get_cygdrive_info (char *user, char *system, char *user_flags,
char *system_flags) char *system_flags)
{ {
shared_info *info = cygwin_getshared(); int res = mount_table->get_cygdrive_info (user, system, user_flags,
int res = info->mount.get_cygdrive_info (user, system, user_flags,
system_flags); system_flags);
return (res == ERROR_SUCCESS) ? 1 : 0; return (res == ERROR_SUCCESS) ? 1 : 0;
} }
@ -138,7 +137,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
case CW_READ_V1_MOUNT_TABLES: case CW_READ_V1_MOUNT_TABLES:
/* Upgrade old v1 registry mounts to new location. */ /* Upgrade old v1 registry mounts to new location. */
cygwin_shared->mount.import_v1_mounts (); mount_table->import_v1_mounts ();
return 0; return 0;
case CW_USER_DATA: case CW_USER_DATA:

View File

@ -20,6 +20,7 @@ details. */
#include <wincon.h> #include <wincon.h>
#include <ctype.h> #include <ctype.h>
#include <sys/cygwin.h> #include <sys/cygwin.h>
#include "cygheap.h"
#include "cygerrno.h" #include "cygerrno.h"
#include "fhandler.h" #include "fhandler.h"
#include "sync.h" #include "sync.h"
@ -49,8 +50,6 @@ const char * get_nonascii_key (INPUT_RECORD&, char *);
static BOOL use_mouse = FALSE; static BOOL use_mouse = FALSE;
HANDLE console_shared_h;
static tty_min NO_COPY *shared_console_info = NULL; static tty_min NO_COPY *shared_console_info = NULL;
/* Allocate and initialize the shared record for the current console. /* Allocate and initialize the shared record for the current console.
@ -61,10 +60,10 @@ get_tty_stuff (int force = 0)
if (shared_console_info && !force) if (shared_console_info && !force)
return shared_console_info; return shared_console_info;
shared_console_info = (tty_min *) open_shared (NULL, console_shared_h, shared_console_info = (tty_min *) open_shared (NULL, cygheap->console_h,
sizeof (*shared_console_info), sizeof (*shared_console_info),
NULL); NULL);
ProtectHandle (console_shared_h); ProtectHandle (cygheap->console_h);
shared_console_info->setntty (TTY_CONSOLE); shared_console_info->setntty (TTY_CONSOLE);
shared_console_info->setsid (myself->sid); shared_console_info->setsid (myself->sid);
return shared_console_info; return shared_console_info;

View File

@ -31,7 +31,7 @@ heap_init ()
/* If we're the forkee, we must allocate the heap at exactly the same place /* If we're the forkee, we must allocate the heap at exactly the same place
as our parent. If not, we don't care where it ends up. */ as our parent. If not, we don't care where it ends up. */
page_const = getpagesize (); page_const = system_info.dwPageSize;
if (brkbase) if (brkbase)
{ {
DWORD chunk = brkchunk; /* allocation chunk */ DWORD chunk = brkchunk; /* allocation chunk */

View File

@ -140,14 +140,7 @@ read_etc_passwd ()
else else
{ {
debug_printf ("Emulating /etc/passwd"); debug_printf ("Emulating /etc/passwd");
char user_name [ MAX_USER_NAME ]; snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", cygheap->user.name (),
DWORD user_name_len = MAX_USER_NAME;
if (! GetUserNameA (user_name, &user_name_len))
{
strncpy (user_name, "Administrator", MAX_USER_NAME);
debug_printf ("Failed to get current user name. %E");
}
snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", user_name,
DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/"); DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
add_pwd_line (linebuf); add_pwd_line (linebuf);
passwd_state = emulated; passwd_state = emulated;

View File

@ -102,12 +102,12 @@ cwdstuff cygcwd; /* The current working directory. */
/* Determine if path prefix matches current cygdrive */ /* Determine if path prefix matches current cygdrive */
#define iscygdrive(path) \ #define iscygdrive(path) \
(path_prefix_p (cygwin_shared->mount.cygdrive, (path), cygwin_shared->mount.cygdrive_len)) (path_prefix_p (mount_table->cygdrive, (path), mount_table->cygdrive_len))
#define iscygdrive_device(path) \ #define iscygdrive_device(path) \
(iscygdrive(path) && isalpha(path[cygwin_shared->mount.cygdrive_len]) && \ (iscygdrive(path) && isalpha(path[mount_table->cygdrive_len]) && \
(isdirsep(path[cygwin_shared->mount.cygdrive_len + 1]) || \ (isdirsep(path[mount_table->cygdrive_len + 1]) || \
!path[cygwin_shared->mount.cygdrive_len + 1])) !path[mount_table->cygdrive_len + 1]))
#define ischrootpath(p) \ #define ischrootpath(p) \
(cygheap->root.length () && \ (cygheap->root.length () && \
@ -214,9 +214,8 @@ path_conv::check (const char *src, unsigned opt,
(p[1] == '\0' || strcmp (p, "\\.") == 0)) (p[1] == '\0' || strcmp (p, "\\.") == 0))
need_directory = 1; need_directory = 1;
/* Must look up path in mount table, etc. */ /* Must look up path in mount table, etc. */
error = cygwin_shared->mount.conv_to_win32_path (src, rel_path, error = mount_table->conv_to_win32_path (src, rel_path, full_path, devn,
full_path, unit, &path_flags);
devn, unit, &path_flags);
MALLOC_CHECK; MALLOC_CHECK;
if (error) if (error)
return; return;
@ -360,7 +359,7 @@ path_conv::check (const char *src, unsigned opt,
p = sym.contents - headlen; p = sym.contents - headlen;
memcpy (p, path_copy, headlen); memcpy (p, path_copy, headlen);
MALLOC_CHECK; MALLOC_CHECK;
error = cygwin_shared->mount.conv_to_posix_path (p, tmp_buf, 1); error = mount_table->conv_to_posix_path (p, tmp_buf, 1);
MALLOC_CHECK; MALLOC_CHECK;
if (error) if (error)
return; return;
@ -949,8 +948,6 @@ conv_path_list (const char *src, char *dst, int to_posix_p)
while (s != NULL); while (s != NULL);
} }
/************************* mount_info class ****************************/
/* init: Initialize the mount table. */ /* init: Initialize the mount table. */
void void
@ -1035,7 +1032,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
{ {
char posix_path[MAX_PATH + 1]; char posix_path[MAX_PATH + 1];
rc = cygwin_shared->mount.conv_to_posix_path (dst, posix_path, 0); rc = mount_table->conv_to_posix_path (dst, posix_path, 0);
if (rc) if (rc)
{ {
debug_printf ("conv_to_posix_path failed, rc %d", rc); debug_printf ("conv_to_posix_path failed, rc %d", rc);
@ -1397,7 +1394,7 @@ mount_info::read_mounts (reg_key& r)
mount_flags = subkey.get_int ("flags", 0); mount_flags = subkey.get_int ("flags", 0);
/* Add mount_item corresponding to registry mount point. */ /* Add mount_item corresponding to registry mount point. */
res = cygwin_shared->mount.add_item (native_path, posix_path, mount_flags, FALSE); res = mount_table->add_item (native_path, posix_path, mount_flags, FALSE);
if (res && get_errno () == EMFILE) if (res && get_errno () == EMFILE)
break; /* The number of entries exceeds MAX_MOUNTS */ break; /* The number of entries exceeds MAX_MOUNTS */
} }
@ -1625,11 +1622,11 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
1. setting user path prefix, or 1. setting user path prefix, or
2. overwriting (a previous) system path prefix */ 2. overwriting (a previous) system path prefix */
if ((flags & MOUNT_SYSTEM) == 0 || if ((flags & MOUNT_SYSTEM) == 0 ||
(cygwin_shared->mount.cygdrive_flags & MOUNT_SYSTEM) != 0) (mount_table->cygdrive_flags & MOUNT_SYSTEM) != 0)
{ {
slashify (cygdrive_prefix, cygwin_shared->mount.cygdrive, 1); slashify (cygdrive_prefix, mount_table->cygdrive, 1);
cygwin_shared->mount.cygdrive_flags = flags; mount_table->cygdrive_flags = flags;
cygwin_shared->mount.cygdrive_len = strlen(cygwin_shared->mount.cygdrive); mount_table->cygdrive_len = strlen(mount_table->cygdrive);
} }
return 0; return 0;
@ -1962,7 +1959,7 @@ mount_info::read_v1_mounts (reg_key r, unsigned which)
we're reading. */ we're reading. */
mountflags |= which; mountflags |= which;
int res = cygwin_shared->mount.add_item (win32path, unixpath, mountflags, TRUE); int res = mount_table->add_item (win32path, unixpath, mountflags, TRUE);
if (res && get_errno () == EMFILE) if (res && get_errno () == EMFILE)
break; /* The number of entries exceeds MAX_MOUNTS */ break; /* The number of entries exceeds MAX_MOUNTS */
} }
@ -2010,42 +2007,42 @@ mount_item::getmntent ()
static NO_COPY struct mntent ret; static NO_COPY struct mntent ret;
#endif #endif
/* Pass back pointers to mount_info strings reserved for use by /* Pass back pointers to mount_table strings reserved for use by
getmntent rather than pointers to strings in the internal mount getmntent rather than pointers to strings in the internal mount
table because the mount table might change, causing weird effects table because the mount table might change, causing weird effects
from the getmntent user's point of view. */ from the getmntent user's point of view. */
strcpy (cygwin_shared->mount.mnt_fsname, native_path); strcpy (mount_table->mnt_fsname, native_path);
ret.mnt_fsname = cygwin_shared->mount.mnt_fsname; ret.mnt_fsname = mount_table->mnt_fsname;
strcpy (cygwin_shared->mount.mnt_dir, posix_path); strcpy (mount_table->mnt_dir, posix_path);
ret.mnt_dir = cygwin_shared->mount.mnt_dir; ret.mnt_dir = mount_table->mnt_dir;
if (!(flags & MOUNT_SYSTEM)) /* user mount */ if (!(flags & MOUNT_SYSTEM)) /* user mount */
strcpy (cygwin_shared->mount.mnt_type, (char *) "user"); strcpy (mount_table->mnt_type, (char *) "user");
else /* system mount */ else /* system mount */
strcpy (cygwin_shared->mount.mnt_type, (char *) "system"); strcpy (mount_table->mnt_type, (char *) "system");
if ((flags & MOUNT_AUTO)) /* cygdrive */ if ((flags & MOUNT_AUTO)) /* cygdrive */
strcat (cygwin_shared->mount.mnt_type, (char *) ",auto"); strcat (mount_table->mnt_type, (char *) ",auto");
ret.mnt_type = cygwin_shared->mount.mnt_type; ret.mnt_type = mount_table->mnt_type;
/* mnt_opts is a string that details mount params such as /* mnt_opts is a string that details mount params such as
binary or textmode, or exec. We don't print binary or textmode, or exec. We don't print
`silent' here; it's a magic internal thing. */ `silent' here; it's a magic internal thing. */
if (! (flags & MOUNT_BINARY)) if (! (flags & MOUNT_BINARY))
strcpy (cygwin_shared->mount.mnt_opts, (char *) "textmode"); strcpy (mount_table->mnt_opts, (char *) "textmode");
else else
strcpy (cygwin_shared->mount.mnt_opts, (char *) "binmode"); strcpy (mount_table->mnt_opts, (char *) "binmode");
if (flags & MOUNT_CYGWIN_EXEC) if (flags & MOUNT_CYGWIN_EXEC)
strcat (cygwin_shared->mount.mnt_opts, (char *) ",cygexec"); strcat (mount_table->mnt_opts, (char *) ",cygexec");
else if (flags & MOUNT_EXEC) else if (flags & MOUNT_EXEC)
strcat (cygwin_shared->mount.mnt_opts, (char *) ",exec"); strcat (mount_table->mnt_opts, (char *) ",exec");
ret.mnt_opts = cygwin_shared->mount.mnt_opts; ret.mnt_opts = mount_table->mnt_opts;
ret.mnt_freq = 1; ret.mnt_freq = 1;
ret.mnt_passno = 1; ret.mnt_passno = 1;
@ -2086,11 +2083,11 @@ mount (const char *win32_path, const char *posix_path, unsigned flags)
/* When flags include MOUNT_AUTO, take this to mean that /* When flags include MOUNT_AUTO, take this to mean that
we actually want to change the cygdrive prefix and flags we actually want to change the cygdrive prefix and flags
without actually mounting anything. */ without actually mounting anything. */
res = cygwin_shared->mount.write_cygdrive_info_to_registry (posix_path, flags); res = mount_table->write_cygdrive_info_to_registry (posix_path, flags);
win32_path = NULL; win32_path = NULL;
} }
else else
res = cygwin_shared->mount.add_item (win32_path, posix_path, flags, TRUE); res = mount_table->add_item (win32_path, posix_path, flags, TRUE);
syscall_printf ("%d = mount (%s, %s, %p)", res, win32_path, posix_path, flags); syscall_printf ("%d = mount (%s, %s, %p)", res, win32_path, posix_path, flags);
return res; return res;
@ -2123,11 +2120,11 @@ cygwin_umount (const char *path, unsigned flags)
/* When flags include MOUNT_AUTO, take this to mean that we actually want /* When flags include MOUNT_AUTO, take this to mean that we actually want
to remove the cygdrive prefix and flags without actually unmounting to remove the cygdrive prefix and flags without actually unmounting
anything. */ anything. */
res = cygwin_shared->mount.remove_cygdrive_info_from_registry (path, flags); res = mount_table->remove_cygdrive_info_from_registry (path, flags);
} }
else else
{ {
res = cygwin_shared->mount.del_item (path, flags, TRUE); res = mount_table->del_item (path, flags, TRUE);
} }
syscall_printf ("%d = cygwin_umount (%s, %d)", res, path, flags); syscall_printf ("%d = cygwin_umount (%s, %d)", res, path, flags);
@ -2152,7 +2149,7 @@ extern "C"
struct mntent * struct mntent *
getmntent (FILE *) getmntent (FILE *)
{ {
return cygwin_shared->mount.getmntent (iteration++); return mount_table->getmntent (iteration++);
} }
extern "C" extern "C"
@ -2643,7 +2640,7 @@ cygwin_conv_to_posix_path (const char *path, char *posix_path)
{ {
if (check_null_empty_path_errno (path)) if (check_null_empty_path_errno (path))
return -1; return -1;
cygwin_shared->mount.conv_to_posix_path (path, posix_path, 1); mount_table->conv_to_posix_path (path, posix_path, 1);
return 0; return 0;
} }
@ -2653,7 +2650,7 @@ cygwin_conv_to_full_posix_path (const char *path, char *posix_path)
{ {
if (check_null_empty_path_errno (path)) if (check_null_empty_path_errno (path))
return -1; return -1;
cygwin_shared->mount.conv_to_posix_path (path, posix_path, 0); mount_table->conv_to_posix_path (path, posix_path, 0);
return 0; return 0;
} }
@ -2671,7 +2668,7 @@ realpath (const char *path, char *resolved)
err = real_path.error; err = real_path.error;
else else
{ {
err = cygwin_shared->mount.conv_to_posix_path (real_path.get_win32 (), resolved, 0); err = mount_table->conv_to_posix_path (real_path.get_win32 (), resolved, 0);
if (err == 0) if (err == 0)
return resolved; return resolved;
} }
@ -2728,11 +2725,11 @@ conv_path_list_buf_size (const char *path_list, int to_posix_p)
++p; ++p;
/* 7: strlen ("//c") + slop, a conservative initial value */ /* 7: strlen ("//c") + slop, a conservative initial value */
for (max_mount_path_len = 7, i = 0; i < cygwin_shared->mount.nmounts; ++i) for (max_mount_path_len = 7, i = 0; i < mount_table->nmounts; ++i)
{ {
int mount_len = (to_posix_p int mount_len = (to_posix_p
? cygwin_shared->mount.mount[i].posix_pathlen ? mount_table->mount[i].posix_pathlen
: cygwin_shared->mount.mount[i].native_pathlen); : mount_table->mount[i].native_pathlen);
if (max_mount_path_len < mount_len) if (max_mount_path_len < mount_len)
max_mount_path_len = mount_len; max_mount_path_len = mount_len;
} }
@ -2944,7 +2941,7 @@ cwdstuff::set (const char *win32_cwd, const char *posix_cwd)
} }
if (!posix_cwd) if (!posix_cwd)
cygwin_shared->mount.conv_to_posix_path (win32, pathbuf, 0); mount_table->conv_to_posix_path (win32, pathbuf, 0);
else else
(void) normalize_posix_path (posix_cwd, pathbuf); (void) normalize_posix_path (posix_cwd, pathbuf);

View File

@ -86,7 +86,7 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
be created and set had_to_create appropriately. */ be created and set had_to_create appropriately. */
if (strcmp (name, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME) == 0) if (strcmp (name, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME) == 0)
if (disp == REG_CREATED_NEW_KEY) if (disp == REG_CREATED_NEW_KEY)
cygwin_shared->mount.had_to_create_mount_areas++; mount_table->had_to_create_mount_areas++;
} }
} }

View File

@ -27,9 +27,8 @@ details. */
cygwin_version.api_minor) cygwin_version.api_minor)
shared_info NO_COPY *cygwin_shared = NULL; shared_info NO_COPY *cygwin_shared = NULL;
mount_info NO_COPY *mount_table = NULL;
/* The handle of the shared data area. */ HANDLE cygwin_mount_h = NULL;
HANDLE cygwin_shared_h = NULL;
/* General purpose security attribute objects for global use. */ /* General purpose security attribute objects for global use. */
SECURITY_ATTRIBUTES NO_COPY sec_none; SECURITY_ATTRIBUTES NO_COPY sec_none;
@ -49,15 +48,24 @@ shared_name (const char *str, int num)
return buf; return buf;
} }
/* Open the shared memory map. */ static void
static void __stdcall mount_table_init ()
open_shared_file_map ()
{ {
cygwin_shared = (shared_info *) open_shared ("shared", void *addr = mount_table_address;
cygwin_shared_h, debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (),
sizeof (*cygwin_shared), mount_table_address);
(void *)0xa000000); mount_table = (mount_info *) open_shared (cygheap->user.name (),
ProtectHandle (cygwin_shared); cygwin_mount_h, sizeof (mount_info),
addr);
ProtectHandle (cygwin_mount_h);
debug_printf ("mount table version %x at %p", mount_table->version, mount_table);
if (!mount_table->version)
{
mount_table->version = MOUNT_VERSION;
debug_printf ("initializing mount table");
mount_table->init (); /* Initialize the mount table. */
}
} }
void * __stdcall void * __stdcall
@ -99,9 +107,9 @@ open_shared (const char *name, HANDLE &shared_h, DWORD size, void *addr)
} }
if (!shared) if (!shared)
api_fatal ("MapViewOfFileEx, %E. Terminating."); api_fatal ("MapViewOfFileEx '%s'(%p), %E. Terminating.", name, shared_h);
debug_printf ("name %s, shared %p, h %p", name, shared, shared_h); debug_printf ("name %s, shared %p (wanted %p), h %p", name, shared, addr, shared_h);
/* FIXME: I couldn't find anywhere in the documentation a note about /* FIXME: I couldn't find anywhere in the documentation a note about
whether the memory is initialized to zero. The code assumes it does whether the memory is initialized to zero. The code assumes it does
@ -124,9 +132,6 @@ shared_info::initialize ()
return; return;
} }
/* Initialize the mount table. */
mount.init ();
/* Initialize the queue of deleted files. */ /* Initialize the queue of deleted files. */
delqueue.init (); delqueue.init ();
@ -155,16 +160,28 @@ shared_info::initialize ()
void __stdcall void __stdcall
shared_init () shared_init ()
{ {
open_shared_file_map (); HANDLE shared_h = cygheap ? cygheap->shared_h : NULL;
cygwin_shared = (shared_info *) open_shared ("shared",
shared_h,
sizeof (*cygwin_shared),
cygwin_shared_address);
if (!cygheap)
cygheap_init ();
mount_table_init ();
cygheap->shared_h = shared_h;
ProtectHandle (cygheap->shared_h);
cygwin_shared->initialize (); cygwin_shared->initialize ();
} }
void __stdcall void __stdcall
shared_terminate () shared_terminate ()
{ {
if (cygwin_shared_h) if (cygheap->shared_h)
ForceCloseHandle (cygwin_shared_h); ForceCloseHandle (cygheap->shared_h);
if (cygwin_mount_h)
ForceCloseHandle (cygwin_mount_h);
} }
unsigned unsigned
@ -292,4 +309,3 @@ sec_user_nih (PVOID sa_buf, PSID sid2)
{ {
return sec_user (sa_buf, sid2, FALSE); return sec_user (sa_buf, sid2, FALSE);
} }

View File

@ -40,12 +40,13 @@ public:
scheme should be satisfactory for a long while yet. */ scheme should be satisfactory for a long while yet. */
#define MAX_MOUNTS 30 #define MAX_MOUNTS 30
#define MOUNT_VERSION 0x01010102
class reg_key; class reg_key;
class mount_info class mount_info
{ {
int posix_sorted[MAX_MOUNTS];
int native_sorted[MAX_MOUNTS];
public: public:
DWORD version;
int nmounts; int nmounts;
mount_item mount[MAX_MOUNTS]; mount_item mount[MAX_MOUNTS];
@ -61,7 +62,11 @@ public:
char cygdrive[MAX_PATH]; char cygdrive[MAX_PATH];
size_t cygdrive_len; size_t cygdrive_len;
unsigned cygdrive_flags; unsigned cygdrive_flags;
private:
int posix_sorted[MAX_MOUNTS];
int native_sorted[MAX_MOUNTS];
public:
/* Increment when setting up a reg_key if mounts area had to be /* Increment when setting up a reg_key if mounts area had to be
created so we know when we need to import old mount tables. */ created so we know when we need to import old mount tables. */
int had_to_create_mount_areas; int had_to_create_mount_areas;
@ -135,9 +140,6 @@ class shared_info
DWORD inited; DWORD inited;
public: public:
/* FIXME: Doesn't work if more than one user on system. */
mount_info mount;
int heap_chunk_in_mb; int heap_chunk_in_mb;
unsigned heap_chunk_size (void); unsigned heap_chunk_size (void);
@ -147,11 +149,20 @@ public:
}; };
extern shared_info *cygwin_shared; extern shared_info *cygwin_shared;
extern HANDLE cygwin_shared_h; extern mount_info *mount_table;
extern HANDLE console_shared_h; extern HANDLE cygwin_mount_h;
void __stdcall shared_init (void); void __stdcall shared_init (void);
void __stdcall shared_terminate (void); void __stdcall shared_terminate (void);
#define shared_align_past(p) \
((char *) (system_info.dwAllocationGranularity * \
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
system_info.dwAllocationGranularity)))
#define cygwin_shared_address ((void *) 0xa000000)
#define mount_table_address shared_align_past (cygwin_shared)
#define cygheap_address shared_align_past ((mount_info *) shared_align_past (cygwin_shared))
char *__stdcall shared_name (const char *, int); char *__stdcall shared_name (const char *, int);
void *__stdcall open_shared (const char *name, HANDLE &shared_h, DWORD size, void *addr); void *__stdcall open_shared (const char *name, HANDLE &shared_h, DWORD size, void *addr);

View File

@ -821,8 +821,6 @@ init_child_info (DWORD chtype, child_info *ch, pid_t pid, HANDLE subproc_ready)
ch->cb = sizeof *ch; ch->cb = sizeof *ch;
ch->type = chtype; ch->type = chtype;
ch->cygpid = pid; ch->cygpid = pid;
ch->shared_h = cygwin_shared_h;
ch->console_h = console_shared_h;
ch->subproc_ready = subproc_ready; ch->subproc_ready = subproc_ready;
ch->pppid_handle = myself->ppid_handle; ch->pppid_handle = myself->ppid_handle;
} }

View File

@ -28,6 +28,7 @@ details. */
#include "sigproc.h" #include "sigproc.h"
#include "cygheap.h" #include "cygheap.h"
#include "child_info.h" #include "child_info.h"
#include "shared_info.h"
#include "pinfo.h" #include "pinfo.h"
#define NEED_VFORK #define NEED_VFORK
#include "perthread.h" #include "perthread.h"
@ -592,6 +593,9 @@ skip_arg_parsing:
if (!hToken) if (!hToken)
{ {
ciresrv.moreinfo->uid = getuid (); ciresrv.moreinfo->uid = getuid ();
/* FIXME: This leaks a handle in the CreateProcessAsUser case since the
child process doesn't know about cygwin_mount_h. */
ciresrv.mount_h = cygwin_mount_h;
rc = CreateProcess (runpath, /* image name - with full path */ rc = CreateProcess (runpath, /* image name - with full path */
one_line.buf, /* what was passed to exec */ one_line.buf, /* what was passed to exec */
/* process security attrs */ /* process security attrs */

View File

@ -38,6 +38,8 @@ details. */
#include "security.h" #include "security.h"
#include "cygheap.h" #include "cygheap.h"
SYSTEM_INFO system_info;
/* Close all files and process any queued deletions. /* Close all files and process any queued deletions.
Lots of unix style applications will open a tmp file, unlink it, Lots of unix style applications will open a tmp file, unlink it,
but never call close. This function is called by _exit to but never call close. This function is called by _exit to
@ -1360,15 +1362,9 @@ getdtablesize ()
extern "C" size_t extern "C" size_t
getpagesize () getpagesize ()
{ {
static DWORD sys_page_size = 0; if (!system_info.dwPageSize)
GetSystemInfo(&system_info);
if (!sys_page_size) return (int) system_info.dwPageSize;
{
SYSTEM_INFO si;
GetSystemInfo(&si);
sys_page_size = si.dwPageSize;
}
return (int)sys_page_size;
} }
/* FIXME: not all values are correct... */ /* FIXME: not all values are correct... */
@ -1952,8 +1948,7 @@ chroot (const char *newroot)
goto done; goto done;
} }
char buf[MAX_PATH + 1]; char buf[MAX_PATH + 1];
ret = cygwin_shared->mount.conv_to_posix_path (path.get_win32 (), ret = mount_table->conv_to_posix_path (path.get_win32 (), buf, 0);
buf, 0);
if (ret) if (ret)
{ {
set_errno (ret); set_errno (ret);

View File

@ -31,10 +31,12 @@ internal_getlogin (cygheap_user &user)
char username[MAX_USER_NAME]; char username[MAX_USER_NAME];
DWORD username_len = MAX_USER_NAME; DWORD username_len = MAX_USER_NAME;
if (!user.name ())
if (!GetUserName (username, &username_len)) if (!GetUserName (username, &username_len))
user.set_name ("unknown"); user.set_name ("unknown");
else else
user.set_name (username); user.set_name (username);
if (os_being_run == winNT) if (os_being_run == winNT)
{ {
LPWKSTA_USER_INFO_1 wui; LPWKSTA_USER_INFO_1 wui;

View File

@ -234,6 +234,7 @@ extern DWORD binmode;
extern char _data_start__, _data_end__, _bss_start__, _bss_end__; extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
extern void (*__CTOR_LIST__) (void); extern void (*__CTOR_LIST__) (void);
extern void (*__DTOR_LIST__) (void); extern void (*__DTOR_LIST__) (void);
extern SYSTEM_INFO system_info;
}; };
/*************************** Unsorted ******************************/ /*************************** Unsorted ******************************/