Mark Geisert | 20 Feb 09:16 2016

[PATCH] gprof profiling of multi-threaded Cygwin programs, ver 2

Version 2 incorporating review comments of version 1.

Change log relative to winsup/cygwin:

         * include/sys/cygwin.h: Add CW_CYGHEAP_PROFTHR_ALL.
         * (cygheap_profthr_all): New C-callable function that
         runs cygheap's threadlist handing each pthread's thread handle in
         turn to profthr_byhandle().
         * (cygwin_internal): Add case CW_CYGHEAP_PROFTHR_ALL.
         * gmon.c (_mcleanup): Add support for multiple simultaneous
         gmon.out* files named via environment variable GMON_OUT_PREFIX.
         * gmon.h (struct gmonparam): Make state decl volatile.
         * mcount.c (_MCOUNT_DECL): Change stores into gmonparam.state to use
         Interlocked operations. Add #include "winsup.h", update commentary.
         * profil.c (profthr_byhandle): New function abstracting out the
         updating of profile counters based on a thread handle.
         (profthr_func): Update to call profthr_byhandle() to sample the main
         thread then call cygheap_profthr_all() indirectly through
         cygwin_internal(CW_CYGHEAP_PROFTHR_ALL) to sample all other threads.



 winsup/cygwin/           | 12 ++++++
 winsup/cygwin/          | 11 ++++++
 winsup/cygwin/gmon.c               | 81 ++++++++++++++++----------------------
(Continue reading)

Jon Turney | 18 Feb 11:50 2016

[PATCH] ssp: Fixes for 64-bit

Fix various 32/64-bit portability issues in ssp, the single-step profiler, and
also build it for 64-bit.

This didn't turn out to actually be very useful for what I wanted to use it for,
so it's only been lightly tested.

It appears that on x86_64, single-step exceptions occur for much more of the
code in system DLLs, unlike x86, so ssp may take much, much longer to profile
some programs.  There is existing code to use breakpoints to mitigate this, but
that is currently disabled.

Signed-off-by: Jon Turney <jon.turney <at>>
 winsup/utils/ssp.c | 204 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 109 insertions(+), 95 deletions(-)

diff --git a/winsup/utils/ssp.c b/winsup/utils/ssp.c
index 3136a9f..c9165f3 100644
--- a/winsup/utils/ssp.c
+++ b/winsup/utils/ssp.c
 <at>  <at>  -13,20 +13,6  <at>  <at> 

-#ifdef __x86_64__
-#include <stdio.h>
-main (int argc, char **argv)
(Continue reading)

Yaakov Selkowitz | 18 Feb 06:21 2016

[PATCH] cygwin: accept SIGIOT as alias of SIGABRT

	* include/cygwin/signal.h (SIGIOT): Define SIGIOT in terms of SIGABRT.
	* (struct sigdesc): Ditto.

	* utils.xml (kill): Document SIGIOT.

Signed-off-by: Yaakov Selkowitz <yselkowi <at>>
 winsup/cygwin/include/cygwin/signal.h | 1 +
 winsup/cygwin/               | 3 ++-
 winsup/doc/utils.xml                  | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/include/cygwin/signal.h b/winsup/cygwin/include/cygwin/signal.h
index 04ddb69..e876dec 100644
--- a/winsup/cygwin/include/cygwin/signal.h
+++ b/winsup/cygwin/include/cygwin/signal.h
 <at>  <at>  -358,6 +358,7  <at>  <at>  struct sigaction
 #define	SIGILL	4	/* illegal instruction (not reset when caught) */
 #define	SIGTRAP	5	/* trace trap (not reset when caught) */
 #define	SIGABRT 6	/* used by abort */
+#define	SIGIOT	SIGABRT	/* synonym for SIGABRT on most systems */
 #define	SIGEMT	7	/* EMT instruction */
 #define	SIGFPE	8	/* floating point exception */
 #define	SIGKILL	9	/* kill (cannot be caught or ignored) */
diff --git a/winsup/cygwin/ b/winsup/cygwin/
index 987e135..bb53e1b 100644
--- a/winsup/cygwin/
+++ b/winsup/cygwin/
(Continue reading)

Irányossy Knoblauch Artúr | 17 Feb 23:30 2016

[PATCH] Multiple timer issues

Dear Cygwin Maintainers,

First of all, thank you for your work, I really enjoy using this software!

However, I have noticed that adjusting the system time can cause some
programs to misbehave. I have found bugs in the POSIX timer
implementation and a bug in the select() function's timeout handling.

Please find the proposed patches attached.

Regarding POSIX timers:

I have also created a small test application (see timer_test.c and the
Makefile) to demonstrate the issue. Please try to run it on both Linux
and Cygwin!

The test tries to set the system time back and forth to see the effect
on different kinds of timers. Please note, that for setting the system
time, the test has to be run with the necessary administrative rights

Regarding select():

The timeout shall be immune to adjustments to the system clock in all
cases; so the 'gtod' clock shouldn't be used, because it is not

I have tried to keep the changes as minimal as possible.
I hope that signing a legal agreement is not necessary, since these
are just bugfixes; if you think otherwise, please let me know.
(Continue reading)

Mark Geisert | 17 Feb 06:28 2016

gprof profiling of multi-threaded Cygwin programs

I've attached a patch set modifying Cygwin's profiling support to sample PC 
values of all an application's threads, not just the main thread.  There is no 
change to how profiling is requested: just compile and link the app with "-pg" 
as usual.  The profiling info is dumped into file gmon.out as usual.

There is a behavioral change that ought to be documented somewhere:  If a 
gmon.out file exists when a profiled application exits, the app will now dump 
its profiling info into another file gmon.outXXXXXX where mkstemp() replaces the 
Xs with random alphanumerics.  I added this functionality to allow a profiled 
program to fork() yet retain profiling info for both parent and child.  The old 
behavior was to simply overwrite any existing gmon.out file.

There is no change to the normal Cygwin execution paths if profiling is not 
enabled.  And when it is enabled, only the one profiling thread per profiled app 
is doing more work than it used to.

Here's a change log of the modifications; all files are in winsup/cygwin:

         * common.din (cygheap_profthr_all): Export.
         * (cygheap_profthr_all): Implement a C-callable function
         that runs cygheap's threadlist handing each pthread's thread handle
         in turn to profthr_byhandle().
         * gmon.c (_mcleanup): Added support for multiple simultaneous
         gmon.out* files created when necessary using mkstemp(). Added
         #include <errno.h>, added extern decl for _setmode().
         * gmon.h (struct gmonparam): Made state decl volatile.
         * mcount.c (_MCOUNT_DECL): Changed stores into gmonparam.state to use
         Interlocked operations. Added #include "winsup.h", updated commentary.
         * profil.c (profthr_byhandle): New function abstracting out the
         updating of profile counters based on a thread handle.
(Continue reading)

john hood | 14 Feb 09:09 2016

Cygwin select() issues and improvements

[I Originally sent this last week, but it bounced.]

Various issues with Cygwin's select() annoyed me, and I've spent some
time gnawing on them.

* With 1-byte reads, select() on Windows Console input would forget
about unread input data stored in the fhandler's readahead buffer.
Hitting F1 would send only the first ESC character, until you released
the key and another Windows event was generated.  (one-line fix, though
I'm not sure it's appropriate/correct)

* On Windows, select() timeouts have coarse 10-16ms granularity (not
fixed-- must use clock_setres(), which has its own issues)

This issue hurts Mosh pretty badly, since it often uses select() with
1-20ms timeouts. Running Mosh on localhost on Cygwin has around 80ms of
extra latency for typing, which is pretty noticeable. Using
clock_setres() mostly cures this.

Older Unix systems used to have this issue too, but modern OS X, FreeBSD
and Linux all do much better.

* select() uses old millisecond-granularity Windows timeouts-- I changed
this to microsecond granularity.  Any actual improvement from this is
small, since Windows doesn't seem to handle timers on a less than 500us
granularity, even when you do use clock_setres().  One thing this does
fix is that selects > 43 days now work, though this is not a big issue
in actual practice, or a POSIX requirement.

* Newer versions of Windows may return early on timers, causing select()
(Continue reading)

Václav Haisman | 12 Feb 11:20 2016

[PATCH] POSIX barrier implementation, take 2


Here is a second take on the POSIX barrier API. This time it is tested
with the attached barrier.c file. Here is a change log.


	* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
	* libc/include/sys/types.h (pthread_barrier_t)
	(pthread_barrierattr_t): Do not define for Cygwin.


	* common.din (pthread_barrierattr_init)
	(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
	(pthread_barrierattr_destroy, pthread_barrier_init)
	(pthread_barrier_destroy, pthread_barrier_wait): Export.
	* include/cygwin/types.h (pthread_barrierattr_t)
	(pthread_barrier_t): Declare.
	* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
	(pthread_barrierattr_init, pthread_barrierattr_setpshared)
	(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
	(pthread_barrier_init, pthread_barrier_destroy)
	(pthread_barrier_wait): Declare.
	* cygwin/thread.h (PTHREAD_BARRIER_MAGIC)
	(class pthread_barrierattr, class pthread_barrier): Declare.
	* cygwin/ (delete_and_clear): New local helper function.
	(class pthread_barrierattr, class pthread_barrier): Implement.

(Continue reading)

Yaakov Selkowitz | 12 Feb 03:38 2016

[PATCH] cygwin: update child info magic

	* child_info.h (CURR_CHILD_INFO_MAGIC): Update.

Signed-off-by: Yaakov Selkowitz <yselkowi <at>>
 winsup/cygwin/child_info.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index ddd5b8b..c11040c 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
 <at>  <at>  -39,7 +39,7  <at>  <at>  enum child_status
 #define EXEC_MAGIC_SIZE sizeof(child_info)

 /* Change this value if you get a message indicating that it is out-of-sync. */
-#define CURR_CHILD_INFO_MAGIC 0x30ea98f6U
+#define CURR_CHILD_INFO_MAGIC 0xf67f938cU

 #define NPROCS	256



Yaakov Selkowitz | 12 Feb 03:26 2016

[PATCH] cygwin: fix errors with GCC 5

GCC 5 switched from C89 to C11 by default, which implies a change from
GNU to C99 inline.

	* (exception::handle): Fix always-true boolean
	comparison warning.
	* include/cygwin/config.h (__getreent): Mark gnu_inline.
	* winbase.h (ilockcmpexch, ilockcmpexch64): Ditto.

Signed-off-by: Yaakov Selkowitz <yselkowi <at>>
 winsup/cygwin/           | 2 +-
 winsup/cygwin/include/cygwin/config.h | 1 +
 winsup/cygwin/winbase.h               | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/ b/winsup/cygwin/
index c3a45d2..a50973b 100644
--- a/winsup/cygwin/
+++ b/winsup/cygwin/
 <at>  <at>  -645,7 +645,7  <at>  <at>  exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
     me.andreas->leave ();	/* Return from a "san" caught fault */

-  if (debugging && ++debugging < 500000)
+  if (debugging && ++debugging)
       SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL);
       return ExceptionContinueExecution;
diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h
(Continue reading)

Václav Haisman | 11 Feb 14:30 2016

[PATCH][RFC] POSIX barrier implementation, take 1


I am attaching a patch that adds (or tries to) POSIX barriers
implementation into Cygwin. I have compiled it but not actually tested
it, yet. I am dumping it here just in case I get run over by a bus on
my way home. :)

diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
index 4ad7fbd..0c6043c 100644
--- a/newlib/libc/include/sys/features.h
+++ b/newlib/libc/include/sys/features.h
 <at>  <at>  -118,10 +118,10  <at>  <at>  extern "C" {

 #define _POSIX_ADVISORY_INFO			200112L
 /* #define _POSIX_ASYNCHRONOUS_IO		    -1 */
-/* #define _POSIX_BARRIERS			    -1 */
+#define _POSIX_BARRIERS				200112L
 #define _POSIX_CHOWN_RESTRICTED			     1
 #define _POSIX_CLOCK_SELECTION			200112L
-#define _POSIX_CPUTIME			    	200112L
+#define _POSIX_CPUTIME				200112L
 #define _POSIX_FSYNC				200112L
 #define _POSIX_IPV6				200112L
 #define _POSIX_JOB_CONTROL			     1
 <at>  <at>  -140,7 +140,7  <at>  <at>  extern "C" {
 #define _POSIX_REGEXP				     1
(Continue reading)

Jon Turney | 14 Jan 19:05 2016

[PATCH] Update FAQ question and answer about gdb and signals

Signed-off-by: Jon Turney <jon.turney <at>>
 winsup/doc/faq-programming.xml | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/winsup/doc/faq-programming.xml b/winsup/doc/faq-programming.xml
index af6102a..7f1ffd9 100644
--- a/winsup/doc/faq-programming.xml
+++ b/winsup/doc/faq-programming.xml
 <at>  <at>  -859,15 +859,22  <at>  <at>  on using <literal>strace</literal>, see the Cygwin User's Guide.

 <qandaentry id="faq.programming.gdb-signals">
-<question><para>Why doesn't gdb handle signals?</para></question>
+<question><para>How does gdb handle signals?</para></question>

-<para>Unfortunately, there is only minimal signal handling support in gdb
-currently.  Signal handling only works with Windows-type signals.
-SIGINT may work, SIGFPE may work, SIGSEGV definitely does.  You cannot
-'stop', 'print' or 'nopass' signals like SIGUSR1 or SIGHUP to the
-process being debugged.
+gdb maps known Windows exceptions to signals such as SIGSEGV, SIGFPE, SIGTRAP,
+SIGINT and SIGILL.  Other Windows exceptions are passed on to the handler (if
+any), and reported as an unknown signal if an unhandled (second chance)
+exception occurs.
(Continue reading)