* cygheap.cc (dup_now): Make fatal error a little more informative.

(cygheap_setup_for_child): Detect when default size of shared region is less
than the current size and allocate that much.
(_cbrk): Just return NULL on inability to allocate.
(_cmalloc): Ditto.
* cygheap.h (CYGHEAPSIZE): Change size to reflect newer, tinier fhandler sizes.
* spawn.cc (av::error): New element, reflects potential errno from cmalloc.
(av::~av): Don't free NULL pointers.
(av::replace0_maybe): Detect out-of-memory conditions.
(av::dup_maybe): Ditto.
(av::dup_all): Ditto.
(av::unshift): Ditto.
(spawn_guts): Set errno and return if argv creation ran into problems.
* fhandler.h (fhandler_union): Change member names to something safer.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Always set
fhandler_console::dev_state regardless of whether shared region is initialized.
* cygthread.cc (cygthread::runner): Use ExitThread rather than return
(planning for future).
This commit is contained in:
Christopher Faylor 2002-10-09 04:08:05 +00:00
parent ce6ac4003f
commit 7da53596cf
8 changed files with 108 additions and 49 deletions

View File

@ -1,3 +1,29 @@
2002-10-08 Christopher Faylor <cgf@redhat.com>
* cygheap.cc (dup_now): Make fatal error a little more informative.
(cygheap_setup_for_child): Detect when default size of shared region is
less than the current size and allocate that much.
(_cbrk): Just return NULL on inability to allocate.
(_cmalloc): Ditto.
* cygheap.h (CYGHEAPSIZE): Change size to reflect newer, tinier
fhandler sizes.
* spawn.cc (av::error): New element, reflects potential errno from cmalloc.
(av::~av): Don't free NULL pointers.
(av::replace0_maybe): Detect out-of-memory conditions.
(av::dup_maybe): Ditto.
(av::dup_all): Ditto.
(av::unshift): Ditto.
(spawn_guts): Set errno and return if argv creation ran into problems.
* fhandler.h (fhandler_union): Change member names to something safer.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Always set
fhandler_console::dev_state regardless of whether shared region is
initialized.
* cygthread.cc (cygthread::runner): Use ExitThread rather than return
(planning for future).
2002-10-08 Christopher Faylor <cgf@redhat.com> 2002-10-08 Christopher Faylor <cgf@redhat.com>
* fhandler.h (dev_console): New class. * fhandler.h (dev_console): New class.

View File

@ -63,12 +63,13 @@ init_cheap ()
cygheap_max = cygheap; cygheap_max = cygheap;
} }
static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3))); // static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3)));
static void static void
dup_now (void *newcygheap, child_info *ci, unsigned n) dup_now (void *newcygheap, child_info *ci, unsigned n)
{ {
if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE)) if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE))
api_fatal ("couldn't allocate new cygwin heap for child, %E"); api_fatal ("couldn't allocate new cygwin heap %p, %d for child, %E",
newcygheap, n);
memcpy (newcygheap, cygheap, n); memcpy (newcygheap, cygheap, n);
} }
@ -77,9 +78,15 @@ cygheap_setup_for_child (child_info *ci, bool dup_later)
{ {
void *newcygheap; void *newcygheap;
cygheap_protect->acquire (); cygheap_protect->acquire ();
if (!ci) try_to_debug ();
unsigned n = (char *) cygheap_max - (char *) cygheap; unsigned n = (char *) cygheap_max - (char *) cygheap;
unsigned size = CYGHEAPSIZE;
if (size < n)
size = n + (128 * 1024);
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none, ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL); CFMAP_OPTIONS, 0, size, NULL);
if (!ci->cygheap_h)
api_fatal ("Couldn't create heap for child, size %d, %E", CYGHEAPSIZE);
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h); ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h);
if (!dup_later) if (!dup_later)
@ -177,7 +184,12 @@ _csbrk (int sbs)
if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max))) if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max)))
/* nothing to do */; /* nothing to do */;
else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
api_fatal ("couldn't commit memory for cygwin heap, %E"); {
malloc_printf ("couldn't commit memory for cygwin heap, %E");
__seterrno ();
(char *) cygheap_max -= sbs;
return NULL;
}
return prebrk; return prebrk;
} }
@ -222,6 +234,11 @@ _cmalloc (int size)
{ {
size = sz + sizeof (_cmalloc_entry); size = sz + sizeof (_cmalloc_entry);
rvc = (_cmalloc_entry *) _csbrk (size); rvc = (_cmalloc_entry *) _csbrk (size);
if (!rvc)
{
cygheap_protect->release ();
return NULL;
}
rvc->b = b; rvc->b = b;
rvc->prev = cygheap->chain; rvc->prev = cygheap->chain;

View File

@ -224,7 +224,7 @@ struct init_cygheap
bool etc_changed (); bool etc_changed ();
}; };
#define CYGHEAPSIZE (sizeof (init_cygheap) + (4000 * sizeof (fhandler_union)) + (2 * 65536)) #define CYGHEAPSIZE (sizeof (init_cygheap) + (16000 * sizeof (fhandler_union)) + (4 * 65536))
extern init_cygheap *cygheap; extern init_cygheap *cygheap;
extern void *cygheap_max; extern void *cygheap_max;

View File

@ -86,10 +86,10 @@ cygthread::runner (VOID *arg)
&threads[i], CREATE_SUSPENDED, &threads[i], CREATE_SUSPENDED,
&threads[i].avail); &threads[i].avail);
else else
return 0; ExitThread (0);
initialized ^= 1; initialized ^= 1;
return 0; ExitThread (0);
} }
/* Start things going. Called from dll_crt0_1. */ /* Start things going. Called from dll_crt0_1. */

View File

@ -725,7 +725,6 @@ enum ansi_intensity
#define eattitle 7 #define eattitle 7
#define MAXARGS 10 #define MAXARGS 10
class fhandler_console;
class dev_console class dev_console
{ {
WORD default_color, underline_color, dim_color; WORD default_color, underline_color, dim_color;
@ -1160,30 +1159,32 @@ class fhandler_process: public fhandler_proc
typedef union typedef union
{ {
char base[sizeof(fhandler_base)]; char __base[sizeof (fhandler_base)];
char console[sizeof(fhandler_console)]; char __console[sizeof (fhandler_console)];
char dev_clipboard[sizeof(fhandler_dev_clipboard)]; char __cygdrive[sizeof (fhandler_cygdrive)];
char dev_dsp[sizeof(fhandler_dev_dsp)]; char __dev_clipboard[sizeof (fhandler_dev_clipboard)];
char dev_floppy[sizeof(fhandler_dev_floppy)]; char __dev_dsp[sizeof (fhandler_dev_dsp)];
char dev_mem[sizeof(fhandler_dev_mem)]; char __dev_floppy[sizeof (fhandler_dev_floppy)];
char dev_null[sizeof(fhandler_dev_null)]; char __dev_mem[sizeof (fhandler_dev_mem)];
char dev_random[sizeof(fhandler_dev_random)]; char __dev_null[sizeof (fhandler_dev_null)];
char dev_raw[sizeof(fhandler_dev_raw)]; char __dev_random[sizeof (fhandler_dev_random)];
char dev_tape[sizeof(fhandler_dev_tape)]; char __dev_raw[sizeof (fhandler_dev_raw)];
char dev_zero[sizeof(fhandler_dev_zero)]; char __dev_tape[sizeof (fhandler_dev_tape)];
char disk_file[sizeof(fhandler_disk_file)]; char __dev_zero[sizeof (fhandler_dev_zero)];
char pipe[sizeof(fhandler_pipe)]; char __disk_file[sizeof (fhandler_disk_file)];
char proc[sizeof(fhandler_proc)]; char __pipe[sizeof (fhandler_pipe)];
char process[sizeof(fhandler_process)]; char __proc[sizeof (fhandler_proc)];
char pty_master[sizeof(fhandler_pty_master)]; char __process[sizeof (fhandler_process)];
char registry[sizeof(fhandler_registry)]; char __pty_master[sizeof (fhandler_pty_master)];
char serial[sizeof(fhandler_serial)]; char __registry[sizeof (fhandler_registry)];
char socket[sizeof(fhandler_socket)]; char __serial[sizeof (fhandler_serial)];
char termios[sizeof(fhandler_termios)]; char __socket[sizeof (fhandler_socket)];
char tty_common[sizeof(fhandler_tty_common)]; char __termios[sizeof (fhandler_termios)];
char tty_master[sizeof(fhandler_tty_master)]; char __tty_common[sizeof (fhandler_tty_common)];
char tty_slave[sizeof(fhandler_tty_slave)]; char __tty_master[sizeof (fhandler_tty_master)];
char windows[sizeof(fhandler_windows)]; char __tty_slave[sizeof (fhandler_tty_slave)];
char __virtual[sizeof (fhandler_virtual)];
char __windows[sizeof (fhandler_windows)];
} fhandler_union; } fhandler_union;
struct select_record struct select_record

View File

@ -100,12 +100,14 @@ dev_console NO_COPY *fhandler_console::dev_state;
tty_min * tty_min *
fhandler_console::get_tty_stuff (int flags = 0) fhandler_console::get_tty_stuff (int flags = 0)
{ {
if (shared_console_info) if (dev_state)
return &shared_console_info->tty_min_state; return &shared_console_info->tty_min_state;
shared_console_info = shared_console_info =
(console_state *) open_shared (NULL, 0, cygheap->console_h, (console_state *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info), NULL); sizeof (*shared_console_info), NULL);
dev_state = &shared_console_info->dev_state;
ProtectHandleINH (cygheap->console_h); ProtectHandleINH (cygheap->console_h);
if (!shared_console_info->tty_min_state.ntty) if (!shared_console_info->tty_min_state.ntty)
{ {
@ -113,7 +115,6 @@ fhandler_console::get_tty_stuff (int flags = 0)
shared_console_info->tty_min_state.setsid (myself->sid); shared_console_info->tty_min_state.setsid (myself->sid);
shared_console_info->tty_min_state.set_ctty (TTY_CONSOLE, flags); shared_console_info->tty_min_state.set_ctty (TTY_CONSOLE, flags);
fhandler_console::dev_state = &shared_console_info->dev_state;
dev_state->scroll_region.Bottom = -1; dev_state->scroll_region.Bottom = -1;
dev_state->dwLastCursorPosition.X = -1; dev_state->dwLastCursorPosition.X = -1;
dev_state->dwLastCursorPosition.Y = -1; dev_state->dwLastCursorPosition.Y = -1;

View File

@ -457,7 +457,7 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
myself->progname, myself->progname, c_flags, &si, &pi); myself->progname, myself->progname, c_flags, &si, &pi);
__malloc_lock (); __malloc_lock ();
void *newheap; void *newheap;
newheap = cygheap_setup_for_child (&ch,cygheap->fdtab.need_fixup_before ()); newheap = cygheap_setup_for_child (&ch, cygheap->fdtab.need_fixup_before ());
rc = CreateProcess (myself->progname, /* image to run */ rc = CreateProcess (myself->progname, /* image to run */
myself->progname, /* what we send in arg0 */ myself->progname, /* what we send in arg0 */
sec_attribs, sec_attribs,

View File

@ -254,39 +254,46 @@ class av
char **argv; char **argv;
int calloced; int calloced;
public: public:
int error;
int argc; int argc;
av (int ac, const char * const *av) : calloced (0), argc (ac) av (int ac, const char * const *av) : calloced (0), error (false), argc (ac)
{ {
argv = (char **) cmalloc (HEAP_1_ARGV, (argc + 5) * sizeof (char *)); argv = (char **) cmalloc (HEAP_1_ARGV, (argc + 5) * sizeof (char *));
memcpy (argv, av, (argc + 1) * sizeof (char *)); memcpy (argv, av, (argc + 1) * sizeof (char *));
} }
~av () ~av ()
{
if (argv)
{ {
for (int i = 0; i < calloced; i++) for (int i = 0; i < calloced; i++)
if (argv[i])
cfree (argv[i]); cfree (argv[i]);
cfree (argv); cfree (argv);
} }
}
int unshift (const char *what, int conv = 0); int unshift (const char *what, int conv = 0);
operator char **() {return argv;} operator char **() {return argv;}
void all_calloced () {calloced = argc;} void all_calloced () {calloced = argc;}
void replace0_maybe (const char *arg0) void replace0_maybe (const char *arg0)
{ {
/* Note: Assumes that argv array has not yet been "unshifted" */ /* Note: Assumes that argv array has not yet been "unshifted" */
if (!calloced) if (!calloced
{ && (argv[0] = cstrdup1 (arg0)))
argv[0] = cstrdup1 (arg0); calloced = true;
calloced = 1; else
} error = errno;
} }
void dup_maybe (int i) void dup_maybe (int i)
{ {
if (i >= calloced) if (i >= calloced
argv[i] = cstrdup1 (argv[i]); && !(argv[i] = cstrdup1 (argv[i])))
error = errno;
} }
void dup_all () void dup_all ()
{ {
for (int i = calloced; i < argc; i++) for (int i = calloced; i < argc; i++)
argv[i] = cstrdup1 (argv[i]); if (!(argv[i] = cstrdup1 (argv[i])))
error = errno;
} }
}; };
@ -309,7 +316,8 @@ av::unshift (const char *what, int conv)
*p = '\0'; *p = '\0';
what = buf; what = buf;
} }
*argv = cstrdup1 (what); if (!(*argv = cstrdup1 (what)))
error = errno;
argc++; argc++;
calloced++; calloced++;
return 1; return 1;
@ -338,7 +346,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
{ {
syscall_printf ("argv is NULL"); syscall_printf ("argv is NULL");
set_errno (EINVAL); set_errno (EINVAL);
return (-1); return -1;
} }
path_conv real_path; path_conv real_path;
@ -561,6 +569,12 @@ spawn_guts (const char * prog_arg, const char *const *argv,
char *envblock; char *envblock;
newargv.all_calloced (); newargv.all_calloced ();
if (newargv.error)
{
set_errno (newargv.error);
return -1;
}
ciresrv.moreinfo->argc = newargv.argc; ciresrv.moreinfo->argc = newargv.argc;
ciresrv.moreinfo->argv = newargv; ciresrv.moreinfo->argv = newargv;
ciresrv.hexec_proc = hexec_proc; ciresrv.hexec_proc = hexec_proc;