* sync.h (new_muto): Just accept an argument which denotes the name of the

muto.  Use this argument to construct static storage.
* cygheap.cc (cygheap_init): Reflect above change.
* exceptions.cc (events_init): Ditto.
* malloc.cc (malloc_init): Ditto.
* path.cc (cwdstuff::init): Ditto.
* cygheap.h (cwdstuff): Change name of lock element to make it less generic.
* path.cc (cwdstuff::get_hash): Ditto.
(cwdstuff::get_initial): Ditto.
(cwdstuff::set): Ditto.
(cwdstuff::get): Ditto.
* sigproc.cc (proc_subproc): Ditto.
* debug.cc (lock_debug): Change to method.  Use method rather than macro
throughout.
* tty.h (tty_min::kill_pgrp): Declare new method.
* fhandler_termios.cc (tty_min::kill_pgrp): New method.
(fhandler_termios::line_edit): Use new method for killing process.
* dcrt0.cc (do_exit): Ditto.
* dtable.cc (dtable::get_debugger_info): New method for inheriting dtable info
from a debugger.
* tty.cc (tty_init): Attempt to grab file handle info from parent debugger, if
appropriate.  # dtable.cc (dtable::stdio_init): Make this a method.
(dtable::init_std_file_from_handle): Don't set fd unless it's not open.
(dtable::build_fhandler_from_name): Move name setting to
dtable::build_fhandler.
(dtable::build_fhandler): Add win32 name parameter.
* dcrt0.cc (dll_crt0_1): Change to use dtable stdio_init.
* dtable.h (dtable): Reflect build_fhandler parameter change.
* mmap.cc (mmap_record::alloc_fh): Don't set name parameter in build_fhandler.
* net.cc (fdsock): Remove set_name call since it is now handled by
build_fhandler.
* sigproc.cc (proc_subproc): Release muto as early as possible.
This commit is contained in:
Christopher Faylor
2002-02-22 19:33:41 +00:00
parent a6790c5f11
commit 083abe5428
18 changed files with 192 additions and 84 deletions

View File

@@ -34,7 +34,7 @@ details. */
#include "cygheap.h"
static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE};
STD_ERROR_HANDLE};
/* Set aside space for the table of fds */
void
@@ -90,49 +90,75 @@ dtable::extend (int howmuch)
return 1;
}
void
dtable::get_debugger_info ()
{
if (IsDebuggerPresent ())
{
char std[3][sizeof ("/dev/ttyNNNN")];
std[0][0] = std[1][0] = std [2][0] = '\0';
char buf[sizeof ("cYgstd %x") + 32];
sprintf (buf, "cYgstd %x %x %x", (unsigned) &std, sizeof (std[0]), 3);
OutputDebugString (buf);
for (int i = 0; i < 3; i++)
if (std[i][0])
{
path_conv pc;
HANDLE h = GetStdHandle (std_consts[i]);
fhandler_base *fh = build_fhandler_from_name (i, std[i], NULL, pc);
if (!fh)
continue;
if (!fh->open (&pc, (i ? O_WRONLY : O_RDONLY) | O_BINARY, 0777))
release (i);
else
CloseHandle (h);
}
}
}
/* Initialize the file descriptor/handle mapping table.
This function should only be called when a cygwin function is invoked
by a non-cygwin function, i.e., it should only happen very rarely. */
void
stdio_init (void)
dtable::stdio_init ()
{
extern void set_console_ctty ();
/* Set these before trying to output anything from strace.
Also, always set them even if we're to pick up our parent's fds
in case they're missed. */
if (!myself->ppid_handle && NOTSTATE (myself, PID_CYGPARENT))
if (myself->ppid_handle || ISSTATE (myself, PID_CYGPARENT))
return;
HANDLE in = GetStdHandle (STD_INPUT_HANDLE);
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
init_std_file_from_handle (0, in, GENERIC_READ);
/* STD_ERROR_HANDLE has been observed to be the same as
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
to pass data from child to parent). */
if (out == err)
{
HANDLE in = GetStdHandle (STD_INPUT_HANDLE);
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
cygheap->fdtab.init_std_file_from_handle (0, in, GENERIC_READ);
/* STD_ERROR_HANDLE has been observed to be the same as
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
to pass data from child to parent). */
if (out == err)
/* Since this code is not invoked for forked tasks, we don't have
to worry about the close-on-exec flag here. */
if (!DuplicateHandle (hMainProc, out, hMainProc, &err, 0,
1, DUPLICATE_SAME_ACCESS))
{
/* Since this code is not invoked for forked tasks, we don't have
to worry about the close-on-exec flag here. */
if (!DuplicateHandle (hMainProc, out, hMainProc, &err, 0,
1, DUPLICATE_SAME_ACCESS))
{
/* If that fails, do this as a fall back. */
err = out;
system_printf ("couldn't make stderr distinct from stdout");
}
/* If that fails, do this as a fall back. */
err = out;
system_printf ("couldn't make stderr distinct from stdout");
}
cygheap->fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE);
cygheap->fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE);
/* Assign the console as the controlling tty for this process if we actually
have a console and no other controlling tty has been assigned. */
if (myself->ctty < 0 && GetConsoleCP () > 0)
set_console_ctty ();
}
init_std_file_from_handle (1, out, GENERIC_WRITE);
init_std_file_from_handle (2, err, GENERIC_WRITE);
/* Assign the console as the controlling tty for this process if we actually
have a console and no other controlling tty has been assigned. */
if (myself->ctty < 0 && GetConsoleCP () > 0)
set_console_ctty ();
}
int
@@ -196,6 +222,9 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
first_fd_for_open = 0;
if (!not_open (fd))
return;
if (!handle || handle == INVALID_HANDLE_VALUE)
{
fds[fd] = NULL;
@@ -258,14 +287,13 @@ dtable::build_fhandler_from_name (int fd, const char *name, HANDLE handle,
return NULL;
}
fhandler_base *fh = build_fhandler (fd, pc.get_devn (), name, pc.get_unitn ());
fh->set_name (name, pc, pc.get_unitn ());
return fh;
return build_fhandler (fd, pc.get_devn (), name, pc, pc.get_unitn ());
}
#define cnew(name) new ((void *) ccalloc (HEAP_FHANDLER, 1, sizeof (name))) name
fhandler_base *
dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
dtable::build_fhandler (int fd, DWORD dev, const char *unix_name,
const char *win32_name, int unit)
{
fhandler_base *fh;
@@ -340,6 +368,20 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
fh = NULL;
}
if (unix_name)
{
char new_win32_name[strlen (unix_name) + 1];
if (!win32_name)
{
char *p;
/* FIXME: ? Should we call win32_device_name here?
It seems like overkill, but... */
win32_name = strcpy (new_win32_name, unix_name);
for (p = (char *) win32_name; (p = strchr (p, '/')); p++)
*p = '\\';
}
fh->set_name (unix_name, win32_name, fh->get_unit ());
}
debug_printf ("fd %d, fh %p", fd, fh);
return fd >= 0 ? (fds[fd] = fh) : fh;
}