[newlib-cygwin] Cygwin: signalfd: implement non-polling select

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Jan 15 11:57:00 GMT 2019


On Jan 15 12:52, Corinna Vinschen wrote:
> On Jan 15 12:22, Corinna Vinschen wrote:
> > On Jan 15 10:50, Václav Haisman wrote:
> > > On Mon, 14 Jan 2019 at 17:19, Corinna Vinschen <corinna@sourceware.org> wrote:
> > > > +  /* context MUST be aligned to 16 byte, otherwise RtlCaptureContext fails.
> > > > +     If you prepend cygtls members here, make sure context stays 16 byte
> > > > +     aligned. */
> > > >    ucontext_t context;
> > > >[...]
> > > Would it not better to do this with `ucontext_t context
> > > __attribute__((__aligned__(16)));` instead?
> > 
> > In theory yes, but it doesn't work.  The simple perl parser in
> > gentls_offsets doesn't understand __attribute__ and screws up,
> > so generating tlsoffsets{64}.h fails.
> > 
> > I'm not good at perl.  My attempts to fix the parser to let
> > __attribute__ statements slip through unchanged failed so far.
> > Right now what it does is:
> > 
> >   ucontext_t context __attribute__((__aligned__(16)));
> > 
> > in the input is mangled to
> > 
> >   ucontext_t context__attribute____aligned__16;
> > 
> > in the output.  Any help appreciated.
> 
> Uhm... I managed to find a solution to keep __attribute__ expressions
> in and to generate the code to compute the offsets.  However, it has
> no effect at all.  I added a long variable which moves the address
> by 8 bytes.  The alignment should have moved context by 16 bytes, but
> it doesn't.
> 
> Before:
> 
>   //; $tls::context = -8624;
>   //; $tls::pcontext = 4176;
> 
> after:
> 
>   //; $tls::foo = -8624;
>   //; $tls::pfoo = 4176;
>   //; $tls::context = -8616;
>   //; $tls::pcontext = 4184;
> 
> 
> /scratching head/
> Corinna

In the interest of full disclosure, here's the patch:

diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h
index 65a905c32078..c60507231ae0 100644
--- a/winsup/cygwin/cygtls.h
+++ b/winsup/cygwin/cygtls.h
@@ -191,10 +191,11 @@ public:
   HANDLE signal_arrived;
   HANDLE signalfd_select_wait;
   bool will_wait_for_signal;
+  long foo;
   /* context MUST be aligned to 16 byte, otherwise RtlCaptureContext fails.
      If you prepend cygtls members here, make sure context stays 16 byte
      aligned. */
-  ucontext_t context;
+  ucontext_t context __attribute__ ((aligned (16)));
   DWORD thread_id;
   siginfo_t infodata;
   struct pthread *tid;
diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets
index 745ea27a035c..1b42b6ceb9cd 100755
--- a/winsup/cygwin/gentls_offsets
+++ b/winsup/cygwin/gentls_offsets
@@ -26,22 +26,29 @@ substr($tls, 0, length($pre)) = '';
 $pre .= "\n//*/";
 $tls =~ s%/\*\s*gentls_offsets.*?/\*\s*gentls_offsets\s*\*/%%ogs;
 foreach ($tls =~ /^.*\n/mg) {
-    /^}|\s*(?:typedef|const)/o and do {
+    /^}|\s*(?:typedef|const)/ and do {
 	$def .= $_ ;
 	next;
     };
     $def .= $_ if $struct;
-    if (!s/;.*$//o) {
-	if (!$struct && /^\s*(?:struct|class)\s*([a-z_0-9]+)/o) {
+    if (!s/;.*$//) {
+	if (!$struct && /^\s*(?:struct|class)\s*([a-z_0-9]+)/) {
 	    $def .= $_;
 	    $struct = $1
 	}
 	next;
     }
-    s/(?:\[[^\]]*\]|struct|class)//o;
-    s/^\s+\S+\s+//o;
-    s/[\*\s()]+//go;
+    s/(?:\[[^\]]*\]|struct|class)//;
+    s/^\s+\S+\s+//;
+    if (! /__attribute__/) {
+	s/[\*\s()]+//g;
+    } else {
+	s/\s*$//g;
+    }
     for my $f (split(/,/)) {
+	if ( $f =~ m/__attribute__/ ) {
+	    $f =~ s/\s*__attribute__\s*\(\([^)]+\)\)+//
+	}
 	push(@fields, $f);
     }
 }
@@ -99,5 +106,5 @@ open OFFS, '-|', "/tmp/$$.a.out" or die "$0: couldn't run \"/tmp/$$.a.out\" - $!
 print TLS_OUT <OFFS>;
 close OFFS;
 close TLS_OUT;
-unlink "/tmp/$$.cc", "/tmp/$$-1.cc", "/tmp/$$-1.d", "/tmp/$$.a.out";
+#unlink "/tmp/$$.cc", "/tmp/$$-1.cc", "/tmp/$$-1.d", "/tmp/$$.a.out";
 exit(0);


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20190115/61d808ea/attachment.sig>


More information about the Cygwin-developers mailing list