glibc/linuxthreads/internals.h
Ulrich Drepper 8619129f3f Update.
1998-04-20 18:00  Ulrich Drepper  <drepper@cygnus.com>

	* libc.map: Add __dgettext to GLIBC_2.0 and __libc_longjmp, and
	__libc_siglongjmp to GLIBC_2.1.

	* elf/dl-minimal.c (__assert_perror_fail): Don't use strerror, use
	__strerror_r.

	* iconv/Makefile: Don't run tests now.

	* iconv/iconv_prog.c (process_block): If loop is repeated, call iconv
	with correct output buffer.

	Major rewrite of the low-level gconv functionality.
	* iconv/gconv.c: Rewritten.
	* iconv/gconv.h: Likewise.
	* iconv/gconv_builtin.c: Likewise.
	* iconv/gconv_builtin.h: Likewise.
	* iconv/gconv_conf.c: Likewise.
	* iconv/gconv_int.h: Likewise.
	* iconv/gconv_open.c: Likewise.
	* iconv/gconv_simple.c: Likewise.
	* iconv/iconv.c: Likewise.
	* iconvdata/8bit-gap.c: Likewise.
	* iconvdata/8bit-generic.c: Likewise.
	* iconvdata/Makefile: Likewise.
	* iconvdata/big5.c: Likewise.
	* iconvdata/cns11643.c: Likewise.
	* iconvdata/cns11643.h: Likewise.
	* iconvdata/cns11643l1.c: Likewise.
	* iconvdata/cns11643l1.h: Likewise.
	* iconvdata/ebcdic-at-de-a.c: Likewise.
	* iconvdata/ebcdic-at-de.c: Likewise.
	* iconvdata/ebcdic-ca-fr.c: Likewise.
	* iconvdata/euccn.c: Likewise.
	* iconvdata/eucjp.c: Likewise.
	* iconvdata/euckr.c: Likewise.
	* iconvdata/euctw.c: Likewise.
	* iconvdata/gb2312.c: Likewise.
	* iconvdata/gb2312.h: Likewise.
	* iconvdata/hp-roman8.c: Likewise.
	* iconvdata/iso646.c: Likewise.
	* iconvdata/iso6937.c: Likewise.
	* iconvdata/iso8859-1.c: Likewise.
	* iconvdata/iso8859-10.c: Likewise.
	* iconvdata/iso8859-2.c: Likewise.
	* iconvdata/iso8859-3.c: Likewise.
	* iconvdata/iso8859-4.c: Likewise.
	* iconvdata/iso8859-5.c: Likewise.
	* iconvdata/iso8859-6.c: Likewise.
	* iconvdata/iso8859-7.c: Likewise.
	* iconvdata/iso8859-8.c: Likewise.
	* iconvdata/iso8859-9.c: Likewise.
	* iconvdata/jis0201.c: Likewise.
	* iconvdata/jis0201.h: Likewise.
	* iconvdata/jis0208.c: Likewise.
	* iconvdata/jis0208.h: Likewise.
	* iconvdata/jis0212.c: Likewise.
	* iconvdata/jis0212.h: Likewise.
	* iconvdata/johab.c: Likewise.
	* iconvdata/koi-8.c: Likewise.
	* iconvdata/koi8-r.c: Likewise.
	* iconvdata/ksc5601.c: Likewise.
	* iconvdata/ksc5601.h: Likewise.
	* iconvdata/latin-greek-1.c: Likewise.
	* iconvdata/latin-greek.c: Likewise.
	* iconvdata/run-iconv-test.sh: Likewise.
	* iconvdata/sjis.c: Likewise.
	* iconvdata/t61.c: Likewise.
	* iconvdata/uhc.c: Likewise.
	* wcsmbs/btowc.c: Likewise.
	* wcsmbs/mbrtowc.c: Likewise.
	* wcsmbs/mbsnrtowcs.c: Likewise.
	* wcsmbs/mbsrtowcs.c: Likewise.
	* wcsmbs/wcrtomb.c: Likewise.
	* wcsmbs/wcsmbsload.c: Likewise.
	* wcsmbs/wcsnrtombs.c: Likewise.
	* wcsmbs/wcsrtombs.c: Likewise.
	* wcsmbs/wctob.c: Likewise.
	* iconv/loop.c: New file.
	* iconv/skeleton.c: New file.

	* stdlib/mblen.c: Handle empty input string correctly.
	* stdlib/mbtowc.c: Likewise.

	* posix/getopt.c: Various cleanups.

	* sysdeps/arm/bits/setjmp.h: Add copyright text.
	* sysdeps/i386/bits/setjmp.h: Likewise.
	* sysdeps/m68k/bits/setjmp.h: Likewise.
	* sysdeps/powerpc/bits/setjmp.h: Likewise.
	* sysdeps/sparc/sparc32/bits/setjmp.h: Likewise.

	* sysdeps/generic/longjmp.c: Rename function to __libc_siglongjmp
	and make longjmp weak alias.

1998-04-18 20:29  Philip Blundell  <Philip.Blundell@pobox.com>

	* iconv/Makefile (routines): Only include gconv_dl if building for
	an ELF system - dynamic linking is not available on a.out.
	(CFLAGS-gconv_conf.c): Define STATIC_GCONV if omitting gconv_dl
	due to above check.
	* iconv/gconv_db.c: If STATIC_GCONV defined, don't try to call
	routines from gconv_dl.

1998-04-17  Gordon Matzigkeit  <gord@profitpress.com>

	* csu/init.c (_IO_stdin_used): Protect with USE_IN_LIBIO so that
	we can compile without libio.

1998-04-20 16:28  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/mach/hurd/Subdirs: Remove login.

1998-04-11  Gordon Matzigkeit  <gord@profitpress.com>

	* db2/compat.h: Include <errno.h>, to make sure we get the
	definition of EFTYPE before we define it ourselves.

1998-04-10  Gordon Matzigkeit  <gord@profitpress.com>

	* sysdeps/generic/bits/socket.h: Protect against multiple inclusion.
	* sysdeps/mach/hurd/bits/ioctls.h: Likewise.
	Fix typo to allow inclusion from sys/ioctl.h again.

1998-04-16  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* iconvdata/*.[ch]: Clean up namespace.  Optimize character lookup.

1998-04-16  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* libc.map: Export __strerror_r.  Remove _strerror_internal.

1998-04-16  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/generic/strcasestr.c: Undefine strcasestr, not strstr.
	Also undefine __strcasestr.

1998-04-16  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* posix/regex.c: Rename __re_max_failures back to re_max_failures,
	aliases do not work with global variables due to copy relocations.

1998-04-20 15:12  Ulrich Drepper  <drepper@cygnus.com>

	* manual/creature.texi: Fix type.  Patch by Andreas Schwab.

1998-04-20 13:47  Ulrich Drepper  <drepper@cygnus.com>

	* signal/sighold.c: Include stddef.h for NULL definition.
	* signal/sigrelse.c: Likewise.
	* sysdeps/posix/sigignore.c: Likewise.
	* sysdeps/posix/sigset.c: Likewise.
	* sysdeps/posix/waitid.c: Likewise.
	* sysdeps/unix/sysv/linux/rt_sigsuspend.c: Likewise.
	* sysdeps/unix/sysv/linux/rt_sigtimedwait.c: Likewise.
	* sysdeps/unix/sysv/linux/sigwaitinfo.c: Likewise.
	* wcsmbs/mbsrtowcs.c: Include stdlib.h for MB_CUR_MAX.
	Patch by Franz Sirl <Franz.Sirl-kernel@lauterbach.com>.

1998-04-13  Mark Kettenis  <kettenis@phys.uva.nl>

	* login/Makefile (headers): Remove utmpx.h and bits/utmpx.h.
	* login/getutent.c (getutxent): Remove alias.
	* login/getutent_r.c (setutxent, pututxline, endutxent):
	Remove aliases.
	* login/getutid.c (getutxid): Remove alias.
	* login/getutline.c (getutxline): Remove alias.
	* login/utmp.h: Add prototypes for __updwtmp, __getutent,
	__getutid, __getutline and __pututline.
	* login/utmpx.h: Moved to ...
	* sysdeps/gnu/utmpx.h: ... here.  [__USE_GNU]: Define UTMPX_FILE,
	UTMPX_FILENAME, WTMPX_FILE and WTMPX_FILENAME, declare utmpxname
	and updwtmpx.
	* login/updwtmp.c: Moved to ...
	* sysdeps/generic/updwtmp.c: ... here.  (updwtmp): Generalized by
	allowing file name transformation.
	* sysdeps/gnu/updwtmp.c: New file.  Use generic implementation with
	additional file name transformation.
	* sysdeps/unix/sysv/linux/updwtmp.c: Likewise.
	* login/utmp_file.c: Moved to ...
	* sysdeps/generic/utmp_file.c: ... here.  (setutent_file):
	Generalized by allowing file name transformation.  Do not
	print error message.  Library functions should not print them.
	Reported by Jim Meyering.
	* sysdeps/gnu/utmp_file.c: New file.  Use generic implementation
	with additional file name transformation.
	* sysdeps/unix/sysv/linux/utmp_file.c: Likewise.
	* sysdeps/gnu/Makefile [$(subdir)=login] (sysdep_routines): Add
	setutxent, getutxent, endutxent, getutxid, getutxid, getutxline,
	pututxline, utmpxname and updwtmpx.  (sysdep_headers): Add utmpx.h
	and bits/utmpx.h.
	* sysdeps/gnu/bits/utmpx.h [__USE_GNU] Include paths.h.
	(_PATH_UTMPX): Define to _PATH_UTMP.  (_PATH_WTMPX): Define to
	_PATH_WTMPX.  (RUN_LVL): Define only if __USE_GNU.  (ACCOUNTING):
	Define if __USE_GNU.
	* sysdeps/gnu/setutxent.c: New file.
	* sysdeps/gnu/getutxent.c: New file.
	* sysdeps/gnu/endutxent.c: New file.
	* sysdeps/gnu/getutxid.c: New file.
	* sysdeps/gnu/getutxline.c: New file.
	* sysdeps/gnu/pututxline.c: New file.
	* sysdeps/gnu/utmpxname.c: New file.
	* sysdeps/gnu/updwtmpx.c: New file.
	* sysdeps/unix/sysv/linux/paths.h (_PATH_UTMP_DB): Remove.
	* sysdeps/generic/bits/utmpx.h: Remove.

1998-04-20  Ulrich Drepper  <drepper@cygnus.com>

	* posix/wordexp-test.c (main): Initialize ifs element of ts for
	~root test.

1998-04-17 07:53  H.J. Lu  <hjl@gnu.org>

	* sysdeps/unix/sysv/linux/i386/s_pread64.S: Fix a typo.

1998-04-17 11:32  Ulrich Drepper  <drepper@cygnus.com>

	* libio/oldfileops.c (_IO_old_file_seekoff): Define temporary st
	variable using _G_stat64.
	* libio/fileops.c: Remove macro definition of fstat, it is in the
	global header.
	Reported by Thorsten Kukuk <kukuk@weber.uni-paderborn.de>.

1998-04-17  Philip Blundell  <pb@nexus.co.uk>

	* sysdeps/arm/strlen.S: New file, based on code by Matthew Wilcox
	<willy@odie.barnet.ac.uk>.

1998-04-16  Philip Blundell  <Philip.Blundell@pobox.com>

	* inet/netinet/in.h (IN6_IS_ADDR_MC_NODELOCAL): New macro,
	required by IPv6 Basic API.
	(IN6_IS_ADDR_MC_LINKLOCAL): Likewise.
	(IN6_IS_ADDR_MC_SITELOCAL): Likewise.
	(IN6_IS_ADDR_MC_ORGLOCAL): Likewise.
	(IN6_IS_ADDR_MC_GLOBAL): Likewise.
1998-04-20 18:41:05 +00:00

301 lines
11 KiB
C

/* 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. */
/* Internal data structures */
/* Includes */
#include <bits/libc-lock.h> /* for _LIBC_TSD_KEY_N */
#include <setjmp.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include "pt-machine.h"
/* Arguments passed to thread creation routine */
struct pthread_start_args {
void * (*start_routine)(void *); /* function to run */
void * arg; /* its argument */
sigset_t mask; /* initial signal mask for thread */
int schedpolicy; /* initial scheduling policy (if any) */
struct sched_param schedparam; /* initial scheduling parameters (if any) */
};
/* We keep thread specific data in a special data structure, a two-level
array. The top-level array contains pointers to dynamically allocated
arrays of a certain number of data pointers. So we can implement a
sparse array. Each dynamic second-level array has
PTHREAD_KEY_2NDLEVEL_SIZE
entries. This value shouldn't be too large. */
#define PTHREAD_KEY_2NDLEVEL_SIZE 32
/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
keys in each subarray. */
#define PTHREAD_KEY_1STLEVEL_SIZE \
((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
/ PTHREAD_KEY_2NDLEVEL_SIZE)
#define PTHREAD_START_ARGS_INITIALIZER { NULL, NULL, {{0, }}, 0, { 0 } }
/* The type of thread descriptors */
typedef struct _pthread_descr_struct * pthread_descr;
struct _pthread_descr_struct {
pthread_descr p_nextlive, p_prevlive;
/* Double chaining of active threads */
pthread_descr p_nextwaiting; /* Next element in the queue holding the thr */
pthread_t p_tid; /* Thread identifier */
int p_pid; /* PID of Unix process */
int p_priority; /* Thread priority (== 0 if not realtime) */
int * p_spinlock; /* Spinlock for synchronized accesses */
int p_signal; /* last signal received */
sigjmp_buf * p_signal_jmp; /* where to siglongjmp on a signal or NULL */
sigjmp_buf * p_cancel_jmp; /* where to siglongjmp on a cancel or NULL */
char p_terminated; /* true if terminated e.g. by pthread_exit */
char p_detached; /* true if detached */
char p_exited; /* true if the assoc. process terminated */
void * p_retval; /* placeholder for return value */
int p_retcode; /* placeholder for return code */
pthread_descr p_joining; /* thread joining on that thread or NULL */
struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */
char p_cancelstate; /* cancellation state */
char p_canceltype; /* cancellation type (deferred/async) */
char p_canceled; /* cancellation request pending */
int * p_errnop; /* pointer to used errno variable */
int p_errno; /* error returned by last system call */
int * p_h_errnop; /* pointer to used h_errno variable */
int p_h_errno; /* error returned by last netdb function */
struct pthread_start_args p_start_args; /* arguments for thread creation */
void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */
void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */
int p_userstack; /* nonzero if the user provided the thread */
void *p_guardaddr; /* address of guard area or NULL */
size_t p_guardsize; /* size of guard area */
};
/* The type of thread handles. */
typedef struct pthread_handle_struct * pthread_handle;
struct pthread_handle_struct {
int h_spinlock; /* Spinlock for sychronized access */
pthread_descr h_descr; /* Thread descriptor or NULL if invalid */
};
/* The type of messages sent to the thread manager thread */
struct pthread_request {
pthread_descr req_thread; /* Thread doing the request */
enum { /* Request kind */
REQ_CREATE, REQ_FREE, REQ_PROCESS_EXIT, REQ_MAIN_THREAD_EXIT
} req_kind;
union { /* Arguments for request */
struct { /* For REQ_CREATE: */
const pthread_attr_t * attr; /* thread attributes */
void * (*fn)(void *); /* start function */
void * arg; /* argument to start function */
sigset_t mask; /* signal mask */
} create;
struct { /* For REQ_FREE: */
pthread_descr thread; /* descriptor of thread to free */
} free;
struct { /* For REQ_PROCESS_EXIT: */
int code; /* exit status */
} exit;
} req_args;
};
/* Signals used for suspend/restart and for cancellation notification. */
#ifdef SIGRTMIN
/* The have real-time signals. */
extern int __pthread_sig_restart;
extern int __pthread_sig_cancel;
# define PTHREAD_SIG_RESTART __pthread_sig_restart
# define PTHREAD_SIG_CANCEL __pthread_sig_cancel
#else
# define PTHREAD_SIG_RESTART SIGUSR1
# define PTHREAD_SIG_CANCEL SIGUSR2
#endif
/* Global array of thread handles, used for validating a thread id
and retrieving the corresponding thread descriptor. Also used for
mapping the available stack segments. */
extern struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX];
/* Descriptor of the initial thread */
extern struct _pthread_descr_struct __pthread_initial_thread;
/* Descriptor of the manager thread */
extern struct _pthread_descr_struct __pthread_manager_thread;
/* Descriptor of the main thread */
extern pthread_descr __pthread_main_thread;
/* Limit between the stack of the initial thread (above) and the
stacks of other threads (below). Aligned on a STACK_SIZE boundary.
Initially 0, meaning that the current thread is (by definition)
the initial thread. */
extern char *__pthread_initial_thread_bos;
/* File descriptor for sending requests to the thread manager.
Initially -1, meaning that pthread_initialize must be called. */
extern int __pthread_manager_request;
/* Other end of the pipe for sending requests to the thread manager. */
extern int __pthread_manager_reader;
/* Limits of the thread manager stack. */
extern char *__pthread_manager_thread_bos;
extern char *__pthread_manager_thread_tos;
/* Pending request for a process-wide exit */
extern int __pthread_exit_requested, __pthread_exit_code;
/* Return the handle corresponding to a thread id */
static inline pthread_handle thread_handle(pthread_t id)
{
return &__pthread_handles[id % PTHREAD_THREADS_MAX];
}
/* Validate a thread handle. Must have acquired h->h_spinlock before. */
static inline int invalid_handle(pthread_handle h, pthread_t id)
{
return h->h_descr == NULL || h->h_descr->p_tid != id;
}
/* Fill in defaults left unspecified by pt-machine.h. */
/* The page size we can get from the system. This should likely not be
changed by the machine file but, you never know. */
#ifndef PAGE_SIZE
#define PAGE_SIZE (sysconf (_SC_PAGE_SIZE))
#endif
/* The max size of the thread stack segments. If the default
THREAD_SELF implementation is used, this must be a power of two and
a multiple of PAGE_SIZE. */
#ifndef STACK_SIZE
#define STACK_SIZE (2 * 1024 * 1024)
#endif
/* The initial size of the thread stack. Must be a multiple of PAGE_SIZE. */
#ifndef INITIAL_STACK_SIZE
#define INITIAL_STACK_SIZE (4 * PAGE_SIZE)
#endif
/* Size of the thread manager stack. The "- 32" avoids wasting space
with some malloc() implementations. */
#ifndef THREAD_MANAGER_STACK_SIZE
#define THREAD_MANAGER_STACK_SIZE (2 * PAGE_SIZE - 32)
#endif
/* The base of the "array" of thread stacks. The array will grow down from
here. Defaults to the calculated bottom of the initial application
stack. */
#ifndef THREAD_STACK_START_ADDRESS
#define THREAD_STACK_START_ADDRESS __pthread_initial_thread_bos
#endif
/* Get some notion of the current stack. Need not be exactly the top
of the stack, just something somewhere in the current frame. */
#ifndef CURRENT_STACK_FRAME
#define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
#endif
/* Recover thread descriptor for the current thread */
static inline pthread_descr thread_self (void) __attribute__ ((const));
static inline pthread_descr thread_self (void)
{
#ifdef THREAD_SELF
return THREAD_SELF;
#else
char *sp = CURRENT_STACK_FRAME;
if (sp >= __pthread_initial_thread_bos)
return &__pthread_initial_thread;
else if (sp >= __pthread_manager_thread_bos
&& sp < __pthread_manager_thread_tos)
return &__pthread_manager_thread;
else
return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
#endif
}
/* Max number of times we must spin on a spinlock calling sched_yield().
After MAX_SPIN_COUNT iterations, we put the calling thread to sleep. */
#ifndef MAX_SPIN_COUNT
#define MAX_SPIN_COUNT 50
#endif
/* Duration of sleep (in nanoseconds) when we can't acquire a spinlock
after MAX_SPIN_COUNT iterations of sched_yield().
With the 2.0 and 2.1 kernels, this MUST BE > 2ms.
(Otherwise the kernel does busy-waiting for realtime threads,
giving other threads no chance to run.) */
#ifndef SPIN_SLEEP_DURATION
#define SPIN_SLEEP_DURATION 2000001
#endif
/* Debugging */
#ifdef DEBUG
#include <assert.h>
#define ASSERT assert
#define MSG __pthread_message
#else
#define ASSERT(x)
#define MSG(msg,arg...)
#endif
/* Internal global functions */
void __pthread_destroy_specifics(void);
void __pthread_perform_cleanup(void);
void __pthread_sighandler(int sig);
void __pthread_message(char * fmt, long arg, ...);
int __pthread_manager(void *reqfd);
void __pthread_manager_sighandler(int sig);
void __pthread_reset_main_thread(void);
void __fresetlockfiles(void);
/* Prototypes for the function without cancelation support when the
normal version has it. */
extern int __libc_close (int fd);
extern int __libc_nanosleep (const struct timespec *requested_time,
struct timespec *remaining);
extern int __libc_read (int fd, void *buf, size_t count);
extern pid_t __libc_waitpid (pid_t pid, int *stat_loc, int options);
extern int __libc_write (int fd, const void *buf, size_t count);