aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog51
-rw-r--r--winsup/cygwin/cygheap.cc35
-rw-r--r--winsup/cygwin/cygheap.h12
-rw-r--r--winsup/cygwin/dcrt0.cc15
-rw-r--r--winsup/cygwin/debug.cc67
-rw-r--r--winsup/cygwin/debug.h28
-rw-r--r--winsup/cygwin/exceptions.cc2
-rw-r--r--winsup/cygwin/fhandler.cc18
-rw-r--r--winsup/cygwin/fhandler_console.cc2
-rw-r--r--winsup/cygwin/fhandler_registry.cc2
-rw-r--r--winsup/cygwin/fhandler_socket.cc9
-rw-r--r--winsup/cygwin/fhandler_tty.cc4
-rw-r--r--winsup/cygwin/fork.cc21
-rw-r--r--winsup/cygwin/shared.cc6
-rw-r--r--winsup/cygwin/sigproc.cc3
-rw-r--r--winsup/cygwin/spawn.cc18
-rw-r--r--winsup/cygwin/syscalls.cc2
-rw-r--r--winsup/cygwin/tty.cc8
18 files changed, 192 insertions, 111 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 2df5619..acdf7e6 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,54 @@
+2002-07-13 Christopher Faylor <cgf@redhat.com>
+
+ * debug.h (handle_list): Move here from debug.cc. Add "inherit" flag
+ functionality.
+ * cygheap.cc (init_cheap): Move cygheap_max calculation to _csbrk.
+ (_csbrk): Reorganize to not assume first allocation is <= 1 page.
+ (cygheap_setup_for_child): Mark protected handle as inheritable.
+ * cygheap.h (cygheap_debug): New struct.
+ (init_cygheap): Add new structure when debugging.
+ * dcrt0.cc (dll_crt0_1): Remove call to debug_init. Close ppid_handle
+ here, if appropriate. Don't protect subproc_ready, since it is already
+ protected in the parent. Call memory_init prior to ProtectHandle to
+ ensure that cygheap is set up. Call debug_fixup_after_fork_exec when
+ appropriate.
+ (_dll_crt0): Don't close ppid_handle here.
+ * debug.cc: Use cygheap debug structure rather than static elements
+ throughout.
+ (add_handle): Don't issue a warning if attempt to protect handle in
+ exactly the same way from exactly the same place. Add pid info to
+ warning output. Accept additional argument controlling whether handle
+ is to be inherited. Add pid to stored information.
+ (debug_fixup_after_fork_exec): Renamed from debug_fixup_after_fork.
+ Reorganize to avoid erroneously skipping handles.
+ (mark_closed): Add pid info to warning output.
+ (setclexec): Rename from setclexec_pid.
+ * fhandler.cc (fhandler_base::get_default_fmode): Minor reorg.
+ (fhandler_base::fstat): Add debugging output.
+ (fhandler_base::set_inheritance): Call setclexec rather than
+ setclexec_pid.
+ (fhandler_base::fork_fixup): Ditto.
+ * fhandler_console.cc (get_tty_stuff): Mark protected handle as
+ inheritable.
+ * fhandler_tty.cc (fhandler_tty_slave::open): Ditto.
+ * tty.cc (tty::make_pipes): Ditto.
+ (tty::common_init): Ditto.
+ * fork.cc (fork_parent): Ditto.
+ (fork_child): Close protected handles with correct name. Remove
+ debug_fixup_after_fork call.
+ * fhandler_socket.cc (fhandler_socket::create_secret_event): Mark
+ protected handle as inheritable/non-inheritable, as appropriate.
+ * shared.cc (memory_init): Mark protected handle as inheritable.
+ Call debug_init here.
+ * sigproc.cc (wait_sig): Close protected handle with correct name.
+ * spawn.cc (spawn_guts): Rename spr to subproc_ready and mark it as
+ inheritable.
+
+ * exceptions.cc (debugger_command): Try to run dumper.exe, if found.
+
+ * syscalls.cc (fstat64): Don't follow symlinks for path_conv lookup
+ since path is already resolved.
+
2002-07-12 Christopher Faylor <cgf@redhat.com>
* cygwin.din: Change erroneous entries.
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index bc3f635..9aa5a4b 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -61,7 +61,6 @@ init_cheap ()
api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n",
m.AllocationBase, m.BaseAddress, m.RegionSize, m.State);
}
- cygheap_max = cygheap + 1;
}
static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3)));
@@ -82,7 +81,7 @@ cygheap_setup_for_child (child_info *ci, bool dup_later)
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL);
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
- ProtectHandle1 (ci->cygheap_h, passed_cygheap_h);
+ ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h);
if (!dup_later)
dup_now (newcygheap, ci, n);
cygheap_protect->release ();
@@ -171,27 +170,27 @@ cygheap_fixup_in_child (bool execed)
static void *__stdcall
_csbrk (int sbs)
{
- void *lastheap;
- bool needalloc;
+ void *prebrk;
- if (cygheap)
- needalloc = 0;
- else
+ if (!cygheap)
{
init_cheap ();
- needalloc = 1;
+ cygheap_max = cygheap;
+ (void) _csbrk ((int) pagetrunc (4095 + sbs + sizeof (*cygheap)));
+ prebrk = (char *) (cygheap + 1) + sbs;
+ }
+ else
+ {
+ prebrk = cygheap_max;
+ void *prebrka = pagetrunc (prebrk);
+ (char *) cygheap_max += sbs;
+ if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max)))
+ /* nothing to do */;
+ else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
+ api_fatal ("couldn't commit memory for cygwin heap, %E");
}
- lastheap = cygheap_max;
- (char *) cygheap_max += sbs;
- void *heapalign = (void *) pagetrunc (lastheap);
-
- if (!needalloc)
- needalloc = sbs && ((heapalign == lastheap) || heapalign != pagetrunc (cygheap_max));
- if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs ?: 1, MEM_COMMIT, PAGE_READWRITE))
- api_fatal ("couldn't commit memory for cygwin heap, %E");
-
- return lastheap;
+ return prebrk;
}
extern "C" void __stdcall
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index d2e06bf..be87810 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -188,6 +188,15 @@ struct cwdstuff
void set (const char *win32_cwd, const char *posix_cwd = NULL);
};
+#ifdef DEBUGGING
+struct cygheap_debug
+{
+ handle_list starth;
+ handle_list *endh;
+ handle_list freeh[500];
+};
+#endif
+
struct init_cygheap
{
_cmalloc_entry *chain;
@@ -207,6 +216,9 @@ struct init_cygheap
char *cygwin_regname;
cwdstuff cwd;
dtable fdtab;
+#ifdef DEBUGGING
+ cygheap_debug debug;
+#endif
bool etc_changed ();
};
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 62724cf..9c31a5b 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -572,7 +572,6 @@ dll_crt0_1 ()
user_data->threadinterface->Init (user_data->forkee);
threadname_init ();
- debug_init ();
(void) getpagesize (); /* initialize page size constant */
regthread ("main", GetCurrentThreadId ());
@@ -590,11 +589,12 @@ dll_crt0_1 ()
cygheap_fixup_in_child (0);
alloc_stack (fork_info);
set_myself (mypid);
- ProtectHandle (fork_info->forker_finished);
break;
case _PROC_SPAWN:
if (spawn_info->hexec_proc)
CloseHandle (spawn_info->hexec_proc);
+ if (child_proc_info->pppid_handle)
+ CloseHandle (child_proc_info->pppid_handle);
goto around;
case _PROC_EXEC:
hexec_proc = spawn_info->hexec_proc;
@@ -619,17 +619,17 @@ dll_crt0_1 ()
old_title = strcpy (title_buf, spawn_info->moreinfo->old_title);
cfree (spawn_info->moreinfo->old_title);
}
- if (child_proc_info->subproc_ready)
- ProtectHandle (child_proc_info->subproc_ready);
break;
}
+ debug_fixup_after_fork_exec ();
}
- ProtectHandle (hMainProc);
- ProtectHandle (hMainThread);
/* Initialize the cygwin subsystem if this is the first process,
or attach to shared data structures if it's already running. */
memory_init ();
+ ProtectHandle (hMainProc);
+ ProtectHandle (hMainThread);
+
cygheap->fdtab.vfork_child_fixup ();
(void) SetErrorMode (SEM_FAILCRITICALERRORS);
@@ -847,9 +847,6 @@ _dll_crt0 ()
should_be_cb = sizeof (child_info_fork);
/* fall through */;
case _PROC_SPAWN:
- if (child_proc_info->pppid_handle)
- CloseHandle (child_proc_info->pppid_handle);
- /* fall through */;
case _PROC_EXEC:
if (!should_be_cb)
should_be_cb = sizeof (child_info);
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index dc786ff..fa01773 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -15,6 +15,13 @@ details. */
#include "perprocess.h"
#include "security.h"
#include "cygerrno.h"
+#ifdef DEBUGGING
+#include <errno.h>
+#include "fhandler.h"
+#include "path.h"
+#include "dtable.h"
+#include "cygheap.h"
+#endif
#undef CloseHandle
@@ -164,23 +171,7 @@ threadname (DWORD tid, int lockit)
/* Here lies extra debugging routines which help track down internal
Cygwin problems when compiled with -DDEBUGGING . */
#include <stdlib.h>
-
-typedef struct _h
- {
- BOOL allocated;
- HANDLE h;
- const char *name;
- const char *func;
- int ln;
- DWORD clexec_pid;
- struct _h *next;
- } handle_list;
-
-static NO_COPY handle_list starth;
-static NO_COPY handle_list *endh;
-
-static NO_COPY handle_list freeh[1000];
-#define NFREEH (sizeof (freeh) / sizeof (freeh[0]))
+#define NFREEH (sizeof (cygheap->debug.freeh) / sizeof (cygheap->debug.freeh[0]))
void debug_init ();
@@ -222,10 +213,10 @@ static handle_list * __stdcall
find_handle (HANDLE h)
{
handle_list *hl;
- for (hl = &starth; hl->next != NULL; hl = hl->next)
+ for (hl = &cygheap->debug.starth; hl->next != NULL; hl = hl->next)
if (hl->next->h == h)
goto out;
- endh = hl;
+ cygheap->debug.endh = hl;
hl = NULL;
out:
@@ -233,12 +224,12 @@ out:
}
void
-setclexec_pid (HANDLE oh, HANDLE nh, bool setit)
+setclexec (HANDLE oh, HANDLE nh, bool setit)
{
handle_list *hl = find_handle (oh);
if (hl)
{
- hl->clexec_pid = setit ? GetCurrentProcessId () : 0;
+ hl->clexec = setit;
hl->h = nh;
}
}
@@ -250,7 +241,7 @@ newh ()
handle_list *hl;
lock_debug here;
- for (hl = freeh; hl < freeh + NFREEH; hl++)
+ for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++)
if (hl->name == NULL)
goto out;
@@ -267,7 +258,7 @@ out:
/* Add a handle to the linked list of known handles. */
void __stdcall
-add_handle (const char *func, int ln, HANDLE h, const char *name)
+add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
{
handle_list *hl;
lock_debug here;
@@ -275,10 +266,12 @@ add_handle (const char *func, int ln, HANDLE h, const char *name)
if ((hl = find_handle (h)))
{
hl = hl->next;
+ if (hl->name == name && hl->func == func && hl->ln == ln)
+ return;
system_printf ("%s:%d - multiple attempts to add handle %s<%p>", func,
ln, name, h);
- system_printf (" previously allocated by %s:%d(%s<%p>)",
- hl->func, hl->ln, hl->name, hl->h);
+ system_printf (" previously allocated by %s:%d(%s<%p>) winpid %d",
+ hl->func, hl->ln, hl->name, hl->h, hl->pid);
return;
}
@@ -294,8 +287,11 @@ add_handle (const char *func, int ln, HANDLE h, const char *name)
hl->func = func;
hl->ln = ln;
hl->next = NULL;
- endh->next = hl;
- endh = hl;
+ hl->clexec = !inh;
+ hl->pid = GetCurrentProcessId ();
+ cygheap->debug.endh->next = hl;
+ cygheap->debug.endh = hl;
+ debug_printf ("protecting handle '%s', clexec flag %d", hl->name, hl->clexec);
return;
}
@@ -312,13 +308,18 @@ delete_handle (handle_list *hl)
}
void
-debug_fixup_after_fork ()
+debug_fixup_after_fork_exec ()
{
/* No lock needed at this point */
handle_list *hl;
- for (hl = &starth; hl->next != NULL; hl = hl->next)
- if (hl->next->clexec_pid)
- delete_handle (hl);
+ for (hl = &cygheap->debug.starth; hl->next != NULL; /* nothing */)
+ if (!hl->next->clexec)
+ hl = hl->next;
+ else
+ {
+ debug_printf ("nuking handle '%s'", hl->next->name);
+ delete_handle (hl); // removes hl->next
+ }
}
static bool __stdcall
@@ -331,8 +332,8 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
{
hl = hl->next;
here.unlock (); // race here
- system_printf ("attempt to close protected handle %s:%d(%s<%p>)",
- hl->func, hl->ln, hl->name, hl->h);
+ system_printf ("attempt to close protected handle %s:%d(%s<%p>) winpid %d",
+ hl->func, hl->ln, hl->name, hl->h, hl->pid);
system_printf (" by %s:%d(%s<%p>)", func, ln, name, h);
return FALSE;
}
diff --git a/winsup/cygwin/debug.h b/winsup/cygwin/debug.h
index 1b6e0fa..6abdcb0 100644
--- a/winsup/cygwin/debug.h
+++ b/winsup/cygwin/debug.h
@@ -45,9 +45,12 @@ int __stdcall iscygthread ();
# define ProtectHandle(h) do {} while (0)
# define ProtectHandle1(h,n) do {} while (0)
# define ProtectHandle2(h,n) do {} while (0)
+# define ProtectHandleINH(h) do {} while (0)
+# define ProtectHandle1INH(h,n) do {} while (0)
+# define ProtectHandle2INH(h,n) do {} while (0)
# define debug_init() do {} while (0)
-# define setclexec_pid(h, nh, b) do {} while (0)
-# define debug_fixup_after_fork() do {} while (0)
+# define setclexec(h, nh, b) do {} while (0)
+# define debug_fixup_after_fork_exec() do {} while (0)
#else
@@ -67,17 +70,32 @@ int __stdcall iscygthread ();
# define ProtectHandle(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h)
# define ProtectHandle1(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n)
# define ProtectHandle2(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n)
+# define ProtectHandleINH(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h, 1)
+# define ProtectHandle1INH(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n, 1)
+# define ProtectHandle2INH(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n, 1)
void debug_init ();
-void __stdcall add_handle (const char *, int, HANDLE, const char *)
+void __stdcall add_handle (const char *, int, HANDLE, const char *, bool = false)
__attribute__ ((regparm (3)));
BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL)
__attribute__ ((regparm (3)));
void __stdcall cygbench (const char *s) __attribute__ ((regparm (1)));
extern "C" void console_printf (const char *fmt,...);
-void setclexec_pid (HANDLE, HANDLE, bool);
-void debug_fixup_after_fork ();
+void setclexec (HANDLE, HANDLE, bool);
+void debug_fixup_after_fork_exec ();
extern int pinger;
+struct handle_list
+ {
+ BOOL allocated;
+ HANDLE h;
+ const char *name;
+ const char *func;
+ int ln;
+ bool clexec;
+ DWORD pid;
+ struct handle_list *next;
+ };
+
#endif /*DEBUGGING*/
#endif /*_DEBUG_H_*/
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 1eb3fba..e2f10ae 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -25,7 +25,7 @@ details. */
#define CALL_HANDLER_RETRY 20
-char debugger_command[2 * MAX_PATH + 20];
+char debugger_command[2 * MAX_PATH + 20] = "dumper.exe";
extern "C" {
static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *);
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 96da497..e0f065b 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -313,13 +313,17 @@ fhandler_base::raw_write (const void *ptr, size_t len)
int
fhandler_base::get_default_fmode (int flags)
{
+ int fmode = __fmode;
if (perfile_table)
{
size_t nlen = strlen (get_name ());
unsigned accflags = ACCFLAGS (flags);
for (__cygwin_perfile *pf = perfile_table; pf->name; pf++)
if (!*pf->name && ACCFLAGS (pf->flags) == accflags)
- return pf->flags & ~(O_RDONLY | O_WRONLY | O_RDWR);
+ {
+ fmode = pf->flags & ~(O_RDONLY | O_WRONLY | O_RDWR);
+ break;
+ }
else
{
size_t pflen = strlen (pf->name);
@@ -327,10 +331,13 @@ fhandler_base::get_default_fmode (int flags)
if (pflen > nlen || (stem != get_name () && !isdirsep (stem[-1])))
continue;
else if (ACCFLAGS (pf->flags) == accflags && strcasematch (stem, pf->name))
- return pf->flags & ~(O_RDONLY | O_WRONLY | O_RDWR);
+ {
+ fmode = pf->flags & ~(O_RDONLY | O_WRONLY | O_RDWR);
+ break;
+ }
}
}
- return __fmode;
+ return fmode;
}
/* Open system call handler function. */
@@ -827,6 +834,7 @@ rootdir(char *full_path)
int __stdcall
fhandler_base::fstat (struct __stat64 *buf, path_conv *)
{
+ debug_printf ("here");
switch (get_device ())
{
case FH_PIPE:
@@ -1072,7 +1080,7 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
debug_printf ("DuplicateHandle failed, %E");
#ifdef DEBUGGING
if (h)
- setclexec_pid (oh, h, not_inheriting);
+ setclexec (oh, h, not_inheriting);
#endif
}
@@ -1092,7 +1100,7 @@ fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
{
debug_printf ("%s success - oldh %p, h %p", get_name (), oh, h);
// someday, maybe ProtectHandle2 (h, name);
- setclexec_pid (oh, h, !get_close_on_exec ());
+ setclexec (oh, h, !get_close_on_exec ());
}
#endif
}
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 76c8065..c8f0856 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -97,7 +97,7 @@ get_tty_stuff (int flags = 0)
shared_console_info = (tty_min *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info),
NULL);
- ProtectHandle (cygheap->console_h);
+ ProtectHandleINH (cygheap->console_h);
if (!shared_console_info->ntty)
{
shared_console_info->setntty (TTY_CONSOLE);
diff --git a/winsup/cygwin/fhandler_registry.cc b/winsup/cygwin/fhandler_registry.cc
index 45b8a85..4fc875a 100644
--- a/winsup/cygwin/fhandler_registry.cc
+++ b/winsup/cygwin/fhandler_registry.cc
@@ -191,7 +191,7 @@ fhandler_proc (FH_REGISTRY)
}
int
-fhandler_registry::fstat (struct __stat64 *buf, path_conv * pc)
+fhandler_registry::fstat (struct __stat64 *buf, path_conv *pc)
{
this->fhandler_base::fstat (buf, pc);
buf->st_mode &= ~_IFMT & NO_W;
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index aed61d7..6e76a65 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -155,12 +155,17 @@ fhandler_socket::create_secret_event (int* secret)
__small_sprintf (buf, SECRET_EVENT_NAME, sin.sin_port,
secret_ptr [0], secret_ptr [1],
secret_ptr [2], secret_ptr [3]);
- secret_event = CreateEvent (get_inheritance(true), FALSE, FALSE, buf);
+ LPSECURITY_ATTRIBUTES sec = get_inheritance (true);
+ secret_event = CreateEvent (sec, FALSE, FALSE, buf);
if (!secret_event && GetLastError () == ERROR_ALREADY_EXISTS)
secret_event = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf);
- if (secret_event)
+ if (!secret_event)
+ /* nothing to do */;
+ else if (sec == &sec_all_nih || sec == &sec_none_nih)
ProtectHandle (secret_event);
+ else
+ ProtectHandleINH (secret_event);
return secret_event;
}
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 918b434..013e8dc 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -555,9 +555,9 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
get_ttyp ()->to_master, to_master_local);
set_io_handle (from_master_local);
- ProtectHandle1 (from_master_local, from_pty);
+ ProtectHandle1INH (from_master_local, from_pty);
set_output_handle (to_master_local);
- ProtectHandle1 (to_master_local, to_pty);
+ ProtectHandle1INH (to_master_local, to_pty);
set_open_status ();
termios_printf ("tty%d opened", ttynum);
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index e25bc47..7486da0 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -275,9 +275,8 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
MALLOC_CHECK;
cygheap->fdtab.fixup_after_fork (hParent);
- ProtectHandle (hParent);
+ ProtectHandleINH (hParent);
- debug_fixup_after_fork ();
pinfo_fixup_after_fork ();
signal_fixup_after_fork ();
@@ -299,8 +298,8 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
}
ForceCloseHandle (hParent);
- (void) ForceCloseHandle (fork_info->subproc_ready);
- (void) ForceCloseHandle (fork_info->forker_finished);
+ (void) ForceCloseHandle1 (fork_info->subproc_ready, subproc_ready);
+ (void) ForceCloseHandle1 (fork_info->forker_finished, forker_finished);
if (fixup_shms_after_fork ())
api_fatal ("recreate_shm areas after fork failed");
@@ -359,16 +358,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
subproc_init ();
-#ifdef DEBUGGING_NOTNEEDED
- /* The ProtectHandle call allocates memory so we need to make sure
- that enough is set aside here so that the sbrk pointer does not
- move when ProtectHandle is called after the child is started.
- Otherwise the sbrk pointers in the parent will not agree with
- the child and when user_data is (regrettably) copied over,
- the user_data->ptr field will not be accurate. */
- free (malloc (4096));
-#endif
-
int c_flags = GetPriorityClass (hMainProc) /*|
CREATE_NEW_PROCESS_GROUP*/;
STARTUPINFO si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL};
@@ -428,8 +417,8 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
return -1;
}
- ProtectHandle (subproc_ready);
- ProtectHandle (forker_finished);
+ ProtectHandleINH (subproc_ready);
+ ProtectHandleINH (forker_finished);
init_child_info (PROC_FORK, &ch, 1, subproc_ready);
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 99218e9..2c3ba8d 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -143,8 +143,10 @@ memory_init ()
cygheap->user.set_name (user_name);
}
+ debug_init ();
+
cygheap->shared_h = shared_h;
- ProtectHandle (cygheap->shared_h);
+ ProtectHandleINH (cygheap->shared_h);
heap_init ();
mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION,
@@ -152,7 +154,7 @@ memory_init ()
sizeof (mount_info), 0);
debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (),
mount_table_address);
- ProtectHandle (cygwin_mount_h);
+ ProtectHandleINH (cygwin_mount_h);
debug_printf ("mount table version %x at %p", mount_table->version, mount_table);
/* Initialize the Cygwin per-user mount table, if necessary */
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index d8e5845..4964582 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -29,7 +29,6 @@ details. */
#include "child_info_magic.h"
#define NEED_VFORK
#include "perthread.h"
-#include <assert.h>
#include "shared_info.h"
/*
@@ -1119,7 +1118,7 @@ wait_sig (VOID *)
debug_printf ("subproc_ready %p", child_proc_info->subproc_ready);
if (!SetEvent (child_proc_info->subproc_ready))
system_printf ("SetEvent (subproc_ready) failed, %E");
- ForceCloseHandle (child_proc_info->subproc_ready);
+ ForceCloseHandle1 (child_proc_info->subproc_ready, subproc_ready);
/* Initialize an "indirect" pid block so that if someone looks up this
process via its Windows PID it will be redirected to the appropriate
Cygwin PID shared memory block. */
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 909cb00..7454adc 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -357,17 +357,17 @@ spawn_guts (const char * prog_arg, const char *const *argv,
else
chtype = PROC_EXEC;
- HANDLE spr;
+ HANDLE subproc_ready;
if (chtype != PROC_EXEC)
- spr = NULL;
+ subproc_ready = NULL;
else
{
- spr = CreateEvent (&sec_all, TRUE, FALSE, NULL);
- ProtectHandle (spr);
+ subproc_ready = CreateEvent (&sec_all, TRUE, FALSE, NULL);
+ ProtectHandleINH (subproc_ready);
}
init_child_info (chtype, &ciresrv, (mode == _P_OVERLAY) ? myself->pid : 1,
- spr);
+ subproc_ready);
if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &ciresrv.parent, 0, 1,
DUPLICATE_SAME_ACCESS))
{
@@ -689,8 +689,8 @@ spawn_guts (const char * prog_arg, const char *const *argv,
{
__seterrno ();
syscall_printf ("CreateProcess failed, %E");
- if (spr)
- ForceCloseHandle (spr);
+ if (subproc_ready)
+ ForceCloseHandle (subproc_ready);
cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0);
return -1;
}
@@ -768,7 +768,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
if (mode == _P_OVERLAY)
{
int nwait = 3;
- HANDLE waitbuf[3] = {pi.hProcess, signal_arrived, spr};
+ HANDLE waitbuf[3] = {pi.hProcess, signal_arrived, subproc_ready};
for (int i = 0; i < 100; i++)
{
switch (WaitForMultipleObjects (nwait, waitbuf, FALSE, INFINITE))
@@ -811,7 +811,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
break;
}
- ForceCloseHandle (spr);
+ ForceCloseHandle (subproc_ready);
sigproc_printf ("res = %x", res);
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index a66b69e..f2d7b19 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1022,7 +1022,7 @@ fstat64 (int fd, struct __stat64 *buf)
res = -1;
else
{
- path_conv pc (cfd->get_win32_name ());
+ path_conv pc (cfd->get_win32_name (), PC_SYM_NOFOLLOW);
memset (buf, 0, sizeof (struct __stat64));
res = cfd->fstat (buf, &pc);
if (!res)
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index c8760b7..8f7fe40 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -361,14 +361,14 @@ tty::make_pipes (fhandler_pty_master *ptym)
return FALSE;
}
- ProtectHandle1 (to_slave, to_pty);
+ ProtectHandle1INH (to_slave, to_pty);
if (CreatePipe (&from_slave, &to_master, &sec_all, 0) == FALSE)
{
termios_printf ("can't create output pipe");
set_errno (ENOENT);
return FALSE;
}
- ProtectHandle1 (from_slave, from_pty);
+ ProtectHandle1INH (from_slave, from_pty);
termios_printf ("tty%d from_slave %p, to_slave %p", ntty, from_slave,
to_slave);
@@ -441,8 +441,8 @@ tty::common_init (fhandler_pty_master *ptym)
return FALSE;
}
- ProtectHandle1 (ptym->output_mutex, output_mutex);
- ProtectHandle1 (ptym->input_mutex, input_mutex);
+ ProtectHandle1INH (ptym->output_mutex, output_mutex);
+ ProtectHandle1INH (ptym->input_mutex, input_mutex);
winsize.ws_col = 80;
winsize.ws_row = 25;