summaryrefslogtreecommitdiff
path: root/libpthread/linuxthreads.old
diff options
context:
space:
mode:
Diffstat (limited to 'libpthread/linuxthreads.old')
-rw-r--r--libpthread/linuxthreads.old/Makefile.in1
-rw-r--r--libpthread/linuxthreads.old/internals.h24
-rw-r--r--libpthread/linuxthreads.old/manager.c18
-rw-r--r--libpthread/linuxthreads.old/pthread.c23
-rw-r--r--libpthread/linuxthreads.old/signals.c1
-rw-r--r--libpthread/linuxthreads.old/sysdeps/c6x/pt-machine.h64
6 files changed, 106 insertions, 25 deletions
diff --git a/libpthread/linuxthreads.old/Makefile.in b/libpthread/linuxthreads.old/Makefile.in
index d2e29c72d..f599b1697 100644
--- a/libpthread/linuxthreads.old/Makefile.in
+++ b/libpthread/linuxthreads.old/Makefile.in
@@ -18,6 +18,7 @@ LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -Wl,-z,defs
else
LDFLAGS-libpthread.so := $(LDFLAGS)
endif
+LDFLAGS-$(UCLIBC_FORMAT_DSBT_ELF)-libpthread.so := -Wl,--dsbt-index=10
LIBS-libpthread.so := $(LIBS) $(ldso)
diff --git a/libpthread/linuxthreads.old/internals.h b/libpthread/linuxthreads.old/internals.h
index 637fcea62..110dd9d56 100644
--- a/libpthread/linuxthreads.old/internals.h
+++ b/libpthread/linuxthreads.old/internals.h
@@ -252,17 +252,25 @@ extern pthread_descr __pthread_main_thread;
Initially 0, meaning that the current thread is (by definition)
the initial thread. */
-/* For non-MMU systems also remember to stack top of the initial thread.
- * This is adapted when other stacks are malloc'ed since we don't know
- * the bounds a-priori. -StS */
-
extern char *__pthread_initial_thread_bos;
#ifndef __ARCH_USE_MMU__
-extern char *__pthread_initial_thread_tos;
+/* For non-MMU systems, we have no idea the bounds of the initial thread
+ * stack, so we have to track it on the fly relative to other stacks. Do
+ * so by scaling back our assumptions on the limits of the bos/tos relative
+ * to the known mid point. See also the comments in pthread_initialize(). */
+extern char *__pthread_initial_thread_tos, *__pthread_initial_thread_mid;
#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) \
- if ((tos)>=__pthread_initial_thread_bos \
- && (bos)<__pthread_initial_thread_tos) \
- __pthread_initial_thread_bos = (tos)+1
+ do { \
+ char *__tos = (tos); \
+ char *__bos = (bos); \
+ if (__tos >= __pthread_initial_thread_bos && \
+ __bos < __pthread_initial_thread_tos) { \
+ if (__bos < __pthread_initial_thread_mid) \
+ __pthread_initial_thread_bos = __tos; \
+ else \
+ __pthread_initial_thread_tos = __bos; \
+ } \
+ } while (0)
#else
#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */
#endif /* __ARCH_USE_MMU__ */
diff --git a/libpthread/linuxthreads.old/manager.c b/libpthread/linuxthreads.old/manager.c
index 52c1ea9b6..85fee5ec5 100644
--- a/libpthread/linuxthreads.old/manager.c
+++ b/libpthread/linuxthreads.old/manager.c
@@ -35,6 +35,9 @@
#include "semaphore.h"
#include "debug.h" /* PDEBUG, added by StS */
+#ifndef THREAD_STACK_OFFSET
+#define THREAD_STACK_OFFSET 0
+#endif
/* poll() is not supported in kernel <= 2.0, therefore is __NR_poll is
* not available, we assume an old Linux kernel is in use and we will
@@ -476,6 +479,7 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
int pid;
pthread_descr new_thread;
char * new_thread_bottom;
+ char * new_thread_top;
pthread_t new_thread_id;
char *guardaddr = NULL;
size_t guardsize = 0;
@@ -561,7 +565,7 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
/* Do the cloning. We have to use two different functions depending
on whether we are debugging or not. */
pid = 0; /* Note that the thread never can have PID zero. */
-
+ new_thread_top = ((char *)new_thread - THREAD_STACK_OFFSET);
/* ******************************************************** */
/* This code was moved from below to cope with running threads
@@ -588,12 +592,12 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
/* We have to report this event. */
#ifdef __ia64__
- pid = __clone2(pthread_start_thread_event, (void **) new_thread,
- (char *)new_thread - new_thread_bottom,
+ pid = __clone2(pthread_start_thread_event, new_thread_top,
+ new_thread_top - new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#else
- pid = clone(pthread_start_thread_event, (void **) new_thread,
+ pid = clone(pthread_start_thread_event, new_thread_top,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#endif
@@ -626,12 +630,12 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
{
PDEBUG("cloning new_thread = %p\n", new_thread);
#ifdef __ia64__
- pid = __clone2(pthread_start_thread, (void **) new_thread,
- (char *)new_thread - new_thread_bottom,
+ pid = __clone2(pthread_start_thread, new_thread_top,
+ new_thread_top - new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#else
- pid = clone(pthread_start_thread, (void **) new_thread,
+ pid = clone(pthread_start_thread, new_thread_top,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
#endif
diff --git a/libpthread/linuxthreads.old/pthread.c b/libpthread/linuxthreads.old/pthread.c
index ad392e34e..a8830b1a4 100644
--- a/libpthread/linuxthreads.old/pthread.c
+++ b/libpthread/linuxthreads.old/pthread.c
@@ -168,12 +168,10 @@ pthread_descr __pthread_main_thread = &__pthread_initial_thread;
char *__pthread_initial_thread_bos = NULL;
-/* For non-MMU systems also remember to stack top of the initial thread.
- * This is adapted when other stacks are malloc'ed since we don't know
- * the bounds a-priori. -StS */
-
#ifndef __ARCH_USE_MMU__
+/* See nommu notes in internals.h and pthread_initialize() below. */
char *__pthread_initial_thread_tos = NULL;
+char *__pthread_initial_thread_mid = NULL;
#endif /* __ARCH_USE_MMU__ */
/* File descriptor for sending requests to the thread manager. */
@@ -457,12 +455,19 @@ static void pthread_initialize(void)
setrlimit(RLIMIT_STACK, &limit);
}
#else
- /* For non-MMU assume __pthread_initial_thread_tos at upper page boundary, and
- * __pthread_initial_thread_bos at address 0. These bounds are refined as we
- * malloc other stack frames such that they don't overlap. -StS
+ /* For non-MMU, the initial thread stack can reside anywhere in memory.
+ * We don't have a way of knowing where the kernel started things -- top
+ * or bottom (well, that isn't exactly true, but the solution is fairly
+ * complex and error prone). All we can determine here is an address
+ * that lies within that stack. Save that address as a reference so that
+ * as other thread stacks are created, we can adjust the estimated bounds
+ * of the initial thread's stack appropriately.
+ *
+ * This checking is handled in NOMMU_INITIAL_THREAD_BOUNDS(), so see that
+ * for a few more details.
*/
- __pthread_initial_thread_tos =
- (char *)(((long)CURRENT_STACK_FRAME + getpagesize()) & ~(getpagesize() - 1));
+ __pthread_initial_thread_mid = CURRENT_STACK_FRAME;
+ __pthread_initial_thread_tos = (char *) -1;
__pthread_initial_thread_bos = (char *) 1; /* set it non-zero so we know we have been here */
PDEBUG("initial thread stack bounds: bos=%p, tos=%p\n",
__pthread_initial_thread_bos, __pthread_initial_thread_tos);
diff --git a/libpthread/linuxthreads.old/signals.c b/libpthread/linuxthreads.old/signals.c
index 2a451f3d2..23d838eb8 100644
--- a/libpthread/linuxthreads.old/signals.c
+++ b/libpthread/linuxthreads.old/signals.c
@@ -20,7 +20,6 @@
#include "pthread.h"
#include "internals.h"
#include "spinlock.h"
-#include <ucontext.h>
#include <bits/sigcontextinfo.h>
/* mods for uClibc: __libc_sigaction is not in any standard headers */
diff --git a/libpthread/linuxthreads.old/sysdeps/c6x/pt-machine.h b/libpthread/linuxthreads.old/sysdeps/c6x/pt-machine.h
new file mode 100644
index 000000000..cabd4e33c
--- /dev/null
+++ b/libpthread/linuxthreads.old/sysdeps/c6x/pt-machine.h
@@ -0,0 +1,64 @@
+/* Machine-dependent pthreads configuration and inline functions.
+ C6x version.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Aurelien Jacquiot <aurelien.jacquiot@jaluna.com>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_MACHINE_H
+#define _PT_MACHINE_H 1
+
+#ifndef PT_EI
+# define PT_EI extern inline
+#endif
+
+extern int __compare_and_swap (long int *p, long int oldval, long int newval);
+
+/* Spinlock implementation; required. */
+static inline long int
+testandset (int *spinlock)
+{
+ register unsigned int ret = 1;
+ int dummy;
+ __asm__ __volatile__ ("mvc .s2 CSR, %0\n\tand .s2 -2, %0, %0\n\tmvc .s2 %0, CSR\n"
+ : "=b" (dummy));
+
+ if (*spinlock == 0) {
+ *spinlock = 1;
+ ret = 0;
+ }
+ __asm__ __volatile__ ("mvc .s2 CSR, %0\n\tor .s2 1, %0, %0\n\tmvc .s2 %0, CSR\n"
+ : "=b" (dummy));
+ return ret;
+}
+
+#define WRITE_MEMORY_BARRIER()
+#define READ_MEMORY_BARRIER()
+
+/* Get some notion of the current stack. Need not be exactly the top
+ of the stack, just something somewhere in the current frame. */
+#define CURRENT_STACK_FRAME get_stack_pointer()
+static inline char * get_stack_pointer(void)
+{
+ char *sp;
+ __asm__ __volatile__ ("mv .d2 B15, %0" : "=b" (sp));
+ return sp;
+}
+
+#define THREAD_STACK_OFFSET 8
+
+#endif /* pt-machine.h */