diff options
Diffstat (limited to 'libpthread')
-rw-r--r-- | libpthread/nptl/sysdeps/riscv32/dl-tls.h | 10 | ||||
-rw-r--r-- | libpthread/nptl/sysdeps/riscv32/tcb-offsets.sym | 7 | ||||
-rw-r--r-- | libpthread/nptl/sysdeps/riscv32/tls.h | 117 | ||||
-rw-r--r-- | libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/createthread.c | 13 | ||||
-rw-r--r-- | libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/fork.c | 18 |
5 files changed, 65 insertions, 100 deletions
diff --git a/libpthread/nptl/sysdeps/riscv32/dl-tls.h b/libpthread/nptl/sysdeps/riscv32/dl-tls.h index 01663edf3..31991be0d 100644 --- a/libpthread/nptl/sysdeps/riscv32/dl-tls.h +++ b/libpthread/nptl/sysdeps/riscv32/dl-tls.h @@ -21,4 +21,14 @@ typedef struct unsigned long int ti_offset; } tls_index; +/* The thread pointer points to the first static TLS block. */ +#define TLS_TP_OFFSET 0 + +/* Dynamic thread vector pointers point 0x800 past the start of each + TLS block. */ +#define TLS_DTV_OFFSET 0x800 + extern void *__tls_get_addr (tls_index *ti); + +#define GET_ADDR_OFFSET (ti->ti_offset + TLS_DTV_OFFSET) +#define __TLS_GET_ADDR(__ti) (__tls_get_addr (__ti) - TLS_DTV_OFFSET) diff --git a/libpthread/nptl/sysdeps/riscv32/tcb-offsets.sym b/libpthread/nptl/sysdeps/riscv32/tcb-offsets.sym index 86025a402..fe6856c5d 100644 --- a/libpthread/nptl/sysdeps/riscv32/tcb-offsets.sym +++ b/libpthread/nptl/sysdeps/riscv32/tcb-offsets.sym @@ -1,6 +1,7 @@ #include <sysdep.h> #include <tls.h> -MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) -TID_OFFSET offsetof (struct pthread, tid) -TP_TO_PTHREAD_OFFSET -(sizeof (struct pthread) + sizeof (tcbhead_t)) +#define thread_offsetof(mem) (long)(offsetof (struct pthread, mem) - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) + +MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) + diff --git a/libpthread/nptl/sysdeps/riscv32/tls.h b/libpthread/nptl/sysdeps/riscv32/tls.h index ed6df8186..8ef9f3511 100644 --- a/libpthread/nptl/sysdeps/riscv32/tls.h +++ b/libpthread/nptl/sysdeps/riscv32/tls.h @@ -1,6 +1,5 @@ /* Definition for thread-local data handling. NPTL/RISCV32 version. Copyright (C) 2005, 2007, 2011 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 @@ -35,15 +34,6 @@ typedef union dtv } pointer; } dtv_t; -typedef struct -{ - dtv_t *dtv; -} tcbhead_t; - -register tcbhead_t *__thread_self __asm__("tp"); - -# define TLS_MULTIPLE_THREADS_IN_TCB 1 - #else /* __ASSEMBLER__ */ # include <tcb-offsets.h> #endif /* __ASSEMBLER__ */ @@ -58,71 +48,56 @@ register tcbhead_t *__thread_self __asm__("tp"); #ifndef __ASSEMBLER__ +register void *__thread_self __asm__("tp"); +# define READ_THREAD_POINTER() ({ __thread_self; }) + /* Get system call information. */ # include <sysdep.h> -/* The TP points to the start of the TLS block. - * As I understand it, this isn't strictly that "TP points to DTV" - it's - * more where to place the TCB in the TLS block. This will place it in - * the beginning. - * - * Layout: - * ------------------------------------ - * | PRE | TCB | TLS MEMORY .. | - * ------------------------------------ - * ^ x4 / TP - * - * PRE is the struct pthread described below - * TCB is tcbhead_t - * TLS memory is where the TLS program sections are loaded - * - * See _dl_allocate_tls_storage and __libc_setup_tls for more information. - */ +/* The TP points to the start of the TLS block. */ # define TLS_DTV_AT_TP 1 /* Get the thread descriptor definition. */ # include <../../descr.h> -/* Requirements for the TCB. */ -# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) -# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t) +typedef struct +{ + dtv_t *dtv; + void *private; +} tcbhead_t; -# define TLS_TCB_SIZE sizeof (tcbhead_t) -# define TLS_TCB_ALIGN __alignof__ (tcbhead_t) +/* This is the size of the initial TCB. Because our TCB is before the thread + pointer, we don't need this. */ +# define TLS_INIT_TCB_SIZE 0 +# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) -/* This is the size of the TCB. */ +/* This is the size of the TCB. Because our TCB is before the thread + pointer, we don't need this. */ +# define TLS_TCB_SIZE 0 +# define TLS_TCB_ALIGN __alignof__ (struct pthread) -/* This is the size we need before TCB. - * To support THREAD_GETMEM with friends we want to have a - * struct pthread available. - * Yank it in infront of everything, I'm sure nobody will mind. - * - * This memory is really allocated PRE the TLS block, so it's possible - * to do ((char*)tlsblock) - TLS_PRE_TCB_SIZE to access it. - * This is done for THREAD_SELF. */ -# define TLS_PRE_TCB_SIZE sizeof (struct pthread) +/* This is the size we need before TCB - actually, it includes the TCB. */ +# define TLS_PRE_TCB_SIZE \ + (sizeof (struct pthread) \ + + ((sizeof (tcbhead_t) + __alignof (struct pthread) - 1) \ + & ~(__alignof (struct pthread) - 1))) +/* The thread pointer tp points to the end of the TCB. + The pthread_descr structure is immediately in front of the TCB. */ +# define TLS_TCB_OFFSET 0 -/* Install the dtv pointer. - * When called, dtvp is a pointer not the DTV per say (which should start - * with the generation counter) but to the length of the DTV. - * We can always index with -1, so we store dtvp[1] - */ +/* Install the dtv pointer. The pointer passed is to the element with + index -1 which contain the length. */ # define INSTALL_DTV(tcbp, dtvp) \ - (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1) + (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1) -/* Install new dtv for current thread - * In a logicial world dtv here would also point to the length of the DTV. - * However it does not, this time it points to the generation counter, - * so just store it. - * - * Note: -1 is still valid and contains the length. */ +/* Install new dtv for current thread */ # define INSTALL_NEW_DTV(dtv) \ (THREAD_DTV() = (dtv)) /* Return dtv of given thread descriptor. */ # define GET_DTV(tcbp) \ - (((tcbhead_t *) (tcbp))->dtv) + (((tcbhead_t *) (tcbp))[-1].dtv) /* Code to initially initialize the thread pointer. * @@ -136,31 +111,21 @@ register tcbhead_t *__thread_self __asm__("tp"); * It's hard to fail this, so return NULL always. */ # define TLS_INIT_TP(tcbp, secondcall) \ - ({__thread_self = ((tcbhead_t *)tcbp + 1); NULL;}) + ({ __thread_self = (char*)tcbp + TLS_TCB_OFFSET; NULL; }) -/* Return the address of the dtv for the current thread. - * - * Dereference TP, offset to dtv - really straightforward. - * Remember that we made TP point to after tcb, so we need to reverse that. - */ +/* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ - ((((tcbhead_t *)__thread_self)-1)->dtv) + (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv) -/* Return the thread descriptor for the current thread. - * - * Return a pointer to the TLS_PRE area where we allocated space for - * a struct pthread. Again, TP points to after tcbhead_t, compensate with - * TLS_INIT_TCB_SIZE. - * - * I regard this is a seperate system from the "normal" TLS. - */ +/* Return the thread descriptor for the current thread. */ # define THREAD_SELF \ - ((struct pthread *) ((char *) __thread_self - TLS_INIT_TCB_SIZE \ - - TLS_PRE_TCB_SIZE)) + ((struct pthread *) (READ_THREAD_POINTER () \ + - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)) -/* Magic for libthread_db to know how to do THREAD_SELF. */ +/* Informs libthread_db that the thread pointer is register 4, which is used + * to know how to do THREAD_SELF. */ # define DB_THREAD_SELF \ - CONST_THREAD_AREA (64, sizeof (struct pthread)) + REGISTER (64, 64, 4 * 8, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) /* Access to data in the thread descriptor is easy. */ #define THREAD_GETMEM(descr, member) \ @@ -172,6 +137,10 @@ register tcbhead_t *__thread_self __asm__("tp"); #define THREAD_SETMEM_NC(descr, member, idx, value) \ descr->member[idx] = (value) +/* l_tls_offset == 0 is perfectly valid, so we have to use some different + value to mean unset l_tls_offset. */ +# define NO_TLS_OFFSET -1 + /* Get and set the global scope generation counter in struct pthread. */ #define THREAD_GSCOPE_FLAG_UNUSED 0 #define THREAD_GSCOPE_FLAG_USED 1 diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/createthread.c b/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/createthread.c index 10bb1bbfe..3079007c7 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/createthread.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/createthread.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2012 Free Software Foundation, Inc. +/* Copyright (C) 2005 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 @@ -7,16 +8,16 @@ 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 + 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; see the file COPYING.LIB. If - not, see <http://www.gnu.org/licenses/>. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* Value passed to 'clone' for initialization of the thread register. */ #define TLS_VALUE ((void *) (pd) \ - + TLS_PRE_TCB_SIZE + TLS_INIT_TCB_SIZE) + + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE) -/* Get the real implementation. */ +/* Get the real implementation. */ #include <sysdeps/pthread/createthread.c> diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/fork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/fork.c index e55d05d41..c5d963aad 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/fork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/riscv32/fork.c @@ -1,19 +1,3 @@ -/* Copyright (C) 2005 Free Software Foundation, Inc. - Contributed by Phil Blundell <pb@nexus.co.uk>, 2005 - - 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 - <http://www.gnu.org/licenses/>. */ #include <sched.h> #include <signal.h> #include <sysdep.h> @@ -22,6 +6,6 @@ #define ARCH_FORK() \ INLINE_SYSCALL (clone, 5, \ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \ - NULL, &THREAD_SELF->tid, NULL) + NULL, NULL, &THREAD_SELF->tid) #include "../fork.c" |