Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Scott <conrad.scott@dsl.pipex.com>2002-08-18 16:09:28 +0400
committerConrad Scott <conrad.scott@dsl.pipex.com>2002-08-18 16:09:28 +0400
commit210a84b5cd6bdac9c4bdea682ccae32582e0b2c7 (patch)
tree9995c9e2be6984f08d0bfe8efaf367d595a031d6
parentc7f4bbda99cdba696d30b510530af90d9434ea2d (diff)
Merged changes from HEAD
-rw-r--r--winsup/cygwin/ChangeLog42
-rw-r--r--winsup/cygwin/cygmalloc.h3
-rw-r--r--winsup/cygwin/cygwin.din1
-rw-r--r--winsup/cygwin/dcrt0.cc5
-rw-r--r--winsup/cygwin/exceptions.cc11
-rw-r--r--winsup/cygwin/fork.cc13
-rw-r--r--winsup/cygwin/include/cygwin/version.h3
-rw-r--r--winsup/cygwin/malloc.cc16
-rw-r--r--winsup/cygwin/malloc_wrapper.cc10
-rw-r--r--winsup/cygwin/perthread.h20
-rw-r--r--winsup/cygwin/sigproc.cc20
-rw-r--r--winsup/cygwin/sigproc.h1
-rw-r--r--winsup/cygwin/spawn.cc8
-rw-r--r--winsup/cygwin/syscalls.cc45
14 files changed, 153 insertions, 45 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 29fe374e0..be01e5dcf 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,43 @@
+2002-08-18 Christopher Faylor <cgf@redhat.com>
+
+ * perthread.h (vfork_save): Add ctty, sid, pgid, exitval fields.
+ (vfork_save::restore_pid): New method.
+ (vfork_save::restore_exit): New method.
+ * fork.cc (vfork): Save ctty, sid, pgid and restore them when returning
+ to "parent". Use exitval field if exiting but never created a new
+ process.
+ * syscalls.cc (setsid): Detect when in "vfork" and force an actual fork
+ so that pid will be allocated (UGLY!).
+ (getsid): New function.
+ * dcrt0.cc (do_exit): Use vfork_save::restore_exit method for returning
+ from a vfork.
+ * spawn.cc (spawnve): Use vfork_save::{restore_pid,restore_exit}
+ methods for returning from vfork.
+ * cygwin.din: Export getsid.
+ * include/cygwin/version.h: Bump api minor number.
+
+ * malloc.cc: #ifdef sYSTRIm for when MORECORE_CANNOT_TRIM is true.
+
+2002-08-18 Christopher Faylor <cgf@redhat.com>
+
+ * cygmalloc.h (MORECORE_CANNOT_TRIM): Define.
+
+2002-08-18 Christopher Faylor <cgf@redhat.com>
+
+ * sigproc.cc (sigCONT): Define.
+ * sigproc.h (sigCONT): Declare.
+ (wait_sig): Create sigCONT event here.
+ * exceptions.cc (sig_handle_tty_stop): Wait for sigCONT event rather
+ than stopping thread.
+ (sig_handle): Set sigCONT event as appropriate on SIGCONT rather than
+ calling ResumeThread.
+
+2002-08-17 Christopher Faylor <cgf@redhat.com>
+
+ * malloc.cc: Update to 2.7.2.
+ * malloc_wrapper.cc (malloc_init): Call user level mallocs to determine
+ if the malloc routines have been overridden.
+
2002-08-16 Christopher Faylor <cgf@redhat.com>
* winsup.h: Remove malloc_*lock functions.
@@ -65,7 +105,7 @@
(wait_for_sigthread): Rename from "wait_for_me". Assume that
wait_sig_inited has been set and that this function is only called from
the main thread.
- * winsup.h (wait_for_sigthread): Declare new function.
+ * sigproc.h (wait_for_sigthread): Declare new function.
2002-08-08 Christopher Faylor <cgf@redhat.com>
diff --git a/winsup/cygwin/cygmalloc.h b/winsup/cygwin/cygmalloc.h
index 818d56ee3..2c1bbde42 100644
--- a/winsup/cygwin/cygmalloc.h
+++ b/winsup/cygwin/cygmalloc.h
@@ -20,7 +20,8 @@ extern "C" int dlmallopt (int p, int v) __attribute__ ((regparm (2)));
extern "C" void dlmalloc_stats ();
#ifndef __INSIDE_CYGWIN__
-# define USE_DL_PREFIX
+# define USE_DL_PREFIX 1
+# define MORECORE_CANNOT_TRIM 1
#else
# define __malloc_lock() mallock->acquire ()
# define __malloc_unlock() mallock->release ()
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index 54063fdb4..b3b54e825 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -394,6 +394,7 @@ getrusage
_getrusage = getrusage
gets
_gets = gets
+getsid
gettimeofday
_gettimeofday = gettimeofday
getuid
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 079fb13b1..8367bf3d9 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -957,10 +957,7 @@ do_exit (int status)
vfork_save *vf = vfork_storage.val ();
if (vf != NULL && vf->pid < 0)
- {
- vf->pid = status < 0 ? status : -status;
- longjmp (vf->j, 1);
- }
+ vf->restore_exit (status);
if (exit_state < ES_SIGNAL)
{
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 914e4424d..cadd6baaf 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -615,7 +615,9 @@ sig_handle_tty_stop (int sig)
}
sigproc_printf ("process %d stopped by signal %d, myself->ppid_handle %p",
myself->pid, sig, myself->ppid_handle);
- SuspendThread (hMainThread);
+ if (WaitForSingleObject (sigCONT, INFINITE) != WAIT_OBJECT_0)
+ api_fatal ("WaitSingleObject failed, %E");
+ (void) ResetEvent (sigCONT);
return;
}
}
@@ -992,6 +994,7 @@ sig_handle (int sig, bool thisproc)
/* FIXME: Should we still do this if SIGCONT has a handler? */
if (sig == SIGCONT)
{
+ DWORD stopped = myself->process_state & PID_STOPPED;
myself->stopsig = 0;
myself->process_state &= ~PID_STOPPED;
/* Clear pending stop signals */
@@ -999,10 +1002,8 @@ sig_handle (int sig, bool thisproc)
sig_clear (SIGTSTP);
sig_clear (SIGTTIN);
sig_clear (SIGTTOU);
- /* Windows 95 hangs on resuming non-suspended thread */
- SuspendThread (hMainThread);
- while (ResumeThread (hMainThread) > 1)
- ;
+ if (stopped)
+ SetEvent (sigCONT);
/* process pending signals */
sig_dispatch_pending (1);
}
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 81ed6e21b..e566bf0e6 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -687,8 +687,7 @@ get_vfork_val ()
}
#endif
-extern "C"
-int
+extern "C" int
vfork ()
{
#ifndef NEWVFORK
@@ -711,9 +710,11 @@ vfork ()
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 2; pp++, esp++)
*pp = *esp;
+ vf->ctty = myself->ctty;
+ vf->sid = myself->sid;
+ vf->pgid = myself->pgid;
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
debug_printf ("%d = vfork()", res);
- debug_printf ("exiting vfork, res %d", res);
return res;
}
@@ -726,9 +727,13 @@ vfork ()
thisframe.init (mainthread);
cygheap->fdtab.vfork_parent_restore ();
+ myself->ctty = vf->ctty;
+ myself->sid = vf->sid;
+ myself->pgid = vf->pgid;
+
if (vf->pid < 0)
{
- int exitval = -vf->pid;
+ int exitval = vf->exitval;
vf->pid = 0;
if ((vf->pid = fork ()) == 0)
exit (exitval);
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index b68c52863..e9459070d 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -157,12 +157,13 @@ details. */
57: Export setgroups.
58: Export memalign, valloc, malloc_trim, malloc_usable_size, mallopt,
malloc_stats
+ 59: getsid
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 58
+#define CYGWIN_VERSION_API_MINOR 59
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible
diff --git a/winsup/cygwin/malloc.cc b/winsup/cygwin/malloc.cc
index 45005fdb8..02832bb99 100644
--- a/winsup/cygwin/malloc.cc
+++ b/winsup/cygwin/malloc.cc
@@ -5,7 +5,7 @@
way you wish. Send questions, comments, complaints, performance
data, etc to dl@cs.oswego.edu
-* VERSION 2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee)
+* VERSION 2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
Note: There may be an updated version of this malloc obtainable at
ftp://gee.cs.oswego.edu/pub/misc/malloc.c
@@ -1567,8 +1567,8 @@ static pthread_mutex_t mALLOC_MUTEx = PTHREAD_MUTEX_INITIALIZER;
/* Substitute anything you like for these */
-#define MALLOC_PREACTION __malloc_lock ()
-#define MALLOC_POSTACTION __malloc_unlock ()
+#define MALLOC_PREACTION (0)
+#define MALLOC_POSTACTION (0)
#endif
@@ -2412,8 +2412,8 @@ struct malloc_state {
/* Normal bins packed as described above */
mchunkptr bins[NBINS * 2];
- /* Bitmap of bins */
- unsigned int binmap[BINMAPSIZE];
+ /* Bitmap of bins. Trailing zero map handles cases of largest binned size */
+ unsigned int binmap[BINMAPSIZE+1];
/* Tunable parameters */
CHUNK_SIZE_T trim_threshold;
@@ -3294,7 +3294,7 @@ static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb; mstate av;
-
+#ifndef MORECORE_CANNOT_TRIM
/*
sYSTRIm is an inverse of sorts to sYSMALLOc. It gives memory back
to the system (via negative arguments to sbrk) if there is unused
@@ -3360,6 +3360,7 @@ static int sYSTRIm(pad, av) size_t pad; mstate av;
}
return 0;
}
+#endif /*MORECORE_CANNOT_TRIM*/
/*
------------------------------ malloc ------------------------------
@@ -5433,6 +5434,9 @@ static int cpuinfo (int whole, CHUNK_SIZE_T *kernel, CHUNK_SIZE_T *user) {
/* ------------------------------------------------------------
History:
+ V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
+ * Fix malloc_state bitmap array misdeclaration
+
V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee)
* Allow tuning of FIRST_SORTED_BIN_SIZE
* Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte.
diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc
index 96c6d2d12..51cc81832 100644
--- a/winsup/cygwin/malloc_wrapper.cc
+++ b/winsup/cygwin/malloc_wrapper.cc
@@ -111,7 +111,7 @@ strdup (const char *s)
extern "C" void
free (void *p)
{
- malloc_printf ("(%p), called by %x", p, ((int *)&p)[-1]);
+ malloc_printf ("(%p), called by %p", p, __builtin_return_address (0));
if (!use_internal_malloc)
user_data->free (p);
else
@@ -135,7 +135,7 @@ malloc (size_t size)
res = dlmalloc (size);
__malloc_unlock ();
}
- malloc_printf ("(%d) = %x, called by %x", size, res, ((int *)&size)[-1]);
+ malloc_printf ("(%d) = %x, called by %p", size, res, __builtin_return_address (0));
return res;
}
@@ -151,7 +151,7 @@ realloc (void *p, size_t size)
res = dlrealloc (p, size);
__malloc_unlock ();
}
- malloc_printf ("(%x, %d) = %x, called by %x", p, size, res, ((int *)&p)[-1]);
+ malloc_printf ("(%x, %d) = %x, called by %x", p, size, res, __builtin_return_address (0));
return res;
}
@@ -167,7 +167,7 @@ calloc (size_t nmemb, size_t size)
res = dlcalloc (nmemb, size);
__malloc_unlock ();
}
- malloc_printf ("(%d, %d) = %x, called by %x", nmemb, size, res, ((int *)&nmemb)[-1]);
+ malloc_printf ("(%d, %d) = %x, called by %x", nmemb, size, res, __builtin_return_address (0));
return res;
}
@@ -313,7 +313,7 @@ malloc_init ()
#ifdef MALLOC_DEBUG
_free_r (NULL, _malloc_r (NULL, 16));
#else
- free (malloc (16));
+ user_data->free (user_data->malloc (16));
#endif
if (!export_malloc_called)
use_internal_malloc = 0;
diff --git a/winsup/cygwin/perthread.h b/winsup/cygwin/perthread.h
index 48ad97621..f8682ae55 100644
--- a/winsup/cygwin/perthread.h
+++ b/winsup/cygwin/perthread.h
@@ -48,14 +48,30 @@ public:
};
#if defined (NEED_VFORK)
-struct vfork_save
+class vfork_save
{
- int pid;
jmp_buf j;
+ int exitval;
+ public:
+ int pid;
DWORD frame[100];
char **vfork_ebp;
char **vfork_esp;
+ int ctty;
+ pid_t sid;
+ pid_t pgid;
int is_active () { return pid < 0; }
+ void restore_pid (int val)
+ {
+ pid = val;
+ longjmp (j, 1);
+ }
+ void restore_exit (int val)
+ {
+ exitval = val;
+ longjmp (j, 1);
+ }
+ friend int vfork ();
};
class per_thread_vfork : public per_thread
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 49c8bda57..b43057e1c 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -80,34 +80,35 @@ HANDLE NO_COPY signal_arrived; // Event signaled when a signal has
Static DWORD proc_loop_wait = 1000; // Wait for subprocesses to exit
Static DWORD sig_loop_wait = INFINITE; // Wait for signals to arrive
-Static HANDLE sigcatch_nonmain = NULL; // The semaphore signaled when
+Static HANDLE sigcatch_nonmain; // The semaphore signaled when
// signals are available for
// processing from non-main thread
-Static HANDLE sigcatch_main = NULL; // Signalled when main thread sends a
+Static HANDLE sigcatch_main; // Signalled when main thread sends a
// signal
-Static HANDLE sigcatch_nosync = NULL; // Signal wait_sig to scan sigtodo
+Static HANDLE sigcatch_nosync; // Signal wait_sig to scan sigtodo
// but not to bother with any
// synchronization
-Static HANDLE sigcomplete_main = NULL; // Event signaled when a signal has
+Static HANDLE sigcomplete_main; // Event signaled when a signal has
// finished processing for the main
// thread
-Static HANDLE sigcomplete_nonmain = NULL;// Semaphore raised for non-main
+Static HANDLE sigcomplete_nonmain; // Semaphore raised for non-main
// threads when a signal has finished
// processing
+HANDLE NO_COPY sigCONT; // Used to "STOP" a process
Static cygthread *hwait_sig; // Handle of wait_sig thread
Static cygthread *hwait_subproc; // Handle of sig_subproc thread
-Static HANDLE wait_sig_inited = NULL; // Control synchronization of
+Static HANDLE wait_sig_inited; // Control synchronization of
// message queue startup
/* Used by WaitForMultipleObjects. These are handles to child processes.
*/
-Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++
+Static HANDLE events[PSIZE + 1]; // All my children's handles++
#define hchildren (events + 1) // Where the children handles begin
Static char cpchildren[PSIZE * sizeof (pinfo)]; // All my children info
-Static int nchildren = 0; // Number of active children
+Static int nchildren; // Number of active children
Static char czombies[NZOMBIES * sizeof (pinfo)]; // All my deceased children info
-Static int nzombies = 0; // Number of deceased children
+Static int nzombies; // Number of deceased children
#define pchildren ((pinfo *) cpchildren)
#define zombies ((pinfo *) czombies)
@@ -1048,6 +1049,7 @@ wait_sig (VOID *self)
sigcomplete_nonmain = CreateSemaphore (&sec_none_nih, 0, MAXLONG, NULL);
sigcomplete_main = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
sigproc_printf ("sigcatch_nonmain %p, sigcatch_main %p", sigcatch_nonmain, sigcatch_main);
+ sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
/* Setting dwProcessId flags that this process is now capable of receiving
* signals. Prior to this, dwProcessId was set to the windows pid of
diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h
index 36babecff..a461efdd6 100644
--- a/winsup/cygwin/sigproc.h
+++ b/winsup/cygwin/sigproc.h
@@ -95,6 +95,7 @@ public:
extern sigthread mainthread;
extern HANDLE signal_arrived;
+extern HANDLE sigCONT;
BOOL __stdcall my_parent_is_alive ();
extern "C" int __stdcall sig_dispatch_pending (int force = FALSE);
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 602c0af69..8c1c18adb 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -907,11 +907,13 @@ spawnve (int mode, const char *path, const char *const *argv,
case _P_DETACH:
subproc_init ();
ret = spawn_guts (path, argv, envp, mode);
- if (vf && ret > 0)
+ if (vf)
{
debug_printf ("longjmping due to vfork");
- vf->pid = ret;
- longjmp (vf->j, 1);
+ if (ret < 0)
+ vf->restore_exit (ret);
+ else
+ vf->restore_pid (ret);
}
break;
default:
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 31eed42b2..f047cbd1c 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -36,6 +36,9 @@ details. */
#include <unistd.h>
#include "shared_info.h"
#include "cygheap.h"
+#define NEED_VFORK
+#include <setjmp.h>
+#include "perthread.h"
SYSTEM_INFO system_info;
@@ -265,11 +268,24 @@ getppid ()
extern "C" pid_t
setsid (void)
{
- if (myself->pgid != _getpid ())
+ vfork_save *vf = vfork_storage.val ();
+ /* This is a horrible, horrible kludge */
+ if (vf && vf->pid < 0)
{
- if (myself->ctty == TTY_CONSOLE &&
- !cygheap->fdtab.has_console_fds () &&
- !check_pty_fds ())
+ pid_t pid = fork ();
+ if (pid > 0)
+ {
+ syscall_printf ("longjmping due to vfork");
+ vf->restore_pid (pid);
+ }
+ /* assuming that fork was successful */
+ }
+
+ if (myself->pgid != myself->pid)
+ {
+ if (myself->ctty == TTY_CONSOLE
+ && !cygheap->fdtab.has_console_fds ()
+ && !check_pty_fds ())
FreeConsole ();
myself->ctty = -1;
myself->sid = _getpid ();
@@ -277,10 +293,31 @@ setsid (void)
syscall_printf ("sid %d, pgid %d, ctty %d", myself->sid, myself->pgid, myself->ctty);
return myself->sid;
}
+
set_errno (EPERM);
return -1;
}
+extern "C" pid_t
+getsid (pid_t pid)
+{
+ pid_t res;
+ if (!pid)
+ res = myself->sid;
+ else
+ {
+ pinfo p (pid);
+ if (p)
+ res = p->sid;
+ else
+ {
+ set_errno (ESRCH);
+ res = -1;
+ }
+ }
+ return res;
+}
+
extern "C" ssize_t
_read (int fd, void *ptr, size_t len)
{