diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-12-09 09:49:32 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-12-09 09:49:32 +0100 |
commit | ce2248ab91b2ea09a378f85012f251f31ac65e31 (patch) | |
tree | bb3fe4e9cd3ce325947f2b3cee4d0570f48e13d5 /sysdeps/i386 | |
parent | 8dbeb0561eeb876f557ac9eef5721912ec074ea5 (diff) | |
download | glibc-ce2248ab91b2ea09a378f85012f251f31ac65e31.zip glibc-ce2248ab91b2ea09a378f85012f251f31ac65e31.tar.gz glibc-ce2248ab91b2ea09a378f85012f251f31ac65e31.tar.bz2 |
nptl: Introduce <tcb-access.h> for THREAD_* accessors
These are common between most architectures. Only the x86 targets
are outliers.
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
Diffstat (limited to 'sysdeps/i386')
-rw-r--r-- | sysdeps/i386/nptl/tcb-access.h | 123 | ||||
-rw-r--r-- | sysdeps/i386/nptl/tls.h | 108 |
2 files changed, 124 insertions, 107 deletions
diff --git a/sysdeps/i386/nptl/tcb-access.h b/sysdeps/i386/nptl/tcb-access.h new file mode 100644 index 0000000..6c6d561 --- /dev/null +++ b/sysdeps/i386/nptl/tcb-access.h @@ -0,0 +1,123 @@ +/* THREAD_* accessors. i386 version. + Copyright (C) 2002-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +/* 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, \ + "size of per-thread data"); \ + if (sizeof (__value) == 1) \ + asm volatile ("movb %%gs:%P2,%b0" \ + : "=q" (__value) \ + : "0" (0), "i" (offsetof (struct pthread, member))); \ + else if (sizeof (__value) == 4) \ + asm volatile ("movl %%gs:%P1,%0" \ + : "=r" (__value) \ + : "i" (offsetof (struct pthread, member))); \ + else /* 8 */ \ + { \ + asm volatile ("movl %%gs:%P1,%%eax\n\t" \ + "movl %%gs:%P2,%%edx" \ + : "=A" (__value) \ + : "i" (offsetof (struct pthread, member)), \ + "i" (offsetof (struct pthread, 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; \ + _Static_assert (sizeof (__value) == 1 \ + || sizeof (__value) == 4 \ + || sizeof (__value) == 8, \ + "size of per-thread data"); \ + if (sizeof (__value) == 1) \ + asm volatile ("movb %%gs:%P2(%3),%b0" \ + : "=q" (__value) \ + : "0" (0), "i" (offsetof (struct pthread, member[0])), \ + "r" (idx)); \ + else if (sizeof (__value) == 4) \ + asm volatile ("movl %%gs:%P1(,%2,4),%0" \ + : "=r" (__value) \ + : "i" (offsetof (struct pthread, member[0])), \ + "r" (idx)); \ + else /* 8 */ \ + { \ + asm volatile ("movl %%gs:%P1(,%2,8),%%eax\n\t" \ + "movl %%gs:4+%P1(,%2,8),%%edx" \ + : "=&A" (__value) \ + : "i" (offsetof (struct pthread, member[0])), \ + "r" (idx)); \ + } \ + __value; }) + + + +/* Set member of the thread descriptor directly. */ +#define THREAD_SETMEM(descr, member, value) \ + ({ \ + _Static_assert (sizeof (descr->member) == 1 \ + || sizeof (descr->member) == 4 \ + || sizeof (descr->member) == 8, \ + "size of per-thread data"); \ + if (sizeof (descr->member) == 1) \ + asm volatile ("movb %b0,%%gs:%P1" : \ + : "iq" (value), \ + "i" (offsetof (struct pthread, member))); \ + else if (sizeof (descr->member) == 4) \ + asm volatile ("movl %0,%%gs:%P1" : \ + : "ir" (value), \ + "i" (offsetof (struct pthread, member))); \ + else /* 8 */ \ + { \ + asm volatile ("movl %%eax,%%gs:%P1\n\t" \ + "movl %%edx,%%gs:%P2" : \ + : "A" ((uint64_t) cast_to_integer (value)), \ + "i" (offsetof (struct pthread, member)), \ + "i" (offsetof (struct pthread, member) + 4)); \ + }}) + + +/* Same as THREAD_SETMEM, but the member offset can be non-constant. */ +#define THREAD_SETMEM_NC(descr, member, idx, value) \ + ({ \ + _Static_assert (sizeof (descr->member[0]) == 1 \ + || sizeof (descr->member[0]) == 4 \ + || sizeof (descr->member[0]) == 8, \ + "size of per-thread data"); \ + if (sizeof (descr->member[0]) == 1) \ + asm volatile ("movb %b0,%%gs:%P1(%2)" : \ + : "iq" (value), \ + "i" (offsetof (struct pthread, member)), \ + "r" (idx)); \ + else if (sizeof (descr->member[0]) == 4) \ + asm volatile ("movl %0,%%gs:%P1(,%2,4)" : \ + : "ir" (value), \ + "i" (offsetof (struct pthread, member)), \ + "r" (idx)); \ + else /* 8 */ \ + { \ + 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 (struct pthread, member)), \ + "r" (idx)); \ + }}) diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h index cfb27f5..d010e14 100644 --- a/sysdeps/i386/nptl/tls.h +++ b/sysdeps/i386/nptl/tls.h @@ -250,113 +250,7 @@ tls_fill_user_desc (union user_desc_init *desc, REGISTER_THREAD_AREA (32, offsetof (struct user_regs_struct, xgs), 3) \ REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */ - -/* 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, \ - "size of per-thread data"); \ - if (sizeof (__value) == 1) \ - asm volatile ("movb %%gs:%P2,%b0" \ - : "=q" (__value) \ - : "0" (0), "i" (offsetof (struct pthread, member))); \ - else if (sizeof (__value) == 4) \ - asm volatile ("movl %%gs:%P1,%0" \ - : "=r" (__value) \ - : "i" (offsetof (struct pthread, member))); \ - else /* 8 */ \ - { \ - asm volatile ("movl %%gs:%P1,%%eax\n\t" \ - "movl %%gs:%P2,%%edx" \ - : "=A" (__value) \ - : "i" (offsetof (struct pthread, member)), \ - "i" (offsetof (struct pthread, 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; \ - _Static_assert (sizeof (__value) == 1 \ - || sizeof (__value) == 4 \ - || sizeof (__value) == 8, \ - "size of per-thread data"); \ - if (sizeof (__value) == 1) \ - asm volatile ("movb %%gs:%P2(%3),%b0" \ - : "=q" (__value) \ - : "0" (0), "i" (offsetof (struct pthread, member[0])), \ - "r" (idx)); \ - else if (sizeof (__value) == 4) \ - asm volatile ("movl %%gs:%P1(,%2,4),%0" \ - : "=r" (__value) \ - : "i" (offsetof (struct pthread, member[0])), \ - "r" (idx)); \ - else /* 8 */ \ - { \ - asm volatile ("movl %%gs:%P1(,%2,8),%%eax\n\t" \ - "movl %%gs:4+%P1(,%2,8),%%edx" \ - : "=&A" (__value) \ - : "i" (offsetof (struct pthread, member[0])), \ - "r" (idx)); \ - } \ - __value; }) - - - -/* Set member of the thread descriptor directly. */ -# define THREAD_SETMEM(descr, member, value) \ - ({ \ - _Static_assert (sizeof (descr->member) == 1 \ - || sizeof (descr->member) == 4 \ - || sizeof (descr->member) == 8, \ - "size of per-thread data"); \ - if (sizeof (descr->member) == 1) \ - asm volatile ("movb %b0,%%gs:%P1" : \ - : "iq" (value), \ - "i" (offsetof (struct pthread, member))); \ - else if (sizeof (descr->member) == 4) \ - asm volatile ("movl %0,%%gs:%P1" : \ - : "ir" (value), \ - "i" (offsetof (struct pthread, member))); \ - else /* 8 */ \ - { \ - asm volatile ("movl %%eax,%%gs:%P1\n\t" \ - "movl %%edx,%%gs:%P2" : \ - : "A" ((uint64_t) cast_to_integer (value)), \ - "i" (offsetof (struct pthread, member)), \ - "i" (offsetof (struct pthread, member) + 4)); \ - }}) - - -/* Same as THREAD_SETMEM, but the member offset can be non-constant. */ -# define THREAD_SETMEM_NC(descr, member, idx, value) \ - ({ \ - _Static_assert (sizeof (descr->member[0]) == 1 \ - || sizeof (descr->member[0]) == 4 \ - || sizeof (descr->member[0]) == 8, \ - "size of per-thread data"); \ - if (sizeof (descr->member[0]) == 1) \ - asm volatile ("movb %b0,%%gs:%P1(%2)" : \ - : "iq" (value), \ - "i" (offsetof (struct pthread, member)), \ - "r" (idx)); \ - else if (sizeof (descr->member[0]) == 4) \ - asm volatile ("movl %0,%%gs:%P1(,%2,4)" : \ - : "ir" (value), \ - "i" (offsetof (struct pthread, member)), \ - "r" (idx)); \ - else /* 8 */ \ - { \ - 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 (struct pthread, member)), \ - "r" (idx)); \ - }}) - +# include <tcb-access.h> /* Set the stack guard field in TCB head. */ #define THREAD_SET_STACK_GUARD(value) \ |