#include "spinlock.h"
#include "restart.h"
#include "semaphore.h"
+#include <stackinfo.h>
/* Array of active threads. Entry 0 is reserved for the initial thread. */
struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX] =
if (attr != NULL && attr->__stackaddr_set)
{
+#ifdef _STACK_GROWS_UP
+ /* The user provided a stack. */
+ new_thread = (pthread_descr) attr->__stackaddr;
+ new_thread_bottom = (char *) (new_thread + 1);
+ guardaddr = attr->__stackaddr + attr->__stacksize;
+ guardsize = 0;
+#else
/* The user provided a stack. For now we interpret the supplied
address as 1 + the highest addr. in the stack segment. If a
separate register stack is needed, we place it at the low end
new_thread_bottom = (char *) attr->__stackaddr - attr->__stacksize;
guardaddr = new_thread_bottom;
guardsize = 0;
+#endif
#ifndef THREAD_SELF
__pthread_nonstandard_stacks = 1;
#endif
/* No more memory available. */
return -1;
+# ifdef _STACK_GROWS_DOWN
guardaddr = map_addr;
if (guardsize > 0)
mprotect (guardaddr, guardsize, PROT_NONE);
new_thread_bottom = (char *) map_addr + guardsize;
new_thread = ((pthread_descr) (new_thread_bottom + stacksize)) - 1;
+# elif _STACK_GROWS_UP
+ guardaddr = map_addr + stacksize;
+ if (guardsize > 0)
+ mprotect (guardaddr, guardsize, PROT_NONE);
+
+ new_thread = (pthread_descr) map_addr;
+ new_thread_bottom = (char *) (new_thread + 1);
+# else
+# error You must define a stack direction
+# endif /* Stack direction */
# else /* !FLOATING_STACKS */
void *res_addr;
stacksize = STACK_SIZE - granularity;
}
+# ifdef _STACK_GROWS_DOWN
new_thread = default_new_thread;
new_thread_bottom = (char *) (new_thread + 1) - stacksize;
map_addr = new_thread_bottom - guardsize;
guardaddr = map_addr;
if (guardsize > 0)
mprotect (guardaddr, guardsize, PROT_NONE);
+# else
+ /* The thread description goes at the bottom of this area, and
+ * the stack starts directly above it.
+ */
+ new_thread = (pthread_descr)((unsigned long)default_new_thread &~ (STACK_SIZE - 1));
+ map_addr = mmap(new_thread, stacksize + guardsize,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (map_addr == MAP_FAILED)
+ return -1;
+
+ new_thread_bottom = map_addr + sizeof(*new_thread);
+ guardaddr = map_addr + stacksize;
+ if (guardsize > 0)
+ mprotect (guardaddr, guardsize, PROT_NONE);
+
+# endif /* stack direction */
# endif
#endif /* !NEED_SEPARATE_REGISTER_STACK */
}
(char *)new_thread - new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
+#elif _STACK_GROWS_UP
+ pid = __clone(pthread_start_thread_event, (void **) 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,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
(char *)new_thread - new_thread_bottom,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
__pthread_sig_cancel, new_thread);
+#elif _STACK_GROWS_UP
+ pid = __clone(pthread_start_thread, (void **) 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,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
- new_thread_bottom);
munmap((caddr_t)new_thread_bottom,
2 * stacksize + new_thread->p_guardsize);
+#elif _STACK_GROWS_UP
+ size_t stacksize = guardaddr - (char *)new_thread;
+ munmap(new_thread, stacksize + guardsize);
#else
size_t stacksize = (char *)(new_thread+1) - new_thread_bottom;
munmap(new_thread_bottom - guardsize, guardsize + stacksize);
size_t guardsize = th->p_guardsize;
/* Free the stack and thread descriptor area */
char *guardaddr = th->p_guardaddr;
+#ifdef _STACK_GROWS_UP
+ size_t stacksize = guardaddr - (char *)th;
+ guardaddr = (char *)th;
+#else
/* Guardaddr is always set, even if guardsize is 0. This allows
us to compute everything else. */
size_t stacksize = (char *)(th+1) - guardaddr - guardsize;
/* Take account of the register stack, which is below guardaddr. */
guardaddr -= stacksize;
stacksize *= 2;
+#endif
#endif
/* Unmap the stack. */
munmap(guardaddr, stacksize + guardsize);
#include "internals.h"
#include "spinlock.h"
#include "restart.h"
+#include <stackinfo.h>
/* We need the global/static resolver state here. */
#include <resolv.h>
/* Test if compare-and-swap is available */
__pthread_has_cas = compare_and_swap_is_available();
#endif
+#ifdef _STACK_GROWS_UP
+ /* The initial thread already has all the stack it needs */
+ __pthread_initial_thread_bos = (char *)
+ ((long)CURRENT_STACK_FRAME &~ (STACK_SIZE - 1));
+#else
/* For the initial stack, reserve at least STACK_SIZE bytes of stack
below the current stack address, and align that on a
STACK_SIZE boundary. */
__pthread_initial_thread_bos =
(char *)(((long)CURRENT_STACK_FRAME - 2 * STACK_SIZE) & ~(STACK_SIZE - 1));
+#endif
/* Update the descriptor for the initial thread. */
__pthread_initial_thread.p_pid = __getpid();
/* Likewise for the resolver state _res. */
THREAD_MANAGER_STACK_SIZE,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
(void *)(long)manager_pipe[0]);
+#elif _STACK_GROWS_UP
+ pid = __clone(__pthread_manager_event,
+ (void **) __pthread_manager_thread_bos,
+ CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
+ (void *)(long)manager_pipe[0]);
#else
pid = __clone(__pthread_manager_event,
(void **) __pthread_manager_thread_tos,
THREAD_MANAGER_STACK_SIZE,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
(void *)(long)manager_pipe[0]);
+#elif _STACK_GROWS_UP
+ pid = __clone(__pthread_manager, (void **) __pthread_manager_thread_bos,
+ CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
+ (void *)(long)manager_pipe[0]);
#else
pid = __clone(__pthread_manager, (void **) __pthread_manager_thread_tos,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,