Changeset fa23560 in mainline


Ignore:
Timestamp:
2007-10-30T22:54:11Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4d21cf8
Parents:
b2a0f6dd
Message:

Unify implementations of TLS variant I and variant II alloc_tls() and
free_tls_arch().

Location:
uspace/lib/libc
Files:
12 added
1 deleted
23 edited
7 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/Makefile

    rb2a0f6dd rfa23560  
    5151        generic/cap.c \
    5252        generic/string.c \
     53        generic/fibril.c \
    5354        generic/thread.c \
     55        generic/tls.c \
    5456        generic/task.c \
    5557        generic/futex.c \
     
    6466        generic/io/printf_core.c \
    6567        malloc/malloc.c \
    66         generic/fibril.c \
    6768        generic/sysinfo.c \
    6869        generic/ipc.c \
  • uspace/lib/libc/arch/amd64/Makefile.inc

    rb2a0f6dd rfa23560  
    3535ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
    3636                arch/$(ARCH)/src/fibril.S \
    37                 arch/$(ARCH)/src/thread.c
     37                arch/$(ARCH)/src/tls.c
    3838
    3939LFLAGS += -N
  • uspace/lib/libc/arch/amd64/include/thread.h

    rb2a0f6dd rfa23560  
    3636#define LIBC_amd64_THREAD_H_
    3737
    38 #include <libc.h>
    39 
    40 typedef struct {
    41         void *self;
    42         void *fibril_data;
    43 } tcb_t;
    44 
    45 static inline void __tcb_set(tcb_t *tcb)
    46 {
    47         __SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
    48 }
    49 
    50 static inline tcb_t * __tcb_get(void)
    51 {
    52         void * retval;
    53 
    54         asm ("movq %%fs:0, %0" : "=r"(retval));
    55         return retval;
    56 }
    57 
    5838#endif
    5939
  • uspace/lib/libc/arch/amd64/src/tls.c

    rb2a0f6dd rfa23560  
    3535 */
    3636
    37 #include <thread.h>
    38 #include <malloc.h>
    39 #include <align.h>
     37#include <tls.h>
     38#include <sys/types.h>
    4039
    41 /** Allocate TLS & TCB for initial module threads
    42  *
    43  * @param data Start of data section
    44  * @return pointer to tcb_t structure
    45  */
    4640tcb_t * __alloc_tls(void **data, size_t size)
    4741{
    48         tcb_t *tcb;
    49        
    50         size = ALIGN_UP(size, &_tls_alignment);
    51         *data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
    52 
    53         tcb = (tcb_t *) (*data + size);
    54         tcb->self = tcb;
    55 
    56         return tcb;
     42        return tls_alloc_variant_2(data, size);
    5743}
    5844
    5945void __free_tls_arch(tcb_t *tcb, size_t size)
    6046{
    61         size = ALIGN_UP(size, &_tls_alignment);
    62         void *start = ((void *)tcb) - size;
    63         free(start);
     47        tls_free_variant_2(tcb, size);
    6448}
    6549
  • uspace/lib/libc/arch/arm32/Makefile.inc

    rb2a0f6dd rfa23560  
    11#
    2 # Copyright (c) 2007 Michal Kebrt, Pavel Jancik
     2# Copyright (c) 2007 Michal Kebrt
     3# Copyright (c) 2007 Pavel Jancik
    34# All rights reserved.
    45#
     
    3839ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    3940                arch/$(ARCH)/src/fibril.S \
    40                 arch/$(ARCH)/src/thread.c \
     41                arch/$(ARCH)/src/tls.c \
    4142                arch/$(ARCH)/src/eabi.S
    4243
  • uspace/lib/libc/arch/arm32/include/thread.h

    rb2a0f6dd rfa23560  
    11/*
    2  * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
     2 * Copyright (c) 2007 Pavel Jancik
     3 * Copyright (c) 2007 Michal Kebrt
    34 * All rights reserved.
    45 *
     
    3132 */
    3233/** @file
    33  *  @brief Uspace threads and TLS.
    3434 */
    3535
     
    3737#define LIBC_arm32_THREAD_H_
    3838
    39 #include <unistd.h>
    40 
    41 /** Stack initial size. */
    42 #define THREAD_INITIAL_STACK_PAGES_NO 1
    43 
    44 /** Offsets for accessing __thread variables are shifted 8 bytes higher. */
    45 #define ARM_TP_OFFSET   (-8)
    46 
    47 /** TCB (Thread Control Block) struct.
    48  *
    49  *  TLS starts just after this struct.
    50  */
    51 typedef struct {
    52         /** Fibril data. */
    53         void *fibril_data;
    54 } tcb_t;
    55 
    56 
    57 /** Sets TLS address to the r9 register.
    58  *
    59  *  @param tcb TCB (TLS starts behind)
    60  */
    61 static inline void __tcb_set(tcb_t *tcb)
    62 {
    63         void *tls = (void *) tcb;
    64         tls += sizeof(tcb_t) + ARM_TP_OFFSET;
    65         asm volatile (
    66                 "mov r9, %0"
    67                 :
    68                 : "r"(tls)
    69         );
    70 }
    71 
    72 
    73 /** Returns TCB address.
    74  *
    75  * @return TCB address (starts before TLS which address is stored in r9 register).
    76  */
    77 static inline tcb_t *__tcb_get(void)
    78 {
    79         void *ret;
    80         asm volatile (
    81                 "mov %0, r9"
    82                 : "=r"(ret)
    83         );
    84         return (tcb_t *) (ret - ARM_TP_OFFSET - sizeof(tcb_t));
    85 }
    86 
    87 
    88 /** Returns TLS address stored.
    89  *
    90  *  Implemented in assembly.
    91  *
    92  *  @return TLS address stored in r9 register
    93  */
    94 extern uintptr_t __aeabi_read_tp(void);
    95 
    9639#endif
    9740
  • uspace/lib/libc/arch/arm32/include/tls.h

    rb2a0f6dd rfa23560  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2007 Pavel Jancik
     3 * Copyright (c) 2007 Michal Kebrt
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup libcsparc64 sparc64
    30  * @ingroup lc
     30/** @addtogroup libcarm32
    3131 * @{
    3232 */
    3333/** @file
    34  *
    3534 */
    3635
    37 #include <thread.h>
    38 #include <malloc.h>
    39 #include <align.h>
     36#ifndef LIBC_arm32_TLS_H_
     37#define LIBC_arm32_TLS_H_
    4038
    41 /*
    42  * sparc64 uses thread-local storage data structures, variant II, as described
    43  * in:
    44  *      Drepper U.: ELF Handling For Thread-Local Storage, 2005
     39#include <sys/types.h>
     40
     41#define CONFIG_TLS_VARIANT_1
     42
     43/** Offsets for accessing __thread variables are shifted 8 bytes higher. */
     44#define ARM_TP_OFFSET  (-8)
     45
     46/** TCB (Thread Control Block) struct.
     47 *
     48 *  TLS starts just after this struct.
    4549 */
     50typedef struct {
     51        /** Fibril data. */
     52        void *fibril_data;
     53} tcb_t;
    4654
    47 /** Allocate TLS variant II data structures for a thread.
     55
     56/** Sets TLS address to the r9 register.
    4857 *
    49  * Only static model is supported.
    50  *
    51  * @param data Pointer to pointer to thread local data. This is actually an
    52  *      output argument.
    53  * @param size Size of thread local data.
    54  * @return Pointer to TCB structure.
     58 *  @param tcb          TCB (TLS starts behind)
    5559 */
    56 tcb_t * __alloc_tls(void **data, size_t size)
     60static inline void __tcb_set(tcb_t *tcb)
    5761{
    58         tcb_t *tcb;
    59        
    60         size = ALIGN_UP(size, &_tls_alignment);
    61         *data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
    62 
    63         tcb = (tcb_t *) (*data + size);
    64         tcb->self = tcb;
    65 
    66         return tcb;
     62        void *tls = (void *) tcb;
     63        tls += sizeof(tcb_t) + ARM_TP_OFFSET;
     64        asm volatile (
     65                "mov r9, %0"
     66                :
     67                : "r" (tls)
     68        );
    6769}
    6870
    69 /** Free TLS variant II data structures of a thread.
     71
     72/** Returns TCB address.
    7073 *
    71  * Only static model is supported.
     74 * @return              TCB address (starts before TLS which address is stored
     75 *                      in r9 register).
     76 */
     77static inline tcb_t *__tcb_get(void)
     78{
     79        void *ret;
     80        asm volatile (
     81                "mov %0, r9"
     82                : "=r"(ret)
     83        );
     84        return (tcb_t *) (ret - ARM_TP_OFFSET - sizeof(tcb_t));
     85}
     86
     87
     88/** Returns TLS address stored.
    7289 *
    73  * @param tcb Pointer to TCB structure.
    74  * @param size Size of thread local data.
     90 *  Implemented in assembly.
     91 *
     92 *  @return             TLS address stored in r9 register
    7593 */
    76 void __free_tls_arch(tcb_t *tcb, size_t size)
    77 {
    78         size = ALIGN_UP(size, &_tls_alignment);
    79         void *start = ((void *) tcb) - size;
    80         free(start);
    81 }
     94extern uintptr_t __aeabi_read_tp(void);
     95
     96#endif
    8297
    8398/** @}
  • uspace/lib/libc/arch/arm32/src/tls.c

    rb2a0f6dd rfa23560  
    3333 */
    3434/** @file
    35  *  @brief Uspace threads and TLS.
    3635 */
    3736
    38 #include <thread.h>
    39 #include <malloc.h>
     37#include <tls.h>
     38#include <sys/types.h>
    4039
    41 /** Allocates TLS & TCB.
    42  *
    43  * @param data Start of data section (output parameter).
    44  * @param size Size of (tbss + tdata) sections.
    45  * @return     Pointer to the allocated #tcb_t structure.
    46  */
    4740tcb_t * __alloc_tls(void **data, size_t size)
    4841{
    49         tcb_t *result;
    50 
    51         result = malloc(sizeof(tcb_t) + size);
    52         *data = ((void *)result) + sizeof(tcb_t);
    53         return result;
     42        return tls_alloc_variant_1(data, size);
    5443}
    5544
    56 /** Deallocates TLS & TCB.
    57  *
    58  * @param tcb TCB structure to be deallocated (along with corresponding TLS).
    59  * @param size Not used.
    60  */
    6145void __free_tls_arch(tcb_t *tcb, size_t size)
    6246{
    63         free(tcb);
     47        tls_free_variant_1(tcb, size);
    6448}
    6549
  • uspace/lib/libc/arch/ia32/Makefile.inc

    rb2a0f6dd rfa23560  
    3535ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    3636                arch/$(ARCH)/src/fibril.S \
    37                 arch/$(ARCH)/src/thread.c
     37                arch/$(ARCH)/src/tls.c
    3838
    3939LFLAGS += -N
  • uspace/lib/libc/arch/ia32/include/thread.h

    rb2a0f6dd rfa23560  
    3636#define LIBC_ia32_THREAD_H_
    3737
    38 #include <libc.h>
    39 
    40 typedef struct {
    41         void *self;
    42         void *fibril_data;
    43 } tcb_t;
    44 
    45 static inline void __tcb_set(tcb_t *tcb)
    46 {
    47         __SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
    48 }
    49 
    50 static inline tcb_t * __tcb_get(void)
    51 {
    52         void *retval;
    53 
    54         asm ("movl %%gs:0, %0" : "=r"(retval));
    55         return retval;
    56 }
    57 
    5838#endif
    5939
  • uspace/lib/libc/arch/ia64/Makefile.inc

    rb2a0f6dd rfa23560  
    3838ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
    3939                arch/$(ARCH)/src/fibril.S \
    40                 arch/$(ARCH)/src/thread.c
     40                arch/$(ARCH)/src/tls.c
    4141
    4242BFD_NAME = elf64-little
  • uspace/lib/libc/arch/ia64/include/thread.h

    rb2a0f6dd rfa23560  
    3838#define THREAD_INITIAL_STACK_PAGES_NO 2
    3939
    40 /* This structure must be exactly 16 bytes long */
    41 typedef struct {
    42         void *dtv; /* unused in static linking*/
    43         void *fibril_data;
    44 } tcb_t;
    45 
    46 static inline void __tcb_set(tcb_t *tcb)
    47 {
    48         asm volatile ("mov r13 = %0\n" : : "r" (tcb) : "r13");
    49 }
    50 
    51 static inline tcb_t *__tcb_get(void)
    52 {
    53         void *retval;
    54 
    55         asm volatile ("mov %0 = r13\n" : "=r" (retval));
    56 
    57         return retval;
    58 }
    59 
    6040#endif
    6141
  • uspace/lib/libc/arch/ia64/src/tls.c

    rb2a0f6dd rfa23560  
    3535 */
    3636
    37 #include <thread.h>
     37#include <tls.h>
    3838#include <malloc.h>
    3939
    40 /** Allocate TLS & TCB for initial module threads
    41  *
    42  * @param data Start of data section
    43  * @return pointer to tcb_t structure
    44  */
    45 extern char _tdata_start;
    46 extern char _tbss_end;
    4740tcb_t * __alloc_tls(void **data, size_t size)
    4841{
    49         tcb_t *tcb;
    50        
    51 /*      ASSERT(sizeof(tcb_t) == 16); */
    52 
    53         tcb = malloc(sizeof(tcb_t) + size);
    54         *data = ((void *) tcb) + 16;
    55 
    56         return tcb;
     42        return tls_alloc_variant_1(data, size);
    5743}
    5844
    5945void __free_tls_arch(tcb_t *tcb, size_t size)
    6046{
    61         free(tcb);
     47        tls_free_variant_1(tcb, size);
    6248}
    6349
  • uspace/lib/libc/arch/mips32/Makefile.inc

    rb2a0f6dd rfa23560  
    4141ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    4242        arch/$(ARCH)/src/fibril.S \
    43         arch/$(ARCH)/src/thread.c
     43        arch/$(ARCH)/src/tls.c
    4444
    4545
  • uspace/lib/libc/arch/mips32/include/thread.h

    rb2a0f6dd rfa23560  
    3434 */
    3535
    36 /* TLS for MIPS is described in http://www.linux-mips.org/wiki/NPTL */
    37 
    3836#ifndef LIBC_mips32_THREAD_H_
    3937#define LIBC_mips32_THREAD_H_
    40 
    41 /* I did not find any specification (neither MIPS nor PowerPC), but
    42  * as I found it
    43  * - it uses Variant II
    44  * - TCB is at Address(First TLS Block)+0x7000.
    45  * - DTV is at Address(First TLS Block)+0x8000
    46  * - What would happen if the TLS data was larger then 0x7000?
    47  * - The linker never accesses DTV directly, has the second definition any
    48  *   sense?
    49  * We will make it this way:
    50  * - TCB is at TP-0x7000-sizeof(tcb)
    51  * - No assumption about DTV etc., but it will not have a fixed address
    52  */
    53 #define MIPS_TP_OFFSET 0x7000
    54 
    55 typedef struct {
    56         void *fibril_data;
    57 } tcb_t;
    58 
    59 static inline void __tcb_set(tcb_t *tcb)
    60 {
    61         void *tp = tcb;
    62         tp += MIPS_TP_OFFSET + sizeof(tcb_t);
    63 
    64         asm volatile ("add $27, %0, $0" : : "r"(tp)); /* Move tls to K1 */
    65 }
    66 
    67 static inline tcb_t * __tcb_get(void)
    68 {
    69         void * retval;
    70 
    71         asm volatile("add %0, $27, $0" : "=r"(retval));
    72 
    73         return (tcb_t *)(retval - MIPS_TP_OFFSET - sizeof(tcb_t));
    74 }
    7538
    7639#endif
  • uspace/lib/libc/arch/mips32/src/tls.c

    rb2a0f6dd rfa23560  
    3434 */
    3535
    36 #include <thread.h>
    37 #include <malloc.h>
     36#include <tls.h>
     37#include <sys/types.h>
    3838
    39 /** Allocate TLS & TCB for initial module threads
    40  *
    41  * @param data (out) Start of TLS section
    42  * @param size Size of tdata+tbss section
    43  * @return pointer to tcb_t structure
    44  */
    4539tcb_t * __alloc_tls(void **data, size_t size)
    4640{
    47         tcb_t *result;
    48 
    49         result = malloc(sizeof(tcb_t) + size);
    50         *data = ((void *)result) + sizeof(tcb_t);
    51         return result;
     41        return tls_alloc_variant_1(data, size);
    5242}
    5343
    5444void __free_tls_arch(tcb_t *tcb, size_t size)
    5545{
    56         free(tcb);
     46        tls_free_variant_1(tcb, size);
    5747}
    5848
  • uspace/lib/libc/arch/mips32eb/Makefile.inc

    rb2a0f6dd rfa23560  
    3636ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    3737                arch/$(ARCH)/src/fibril.S \
    38                 arch/$(ARCH)/src/thread.c
     38                arch/$(ARCH)/src/tls.c
    3939
    4040LFLAGS += -N
  • uspace/lib/libc/arch/ppc32/Makefile.inc

    rb2a0f6dd rfa23560  
    3535ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    3636                arch/$(ARCH)/src/fibril.S \
    37                 arch/$(ARCH)/src/thread.c
     37                arch/$(ARCH)/src/tls.c
    3838
    3939CFLAGS += -mcpu=powerpc -msoft-float -m32
  • uspace/lib/libc/arch/ppc32/include/thread.h

    rb2a0f6dd rfa23560  
    3636#define LIBC_ppc32_THREAD_H_
    3737
    38 #define PPC_TP_OFFSET 0x7000
    39 
    40 typedef struct {
    41         void *fibril_data;
    42 } tcb_t;
    43 
    44 static inline void __tcb_set(tcb_t *tcb)
    45 {
    46         void *tp = tcb;
    47         tp += PPC_TP_OFFSET + sizeof(tcb_t);
    48        
    49         asm volatile (
    50                 "mr %%r2, %0\n"
    51                 :
    52                 : "r" (tp)
    53         );
    54 }
    55 
    56 static inline tcb_t * __tcb_get(void)
    57 {
    58         void * retval;
    59        
    60         asm volatile (
    61                 "mr %0, %%r2\n"
    62                 : "=r" (retval)
    63         );
    64 
    65         return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
    66 }
    67 
    6838#endif
    6939
  • uspace/lib/libc/arch/ppc32/src/tls.c

    rb2a0f6dd rfa23560  
    3333 */
    3434
    35 #include <thread.h>
    36 #include <malloc.h>
     35#include <tls.h>
     36#include <sys/types.h>
    3737
    38 /** Allocate TLS & TCB for initial module threads
    39  *
    40  * @param data Start of data section
    41  * @return pointer to tcb_t structure
    42  *
    43  */
    4438tcb_t * __alloc_tls(void **data, size_t size)
    4539{
    46         tcb_t *result;
    47 
    48         result = malloc(sizeof(tcb_t) + size);
    49         *data = ((void *)result) + sizeof(tcb_t);
    50         return result;
     40        return tls_alloc_variant_1(data, size);
    5141}
    5242
    5343void __free_tls_arch(tcb_t *tcb, size_t size)
    5444{
    55         free(tcb);
     45        tls_free_variant_1(tcb, size);
    5646}
    5747
  • uspace/lib/libc/arch/ppc64/Makefile.inc

    rb2a0f6dd rfa23560  
    3535ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
    3636                arch/$(ARCH)/src/fibril.S \
    37                 arch/$(ARCH)/src/thread.c
     37                arch/$(ARCH)/src/tls.c
    3838
    3939CFLAGS += -mcpu=powerpc64 -msoft-float -m64
  • uspace/lib/libc/arch/ppc64/include/thread.h

    rb2a0f6dd rfa23560  
    3636#define LIBC_ppc64_THREAD_H_
    3737
    38 #define PPC_TP_OFFSET 0x7000
    39 
    40 typedef struct {
    41         void *fibril_data;
    42 } tcb_t;
    43 
    44 static inline void __tcb_set(tcb_t *tcb)
    45 {
    46         void *tp = tcb;
    47         tp += PPC_TP_OFFSET + sizeof(tcb_t);
    48        
    49         asm volatile (
    50                 "mr %%r2, %0\n"
    51                 :
    52                 : "r" (tp)
    53         );
    54 }
    55 
    56 static inline tcb_t * __tcb_get(void)
    57 {
    58         void * retval;
    59        
    60         asm volatile (
    61                 "mr %0, %%r2\n"
    62                 : "=r" (retval)
    63         );
    64 
    65         return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
    66 }
    67 
    6838#endif
    6939
  • uspace/lib/libc/arch/sparc64/Makefile.inc

    rb2a0f6dd rfa23560  
    3434
    3535ARCH_SOURCES += arch/$(ARCH)/src/fibril.S \
    36                 arch/$(ARCH)/src/thread.c
     36                arch/$(ARCH)/src/tls.c
    3737
    3838CFLAGS += -mcpu=ultrasparc -m64
  • uspace/lib/libc/arch/sparc64/include/thread.h

    rb2a0f6dd rfa23560  
    3131 * @{
    3232 */
    33 /**
    34  * @file
    35  * @brief       sparc64 TLS functions.
    36  */
    3733
    3834#ifndef LIBC_sparc64_THREAD_H_
    3935#define LIBC_sparc64_THREAD_H_
    40 
    41 typedef struct {
    42         void *self;
    43         void *fibril_data;
    44 } tcb_t;
    45 
    46 static inline void __tcb_set(tcb_t *tcb)
    47 {
    48         asm volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7");
    49 }
    50 
    51 static inline tcb_t * __tcb_get(void)
    52 {
    53         void *retval;
    54 
    55         asm volatile ("mov %%g7, %0\n" : "=r" (retval));
    56 
    57         return retval;
    58 }
    5936
    6037#endif
  • uspace/lib/libc/generic/fibril.c

    rb2a0f6dd rfa23560  
    3636#include <libadt/list.h>
    3737#include <fibril.h>
     38#include <thread.h>
     39#include <tls.h>
    3840#include <malloc.h>
    3941#include <unistd.h>
    40 #include <thread.h>
    4142#include <stdio.h>
    4243#include <libarch/faddr.h>
  • uspace/lib/libc/generic/libc.c

    rb2a0f6dd rfa23560  
    4141#include <libc.h>
    4242#include <unistd.h>
     43#include <malloc.h>
     44#include <tls.h>
    4345#include <thread.h>
    44 #include <malloc.h>
    4546#include <fibril.h>
    4647#include <io/stream.h>
  • uspace/lib/libc/generic/thread.c

    rb2a0f6dd rfa23560  
    4242#include <async.h>
    4343
    44 #include <stdio.h>
    45 
    46 
    4744#ifndef THREAD_INITIAL_STACK_PAGES_NO
    4845#define THREAD_INITIAL_STACK_PAGES_NO 1
    4946#endif
    50 
    51 static LIST_INITIALIZE(thread_garbage);
    52 
    53 extern char _tdata_start;
    54 extern char _tdata_end;
    55 extern char _tbss_start;
    56 extern char _tbss_end;
    57 
    58 /** Create TLS (Thread Local Storage) data structures.
    59  *
    60  * The code requires, that sections .tdata and .tbss are adjacent. It may be
    61  * changed in the future.
    62  *
    63  * @return Pointer to TCB.
    64  */
    65 tcb_t *__make_tls(void)
    66 {
    67         void *data;
    68         tcb_t *tcb;
    69         size_t tls_size = &_tbss_end - &_tdata_start;
    70        
    71         tcb = __alloc_tls(&data, tls_size);
    72        
    73         /*
    74          * Copy thread local data from the initialization image.
    75          */
    76         memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);
    77         /*
    78          * Zero out the thread local uninitialized data.
    79          */
    80         memset(data + (&_tbss_start - &_tdata_start), 0,
    81             &_tbss_end - &_tbss_start);
    82 
    83         return tcb;
    84 }
    85 
    86 void __free_tls(tcb_t *tcb)
    87 {
    88         size_t tls_size = &_tbss_end - &_tdata_start;
    89         __free_tls_arch(tcb, tls_size);
    90 }
    9147
    9248/** Main thread function.
  • uspace/lib/libc/include/fibril.h

    rb2a0f6dd rfa23560  
    3838#include <libarch/fibril.h>
    3939#include <libadt/list.h>
    40 #include <libarch/thread.h>
     40#include <libarch/tls.h>
    4141
    4242#ifndef context_set
  • uspace/lib/libc/include/thread.h

    rb2a0f6dd rfa23560  
    4242typedef uint64_t thread_id_t;
    4343
    44 extern char _tls_alignment;
     44extern void __thread_entry(void);
     45extern void __thread_main(uspace_arg_t *);
    4546
    46 extern void __thread_entry(void);
    47 extern void __thread_main(uspace_arg_t *uarg);
    48 
    49 extern int thread_create(void (* function)(void *), void *arg, char *name, thread_id_t *tid);
    50 extern void thread_exit(int status);
    51 extern void thread_detach(thread_id_t thread);
    52 extern int thread_join(thread_id_t thread);
     47extern int thread_create(void (*)(void *), void *, char *, thread_id_t *);
     48extern void thread_exit(int);
     49extern void thread_detach(thread_id_t);
     50extern int thread_join(thread_id_t);
    5351extern thread_id_t thread_get_id(void);
    54 extern tcb_t * __make_tls(void);
    55 extern tcb_t * __alloc_tls(void **data, size_t size);
    56 extern void __free_tls(tcb_t *);
    57 extern void __free_tls_arch(tcb_t *, size_t size);
    5852
    5953#endif
Note: See TracChangeset for help on using the changeset viewer.