From 41f9a410cc30786e7787553113610ed4c898f5c4 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 10 Jul 2013 20:58:33 +0000 Subject: [PATCH] * gentlsoffsets: Clean up a little. * thread.cc (semaphore::_fixup_after_fork): Report on potential problem parameter. Make sure that currentvalue is never zero. (semaphore::init): Make cosmetic change. --- winsup/cygwin/ChangeLog | 8 ++++++++ winsup/cygwin/gentls_offsets | 20 +++++++++++--------- winsup/cygwin/thread.cc | 10 +++++----- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0aa345514..7eb8f07bf 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2013-07-10 Christopher Faylor + + * gentlsoffsets: Clean up a little. + + * thread.cc (semaphore::_fixup_after_fork): Report on potential problem + parameter. Make sure that currentvalue is never zero. + (semaphore::init): Make cosmetic change. + 2013-07-10 Corinna Vinschen * cygwin.sc.in (.text.*): Fold into .text on all platforms. diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets index d2400bb29..e4543f597 100755 --- a/winsup/cygwin/gentls_offsets +++ b/winsup/cygwin/gentls_offsets @@ -14,9 +14,8 @@ my $tgt = shift; # Another method which doesn't requires to run an executable would be to # generate assembler code accessing the various struct members and analyzing # it, but that's arguably a lot more effort. -my $tgt_opt='-m64'; -$tgt_opt='-m32' unless ($tgt eq 'x86_64'); -open(TLS, $tls) or die "$0: couldn't open tls file \"$tls\" - $!\n"; +my $tgt_opt = $tgt eq 'x86_64' ? '-m64' : '-m32'; +open TLS, '<', $tls or die "$0: couldn't open tls file \"$tls\" - $!\n"; my $struct = ''; my @fields = (); my $def = ''; @@ -48,7 +47,7 @@ foreach ($tls =~ /^.*\n/mg) { } } close TLS; -open(TMP, '>', "/tmp/$$.cc") or die "$0: couldn't open temporary index file \"/tmp/$$.c\" - $!\n"; +open TMP, '>', "/tmp/$$.cc" or die "$0: couldn't open temporary index file \"/tmp/$$.c\" - $!\n"; print TMP <f)) - foo_beg) - CYGTLS_PADSIZE) -# define poffset(f) (((char *) &(foo->f)) - ((char *) foo)) +# define offset(f) ((unsigned)((int) (((char *) &(foo->f)) - foo_beg) - CYGTLS_PADSIZE)) +# define poffset(f) ((unsigned)(((char *) &(foo->f)) - ((char *) foo))) EOF print TMP 'puts ("//;# autogenerated: Do not edit.\n");', "\n\n"; print TMP "printf (\"//; \$tls::start_offset = -%d;\\n\", CYGTLS_PADSIZE);\n"; @@ -89,12 +88,15 @@ EOF } EOF close TMP; -system @ARGV, '-o', "/tmp/$$-1.cc", '-E', "/tmp/$$.cc"; +my @avoid_headers = qw'-D_XMMINTRIN_H_INCLUDED -D_ADXINTRIN_H_INCLUDED -D_EMMINTRIN_H_INCLUDED -D_X86INTRIN_H_INCLUDED'; +my @cmd = (@ARGV, @avoid_headers, '-o', "/tmp/$$-1.cc", '-E', "/tmp/$$.cc"); +$ENV{CCWRAP_VERBOSE}=1; +system @cmd; system 'g++', "$tgt_opt", '-o', "/tmp/$$.a.out", "/tmp/$$-1.cc" and ($? == 127 && system 'c++', "$tgt_opt", '-o', "/tmp/$$.a.out", "/tmp/$$-1.cc") and die "$0: couldn't generate executable for offset calculation \"/tmp/$$.a.out\" - $!\n"; -open(TLS_OUT, '>', $tls_out) or die "$0: couldn't open tls index file \"$tls_out\" - $!\n"; -open(OFFS, "/tmp/$$.a.out|") or die "$0: couldn't run \"/tmp/$$.a.out\" - $!\n"; +open TLS_OUT, '>', $tls_out or die "$0: couldn't open tls index file \"$tls_out\" - $!\n"; +open OFFS, '-|', "/tmp/$$.a.out" or die "$0: couldn't run \"/tmp/$$.a.out\" - $!\n"; print TLS_OUT ; close OFFS; close TLS_OUT; diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 0d5ded675..450888d91 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3529,11 +3529,13 @@ semaphore::_fixup_after_fork () if (shared == PTHREAD_PROCESS_PRIVATE) { pthread_printf ("sem %p", this); + if (!currentvalue) + currentvalue = 1; /* FIXME: duplicate code here and in the constructor. */ - this->win32_obj_id = ::CreateSemaphore (&sec_none_nih, currentvalue, + win32_obj_id = ::CreateSemaphore (&sec_none_nih, currentvalue, INT32_MAX, NULL); if (!win32_obj_id) - api_fatal ("failed to create new win32 semaphore, %E"); + api_fatal ("failed to create new win32 semaphore, currentvalue %ld, %E", currentvalue); } } @@ -3557,9 +3559,7 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value) contents happen to be a valid pointer */ if (is_good_object (sem)) - { - paranoid_printf ("potential attempt to reinitialise a semaphore"); - } + paranoid_printf ("potential attempt to reinitialise a semaphore"); if (value > SEM_VALUE_MAX) {