summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.topmsg56
-rw-r--r--csu/libc-start.c2
-rw-r--r--hurd/hurd.h4
-rw-r--r--hurd/hurd/fd.h20
-rw-r--r--hurd/hurd/port.h31
-rw-r--r--hurd/hurd/signal.h16
-rw-r--r--hurd/hurd/threadvar.h5
-rw-r--r--hurd/hurd/userlink.h14
-rw-r--r--hurd/hurdfault.c2
-rw-r--r--hurd/hurdsig.c2
-rw-r--r--include/errno.h14
-rw-r--r--mach/lock-intern.h20
-rw-r--r--mach/mach.h3
-rw-r--r--mach/mach/mig_support.h3
-rw-r--r--mach/setup-thread.c30
-rw-r--r--mach/spin-lock.c1
-rw-r--r--sysdeps/generic/machine-lock.h12
-rw-r--r--sysdeps/generic/machine-sp.h4
-rw-r--r--sysdeps/generic/thread_state.h1
-rw-r--r--sysdeps/mach/hurd/bits/libc-lock.h3
-rw-r--r--sysdeps/mach/hurd/fork.c7
-rw-r--r--sysdeps/mach/hurd/i386/Makefile5
-rw-r--r--sysdeps/mach/hurd/i386/getcontext.S74
-rw-r--r--sysdeps/mach/hurd/i386/init-first.c53
-rw-r--r--sysdeps/mach/hurd/i386/makecontext-helper.c69
-rw-r--r--sysdeps/mach/hurd/i386/makecontext.S130
-rw-r--r--sysdeps/mach/hurd/i386/setcontext.S92
-rw-r--r--sysdeps/mach/hurd/i386/swapcontext.S110
-rw-r--r--sysdeps/mach/hurd/i386/tls.h53
-rw-r--r--sysdeps/mach/hurd/i386/trampoline.c2
-rw-r--r--sysdeps/mach/hurd/i386/ucontext_i.sym29
-rw-r--r--sysdeps/mach/hurd/profil.c2
-rw-r--r--sysdeps/mach/hurd/setitimer.c3
-rw-r--r--sysdeps/mach/hurd/tls.h2
-rw-r--r--sysdeps/mach/i386/machine-lock.h12
-rw-r--r--sysdeps/mach/i386/thread_state.h11
-rw-r--r--sysdeps/mach/thread_state.h3
37 files changed, 843 insertions, 57 deletions
diff --git a/.topmsg b/.topmsg
index 123198f38f..6f7e3b13b6 100644
--- a/.topmsg
+++ b/.topmsg
@@ -1,18 +1,48 @@
-From upstream git:
+From: Thomas Schwinge <thomas@schwinge.name>
+Subject: [PATCH] tls
-commit 9f2a4fbc3c3265227f1493469ad67a81a786c3b1
-Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
-Date: Wed Apr 16 23:43:28 2014 +0200
+TLS support.
- hurd: Move dtv, dtv_t, tcbhead_t declaration to per-arch file.
+2009-07-30 Samuel Thibault <samuel.thibault@gnu.org>
+ * sysdeps/mach/hurd/bits/libc-lock.h [_LIBC - 0]: Include <tls.h>
+ * sysdeps/mach/hurd/tls.h: Include <stdint.h> and <sysdep.h>
+ * include/errno.h (__GNU__): Do not define TLS errno for now.
-commit 3c799e913168a84197c08e62d47be666329308e0
-Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
-Date: Wed Apr 16 23:45:36 2014 +0200
+ * sysdeps/generic/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR): New
+ macro.
+ * sysdeps/mach/thread_state.h (MACHINE_THREAD_STATE_FIX_NEW): New macro.
+ * sysdeps/mach/i386/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR):
+ New macro, defined to i386_THREAD_STATE.
+ (MACHINE_THREAD_STATE_FLAVOR): Define to i386_REGS_SEGS_STATE instead
+ of i386_THREAD_STATE.
+ (MACHINE_THREAD_STATE_FIX_NEW): New macro, reads segments.
- hurd: Add i386 fields to TLS structure
-
- * sysdeps/mach/hurd/i386/tls.h (tcbhead_t): Add multiple_threads,
- sysinfo, stack_guard, pointer_guard, gscope_flag, private_futex,
- __private_tm, __private_ss fields.
+ * 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.
+ (_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.
+
+ * mach/mach.h (__mach_setup_tls,mach_setup_tls): Add declarations.
+ * mach/setup-thread.c: Include <ldsodefs.h>.
+ (__mach_setup_thread): Use MACHINE_NEW_THREAD_STATE_FLAVOR instead of
+ MACHINE_THREAD_STATE_FLAVOR.
+ (__mach_setup_tls): New function.
+ * hurd/hurdfault.c (_hurdsig_fault_init): Call
+ MACHINE_THREAD_STATE_FIX_NEW.
+
+ * sysdeps/mach/hurd/profil.c (update_waiter): Call __mach_setup_tls.
+ * sysdeps/mach/hurd/setitimer.c (setitimer_locked): Call
+ __mach_setup_tls.
+ * hurd/hurdsig.c (_hurdsig_init): Call __mach_setup_tls.
+ * sysdeps/mach/hurd/fork.c (__fork): Call _hurd_tls_fork for
+ sigthread. Pass kernel thread to _hurd_tls_fork.
+ * sysdeps/mach/hurd/i386/init-first.c (init): Move ELF header parsing
+ after getting up the environment pointer. Call
+ __pthread_initialize_minimal.
+ * csu/libc-start.c (LIBC_START_MAIN) [__GNU__]: Do not call
+ __pthread_initialize_minimal.
diff --git a/csu/libc-start.c b/csu/libc-start.c
index 146e16ba46..c8a77e6655 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -189,10 +189,12 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Perform IREL{,A} relocations. */
apply_irel ();
+#ifndef __GNU__
/* Initialize the thread library at least a bit since the libgcc
functions are using thread functions if these are available and
we need to setup errno. */
__pthread_initialize_minimal ();
+#endif
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/hurd/hurd.h b/hurd/hurd.h
index 38bb2caa52..b9799acaf7 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -46,6 +46,9 @@
#define _HURD_H_EXTERN_INLINE __extern_inline
#endif
+int __hurd_fail (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_H_EXTERN_INLINE int
__hurd_fail (error_t err)
{
@@ -75,6 +78,7 @@ __hurd_fail (error_t err)
errno = err;
return -1;
}
+#endif
/* Basic ports and info, initialized by startup. */
diff --git a/hurd/hurd/fd.h b/hurd/hurd/fd.h
index adb865a3b6..6d4b637582 100644
--- a/hurd/hurd/fd.h
+++ b/hurd/hurd/fd.h
@@ -58,6 +58,9 @@ extern struct mutex _hurd_dtable_lock; /* Locks those two variables. */
NULL. The cell is unlocked; when ready to use it, lock it and check for
it being unused. */
+struct hurd_fd *_hurd_fd_get (int fd);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_FD_H_EXTERN_INLINE struct hurd_fd *
_hurd_fd_get (int fd)
{
@@ -90,6 +93,7 @@ _hurd_fd_get (int fd)
return descriptor;
}
+#endif
/* Evaluate EXPR with the variable `descriptor' bound to a pointer to the
@@ -137,6 +141,9 @@ _hurd_fd_get (int fd)
/* Check if ERR should generate a signal.
Returns the signal to take, or zero if none. */
+int _hurd_fd_error_signal (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
_hurd_fd_error_signal (error_t err)
{
@@ -153,11 +160,15 @@ _hurd_fd_error_signal (error_t err)
return 0;
}
}
+#endif
/* Handle an error from an RPC on a file descriptor's port. You should
always use this function to handle errors from RPCs made on file
descriptor ports. Some errors are translated into signals. */
+error_t _hurd_fd_error (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE error_t
_hurd_fd_error (int fd, error_t err)
{
@@ -170,20 +181,28 @@ _hurd_fd_error (int fd, error_t err)
}
return err;
}
+#endif
/* Handle error code ERR from an RPC on file descriptor FD's port.
Set `errno' to the appropriate error code, and always return -1. */
+int __hurd_dfail (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
__hurd_dfail (int fd, error_t err)
{
errno = _hurd_fd_error (fd, err);
return -1;
}
+#endif
/* Likewise, but do not raise SIGPIPE on EPIPE if flags contain
MSG_NOSIGNAL. */
+int __hurd_sockfail (int fd, int flags, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
__hurd_sockfail (int fd, int flags, error_t err)
{
@@ -192,6 +211,7 @@ __hurd_sockfail (int fd, int flags, error_t err)
errno = err;
return -1;
}
+#endif
/* Set up *FD to have PORT its server port, doing appropriate ctty magic.
Does no locking or unlocking. */
diff --git a/hurd/hurd/port.h b/hurd/hurd/port.h
index a44369817b..ee7caa0c10 100644
--- a/hurd/hurd/port.h
+++ b/hurd/hurd/port.h
@@ -60,6 +60,9 @@ struct hurd_port
/* Initialize *PORT to INIT. */
+void _hurd_port_init (struct hurd_port *port, mach_port_t init);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_init (struct hurd_port *port, mach_port_t init)
{
@@ -67,6 +70,7 @@ _hurd_port_init (struct hurd_port *port, mach_port_t init)
port->users = NULL;
port->port = init;
}
+#endif
/* Cleanup function for non-local exits. */
@@ -75,6 +79,11 @@ extern void _hurd_port_cleanup (void *, jmp_buf, int);
/* Get a reference to *PORT, which is locked.
Pass return value and LINK to _hurd_port_free when done. */
+mach_port_t
+_hurd_port_locked_get (struct hurd_port *port,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE mach_port_t
_hurd_port_locked_get (struct hurd_port *port,
struct hurd_userlink *link)
@@ -90,9 +99,15 @@ _hurd_port_locked_get (struct hurd_port *port,
__spin_unlock (&port->lock);
return result;
}
+#endif
/* Same, but locks PORT first. */
+mach_port_t
+_hurd_port_get (struct hurd_port *port,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE mach_port_t
_hurd_port_get (struct hurd_port *port,
struct hurd_userlink *link)
@@ -104,10 +119,17 @@ _hurd_port_get (struct hurd_port *port,
HURD_CRITICAL_END;
return result;
}
+#endif
/* Free a reference gotten with `USED_PORT = _hurd_port_get (PORT, LINK);' */
+void
+_hurd_port_free (struct hurd_port *port,
+ struct hurd_userlink *link,
+ mach_port_t used_port);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_free (struct hurd_port *port,
struct hurd_userlink *link,
@@ -127,11 +149,15 @@ _hurd_port_free (struct hurd_port *port,
if (dealloc)
__mach_port_deallocate (__mach_task_self (), used_port);
}
+#endif
/* Set *PORT's port to NEWPORT. NEWPORT's reference is consumed by PORT->port.
PORT->lock is locked. */
+void _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
{
@@ -142,9 +168,13 @@ _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
if (old != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), old);
}
+#endif
/* Same, but locks PORT first. */
+void _hurd_port_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_set (struct hurd_port *port, mach_port_t newport)
{
@@ -153,6 +183,7 @@ _hurd_port_set (struct hurd_port *port, mach_port_t newport)
_hurd_port_locked_set (port, newport);
HURD_CRITICAL_END;
}
+#endif
#endif /* hurd/port.h */
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 8355d67ff3..4ca568a7fb 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -129,15 +129,17 @@ extern struct hurd_sigstate *_hurd_self_sigstate (void)
#define _HURD_SIGNAL_H_EXTERN_INLINE __extern_inline
#endif
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
_hurd_self_sigstate (void)
{
- struct hurd_sigstate **location =
+ struct hurd_sigstate **location = (struct hurd_sigstate **)
(void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
if (*location == NULL)
*location = _hurd_thread_sigstate (__mach_thread_self ());
return *location;
}
+#endif
/* Thread listening on our message port; also called the "signal thread". */
@@ -164,10 +166,13 @@ extern int _hurd_core_limit;
interrupted lest the signal handler try to take the same lock and
deadlock result. */
+void *_hurd_critical_section_lock (void);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_SIGNAL_H_EXTERN_INLINE void *
_hurd_critical_section_lock (void)
{
- struct hurd_sigstate **location =
+ struct hurd_sigstate **location = (struct hurd_sigstate **)
(void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
struct hurd_sigstate *ss = *location;
if (ss == NULL)
@@ -189,7 +194,11 @@ _hurd_critical_section_lock (void)
_hurd_critical_section_unlock to unlock it. */
return ss;
}
+#endif
+void _hurd_critical_section_unlock (void *our_lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_SIGNAL_H_EXTERN_INLINE void
_hurd_critical_section_unlock (void *our_lock)
{
@@ -199,7 +208,7 @@ _hurd_critical_section_unlock (void *our_lock)
else
{
/* It was us who acquired the critical section lock. Unlock it. */
- struct hurd_sigstate *ss = our_lock;
+ struct hurd_sigstate *ss = (struct hurd_sigstate *) our_lock;
sigset_t pending;
__spin_lock (&ss->lock);
__spin_unlock (&ss->critical_section_lock);
@@ -212,6 +221,7 @@ _hurd_critical_section_unlock (void *our_lock)
__msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
}
}
+#endif
/* Convenient macros for simple uses of critical sections.
These two must be used as a pair at the same C scoping level. */
diff --git a/hurd/hurd/threadvar.h b/hurd/hurd/threadvar.h
index b62f5a6d86..efaf6f2f11 100644
--- a/hurd/hurd/threadvar.h
+++ b/hurd/hurd/threadvar.h
@@ -81,6 +81,8 @@ enum __hurd_threadvar_index
extern unsigned long int *__hurd_threadvar_location_from_sp
(enum __hurd_threadvar_index __index, void *__sp);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
__hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
void *__sp)
@@ -92,6 +94,7 @@ __hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
: (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) +
__hurd_threadvar_stack_offset))[__index];
}
+#endif
#include <machine-sp.h> /* Define __thread_stack_pointer. */
@@ -105,12 +108,14 @@ __hurd_threadvar_location (enum __hurd_threadvar_index __index) __THROW
the same stack frame by different threads. */
__attribute__ ((__const__));
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
__hurd_threadvar_location (enum __hurd_threadvar_index __index)
{
return __hurd_threadvar_location_from_sp (__index,
__thread_stack_pointer ());
}
+#endif
#endif /* hurd/threadvar.h */
diff --git a/hurd/hurd/userlink.h b/hurd/hurd/userlink.h
index 39737c6895..03a9d60970 100644
--- a/hurd/hurd/userlink.h
+++ b/hurd/hurd/userlink.h
@@ -76,6 +76,11 @@ struct hurd_userlink
/* Attach LINK to the chain of users at *CHAINP. */
+void
+_hurd_userlink_link (struct hurd_userlink **chainp,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_USERLINK_H_EXTERN_INLINE void
_hurd_userlink_link (struct hurd_userlink **chainp,
struct hurd_userlink *link)
@@ -96,11 +101,15 @@ _hurd_userlink_link (struct hurd_userlink **chainp,
link->thread.prevp = thread_chainp;
*thread_chainp = link;
}
+#endif
/* Detach LINK from its chain. Returns nonzero iff this was the
last user of the resource and it should be deallocated. */
+int _hurd_userlink_unlink (struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_USERLINK_H_EXTERN_INLINE int
_hurd_userlink_unlink (struct hurd_userlink *link)
{
@@ -123,6 +132,7 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
return dealloc;
}
+#endif
/* Clear all users from *CHAINP. Call this when the resource *CHAINP
@@ -131,6 +141,9 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
value is zero, someone is still using the resource and they will
deallocate it when they are finished. */
+int _hurd_userlink_clear (struct hurd_userlink **chainp);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC && !defined NOT_IN_libc
_HURD_USERLINK_H_EXTERN_INLINE int
_hurd_userlink_clear (struct hurd_userlink **chainp)
{
@@ -143,5 +156,6 @@ _hurd_userlink_clear (struct hurd_userlink **chainp)
*chainp = NULL;
return 0;
}
+#endif
#endif /* hurd/userlink.h */
diff --git a/hurd/hurdfault.c b/hurd/hurdfault.c
index 02a5021a25..4903f1675d 100644
--- a/hurd/hurdfault.c
+++ b/hurd/hurdfault.c
@@ -204,6 +204,8 @@ _hurdsig_fault_init (void)
/* This state will be restored when we fault.
It runs the function above. */
memset (&state, 0, sizeof state);
+
+ MACHINE_THREAD_STATE_FIX_NEW (&state);
MACHINE_THREAD_STATE_SET_PC (&state, faulted);
MACHINE_THREAD_STATE_SET_SP (&state, faultstack, sizeof faultstack);
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index bb37286c9b..556b3eec24 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -1266,6 +1266,8 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
(vm_address_t *) &__hurd_sigthread_stack_base,
&stacksize);
assert_perror (err);
+ err = __mach_setup_tls (_hurd_msgport_thread);
+ assert_perror (err);
__hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
__hurd_sigthread_variables =
diff --git a/include/errno.h b/include/errno.h
index f1b93a881b..effa593a27 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -21,13 +21,15 @@ extern int rtld_errno attribute_hidden;
# include <tls.h>
-# undef errno
-# ifndef NOT_IN_libc
-# define errno __libc_errno
-# else
-# define errno errno /* For #ifndef errno tests. */
-# endif
+# if !defined(__GNU__)
+# undef errno
+# ifndef NOT_IN_libc
+# define errno __libc_errno
+# else
+# define errno errno /* For #ifndef errno tests. */
+# endif
extern __thread int errno attribute_tls_model_ie;
+# endif
# endif /* !NOT_IN_libc || IN_LIB */
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index b85ed73675..6d315bbb6b 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -28,11 +28,15 @@
/* Initialize LOCK. */
+void __spin_lock_init (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__spin_lock_init (__spin_lock_t *__lock)
{
*__lock = __SPIN_LOCK_INITIALIZER;
}
+#endif
/* Lock LOCK, blocking if we can't get it. */
@@ -40,12 +44,16 @@ extern void __spin_lock_solid (__spin_lock_t *__lock);
/* Lock the spin lock LOCK. */
+void __spin_lock (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__spin_lock (__spin_lock_t *__lock)
{
if (! __spin_try_lock (__lock))
__spin_lock_solid (__lock);
}
+#endif
/* Name space-clean internal interface to mutex locks.
@@ -70,27 +78,39 @@ extern void __mutex_unlock_solid (void *__lock);
/* Lock the mutex lock LOCK. */
+void __mutex_lock (void *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__mutex_lock (void *__lock)
{
if (! __spin_try_lock ((__spin_lock_t *) __lock))
__mutex_lock_solid (__lock);
}
+#endif
/* Unlock the mutex lock LOCK. */
+void __mutex_unlock (void *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__mutex_unlock (void *__lock)
{
__spin_unlock ((__spin_lock_t *) __lock);
__mutex_unlock_solid (__lock);
}
+#endif
+int __mutex_trylock (void *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE int
__mutex_trylock (void *__lock)
{
return __spin_try_lock ((__spin_lock_t *) __lock);
}
+#endif
#endif /* lock-intern.h */
diff --git a/mach/mach.h b/mach/mach.h
index 066762aa9d..f70a45375c 100644
--- a/mach/mach.h
+++ b/mach/mach.h
@@ -100,5 +100,8 @@ kern_return_t mach_setup_thread (task_t task, thread_t thread, void *pc,
vm_address_t *stack_base,
vm_size_t *stack_size);
+/* Give THREAD a TLS area. */
+kern_return_t __mach_setup_tls (thread_t thread);
+kern_return_t mach_setup_tls (thread_t thread);
#endif /* mach.h */
diff --git a/mach/mach/mig_support.h b/mach/mach/mig_support.h
index cc31f07e6b..0d0a61bb41 100644
--- a/mach/mach/mig_support.h
+++ b/mach/mach/mig_support.h
@@ -66,6 +66,8 @@ extern void mig_reply_setup (const mach_msg_header_t *__request,
/* Idiocy support function. */
extern vm_size_t mig_strncpy (char *__dst, const char *__src, vm_size_t __len);
extern vm_size_t __mig_strncpy (char *__dst, const char *__src, vm_size_t);
+
+#ifdef __USE_EXTERN_INLINES
__extern_inline vm_size_t
__mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
{
@@ -76,6 +78,7 @@ mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
{
return __mig_strncpy (__dst, __src, __len);
}
+#endif
diff --git a/mach/setup-thread.c b/mach/setup-thread.c
index 5f2051efcc..198fd0fd3f 100644
--- a/mach/setup-thread.c
+++ b/mach/setup-thread.c
@@ -19,6 +19,7 @@
#include <thread_state.h>
#include <string.h>
#include <mach/machine/vm_param.h>
+#include <ldsodefs.h>
#include "sysdep.h" /* Defines stack direction. */
#define STACK_SIZE (16 * 1024 * 1024) /* 16MB, arbitrary. */
@@ -72,8 +73,35 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
return error;
- return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ return __thread_set_state (thread, MACHINE_NEW_THREAD_STATE_FLAVOR,
(natural_t *) &ts, tssize);
}
weak_alias (__mach_setup_thread, mach_setup_thread)
+
+/* Give THREAD a TLS area. */
+kern_return_t
+__mach_setup_tls (thread_t thread)
+{
+ kern_return_t error;
+ struct machine_thread_state ts;
+ mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
+ tcbhead_t *tcb;
+
+ 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)
+ return KERN_RESOURCE_SHORTAGE;
+
+ _hurd_tls_new(thread, &ts, tcb);
+
+ error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ (natural_t *) &ts, tssize);
+ return error;
+}
+
+weak_alias (__mach_setup_tls, mach_setup_tls)
diff --git a/mach/spin-lock.c b/mach/spin-lock.c
index aaebc55cf4..1b1e69c8d6 100644
--- a/mach/spin-lock.c
+++ b/mach/spin-lock.c
@@ -1,3 +1,4 @@
+#define __USE_EXTERN_INLINES 1
#define _EXTERN_INLINE /* Empty to define the real functions. */
#include "spin-lock.h"
diff --git a/sysdeps/generic/machine-lock.h b/sysdeps/generic/machine-lock.h
index 5b9b2145e6..9a30226aba 100644
--- a/sysdeps/generic/machine-lock.h
+++ b/sysdeps/generic/machine-lock.h
@@ -34,14 +34,21 @@ typedef volatile int __spin_lock_t;
/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__spin_unlock (__spin_lock_t *__lock)
{
*__lock = 0;
}
+#endif
/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE int
__spin_try_lock (__spin_lock_t *__lock)
{
@@ -50,14 +57,19 @@ __spin_try_lock (__spin_lock_t *__lock)
*__lock = 1;
return 1;
}
+#endif
/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE int
__spin_lock_locked (__spin_lock_t *__lock)
{
return *__lock != 0;
}
+#endif
#endif /* machine-lock.h */
diff --git a/sysdeps/generic/machine-sp.h b/sysdeps/generic/machine-sp.h
index cc48eac674..e76d382fc4 100644
--- a/sysdeps/generic/machine-sp.h
+++ b/sysdeps/generic/machine-sp.h
@@ -25,11 +25,15 @@
#define _EXTERN_INLINE __extern_inline
#endif
+void * __thread_stack_pointer (void);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void *
__thread_stack_pointer (void)
{
register void *__sp__ ("{STACK-POINTER}");
return __sp__;
}
+#endif
#endif /* machine-sp.h */
diff --git a/sysdeps/generic/thread_state.h b/sysdeps/generic/thread_state.h
index 28d6c9a895..e0a0b2774a 100644
--- a/sysdeps/generic/thread_state.h
+++ b/sysdeps/generic/thread_state.h
@@ -22,6 +22,7 @@
/* Replace <machine> with "i386" or "mips" or whatever. */
+#define MACHINE_NEW_THREAD_STATE_FLAVOR <machine>_NEW_THREAD_STATE
#define MACHINE_THREAD_STATE_FLAVOR <machine>_THREAD_STATE
#define MACHINE_THREAD_STATE_COUNT <machine>_THREAD_STATE_COUNT
diff --git a/sysdeps/mach/hurd/bits/libc-lock.h b/sysdeps/mach/hurd/bits/libc-lock.h
index 28c69fa0b4..3807971c8b 100644
--- a/sysdeps/mach/hurd/bits/libc-lock.h
+++ b/sysdeps/mach/hurd/bits/libc-lock.h
@@ -20,6 +20,9 @@
#define _BITS_LIBC_LOCK_H 1
#if (_LIBC - 0) || (_CTHREADS_ - 0)
+#if (_LIBC - 0)
+#include <tls.h>
+#endif
#include <cthreads.h>
#include <hurd/threadvar.h>
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index 60c34c7620..2591713c5a 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -528,6 +528,11 @@ __fork (void)
#endif
MACHINE_THREAD_STATE_SET_PC (&state,
(unsigned long int) _hurd_msgport_receive);
+
+ /* Do special thread setup for TLS if needed. */
+ if (err = _hurd_tls_fork (sigthread, _hurd_msgport_thread, &state))
+ LOSE;
+
if (err = __thread_set_state (sigthread, MACHINE_THREAD_STATE_FLAVOR,
(natural_t *) &state, statecount))
LOSE;
@@ -538,7 +543,7 @@ __fork (void)
_hurd_longjmp_thread_state (&state, env, 1);
/* Do special thread setup for TLS if needed. */
- if (err = _hurd_tls_fork (thread, &state))
+ if (err = _hurd_tls_fork (thread, ss->thread, &state))
LOSE;
if (err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
diff --git a/sysdeps/mach/hurd/i386/Makefile b/sysdeps/mach/hurd/i386/Makefile
index 5f988097c2..9e1a978b6f 100644
--- a/sysdeps/mach/hurd/i386/Makefile
+++ b/sysdeps/mach/hurd/i386/Makefile
@@ -6,3 +6,8 @@ endif
ifeq ($(subdir),debug)
gen-as-const-headers += signal-defines.sym
endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+sysdep_routines += makecontext-helper
+endif
diff --git a/sysdeps/mach/hurd/i386/getcontext.S b/sysdeps/mach/hurd/i386/getcontext.S
new file mode 100644
index 0000000000..b456158f21
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/getcontext.S
@@ -0,0 +1,74 @@
+/* Save current context.
+ Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ 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 <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__getcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Return value of getcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx /* Exclude the return address. */
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ leal oFPREGS(%eax), %ecx
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+ /* And load it right back since the processor changes the mask.
+ Intel thought this opcode to be used in interrupt handlers which
+ would block all exceptions. */
+ fldenv (%ecx)
+
+ /* Save the current signal mask. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 8(%esp)
+ movl $0, 4(%esp)
+ movl $SIG_BLOCK, (%esp)
+ call HIDDEN_JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ /* Propagate %eax (and errno, in case). */
+
+ ret
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index fc355ed6c3..2978c24c79 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -113,31 +113,11 @@ init1 (int argc, char *arg0, ...)
data block; the argument strings start there. */
if ((void *) d == argv[0])
{
-#ifndef SHARED
- /* With a new enough linker (binutils-2.23 or better),
- the magic __ehdr_start symbol will be available and
- __libc_start_main will have done this that way already. */
- if (_dl_phdr == NULL)
- {
- /* We may need to see our own phdrs, e.g. for TLS setup.
- Try the usual kludge to find the headers without help from
- the exec server. */
- extern const void __executable_start;
- const ElfW(Ehdr) *const ehdr = &__executable_start;
- _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
- _dl_phnum = ehdr->e_phnum;
- assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
- }
-#endif
return;
}
#ifndef SHARED
__libc_enable_secure = d->flags & EXEC_SECURE;
-
- _dl_phdr = (ElfW(Phdr) *) d->phdr;
- _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
- assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
#endif
_hurd_init_dtable = d->dtable;
@@ -193,6 +173,39 @@ init (int *data)
++envp;
d = (void *) ++envp;
+#ifndef SHARED
+ /* If we are the bootstrap task started by the kernel,
+ then after the environment pointers there is no Hurd
+ data block; the argument strings start there. */
+ if ((void *) d == argv[0])
+ {
+ /* With a new enough linker (binutils-2.23 or better),
+ the magic __ehdr_start symbol will be available and
+ __libc_start_main will have done this that way already. */
+ if (_dl_phdr == NULL)
+ {
+ /* We may need to see our own phdrs, e.g. for TLS setup.
+ Try the usual kludge to find the headers without help from
+ the exec server. */
+ extern const void __executable_start;
+ const ElfW(Ehdr) *const ehdr = &__executable_start;
+ _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
+ _dl_phnum = ehdr->e_phnum;
+ assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
+ }
+ }
+ else
+ {
+ _dl_phdr = (ElfW(Phdr) *) d->phdr;
+ _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
+ assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
+ }
+
+ /* We need to setup TLS before starting sigthread */
+ extern void __pthread_initialize_minimal(void);
+ __pthread_initialize_minimal();
+#endif
+
/* The user might have defined a value for this, to get more variables.
Otherwise it will be zero on startup. We must make sure it is set
properly before before cthreads initialization, so cthreads can know
diff --git a/sysdeps/mach/hurd/i386/makecontext-helper.c b/sysdeps/mach/hurd/i386/makecontext-helper.c
new file mode 100644
index 0000000000..6db3b7e018
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/makecontext-helper.c
@@ -0,0 +1,69 @@
+/* Helper for makecontext: handle threadvars.
+ Copyright (C) 2013 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
+ 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 <hurd/threadvar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ucontext.h>
+
+
+void
+__makecontext_helper (ucontext_t *ucp)
+{
+ if (__hurd_threadvar_stack_mask == 0)
+ {
+ /* We are not using threads, so per init-first.c:init, the threadvars
+ live in a malloced space, addressed relative to the base of the
+ virtual address space. Just keep using that one. */
+ }
+ else
+ {
+ /* The following is only prepared to work with libpthread, which only
+ keeps the threadvars at the bottom of the stack -- contrary to
+ libthreads, which also puts additional data there. */
+
+ void *s = ucp->uc_stack.ss_sp;
+ size_t s_size = ucp->uc_stack.ss_size;
+
+ /* Is the new stack suitable? Check that that the last threadvar
+ occupies the last storage unit within the bounds of the new stack.
+ Alignment according to (sp & __hurd_threadvar_stack_mask) == sp is not
+ actually a requirement (though, in practice it often will be). */
+ if (__hurd_threadvar_location_from_sp (_HURD_THREADVAR_MAX, s)
+ != s + s_size)
+ {
+ /* Instead of having makecontext return an error, we bail out the
+ hard way, as we can't expect its caller to be able to properly
+ react to this situation. */
+ fprintf (stderr,
+ "*** makecontext: a stack at %p with size %#x is not "
+ "usable with threadvars\n",
+ s, s_size);
+ abort ();
+ }
+
+ /* Copy the threadvars to the new stack. */
+ void *t_old = __hurd_threadvar_location (0);
+ void *t_new = __hurd_threadvar_location_from_sp (0, s);
+ size_t t_size = __hurd_threadvar_max * sizeof (unsigned long int);
+ memcpy (t_new, t_old, t_size);
+ /* Account for the space taken by the threadvars. */
+ ucp->uc_stack.ss_size -= t_size;
+ }
+}
diff --git a/sysdeps/mach/hurd/i386/makecontext.S b/sysdeps/mach/hurd/i386/makecontext.S
new file mode 100644
index 0000000000..7f3f6b0b90
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/makecontext.S
@@ -0,0 +1,130 @@
+/* Create new context.
+ Copyright (C) 2001,2002,2005,2007,2008,2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ 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 <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__makecontext)
+ movl 4(%esp), %eax
+ subl $4, %esp
+ cfi_adjust_cfa_offset (4)
+ movl %eax, (%esp)
+ call HIDDEN_JUMPTARGET (__makecontext_helper)
+ addl $4, %esp
+ cfi_adjust_cfa_offset (-4)
+
+ movl 4(%esp), %eax
+
+ /* Load the address of the function we are supposed to run. */
+ movl 8(%esp), %ecx
+
+ /* Compute the address of the stack. The information comes from
+ to us_stack element. */
+ movl oSS_SP(%eax), %edx
+ movl %ecx, oEIP(%eax)
+ addl oSS_SIZE(%eax), %edx
+
+ /* Remember the number of parameters for the exit handler since
+ it has to remove them. We store the number in the EBX register
+ which the function we will call must preserve. */
+ movl 12(%esp), %ecx
+ movl %ecx, oEBX(%eax)
+
+ /* Make room on the new stack for the parameters.
+ Room for the arguments, return address (== L(exitcode)) and
+ oLINK pointer is needed. One of the pointer sizes is subtracted
+ after aligning the stack. */
+ negl %ecx
+ leal -4(%edx,%ecx,4), %edx
+ negl %ecx
+
+ /* Align the stack. */
+ andl $0xfffffff0, %edx
+ subl $4, %edx
+
+ /* Store the future stack pointer. */
+ movl %edx, oESP(%eax)
+
+ /* Put the next context on the new stack (from the uc_link
+ element). */
+ movl oLINK(%eax), %eax
+ movl %eax, 4(%edx,%ecx,4)
+
+ /* Copy all the parameters. */
+ jecxz 2f
+1: movl 12(%esp,%ecx,4), %eax
+ movl %eax, (%edx,%ecx,4)
+ decl %ecx
+ jnz 1b
+2:
+
+ /* If the function we call returns we must continue with the
+ context which is given in the uc_link element. To do this
+ set the return address for the function the user provides
+ to a little bit of helper code which does the magic (see
+ below). */
+#ifdef PIC
+ call 1f
+ cfi_adjust_cfa_offset (4)
+1: popl %ecx
+ cfi_adjust_cfa_offset (-4)
+ addl $L(exitcode)-1b, %ecx
+ movl %ecx, (%edx)
+#else
+ movl $L(exitcode), (%edx)
+#endif
+ /* 'makecontext' returns no value. */
+ ret
+
+ /* This is the helper code which gets called if a function which
+ is registered with 'makecontext' returns. In this case we
+ have to install the context listed in the uc_link element of
+ the context 'makecontext' manipulated at the time of the
+ 'makecontext' call. If the pointer is NULL the process must
+ terminate. */
+ cfi_endproc
+L(exitcode):
+ /* This removes the parameters passed to the function given to
+ 'makecontext' from the stack. EBX contains the number of
+ parameters (see above). */
+ leal (%esp,%ebx,4), %esp
+
+#ifdef PIC
+ call 1f
+1: popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#endif
+ cmpl $0, (%esp) /* Check the next context. */
+ je 2f /* If it is zero exit. */
+
+ call JUMPTARGET(__setcontext)
+ /* If this returns (which can happen if the syscall fails) we'll
+ exit the program with the return error value (-1). */
+
+ movl %eax, (%esp)
+2: call HIDDEN_JUMPTARGET(exit)
+ /* The 'exit' call should never return. In case it does cause
+ the process to terminate. */
+ hlt
+ cfi_startproc
+END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/sysdeps/mach/hurd/i386/setcontext.S b/sysdeps/mach/hurd/i386/setcontext.S
new file mode 100644
index 0000000000..2294eb623a
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/setcontext.S
@@ -0,0 +1,92 @@
+/* Install given context.
+ Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ 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 <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__setcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Get the current signal mask. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ movl $0, 8(%esp)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 4(%esp)
+ movl $SIG_SETMASK, (%esp)
+ call HIDDEN_JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ testl %eax, %eax
+ jne L(pseudo_end)
+
+ /* EAX was modified, reload it. */
+ movl 4(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ leal oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %ecx
+ movw %cx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ cfi_def_cfa (eax, 0)
+ cfi_offset (edi, oEDI)
+ cfi_offset (esi, oESI)
+ cfi_offset (ebp, oEBP)
+ cfi_offset (ebx, oEBX)
+ cfi_offset (edx, oEDX)
+ cfi_offset (ecx, oECX)
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* End FDE here, we fall into another context. */
+ cfi_endproc
+ cfi_startproc
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/sysdeps/mach/hurd/i386/swapcontext.S b/sysdeps/mach/hurd/i386/swapcontext.S
new file mode 100644
index 0000000000..fb45b70849
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/swapcontext.S
@@ -0,0 +1,110 @@
+/* Save current context and install the given one.
+ Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ 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 <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__swapcontext)
+ /* Load address of the context data structure we save in. */
+ movl 4(%esp), %eax
+
+ /* Return value of swapcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ leal oFPREGS(%eax), %ecx
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+
+ /* Load address of the context data structure we have to load. */
+ movl 8(%esp), %ecx
+
+ /* Save the current signal mask and install the new one. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 8(%esp)
+ leal oSIGMASK(%ecx), %eax
+ movl %eax, 4(%esp)
+ movl $SIG_SETMASK, (%esp)
+ call HIDDEN_JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ testl %eax, %eax
+ jne L(pseudo_end)
+
+ /* EAX was modified, reload it. */
+ movl 8(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ leal oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %edx
+ movw %dx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 6432aedcec..77f456f080 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -104,7 +104,7 @@ _hurd_tls_init (tcbhead_t *tcb, int secondcall)
/* Get the first available selector. */
int sel = -1;
- 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. */
@@ -128,16 +128,16 @@ _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, 0x50) & 4) /* LDT selector */
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
{
- error_t err = __i386_set_ldt (tcb->self, sel, &desc, 1);
+ kern_return_t err = __i386_set_ldt (tcb->self, sel, &desc, 1);
assert_perror (err);
if (err)
return "i386_set_ldt failed";
}
else
{
- error_t err = __i386_set_gdt (tcb->self, &sel, desc);
+ kern_return_t err = __i386_set_gdt (tcb->self, &sel, desc);
assert_perror (err);
if (err)
return "i386_set_gdt failed";
@@ -173,9 +173,40 @@ _hurd_tls_init (tcbhead_t *tcb, int secondcall)
# include <mach/machine/thread_status.h>
-/* Set up TLS in the new thread of a fork child, copying from our own. */
-static inline error_t __attribute__ ((unused))
-_hurd_tls_fork (thread_t child, struct i386_thread_state *state)
+/* Set up TLS in the new thread of a fork child, copying from the original. */
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state)
+{
+ /* Fetch the selector set by _hurd_tls_init. */
+ int sel;
+ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+ if (sel == state->ds) /* _hurd_tls_init was never called. */
+ return 0;
+
+ struct descriptor desc, *_desc = &desc;
+ kern_return_t err;
+ unsigned int count = 1;
+
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
+ err = __i386_get_ldt (orig, sel, 1, &_desc, &count);
+ else
+ err = __i386_get_gdt (orig, sel, &desc);
+
+ assert_perror (err);
+ if (err)
+ return err;
+
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
+ err = __i386_set_ldt (child, sel, &desc, 1);
+ else
+ err = __i386_set_gdt (child, &sel, desc);
+
+ state->gs = sel;
+ return err;
+}
+
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
{
/* Fetch the selector set by _hurd_tls_init. */
int sel;
@@ -183,11 +214,13 @@ _hurd_tls_fork (thread_t child, struct i386_thread_state *state)
if (sel == state->ds) /* _hurd_tls_init was never called. */
return 0;
- tcbhead_t *const tcb = THREAD_SELF;
HURD_TLS_DESC_DECL (desc, tcb);
- error_t err;
+ kern_return_t err;
+
+ tcb->tcb = tcb;
+ tcb->self = child;
- if (__builtin_expect (sel, 0x50) & 4) /* LDT selector */
+ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
err = __i386_set_ldt (child, sel, &desc, 1);
else
err = __i386_set_gdt (child, &sel, desc);
diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c
index d4a839304b..7e0d093b93 100644
--- a/sysdeps/mach/hurd/i386/trampoline.c
+++ b/sysdeps/mach/hurd/i386/trampoline.c
@@ -63,7 +63,7 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
sizeof (state->basic));
memcpy (&state->fpu, &ss->context->sc_i386_float_state,
sizeof (state->fpu));
- state->set |= (1 << i386_THREAD_STATE) | (1 << i386_FLOAT_STATE);
+ state->set |= (1 << i386_REGS_SEGS_STATE) | (1 << i386_FLOAT_STATE);
}
}
diff --git a/sysdeps/mach/hurd/i386/ucontext_i.sym b/sysdeps/mach/hurd/i386/ucontext_i.sym
new file mode 100644
index 0000000000..cc1cfd578d
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/ucontext_i.sym
@@ -0,0 +1,29 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+#define mreg(reg) mcontext (gregs[REG_##reg])
+
+oLINK ucontext (uc_link)
+oSS_SP ucontext (uc_stack.ss_sp)
+oSS_SIZE ucontext (uc_stack.ss_size)
+oGS mreg (GS)
+oFS mreg (FS)
+oEDI mreg (EDI)
+oESI mreg (ESI)
+oEBP mreg (EBP)
+oESP mreg (ESP)
+oEBX mreg (EBX)
+oEDX mreg (EDX)
+oECX mreg (ECX)
+oEAX mreg (EAX)
+oEIP mreg (EIP)
+oFPREGS mcontext (fpregs)
+oSIGMASK ucontext (uc_sigmask)
diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c
index 7ea7272926..3e409bf2cd 100644
--- a/sysdeps/mach/hurd/profil.c
+++ b/sysdeps/mach/hurd/profil.c
@@ -68,6 +68,8 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
if (! err)
err = __mach_setup_thread (__mach_task_self (), profile_thread,
&profile_waiter, NULL, NULL);
+ if (! err)
+ err = __mach_setup_tls(profile_thread);
}
else
err = 0;
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index 5459b56420..8d77d1d345 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -221,11 +221,12 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
goto out;
_hurd_itimer_thread_stack_base = 0; /* Anywhere. */
_hurd_itimer_thread_stack_size = __vm_page_size; /* Small stack. */
- if (err = __mach_setup_thread (__mach_task_self (),
+ if ((err = __mach_setup_thread (__mach_task_self (),
_hurd_itimer_thread,
&timer_thread,
&_hurd_itimer_thread_stack_base,
&_hurd_itimer_thread_stack_size))
+ || (err = __mach_setup_tls(_hurd_itimer_thread)))
{
__thread_terminate (_hurd_itimer_thread);
_hurd_itimer_thread = MACH_PORT_NULL;
diff --git a/sysdeps/mach/hurd/tls.h b/sysdeps/mach/hurd/tls.h
index 3b8b713170..5f3f8df053 100644
--- a/sysdeps/mach/hurd/tls.h
+++ b/sysdeps/mach/hurd/tls.h
@@ -22,7 +22,9 @@
#ifndef __ASSEMBLER__
# include <stddef.h>
+# include <stdint.h>
# include <stdbool.h>
+# include <sysdep.h>
# include <mach/mig_errors.h>
# include <mach.h>
diff --git a/sysdeps/mach/i386/machine-lock.h b/sysdeps/mach/i386/machine-lock.h
index 408c2b39cf..ea8d6f1f70 100644
--- a/sysdeps/mach/i386/machine-lock.h
+++ b/sysdeps/mach/i386/machine-lock.h
@@ -34,6 +34,9 @@ typedef volatile int __spin_lock_t;
/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE void
__spin_unlock (__spin_lock_t *__lock)
{
@@ -42,9 +45,13 @@ __spin_unlock (__spin_lock_t *__lock)
: "=&r" (__unlocked), "=m" (*__lock) : "0" (0)
: "memory");
}
+#endif
/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE int
__spin_try_lock (__spin_lock_t *__lock)
{
@@ -54,14 +61,19 @@ __spin_try_lock (__spin_lock_t *__lock)
: "memory");
return !__locked;
}
+#endif
/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#ifdef __USE_EXTERN_INLINES
_EXTERN_INLINE int
__spin_lock_locked (__spin_lock_t *__lock)
{
return *__lock != 0;
}
+#endif
#endif /* machine-lock.h */
diff --git a/sysdeps/mach/i386/thread_state.h b/sysdeps/mach/i386/thread_state.h
index 207256658e..d67fccb15c 100644
--- a/sysdeps/mach/i386/thread_state.h
+++ b/sysdeps/mach/i386/thread_state.h
@@ -21,7 +21,8 @@
#include <mach/machine/thread_status.h>
-#define MACHINE_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_NEW_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_FLAVOR i386_REGS_SEGS_STATE
#define MACHINE_THREAD_STATE_COUNT i386_THREAD_STATE_COUNT
#define machine_thread_state i386_thread_state
@@ -30,6 +31,14 @@
#define SP uesp
#define SYSRETURN eax
+#define MACHINE_THREAD_STATE_FIX_NEW(ts) do { \
+ asm ("mov %%cs, %w0" : "=q" ((ts)->cs)); \
+ asm ("mov %%ds, %w0" : "=q" ((ts)->ds)); \
+ asm ("mov %%es, %w0" : "=q" ((ts)->es)); \
+ asm ("mov %%fs, %w0" : "=q" ((ts)->fs)); \
+ asm ("mov %%gs, %w0" : "=q" ((ts)->gs)); \
+} while(0)
+
struct machine_thread_all_state
{
int set; /* Mask of bits (1 << FLAVOR). */
diff --git a/sysdeps/mach/thread_state.h b/sysdeps/mach/thread_state.h
index 28f9b2b12f..357c8bfbea 100644
--- a/sysdeps/mach/thread_state.h
+++ b/sysdeps/mach/thread_state.h
@@ -37,6 +37,9 @@
((ts)->SP = (unsigned long int) (stack) + (size))
#endif
#endif
+#ifndef MACHINE_THREAD_STATE_FIX_NEW
+#define MACHINE_THREAD_STATE_FIX_NEW(ts)
+#endif
/* These functions are of use in machine-dependent signal trampoline
implementations. */