| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2007 Jakub Jermar
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup libc
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | #ifndef _LIBC_TLS_H_
|
|---|
| 14 | #define _LIBC_TLS_H_
|
|---|
| 15 |
|
|---|
| 16 | #include <libarch/tls.h>
|
|---|
| 17 | #include <stdbool.h>
|
|---|
| 18 | #include <stddef.h>
|
|---|
| 19 | #include <stdint.h>
|
|---|
| 20 |
|
|---|
| 21 | static inline void __tcb_reset(void)
|
|---|
| 22 | {
|
|---|
| 23 | __tcb_raw_set(NULL);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | static inline void __tcb_set(tcb_t *tcb)
|
|---|
| 27 | {
|
|---|
| 28 | __tcb_raw_set((uint8_t *)tcb + ARCH_TP_OFFSET);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | static inline tcb_t *__tcb_get(void)
|
|---|
| 32 | {
|
|---|
| 33 | return (tcb_t *)((uint8_t *)__tcb_raw_get() - ARCH_TP_OFFSET);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | /*
|
|---|
| 37 | * The TP register is supposed to be zero when the thread is first created
|
|---|
| 38 | * by the kernel. We use this for some debugging assertions.
|
|---|
| 39 | */
|
|---|
| 40 | static inline bool __tcb_is_set(void)
|
|---|
| 41 | {
|
|---|
| 42 | return __tcb_raw_get() != NULL;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /** DTV Generation number - equals vector length */
|
|---|
| 46 | #define DTV_GN(dtv) (((uintptr_t *)(dtv))[0])
|
|---|
| 47 |
|
|---|
| 48 | extern tcb_t *tls_make(const void *);
|
|---|
| 49 | extern tcb_t *tls_make_initial(const void *);
|
|---|
| 50 | extern tcb_t *tls_alloc_arch(size_t, size_t);
|
|---|
| 51 | extern void tls_free(tcb_t *);
|
|---|
| 52 | extern void tls_free_arch(tcb_t *, size_t, size_t);
|
|---|
| 53 | extern void *tls_get(void);
|
|---|
| 54 |
|
|---|
| 55 | #ifdef CONFIG_TLS_VARIANT_1
|
|---|
| 56 | extern tcb_t *tls_alloc_variant_1(size_t, size_t);
|
|---|
| 57 | extern void tls_free_variant_1(tcb_t *, size_t, size_t);
|
|---|
| 58 | #endif
|
|---|
| 59 |
|
|---|
| 60 | #ifdef CONFIG_TLS_VARIANT_2
|
|---|
| 61 | extern tcb_t *tls_alloc_variant_2(size_t, size_t);
|
|---|
| 62 | extern void tls_free_variant_2(tcb_t *, size_t, size_t);
|
|---|
| 63 | #endif
|
|---|
| 64 |
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 | /** @}
|
|---|
| 68 | */
|
|---|