/* Linuxthreads - a simple clone()-based implementation of Posix */
/* threads for Linux. */
/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
/* */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Library General Public License */
/* as published by the Free Software Foundation; either version 2 */
/* of the License, or (at your option) any later version. */
/* */
/* This program 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 Library General Public License for more details. */
/* The "thread manager" thread: manages creation and termination of threads */
#include <errno.h>
#include <sched.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/poll.h> /* for poll */
#include <sys/mman.h> /* for mmap */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/wait.h> /* for waitpid macros */
#include "pthread.h"
#include "internals.h"
#include "spinlock.h"
#include "restart.h"
#include "semaphore.h"
/* Array of active threads. Entry 0 is reserved for the initial thread. */
struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX] =
{ { __LOCK_INITIALIZER, &__pthread_initial_thread, 0},
{ __LOCK_INITIALIZER, &__pthread_manager_thread, 0}, /* All NULLs */ };
/* For debugging purposes put the maximum number of threads in a variable. */
const int __linuxthreads_pthread_threads_max = PTHREAD_THREADS_MAX;
#ifndef THREAD_SELF
/* Indicate whether at least one thread has a user-defined stack (if 1),
or if all threads have stacks supplied by LinuxThreads (if 0). */
int __pthread_nonstandard_stacks;
#endif
/* Number of active entries in __pthread_handles (used by gdb) */
volatile int __pthread_handles_num = 2;
/* Whether to use debugger additional actions for thread creation
(set to 1 by gdb) */
volatile int __pthread_threads_debug;
/* Globally enabled events. */
volatile td_thr_events_t __pthread_threads_events;
/* Pointer to thread descriptor with last event. */
volatile pthread_descr __pthread_last_event;
/* Mapping from stack segment to thread descriptor. */
/* Stack segment numbers are also indices into the __pthread_handles array. */
/* Stack segment number 0 is reserved for the initial thread. */
#if FLOATING_STACKS
# define thread_segment(seq) NULL
#else
static inline pthread_descr