public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC
@ 2020-02-15 13:23 Samuel Thibault
  2020-02-15 13:51 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Thibault @ 2020-02-15 13:23 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

Store them in the TCB, and use them for accessing _hurd_sigstate.
---
 hurd/hurd/signal.h           |  11 ++--
 sysdeps/mach/hurd/i386/tls.h | 108 +++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 5 deletions(-)

diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 6583dcb5b1..ef6a8e6687 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -164,9 +164,9 @@ extern void _hurd_sigstate_delete (thread_t thread);
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
-  if (THREAD_SELF->_hurd_sigstate == NULL)
-    THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
-  return THREAD_SELF->_hurd_sigstate;
+  if (THREAD_GETMEM (THREAD_SELF, _hurd_sigstate) == NULL)
+    THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, _hurd_thread_sigstate (__mach_thread_self ()));
+  return THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
 }
 # endif
 #endif
@@ -210,14 +210,15 @@ _hurd_critical_section_lock (void)
     return NULL;
 #endif
 
-  ss = THREAD_SELF->_hurd_sigstate;
+  ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
   if (ss == NULL)
     {
       /* The thread variable is unset; this must be the first time we've
 	 asked for it.  In this case, the critical section flag cannot
 	 possible already be set.  Look up our sigstate structure the slow
 	 way.  */
-      ss = THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
+      ss = _hurd_thread_sigstate (__mach_thread_self ());
+      THREAD_SETMEM(THREAD_SELF, _hurd_sigstate, ss);
     }
 
   if (! __spin_try_lock (&ss->critical_section_lock))
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index c0341ce2c9..7ec8c81a76 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -163,6 +163,114 @@ out:
 	      : "i" (offsetof (tcbhead_t, tcb)));			      \
      __tcb;})
 
+/* Read member of the thread descriptor directly.  */
+# define THREAD_GETMEM(descr, member) \
+  ({ __typeof (descr->member) __value;					      \
+     if (sizeof (__value) == 1)						      \
+       asm volatile ("movb %%gs:%P2,%b0"				      \
+		     : "=q" (__value)					      \
+		     : "0" (0), "i" (offsetof (tcbhead_t, member)));	      \
+     else if (sizeof (__value) == 4)					      \
+       asm volatile ("movl %%gs:%P1,%0"					      \
+		     : "=r" (__value)					      \
+		     : "i" (offsetof (tcbhead_t, member)));		      \
+     else								      \
+       {								      \
+	 if (sizeof (__value) != 8)					      \
+	   /* There should not be any value with a size other than 1,	      \
+	      4 or 8.  */						      \
+	   abort ();							      \
+									      \
+	 asm volatile ("movl %%gs:%P1,%%eax\n\t"			      \
+		       "movl %%gs:%P2,%%edx"				      \
+		       : "=A" (__value)					      \
+		       : "i" (offsetof (tcbhead_t, member)),		      \
+			 "i" (offsetof (tcbhead_t, member) + 4));	      \
+       }								      \
+     __value; })
+
+
+/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
+# define THREAD_GETMEM_NC(descr, member, idx) \
+  ({ __typeof (descr->member[0]) __value;				      \
+     if (sizeof (__value) == 1)						      \
+       asm volatile ("movb %%gs:%P2(%3),%b0"				      \
+		     : "=q" (__value)					      \
+		     : "0" (0), "i" (offsetof (tcbhead_t, member[0])),	      \
+		     "r" (idx));					      \
+     else if (sizeof (__value) == 4)					      \
+       asm volatile ("movl %%gs:%P1(,%2,4),%0"				      \
+		     : "=r" (__value)					      \
+		     : "i" (offsetof (tcbhead_t, member[0])),		      \
+		       "r" (idx));					      \
+     else								      \
+       {								      \
+	 if (sizeof (__value) != 8)					      \
+	   /* There should not be any value with a size other than 1,	      \
+	      4 or 8.  */						      \
+	   abort ();							      \
+									      \
+	 asm volatile  ("movl %%gs:%P1(,%2,8),%%eax\n\t"		      \
+			"movl %%gs:4+%P1(,%2,8),%%edx"			      \
+			: "=&A" (__value)				      \
+			: "i" (offsetof (tcbhead_t, member[0])),	      \
+			  "r" (idx));					      \
+       }								      \
+     __value; })
+
+
+
+/* Set member of the thread descriptor directly.  */
+# define THREAD_SETMEM(descr, member, value) \
+  ({ if (sizeof (descr->member) == 1)					      \
+       asm volatile ("movb %b0,%%gs:%P1" :				      \
+		     : "iq" (value),					      \
+		       "i" (offsetof (tcbhead_t, member)));		      \
+     else if (sizeof (descr->member) == 4)				      \
+       asm volatile ("movl %0,%%gs:%P1" :				      \
+		     : "ir" (value),					      \
+		       "i" (offsetof (tcbhead_t, member)));		      \
+     else								      \
+       {								      \
+	 if (sizeof (descr->member) != 8)				      \
+	   /* There should not be any value with a size other than 1,	      \
+	      4 or 8.  */						      \
+	   abort ();							      \
+									      \
+	 asm volatile ("movl %%eax,%%gs:%P1\n\t"			      \
+		       "movl %%edx,%%gs:%P2" :				      \
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
+			 "i" (offsetof (tcbhead_t, member)),		      \
+			 "i" (offsetof (tcbhead_t, member) + 4));	      \
+       }})
+
+
+/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+  ({ if (sizeof (descr->member[0]) == 1)				      \
+       asm volatile ("movb %b0,%%gs:%P1(%2)" :				      \
+		     : "iq" (value),					      \
+		       "i" (offsetof (tcbhead_t, member)),		      \
+		       "r" (idx));					      \
+     else if (sizeof (descr->member[0]) == 4)				      \
+       asm volatile ("movl %0,%%gs:%P1(,%2,4)" :			      \
+		     : "ir" (value),					      \
+		       "i" (offsetof (tcbhead_t, member)),		      \
+		       "r" (idx));					      \
+     else								      \
+       {								      \
+	 if (sizeof (descr->member[0]) != 8)				      \
+	   /* There should not be any value with a size other than 1,	      \
+	      4 or 8.  */						      \
+	   abort ();							      \
+									      \
+	 asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t"			      \
+		       "movl %%edx,%%gs:4+%P1(,%2,8)" :			      \
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
+			 "i" (offsetof (tcbhead_t, member)),		      \
+			 "r" (idx));					      \
+       }})
+
 /* Return the TCB address of a thread given its state.
    Note: this is expensive.  */
 # define THREAD_TCB(thread, thread_state)				      \
-- 
2.24.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC
  2020-02-15 13:23 [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC Samuel Thibault
@ 2020-02-15 13:51 ` Andreas Schwab
  2020-02-15 13:54   ` Samuel Thibault
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2020-02-15 13:51 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: libc-alpha, bug-hurd, commit-hurd

On Feb 15 2020, Samuel Thibault wrote:

> diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
> index c0341ce2c9..7ec8c81a76 100644
> --- a/sysdeps/mach/hurd/i386/tls.h
> +++ b/sysdeps/mach/hurd/i386/tls.h
> @@ -163,6 +163,114 @@ out:
>  	      : "i" (offsetof (tcbhead_t, tcb)));			      \
>       __tcb;})
>  
> +/* Read member of the thread descriptor directly.  */
> +# define THREAD_GETMEM(descr, member) \
> +  ({ __typeof (descr->member) __value;					      \
> +     if (sizeof (__value) == 1)						      \
> +       asm volatile ("movb %%gs:%P2,%b0"				      \
> +		     : "=q" (__value)					      \
> +		     : "0" (0), "i" (offsetof (tcbhead_t, member)));	      \
> +     else if (sizeof (__value) == 4)					      \
> +       asm volatile ("movl %%gs:%P1,%0"					      \
> +		     : "=r" (__value)					      \
> +		     : "i" (offsetof (tcbhead_t, member)));		      \
> +     else								      \
> +       {								      \
> +	 if (sizeof (__value) != 8)					      \
> +	   /* There should not be any value with a size other than 1,	      \
> +	      4 or 8.  */						      \
> +	   abort ();							      \

_Static_assert?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC
  2020-02-15 13:51 ` Andreas Schwab
@ 2020-02-15 13:54   ` Samuel Thibault
  2020-02-17  5:22     ` Samuel Thibault
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Thibault @ 2020-02-15 13:54 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha, bug-hurd, commit-hurd

Andreas Schwab, le sam. 15 févr. 2020 14:51:24 +0100, a ecrit:
> On Feb 15 2020, Samuel Thibault wrote:
> > diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
> > index c0341ce2c9..7ec8c81a76 100644
> > --- a/sysdeps/mach/hurd/i386/tls.h
> > +++ b/sysdeps/mach/hurd/i386/tls.h
> > @@ -163,6 +163,114 @@ out:
> >  	      : "i" (offsetof (tcbhead_t, tcb)));			      \
> >       __tcb;})
> >  
> > +/* Read member of the thread descriptor directly.  */
> > +# define THREAD_GETMEM(descr, member) \
> > +  ({ __typeof (descr->member) __value;					      \
> > +     if (sizeof (__value) == 1)						      \
> > +       asm volatile ("movb %%gs:%P2,%b0"				      \
> > +		     : "=q" (__value)					      \
> > +		     : "0" (0), "i" (offsetof (tcbhead_t, member)));	      \
> > +     else if (sizeof (__value) == 4)					      \
> > +       asm volatile ("movl %%gs:%P1,%0"					      \
> > +		     : "=r" (__value)					      \
> > +		     : "i" (offsetof (tcbhead_t, member)));		      \
> > +     else								      \
> > +       {								      \
> > +	 if (sizeof (__value) != 8)					      \
> > +	   /* There should not be any value with a size other than 1,	      \
> > +	      4 or 8.  */						      \
> > +	   abort ();							      \
> 
> _Static_assert?

I just copied from i386's tls.h. We should fix them at the same time :)

Samuel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC
  2020-02-15 13:54   ` Samuel Thibault
@ 2020-02-17  5:22     ` Samuel Thibault
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Thibault @ 2020-02-17  5:22 UTC (permalink / raw)
  To: Andreas Schwab, libc-alpha, bug-hurd, commit-hurd

Samuel Thibault, le sam. 15 févr. 2020 05:54:36 -0800, a ecrit:
> Andreas Schwab, le sam. 15 févr. 2020 14:51:24 +0100, a ecrit:
> > On Feb 15 2020, Samuel Thibault wrote:
> > > +	 if (sizeof (__value) != 8)					      \
> > > +	   /* There should not be any value with a size other than 1,	      \
> > > +	      4 or 8.  */						      \
> > > +	   abort ();							      \
> > 
> > _Static_assert?
> 
> I just copied from i386's tls.h. We should fix them at the same time :)

Now done so in all x86 variants.

Samuel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-17  5:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15 13:23 [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC Samuel Thibault
2020-02-15 13:51 ` Andreas Schwab
2020-02-15 13:54   ` Samuel Thibault
2020-02-17  5:22     ` Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).