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