From cad16dd586734ae2e05ebed9ce49261cedbc53be Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 7 Feb 2015 23:19:22 +0100 Subject: indent --- mach/setup-thread.c | 4 ++-- sysdeps/mach/hurd/i386/init-first.c | 2 +- sysdeps/mach/hurd/profil.c | 2 +- sysdeps/mach/hurd/setitimer.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/setup-thread.c b/mach/setup-thread.c index bf3e843d15..3a57125269 100644 --- a/mach/setup-thread.c +++ b/mach/setup-thread.c @@ -93,11 +93,11 @@ __mach_setup_tls (thread_t thread) return error; assert (tssize == MACHINE_THREAD_STATE_COUNT); - tcb = _dl_allocate_tls(NULL); + tcb = _dl_allocate_tls (NULL); if (!tcb) return KERN_RESOURCE_SHORTAGE; - _hurd_tls_new(thread, &ts, tcb); + _hurd_tls_new (thread, &ts, tcb); error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR, (natural_t *) &ts, tssize); diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index 842efef260..74b3a5693c 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -203,7 +203,7 @@ init (int *data) /* We need to setup TLS before starting sigthread */ extern void __pthread_initialize_minimal(void); - __pthread_initialize_minimal(); + __pthread_initialize_minimal (); #endif /* The user might have defined a value for this, to get more variables. diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c index 328bb29df2..d590ff0678 100644 --- a/sysdeps/mach/hurd/profil.c +++ b/sysdeps/mach/hurd/profil.c @@ -69,7 +69,7 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale) err = __mach_setup_thread (__mach_task_self (), profile_thread, &profile_waiter, NULL, NULL); if (! err) - err = __mach_setup_tls(profile_thread); + err = __mach_setup_tls (profile_thread); } else err = 0; diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c index c1516b6345..bad1fa3860 100644 --- a/sysdeps/mach/hurd/setitimer.c +++ b/sysdeps/mach/hurd/setitimer.c @@ -226,7 +226,7 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old, &timer_thread, &_hurd_itimer_thread_stack_base, &_hurd_itimer_thread_stack_size)) - || (err = __mach_setup_tls(_hurd_itimer_thread))) + || (err = __mach_setup_tls (_hurd_itimer_thread))) { __thread_terminate (_hurd_itimer_thread); _hurd_itimer_thread = MACH_PORT_NULL; -- cgit v1.2.3 From 75d607940699ef082ff425c8a499ab6d988444c1 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 7 Feb 2015 23:26:16 +0100 Subject: Fix changelog --- .topmsg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.topmsg b/.topmsg index 6f7e3b13b6..c1ce4031c3 100644 --- a/.topmsg +++ b/.topmsg @@ -1,10 +1,12 @@ -From: Thomas Schwinge -Subject: [PATCH] tls - -TLS support. +From: Samuel Thibault +Subject: [PATCH] hurd: add TLS support 2009-07-30 Samuel Thibault + Add TLS support: __mach_setup_tls allocates and sets + architecture state for the TLS area. i386 fork needs to + propagate the segment kernel definitions. + * sysdeps/mach/hurd/bits/libc-lock.h [_LIBC - 0]: Include * sysdeps/mach/hurd/tls.h: Include and * include/errno.h (__GNU__): Do not define TLS errno for now. -- cgit v1.2.3 From db4857c035a52a01f337a8ef6fe70ac08ad66ad5 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 7 Feb 2015 23:27:47 +0100 Subject: style --- include/errno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/errno.h b/include/errno.h index effa593a27..8beb1b81ba 100644 --- a/include/errno.h +++ b/include/errno.h @@ -21,7 +21,7 @@ extern int rtld_errno attribute_hidden; # include -# if !defined(__GNU__) +# if !defined __GNU__ # undef errno # ifndef NOT_IN_libc # define errno __libc_errno -- cgit v1.2.3 From 5eb8bf00737bafdeb78b0df2688876f538d74857 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 8 Feb 2015 19:37:57 +0100 Subject: Address some of Roland McGrath comments --- .topmsg | 6 ++++-- mach/setup-thread.c | 2 +- sysdeps/mach/hurd/bits/libc-lock.h | 6 +++--- sysdeps/mach/hurd/i386/init-first.c | 8 +++----- sysdeps/mach/hurd/i386/tls.h | 10 ++++++---- sysdeps/mach/thread_state.h | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.topmsg b/.topmsg index c1ce4031c3..af8305fe8f 100644 --- a/.topmsg +++ b/.topmsg @@ -23,8 +23,10 @@ Subject: [PATCH] hurd: add TLS support * sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): Use i386_REGS_SEGS_STATE instead of i386_THREAD_STATE. - * sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use kern_return_t - error type. Use first GDT slot, 0x48. + * sysdeps/mach/hurd/i386/tls.h (__i386_selector_is_ldt): New + macro. + (_hurd_tls_init): Use kern_return_t error type. Use + __i386_selector_is_ldt to test for LDT segment type. (_hurd_tls_fork): Use kern_return_t error type. Duplicate existing LDT descriptor instead of creating a new one. (_hurd_tls_new): New function, creates a new descriptor and updates tcb. diff --git a/mach/setup-thread.c b/mach/setup-thread.c index 3a57125269..23f004d396 100644 --- a/mach/setup-thread.c +++ b/mach/setup-thread.c @@ -94,7 +94,7 @@ __mach_setup_tls (thread_t thread) assert (tssize == MACHINE_THREAD_STATE_COUNT); tcb = _dl_allocate_tls (NULL); - if (!tcb) + if (tcb == NULL) return KERN_RESOURCE_SHORTAGE; _hurd_tls_new (thread, &ts, tcb); diff --git a/sysdeps/mach/hurd/bits/libc-lock.h b/sysdeps/mach/hurd/bits/libc-lock.h index 8bf5656f26..6850f198cd 100644 --- a/sysdeps/mach/hurd/bits/libc-lock.h +++ b/sysdeps/mach/hurd/bits/libc-lock.h @@ -20,9 +20,9 @@ #define _BITS_LIBC_LOCK_H 1 #if (_LIBC - 0) || (_CTHREADS_ - 0) -#if (_LIBC - 0) -#include -#endif +# if (_LIBC - 0) +# include +# endif #include #include diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index 74b3a5693c..db9c69f3b2 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -112,9 +112,7 @@ init1 (int argc, char *arg0, ...) then after the environment pointers there is no Hurd data block; the argument strings start there. */ if ((void *) d == argv[0]) - { - return; - } + return; #ifndef SHARED __libc_enable_secure = d->flags & EXEC_SECURE; @@ -201,8 +199,8 @@ init (int *data) assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0); } - /* We need to setup TLS before starting sigthread */ - extern void __pthread_initialize_minimal(void); + /* We need to setup TLS before starting the signal thread. */ + extern void __pthread_initialize_minimal (void); __pthread_initialize_minimal (); #endif diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 88baeeb3d8..e6ede35a7e 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -37,6 +37,8 @@ # define __i386_set_gdt(thr, sel, desc) ((void) (thr), (void) (sel), (void) (desc), MIG_BAD_ID) # endif +#define __i386_selector_is_ldt(sel) (!!((sel) & 4)) + # include # include @@ -94,7 +96,7 @@ _hurd_tls_init (tcbhead_t *tcb, int secondcall) /* Fetch the selector set by the first call. */ int sel; asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0)); - if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ + if (__glibc_unlikely (__i386_selector_is_ldt(sel))) { kern_return_t err = __i386_set_ldt (tcb->self, sel, &desc, 1); assert_perror (err); @@ -153,7 +155,7 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state) kern_return_t err; unsigned int count = 1; - if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ + if (__glibc_unlikely (__i386_selector_is_ldt(sel))) err = __i386_get_ldt (orig, sel, 1, &_desc, &count); else err = __i386_get_gdt (orig, sel, &desc); @@ -162,7 +164,7 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state) if (err) return err; - if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ + if (__glibc_unlikely (__i386_selector_is_ldt(sel))) err = __i386_set_ldt (child, sel, &desc, 1); else err = __i386_set_gdt (child, &sel, desc); @@ -186,7 +188,7 @@ _hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb) tcb->tcb = tcb; tcb->self = child; - if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ + if (__glibc_unlikely (__i386_selector_is_ldt(sel))) err = __i386_set_ldt (child, sel, &desc, 1); else err = __i386_set_gdt (child, &sel, desc); diff --git a/sysdeps/mach/thread_state.h b/sysdeps/mach/thread_state.h index 2e08af2e2d..f7323f7139 100644 --- a/sysdeps/mach/thread_state.h +++ b/sysdeps/mach/thread_state.h @@ -38,7 +38,7 @@ #endif #endif #ifndef MACHINE_THREAD_STATE_FIX_NEW -#define MACHINE_THREAD_STATE_FIX_NEW(ts) +# define MACHINE_THREAD_STATE_FIX_NEW(ts) #endif /* These functions are of use in machine-dependent signal trampoline -- cgit v1.2.3 From cd1b3ca856e24e560dfc4583b8ca6c744ab6f3e8 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 20 Aug 2016 20:40:26 +0200 Subject: New TopGit dependency: baseline --- .topdeps | 1 + 1 file changed, 1 insertion(+) diff --git a/.topdeps b/.topdeps index 70f54c7bf8..c0c827fa6f 100644 --- a/.topdeps +++ b/.topdeps @@ -1 +1,2 @@ 64a17f1adde4715bb6607f64decd73b2df9e6852 +baseline -- cgit v1.2.3 From 5cb1a5819a3ab6687d772cccdb507b9812feaa01 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 20 Aug 2016 21:24:30 +0200 Subject: fix merge --- sysdeps/mach/hurd/i386/tls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 4b02910dad..595281768d 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -105,7 +105,7 @@ _hurd_tls_init (tcbhead_t *tcb) /* Get the first available selector. */ int sel = -1; - kern_error_t err = __i386_set_gdt (tcb->self, &sel, desc); + kern_return_t err = __i386_set_gdt (tcb->self, &sel, desc); if (err == MIG_BAD_ID) { /* Old kernel, use a per-thread LDT. */ -- cgit v1.2.3 From 0b113e90a20146a2783f7cb2f3e7de716b892d5f Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 9 Oct 2016 19:53:30 +0200 Subject: drop spurious depend --- .topdeps | 1 - 1 file changed, 1 deletion(-) diff --git a/.topdeps b/.topdeps index c0c827fa6f..180b47c18b 100644 --- a/.topdeps +++ b/.topdeps @@ -1,2 +1 @@ -64a17f1adde4715bb6607f64decd73b2df9e6852 baseline -- cgit v1.2.3 From 2846a249a649f0b78fea44f120aeebf5ae5dbe93 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 2 Aug 2017 22:25:14 +0200 Subject: Add TCB_ALIGNMENT to i386-gnu TLS implementation * sysdeps/mach/hurd/i386/tls.h (TCB_ALIGNMENT): Define to 64. --- sysdeps/mach/hurd/i386/tls.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 61fcac8397..3108be68b4 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -62,6 +62,15 @@ typedef struct #define TLS_TCB_AT_TP 1 #define TLS_DTV_AT_TP 0 +/* Alignment requirement for TCB. + + Some processors such as Intel Atom pay a big penalty on every + access using a segment override if that segment's base is not + aligned to the size of a cache line. (See Intel 64 and IA-32 + Architectures Optimization Reference Manual, section 13.3.3.3, + "Segment Base".) On such machines, a cache line is 64 bytes. */ +#define TCB_ALIGNMENT 64 + #ifndef __ASSEMBLER__ /* Use i386-specific RPCs to arrange that %gs segment register prefix -- cgit v1.2.3 From 25661ce393012ec2dba88f083fc933a84c6b6778 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 3 Aug 2017 21:27:31 +0200 Subject: Compatibility with glibc 2.25 --- sysdeps/mach/hurd/i386/init-first.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index 8bff4ea60f..7895206417 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -206,7 +206,8 @@ init (int *data) /* We need to setup TLS before starting the signal thread. */ extern void __pthread_initialize_minimal (void); - __pthread_initialize_minimal (); + if (__pthread_initialize_minimal != NULL) + __pthread_initialize_minimal (); #endif /* The user might have defined a value for this, to get more variables. -- cgit v1.2.3 From 48dc719b10bcb4ffe1ee64473806fd33bf26af8c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 15 Mar 2018 00:45:24 +0100 Subject: drop useless change --- sysdeps/mach/hurd/libc-lock.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h index af8fe268cc..f6cbe50fc2 100644 --- a/sysdeps/mach/hurd/libc-lock.h +++ b/sysdeps/mach/hurd/libc-lock.h @@ -20,9 +20,6 @@ #define _LIBC_LOCK_H 1 #if (_LIBC - 0) || (_CTHREADS_ - 0) -# if (_LIBC - 0) -# include -# endif #include #include -- cgit v1.2.3 From d9c9e4269bc30080f1b0124776e64e2f6fb8cd9a Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 15 Mar 2018 00:45:54 +0100 Subject: fix style --- mach/setup-thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/setup-thread.c b/mach/setup-thread.c index 3e3fbcf93c..c1de3a1fb6 100644 --- a/mach/setup-thread.c +++ b/mach/setup-thread.c @@ -88,15 +88,15 @@ __mach_setup_tls (thread_t thread) mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT; tcbhead_t *tcb; + tcb = _dl_allocate_tls (NULL); + if (tcb == NULL) + return KERN_RESOURCE_SHORTAGE; + if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR, (natural_t *) &ts, &tssize)) return error; assert (tssize == MACHINE_THREAD_STATE_COUNT); - tcb = _dl_allocate_tls (NULL); - if (tcb == NULL) - return KERN_RESOURCE_SHORTAGE; - _hurd_tls_new (thread, &ts, tcb); error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR, -- cgit v1.2.3 From 7aadc171e217ffbe8091b54d36c69dbcefd9a829 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 16 Mar 2018 00:10:47 +0100 Subject: Apply Roland remarks --- sysdeps/mach/hurd/i386/tls.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 3108be68b4..fe0622868b 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -114,7 +114,7 @@ _hurd_tls_init (tcbhead_t *tcb) /* Get the first available selector. */ int sel = -1; - kern_return_t err = __i386_set_gdt (tcb->self, &sel, desc); + error_t err = __i386_set_gdt (tcb->self, &sel, desc); if (err == MIG_BAD_ID) { /* Old kernel, use a per-thread LDT. */ @@ -173,7 +173,7 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state) return 0; struct descriptor desc, *_desc = &desc; - kern_return_t err; + error_t err; unsigned int count = 1; if (__glibc_unlikely (__i386_selector_is_ldt(sel))) @@ -204,7 +204,7 @@ _hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb) return 0; HURD_TLS_DESC_DECL (desc, tcb); - kern_return_t err; + error_t err; tcb->tcb = tcb; tcb->self = child; -- cgit v1.2.3 From 6f0fe3b48fc2b363c9dbc730f2bb8c33f1a36d14 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 18 Mar 2018 20:25:26 +0100 Subject: mark as almost commited --- .topmsg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.topmsg b/.topmsg index af8305fe8f..8660707a5a 100644 --- a/.topmsg +++ b/.topmsg @@ -1,3 +1,5 @@ +Almost finished commiting, remains only the initialization bit. + From: Samuel Thibault Subject: [PATCH] hurd: add TLS support -- cgit v1.2.3 From 0bbb676a2342367c4e52b35e890f24667dabb348 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 25 Mar 2018 03:14:33 +0200 Subject: mark as commited --- .topmsg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.topmsg b/.topmsg index 8660707a5a..38bf5ea403 100644 --- a/.topmsg +++ b/.topmsg @@ -1,4 +1,4 @@ -Almost finished commiting, remains only the initialization bit. +COMMITED From: Samuel Thibault Subject: [PATCH] hurd: add TLS support -- cgit v1.2.3