summary refs log tree commit diff
path: root/sysdeps/i386/nptl/tls.h
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-02-17 00:40:39 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-02-17 00:40:39 +0100
commitf1bdee617975bfd962a7940b76ec75c8b1d768d7 (patch)
treefd7cfb50713ffd5754576f4b7fc0b483da4eefd4 /sysdeps/i386/nptl/tls.h
parentedba4e5f91ee3f5aea32e77df7eb1019d32ae5ed (diff)
downloadglibc-f1bdee617975bfd962a7940b76ec75c8b1d768d7.tar.gz
glibc-f1bdee617975bfd962a7940b76ec75c8b1d768d7.tar.xz
glibc-f1bdee617975bfd962a7940b76ec75c8b1d768d7.zip
x86 tls: Use _Static_assert for TLS access size assertion
Diffstat (limited to 'sysdeps/i386/nptl/tls.h')
-rw-r--r--sysdeps/i386/nptl/tls.h46
1 files changed, 20 insertions, 26 deletions
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index ffead90857..28053a77f3 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -255,6 +255,9 @@ tls_fill_user_desc (union user_desc_init *desc,
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) \
   ({ __typeof (descr->member) __value;					      \
+     _Static_assert (sizeof (__value) == 1				      \
+		  || sizeof (__value) == 4				      \
+		  || sizeof (__value) == 8);				      \
      if (sizeof (__value) == 1)						      \
        asm volatile ("movb %%gs:%P2,%b0"				      \
 		     : "=q" (__value)					      \
@@ -263,13 +266,8 @@ tls_fill_user_desc (union user_desc_init *desc,
        asm volatile ("movl %%gs:%P1,%0"					      \
 		     : "=r" (__value)					      \
 		     : "i" (offsetof (struct pthread, member)));	      \
-     else								      \
+     else /* 8 */								      \
        {								      \
-	 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)					      \
@@ -282,6 +280,9 @@ tls_fill_user_desc (union user_desc_init *desc,
 /* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
 # define THREAD_GETMEM_NC(descr, member, idx) \
   ({ __typeof (descr->member[0]) __value;				      \
+     _Static_assert (sizeof (__value) == 1				      \
+		  || sizeof (__value) == 4				      \
+		  || sizeof (__value) == 8);				      \
      if (sizeof (__value) == 1)						      \
        asm volatile ("movb %%gs:%P2(%3),%b0"				      \
 		     : "=q" (__value)					      \
@@ -292,13 +293,8 @@ tls_fill_user_desc (union user_desc_init *desc,
 		     : "=r" (__value)					      \
 		     : "i" (offsetof (struct pthread, member[0])),	      \
 		       "r" (idx));					      \
-     else								      \
+     else /* 8 */							      \
        {								      \
-	 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)				      \
@@ -311,7 +307,11 @@ tls_fill_user_desc (union user_desc_init *desc,
 
 /* Set member of the thread descriptor directly.  */
 # define THREAD_SETMEM(descr, member, value) \
-  ({ if (sizeof (descr->member) == 1)					      \
+  ({									      \
+     _Static_assert (sizeof (descr->member) == 1			      \
+		  || sizeof (descr->member) == 4			      \
+		  || sizeof (descr->member) == 8);			      \
+     if (sizeof (descr->member) == 1)					      \
        asm volatile ("movb %b0,%%gs:%P1" :				      \
 		     : "iq" (value),					      \
 		       "i" (offsetof (struct pthread, member)));	      \
@@ -319,13 +319,8 @@ tls_fill_user_desc (union user_desc_init *desc,
        asm volatile ("movl %0,%%gs:%P1" :				      \
 		     : "ir" (value),					      \
 		       "i" (offsetof (struct pthread, member)));	      \
-     else								      \
+     else /* 8 */							      \
        {								      \
-	 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)),	      \
@@ -336,7 +331,11 @@ tls_fill_user_desc (union user_desc_init *desc,
 
 /* 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)				      \
+  ({									      \
+     _Static_assert (sizeof (descr->member[0]) == 1			      \
+		  || sizeof (descr->member[0]) == 4			      \
+		  || sizeof (descr->member[0]) == 8);			      \
+     if (sizeof (descr->member[0]) == 1)				      \
        asm volatile ("movb %b0,%%gs:%P1(%2)" :				      \
 		     : "iq" (value),					      \
 		       "i" (offsetof (struct pthread, member)),		      \
@@ -346,13 +345,8 @@ tls_fill_user_desc (union user_desc_init *desc,
 		     : "ir" (value),					      \
 		       "i" (offsetof (struct pthread, member)),		      \
 		       "r" (idx));					      \
-     else								      \
+     else /* 8 */							      \
        {								      \
-	 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)),	      \