aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-11-14 05:53:32 +0000
committerChristopher Faylor <me@cgf.cx>2000-11-14 05:53:32 +0000
commita4785603b85b80ea0cc5ea0038bbbb3a13513714 (patch)
tree3bb9ab5f76acbe2fbca946b6c4f9439a8aa42c58 /winsup
parent70a11195b9bf3617e3dbe4b9de034b3792c65621 (diff)
downloadnewlib-a4785603b85b80ea0cc5ea0038bbbb3a13513714.zip
newlib-a4785603b85b80ea0cc5ea0038bbbb3a13513714.tar.gz
newlib-a4785603b85b80ea0cc5ea0038bbbb3a13513714.tar.bz2
* cygheap.h (init_cygheap): New struct holding values that live in the Cygwin
heap. * child_info.h (child_info): Change pointer type of cygheap to init_cygheap. * cygheap.cc (init_cheap): Point cygheap_max after contents of cygheap. Move some stuff into cygheap.h. * dir.cc (opendir): Change to use root and rootlen in cygheap rather than in myself. (mkdir): Change to use umask in cygheap rather than in myself. * path.cc: Ditto, throughout. * syscalls.cc (_open): Ditto. Change to use umask in cygheap rather than in myself. (chroot): Change to allocate root dir on the cygwin heap. (umask): Change to use umask in cygheap rather than in myself. (cygwin_bind): Ditto. * sigproc.cc (proc_subproc): Don't copy umask or root stuff as this happens automatically now. * pinfo.h (_pinfo): Migrate stuff out of here and into init_cheap. * dcrt0.cc (dll_crt0_1): Call cygheap_init later in startup for first cygwin process.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog23
-rw-r--r--winsup/cygwin/child_info.h2
-rw-r--r--winsup/cygwin/cygheap.cc66
-rw-r--r--winsup/cygwin/cygheap.h31
-rw-r--r--winsup/cygwin/dcrt0.cc21
-rw-r--r--winsup/cygwin/dir.cc5
-rw-r--r--winsup/cygwin/external.cc2
-rw-r--r--winsup/cygwin/net.cc2
-rw-r--r--winsup/cygwin/path.cc30
-rw-r--r--winsup/cygwin/pinfo.h6
-rw-r--r--winsup/cygwin/sigproc.cc3
-rw-r--r--winsup/cygwin/syscalls.cc18
12 files changed, 122 insertions, 87 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 8e137c9..ba20476 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,26 @@
+Tue Nov 14 00:51:28 2000 Christopher Faylor <cgf@cygnus.com>
+
+ * cygheap.h (init_cygheap): New struct holding values that live in the
+ Cygwin heap.
+ * child_info.h (child_info): Change pointer type of cygheap to
+ init_cygheap.
+ * cygheap.cc (init_cheap): Point cygheap_max after contents of cygheap.
+ Move some stuff into cygheap.h.
+ * dir.cc (opendir): Change to use root and rootlen in cygheap rather
+ than in myself.
+ (mkdir): Change to use umask in cygheap rather than in myself.
+ * path.cc: Ditto, throughout.
+ * syscalls.cc (_open): Ditto. Change to use umask in cygheap rather
+ than in myself.
+ (chroot): Change to allocate root dir on the cygwin heap.
+ (umask): Change to use umask in cygheap rather than in myself.
+ (cygwin_bind): Ditto.
+ * sigproc.cc (proc_subproc): Don't copy umask or root stuff as this
+ happens automatically now.
+ * pinfo.h (_pinfo): Migrate stuff out of here and into init_cheap.
+ * dcrt0.cc (dll_crt0_1): Call cygheap_init later in startup for first
+ cygwin process.
+
Sun Nov 12 23:01:35 2000 Christopher Faylor <cgf@cygnus.com>
* path.cc (get_device_number): Allow /dev/ttySn to designate a com
diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index 9249247..120e1fc 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
@@ -39,7 +39,7 @@ public:
HANDLE parent_alive; // handle of thread used to track children
HANDLE parent;
HANDLE pppid_handle;
- void *cygheap;
+ init_cygheap *cygheap;
void *cygheap_max;
};
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index c6503c4..15c2667 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -18,24 +18,18 @@
#include "cygerrno.h"
#include "sync.h"
-void NO_COPY *cygheap = NULL;
+init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max = NULL;
static NO_COPY muto *cygheap_protect = NULL;
-extern "C" void __stdcall
-cygheap_init ()
-{
- cygheap_protect = new_muto (FALSE, "cygheap_protect");
-}
-
inline static void
init_cheap ()
{
- cygheap = VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
+ cygheap = (init_cygheap *) VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
if (!cygheap)
api_fatal ("Couldn't reserve space for cygwin's heap, %E");
- cygheap_max = (((char **) cygheap) + 1);
+ cygheap_max = cygheap + 1;
}
#define pagetrunc(x) ((void *) (((DWORD) (x)) & ~(4096 - 1)))
@@ -60,32 +54,26 @@ _csbrk (int sbs)
if (!needalloc)
needalloc = sbs && ((heapalign == lastheap) || heapalign != pagetrunc (cygheap_max));
- if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
+ if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs ?: 1, MEM_COMMIT, PAGE_READWRITE))
api_fatal ("couldn't commit memory for cygwin heap, %E");
return lastheap;
}
+extern "C" void __stdcall
+cygheap_init ()
+{
+ cygheap_protect = new_muto (FALSE, "cygheap_protect");
+ _csbrk (0);
+}
+
/* Copyright (C) 1997, 2000 DJ Delorie */
#define NBUCKETS 32
char *buckets[NBUCKETS] = {0};
-struct _cmalloc_entry
-{
- union
- {
- DWORD b;
- char *ptr;
- };
- struct _cmalloc_entry *prev;
- char data[0];
-};
-
-
#define N0 ((_cmalloc_entry *) NULL)
#define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data)))
-#define cygheap_chain ((_cmalloc_entry **)cygheap)
static void *_cmalloc (int size) __attribute ((regparm(1)));
static void *__stdcall _crealloc (void *ptr, int size) __attribute ((regparm(2)));
@@ -113,8 +101,8 @@ _cmalloc (int size)
rvc = (_cmalloc_entry *) _csbrk (size);
rvc->b = b;
- rvc->prev = *cygheap_chain;
- *cygheap_chain = rvc;
+ rvc->prev = cygheap->chain;
+ cygheap->chain = rvc;
}
cygheap_protect->release ();
return rvc->data;
@@ -172,7 +160,7 @@ cygheap_fixup_in_child (HANDLE parent, bool execed)
/* Reserve cygwin heap in same spot as parent */
if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS))
- api_fatal ("Couldn't reserve space for cygwin's heap in child, %E");
+ api_fatal ("Couldn't reserve space for cygwin's heap (%p) in child, cygheap, %E", cygheap);
/* Allocate same amount of memory as parent */
if (!VirtualAlloc (cygheap, n, MEM_COMMIT, PAGE_READWRITE))
@@ -185,20 +173,22 @@ cygheap_fixup_in_child (HANDLE parent, bool execed)
api_fatal ("Couldn't read parent's cygwin heap %d bytes != %d, %E",
n, m);
- if (!execed)
- return; /* Forked. Nothing extra to do. */
+ cygheap_init ();
- /* Walk the allocated memory chain looking for orphaned memory from
- previous execs */
- for (_cmalloc_entry *rvc = *cygheap_chain; rvc; rvc = rvc->prev)
+ if (execed)
{
- cygheap_entry *ce = (cygheap_entry *) rvc->data;
- if (rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
- continue;
- else if (ce->type < HEAP_1_MAX)
- ce->type += HEAP_1_MAX; /* Mark for freeing after next exec */
- else
- _cfree (ce); /* Marked by parent for freeing in child */
+ /* Walk the allocated memory chain looking for orphaned memory from
+ previous execs */
+ for (_cmalloc_entry *rvc = cygheap->chain; rvc; rvc = rvc->prev)
+ {
+ cygheap_entry *ce = (cygheap_entry *) rvc->data;
+ if (rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
+ continue;
+ else if (ce->type < HEAP_1_MAX)
+ ce->type += HEAP_1_MAX; /* Mark for freeing after next exec */
+ else
+ _cfree (ce); /* Marked by parent for freeing in child */
+ }
}
}
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index 8ed3aa3..faa50bf 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -24,13 +24,36 @@ enum cygheap_types
HEAP_1_MAX = 100
};
-#define CYGHEAPSIZE ((2000 * sizeof (fhandler_union)) + (2 * 65536))
-
-extern HANDLE cygheap;
-extern HANDLE cygheap_max;
+#define CYGHEAPSIZE ((4000 * sizeof (fhandler_union)) + (2 * 65536))
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
+struct _cmalloc_entry
+{
+ union
+ {
+ DWORD b;
+ char *ptr;
+ };
+ struct _cmalloc_entry *prev;
+ char data[0];
+};
+
+
+struct init_cygheap
+{
+ _cmalloc_entry *chain;
+ struct
+ {
+ size_t rootlen;
+ char *root;
+ };
+ mode_t umask;
+};
+
+extern init_cygheap *cygheap;
+extern void *cygheap_max;
+
extern "C" {
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
void __stdcall cygheap_fixup_in_child (HANDLE, bool);
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 8682685..7f75eca 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -654,7 +654,6 @@ dll_crt0_1 ()
threadname_init ();
debug_init ();
- cygheap_init (); /* Initialize cygheap muto */
regthread ("main", GetCurrentThreadId ());
mainthread.init ("mainthread"); // For use in determining if signals
@@ -734,6 +733,9 @@ dll_crt0_1 ()
/* Initialize events. */
events_init ();
+ if (!child_proc_info)
+ cygheap_init ();
+
cygcwd.init ();
cygbench ("pre-forkee");
@@ -861,14 +863,6 @@ dll_crt0_1 ()
extern "C" void __stdcall
_dll_crt0 ()
{
- char zeros[sizeof (fork_info->zero)] = {0};
-#ifdef DEBUGGING
- strace.microseconds ();
-#endif
-
- /* Set the os_being_run global. */
- set_os_type ();
-
#ifdef DEBUGGING
char buf[80];
if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf)))
@@ -878,7 +872,16 @@ _dll_crt0 ()
}
#endif
+ char zeros[sizeof (fork_info->zero)] = {0};
+#ifdef DEBUGGING
+ strace.microseconds ();
+#endif
+
+ /* Set the os_being_run global. */
+ set_os_type ();
+
main_environ = user_data->envptr;
+ *main_environ = NULL;
user_data->heapbase = user_data->heapptr = user_data->heaptop = NULL;
set_console_handler ();
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index d2b8bfe..b510e22 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -24,6 +24,7 @@ details. */
#include "fhandler.h"
#include "path.h"
#include "security.h"
+#include "cygheap.h"
/* Cygwin internal */
/* Return whether the directory of a file is writable. Return 1 if it
@@ -75,7 +76,7 @@ opendir (const char *dirname)
goto failed;
}
- if (stat (myself->rootlen ? dirname : real_dirname.get_win32 (),
+ if (stat (cygheap->rootlen ? dirname : real_dirname.get_win32 (),
&statbuf) == -1)
goto failed;
@@ -298,7 +299,7 @@ mkdir (const char *dir, mode_t mode)
if (CreateDirectoryA (real_dir.get_win32 (), 0))
{
set_file_attribute (real_dir.has_acls (), real_dir.get_win32 (),
- S_IFDIR | ((mode & 0777) & ~myself->umask));
+ S_IFDIR | ((mode & 0777) & ~cygheap->umask));
res = 0;
}
else
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc
index cf026eb..19515b5 100644
--- a/winsup/cygwin/external.cc
+++ b/winsup/cygwin/external.cc
@@ -65,7 +65,7 @@ fillout_pinfo (pid_t pid, int winpid)
ep.gid = p->gid;
ep.pgid = p->pgid;
ep.sid = p->sid;
- ep.umask = p->umask;
+ ep.umask = 0;
ep.start_time = p->start_time;
ep.rusage_self = p->rusage_self;
ep.rusage_children = p->rusage_children;
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 31c4029..663fd16 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -807,7 +807,7 @@ cygwin_bind (int fd, struct sockaddr *my_addr, int addrlen)
{
_close (fd);
chmod (un_addr->sun_path,
- (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~myself->umask);
+ (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask);
res = 0;
}
#undef un_addr
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 1b487ce..b415afa 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -110,9 +110,9 @@ cwdstuff cygcwd; /* The current working directory. */
!path[cygwin_shared->mount.cygdrive_len + 1]))
#define ischrootpath(path) \
- (myself->rootlen && \
- strncasematch (myself->root, path, myself->rootlen) && \
- (path[myself->rootlen] == '/' || path[myself->rootlen] == '\0'))
+ (cygheap->rootlen && \
+ strncasematch (cygheap->root, path, cygheap->rootlen) && \
+ (path[cygheap->rootlen] == '/' || path[cygheap->rootlen] == '\0'))
/* Return non-zero if PATH1 is a prefix of PATH2.
Both are assumed to be of the same path style and / vs \ usage.
@@ -615,7 +615,7 @@ normalize_posix_path (const char *src, char *dst)
/* Two leading /'s? If so, preserve them. */
else if (isslash (src[1]))
{
- if (myself->rootlen)
+ if (cygheap->rootlen)
{
debug_printf ("ENOENT = normalize_posix_path (%s)", src);
return ENOENT;
@@ -631,10 +631,10 @@ normalize_posix_path (const char *src, char *dst)
}
}
/* Exactly one leading slash. Absolute path. Check for chroot. */
- else if (myself->rootlen)
+ else if (cygheap->rootlen)
{
- strcpy (dst, myself->root);
- dst += myself->rootlen;
+ strcpy (dst, cygheap->root);
+ dst += cygheap->rootlen;
}
while (*src)
@@ -669,7 +669,7 @@ normalize_posix_path (const char *src, char *dst)
else
{
if (!ischrootpath (dst_start) ||
- dst - dst_start != (int) myself->rootlen)
+ dst - dst_start != (int) cygheap->rootlen)
while (dst > dst_start && !isslash (*--dst))
continue;
src++;
@@ -718,7 +718,7 @@ normalize_win32_path (const char *src, char *dst)
/* Two leading \'s? If so, preserve them. */
else if (SLASH_P (src[0]) && SLASH_P (src[1]))
{
- if (myself->rootlen)
+ if (cygheap->rootlen)
{
debug_printf ("ENOENT = normalize_win32_path (%s)", src);
return ENOENT;
@@ -727,13 +727,13 @@ normalize_win32_path (const char *src, char *dst)
++src;
}
/* If absolute path, care for chroot. */
- else if (SLASH_P (src[0]) && !SLASH_P (src[1]) && myself->rootlen)
+ else if (SLASH_P (src[0]) && !SLASH_P (src[1]) && cygheap->rootlen)
{
- strcpy (dst, myself->root);
+ strcpy (dst, cygheap->root);
char *c;
while ((c = strchr (dst, '/')) != NULL)
*c = '\\';
- dst += myself->rootlen;
+ dst += cygheap->rootlen;
dst_root_start = dst;
*dst++ = '\\';
}
@@ -997,7 +997,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
}
isrelpath = !isabspath (src_path);
*flags = set_flags_from_win32_path (dst);
- if (myself->rootlen && dst[0] && dst[1] == ':')
+ if (cygheap->rootlen && dst[0] && dst[1] == ':')
{
char posix_path[MAX_PATH + 1];
@@ -2939,9 +2939,9 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
tocopy = win32;
else
tocopy = with_chroot && ischrootpath(posix) ?
- posix + myself->rootlen : posix;
+ posix + cygheap->rootlen : posix;
- debug_printf("myself->root: %s, posix: %s", myself->root, posix);
+ debug_printf("cygheap->root: %s, posix: %s", cygheap->root, posix);
if (strlen (tocopy) >= ulen)
{
set_errno (ERANGE);
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 940e103..74ceb95 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -72,7 +72,6 @@ public:
pid_t pgid; /* Process group ID */
pid_t sid; /* Session ID */
int ctty; /* Control tty */
- mode_t umask;
bool has_pgid_children;/* True if we've forked or spawned children with our GID. */
char username[MAX_USER_NAME]; /* user's name */
@@ -93,11 +92,6 @@ public:
uid_t real_uid; /* Remains intact on seteuid, replaced by setuid */
gid_t real_gid; /* Ditto */
- /* Filled when chroot() is called by the process or one of it's parents.
- Saved without trailing backslash. */
- char root[MAX_PATH+1];
- size_t rootlen;
-
/* Resources used by process. */
long start_time;
struct rusage rusage_self;
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 28fec50..999dc73 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -263,7 +263,6 @@ proc_subproc (DWORD what, DWORD val)
vchild->pgid = myself->pgid;
vchild->sid = myself->sid;
vchild->ctty = myself->ctty;
- vchild->umask = myself->umask;
vchild->orig_uid = myself->orig_uid;
vchild->orig_gid = myself->orig_gid;
vchild->real_uid = myself->real_uid;
@@ -276,9 +275,7 @@ proc_subproc (DWORD what, DWORD val)
}
memcpy (vchild->logsrv, myself->logsrv, MAX_HOST_NAME);
memcpy (vchild->domain, myself->domain, MAX_COMPUTERNAME_LENGTH+1);
- memcpy (vchild->root, myself->root, MAX_PATH+1);
vchild->token = myself->token;
- vchild->rootlen = myself->rootlen;
vchild->process_state |= PID_INITIALIZING | (myself->process_state & PID_USETTY);
sigproc_printf ("added pid %d to wait list, slot %d, winpid %p, handle %p",
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 15bcbfb..348a49b 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -36,6 +36,7 @@ details. */
#include "shared_info.h"
#include "perprocess.h"
#include "security.h"
+#include "cygheap.h"
extern BOOL allow_ntsec;
@@ -401,7 +402,7 @@ _open (const char *unix_path, int flags, ...)
set_errno (ENMFILE);
else if ((fh = fdtab.build_fhandler (fd, unix_path, NULL)) == NULL)
res = -1; // errno already set
- else if (!fh->open (unix_path, flags, (mode & 0777) & ~myself->umask))
+ else if (!fh->open (unix_path, flags, (mode & 0777) & ~cygheap->umask))
{
fdtab.release (fd);
res = -1;
@@ -764,8 +765,8 @@ umask (mode_t mask)
{
mode_t oldmask;
- oldmask = myself->umask;
- myself->umask = mask & 0777;
+ oldmask = cygheap->umask;
+ cygheap->umask = mask & 0777;
return oldmask;
}
@@ -1921,16 +1922,19 @@ chroot (const char *newroot)
set_errno (ENOTDIR);
goto done;
}
+ char buf[MAX_PATH + 1];
ret = cygwin_shared->mount.conv_to_posix_path (path.get_win32 (),
- myself->root, 0);
+ buf, 0);
if (ret)
{
set_errno (ret);
goto done;
}
- myself->rootlen = strlen (myself->root);
- if (myself->root[myself->rootlen - 1] == '/')
- myself->root[--myself->rootlen] = '\0';
+ cygheap->rootlen = strlen (cygheap->root);
+ if (cygheap->rootlen > 1 && buf[cygheap->rootlen - 1] == '/')
+ buf[--cygheap->rootlen] = '\0';
+ cygheap->root = (char *) crealloc (cygheap->root, cygheap->rootlen + 1);
+ strcpy (cygheap->root, buf);
ret = 0;
done: