4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-01 03:50:28 +08:00

* dcrt0.cc (dll_crt0_1): Move debug_init call back to here. Avoid a compiler

warning.
* shared.cc (memory_init): Remove debug_init call.
* debug.h (handle_list): Change "clexec" to "inherited".
* debug.cc: Remove a spurious declaration.
(setclexec): Conditionalize away since it is currently unused.
(add_handle): Use inherited field rather than clexec.
(debug_fixup_after_fork_exec): Ditto.  Move debugging output to delete_handle.
(delete_handle): Add debugging output.
* fhandler.cc (fhandler_base::set_inheritance): Don't bother setting
inheritance in debugging table since the handle was never protected anyway.
(fhandler_base::fork_fixup): Ditto.
* exceptions.cc (debugger_command): Revert.
This commit is contained in:
Christopher Faylor 2002-07-14 19:15:32 +00:00
parent f5c3d18080
commit 3d0ba393df
7 changed files with 42 additions and 27 deletions

View File

@ -1,3 +1,22 @@
2002-07-14 Christopher Faylor <cgf@redhat.com>
* dcrt0.cc (dll_crt0_1): Move debug_init call back to here. Avoid a
compiler warning.
* shared.cc (memory_init): Remove debug_init call.
* debug.h (handle_list): Change "clexec" to "inherited".
* debug.cc: Remove a spurious declaration.
(setclexec): Conditionalize away since it is currently unused.
(add_handle): Use inherited field rather than clexec.
(debug_fixup_after_fork_exec): Ditto. Move debugging output to
delete_handle.
(delete_handle): Add debugging output.
* fhandler.cc (fhandler_base::set_inheritance): Don't bother setting
inheritance in debugging table since the handle was never protected
anyway.
(fhandler_base::fork_fixup): Ditto.
* exceptions.cc (debugger_command): Revert.
2002-07-14 Conrad Scott <conrad.scott@dsl.pipex.com> 2002-07-14 Conrad Scott <conrad.scott@dsl.pipex.com>
* debug.cc (clexec): Add missing `hl = hl->next'. * debug.cc (clexec): Add missing `hl = hl->next'.

View File

@ -633,9 +633,14 @@ dll_crt0_1 ()
/* Initialize the cygwin subsystem if this is the first process, /* Initialize the cygwin subsystem if this is the first process,
or attach to shared data structures if it's already running. */ or attach to shared data structures if it's already running. */
memory_init (); memory_init ();
ProtectHandle (hMainProc); ProtectHandle (hMainProc);
ProtectHandle (hMainThread); ProtectHandle (hMainThread);
/* Initialize debug muto, if DLL is built with --enable-debugging.
Need to do this before any helper threads start. */
debug_init ();
cygheap->fdtab.vfork_child_fixup (); cygheap->fdtab.vfork_child_fixup ();
(void) SetErrorMode (SEM_FAILCRITICALERRORS); (void) SetErrorMode (SEM_FAILCRITICALERRORS);
@ -807,7 +812,7 @@ initial_env ()
len = GetModuleFileName (NULL, buf1, MAX_PATH); len = GetModuleFileName (NULL, buf1, MAX_PATH);
char *p = strchr (buf, '='); char *p = strchr (buf, '=');
if (!p) if (!p)
p = "gdb.exe -nw"; p = (char *) "gdb.exe -nw";
else else
*p++ = '\0'; *p++ = '\0';
if (strstr (buf1, buf)) if (strstr (buf1, buf))

View File

@ -173,8 +173,6 @@ threadname (DWORD tid, int lockit)
#include <stdlib.h> #include <stdlib.h>
#define NFREEH (sizeof (cygheap->debug.freeh) / sizeof (cygheap->debug.freeh[0])) #define NFREEH (sizeof (cygheap->debug.freeh) / sizeof (cygheap->debug.freeh[0]))
void debug_init ();
class lock_debug class lock_debug
{ {
static muto *locker; static muto *locker;
@ -223,17 +221,19 @@ out:
return hl; return hl;
} }
#ifdef DEBUGGING_AND_FDS_PROTECTED
void void
setclexec (HANDLE oh, HANDLE nh, bool setit) setclexec (HANDLE oh, HANDLE nh, bool not_inheriting)
{ {
handle_list *hl = find_handle (oh); handle_list *hl = find_handle (oh);
if (hl) if (hl)
{ {
hl = hl->next; hl = hl->next;
hl->clexec = setit; hl->inherited = !not_inheriting;
hl->h = nh; hl->h = nh;
} }
} }
#endif
/* Create a new handle record */ /* Create a new handle record */
static handle_list * __stdcall static handle_list * __stdcall
@ -288,11 +288,11 @@ add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
hl->func = func; hl->func = func;
hl->ln = ln; hl->ln = ln;
hl->next = NULL; hl->next = NULL;
hl->clexec = !inh; hl->inherited = inh;
hl->pid = GetCurrentProcessId (); hl->pid = GetCurrentProcessId ();
cygheap->debug.endh->next = hl; cygheap->debug.endh->next = hl;
cygheap->debug.endh = hl; cygheap->debug.endh = hl;
debug_printf ("protecting handle '%s', clexec flag %d", hl->name, hl->clexec); debug_printf ("protecting handle '%s', inherited flag %d", hl->name, hl->inherited);
return; return;
} }
@ -301,6 +301,7 @@ static void __stdcall
delete_handle (handle_list *hl) delete_handle (handle_list *hl)
{ {
handle_list *hnuke = hl->next; handle_list *hnuke = hl->next;
debug_printf ("nuking handle '%s'", hnuke->name);
hl->next = hl->next->next; hl->next = hl->next->next;
if (hnuke->allocated) if (hnuke->allocated)
free (hnuke); free (hnuke);
@ -314,13 +315,10 @@ debug_fixup_after_fork_exec ()
/* No lock needed at this point */ /* No lock needed at this point */
handle_list *hl; handle_list *hl;
for (hl = &cygheap->debug.starth; hl->next != NULL; /* nothing */) for (hl = &cygheap->debug.starth; hl->next != NULL; /* nothing */)
if (!hl->next->clexec) if (hl->next->inherited)
hl = hl->next; hl = hl->next;
else else
{ delete_handle (hl); // removes hl->next
debug_printf ("nuking handle '%s'", hl->next->name);
delete_handle (hl); // removes hl->next
}
} }
static bool __stdcall static bool __stdcall

View File

@ -92,7 +92,7 @@ struct handle_list
const char *name; const char *name;
const char *func; const char *func;
int ln; int ln;
bool clexec; bool inherited;
DWORD pid; DWORD pid;
struct handle_list *next; struct handle_list *next;
}; };

View File

@ -25,7 +25,7 @@ details. */
#define CALL_HANDLER_RETRY 20 #define CALL_HANDLER_RETRY 20
char debugger_command[2 * MAX_PATH + 20] = "dumper.exe %s"; char debugger_command[2 * MAX_PATH + 20];
extern "C" { extern "C" {
static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *); static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *);

View File

@ -1067,7 +1067,7 @@ fhandler_dev_null::dump (void)
void void
fhandler_base::set_inheritance (HANDLE &h, int not_inheriting) fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
{ {
#ifdef DEBUGGING #ifdef DEBUGGING_AND_FDS_PROTECTED
HANDLE oh = h; HANDLE oh = h;
#endif #endif
/* Note that we could use SetHandleInformation here but it is not available /* Note that we could use SetHandleInformation here but it is not available
@ -1078,7 +1078,7 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
if (!DuplicateHandle (hMainProc, h, hMainProc, &h, 0, !not_inheriting, if (!DuplicateHandle (hMainProc, h, hMainProc, &h, 0, !not_inheriting,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
debug_printf ("DuplicateHandle failed, %E"); debug_printf ("DuplicateHandle failed, %E");
#ifdef DEBUGGING #ifdef DEBUGGING_AND_FDS_PROTECTED
if (h) if (h)
setclexec (oh, h, not_inheriting); setclexec (oh, h, not_inheriting);
#endif #endif
@ -1087,21 +1087,16 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
void void
fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name) fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
{ {
#ifdef DEBUGGING
HANDLE oh = h;
#endif
if (/* !is_socket () && */ !get_close_on_exec ()) if (/* !is_socket () && */ !get_close_on_exec ())
debug_printf ("handle %p already opened", h); debug_printf ("handle %p already opened", h);
else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !get_close_on_exec (), else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !get_close_on_exec (),
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h); system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
#ifdef DEBUGGING #ifdef DEBUGGING_AND_FDS_PROTECTED
else if (get_close_on_exec ())
ProtectHandle (h); /* would have to be fancier than this */
else else
{ /* ProtectHandleINH (h) */; /* Should already be protected */
debug_printf ("%s success - oldh %p, h %p", get_name (), oh, h);
// someday, maybe ProtectHandle2 (h, name);
setclexec (oh, h, !get_close_on_exec ());
}
#endif #endif
} }

View File

@ -143,8 +143,6 @@ memory_init ()
cygheap->user.set_name (user_name); cygheap->user.set_name (user_name);
} }
debug_init ();
cygheap->shared_h = shared_h; cygheap->shared_h = shared_h;
ProtectHandleINH (cygheap->shared_h); ProtectHandleINH (cygheap->shared_h);