libc_private.h revision 165968
135124Sjb/*
235124Sjb * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
335124Sjb * All rights reserved.
435124Sjb *
535124Sjb * Redistribution and use in source and binary forms, with or without
635124Sjb * modification, are permitted provided that the following conditions
735124Sjb * are met:
835124Sjb * 1. Redistributions of source code must retain the above copyright
935124Sjb *    notice, this list of conditions and the following disclaimer.
1035124Sjb * 2. Redistributions in binary form must reproduce the above copyright
1135124Sjb *    notice, this list of conditions and the following disclaimer in the
1235124Sjb *    documentation and/or other materials provided with the distribution.
13165968Simp * 3. Neither the name of the author nor the names of any co-contributors
1435124Sjb *    may be used to endorse or promote products derived from this software
1535124Sjb *    without specific prior written permission.
1635124Sjb *
1735124Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
1835124Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1935124Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2035124Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2135124Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2235124Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2335124Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2435124Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2535124Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2635124Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2735124Sjb * SUCH DAMAGE.
2835124Sjb *
2950476Speter * $FreeBSD: head/lib/libc/include/libc_private.h 165968 2007-01-12 07:31:30Z imp $
3035124Sjb *
3135124Sjb * Private definitions for libc, libc_r and libpthread.
3235124Sjb *
3335124Sjb */
3435124Sjb
3535124Sjb#ifndef _LIBC_PRIVATE_H_
3635124Sjb#define _LIBC_PRIVATE_H_
3735124Sjb
3835124Sjb/*
3935124Sjb * This global flag is non-zero when a process has created one
4035124Sjb * or more threads. It is used to avoid calling locking functions
4135124Sjb * when they are not required.
4235124Sjb */
4335124Sjbextern int	__isthreaded;
4435124Sjb
4535124Sjb/*
4635124Sjb * File lock contention is difficult to diagnose without knowing
4735124Sjb * where locks were set. Allow a debug library to be built which
4835124Sjb * records the source file and line number of each lock call.
4935124Sjb */
5035124Sjb#ifdef	_FLOCK_DEBUG
5135124Sjb#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
5235124Sjb#else
5371579Sdeischen#define _FLOCKFILE(x)	_flockfile(x)
5435124Sjb#endif
5535124Sjb
5635124Sjb/*
5735124Sjb * Macros for locking and unlocking FILEs. These test if the
5835124Sjb * process is threaded to avoid locking when not required.
5935124Sjb */
6035124Sjb#define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
6171579Sdeischen#define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
6235124Sjb
6393399Smarkm/*
64106866Sdeischen * Indexes into the pthread jump table.
65106866Sdeischen *
66106866Sdeischen * Warning! If you change this type, you must also change the threads
67106866Sdeischen * libraries that reference it (libc_r, libpthread).
68106866Sdeischen */
69106866Sdeischentypedef enum {
70156319Sdeischen	PJT_ATFORK,
71156319Sdeischen	PJT_ATTR_DESTROY,
72156319Sdeischen	PJT_ATTR_GETDETACHSTATE,
73156319Sdeischen	PJT_ATTR_GETGUARDSIZE,
74156319Sdeischen	PJT_ATTR_GETINHERITSCHED,
75156319Sdeischen	PJT_ATTR_GETSCHEDPARAM,
76156319Sdeischen	PJT_ATTR_GETSCHEDPOLICY,
77156319Sdeischen	PJT_ATTR_GETSCOPE,
78156319Sdeischen	PJT_ATTR_GETSTACKADDR,
79156319Sdeischen	PJT_ATTR_GETSTACKSIZE,
80156319Sdeischen	PJT_ATTR_INIT,
81156319Sdeischen	PJT_ATTR_SETDETACHSTATE,
82156319Sdeischen	PJT_ATTR_SETGUARDSIZE,
83156319Sdeischen	PJT_ATTR_SETINHERITSCHED,
84156319Sdeischen	PJT_ATTR_SETSCHEDPARAM,
85156319Sdeischen	PJT_ATTR_SETSCHEDPOLICY,
86156319Sdeischen	PJT_ATTR_SETSCOPE,
87156319Sdeischen	PJT_ATTR_SETSTACKADDR,
88156319Sdeischen	PJT_ATTR_SETSTACKSIZE,
89156319Sdeischen	PJT_CANCEL,
90156319Sdeischen	PJT_CLEANUP_POP,
91156319Sdeischen	PJT_CLEANUP_PUSH,
92106866Sdeischen	PJT_COND_BROADCAST,
93106866Sdeischen	PJT_COND_DESTROY,
94106866Sdeischen	PJT_COND_INIT,
95106866Sdeischen	PJT_COND_SIGNAL,
96156319Sdeischen	PJT_COND_TIMEDWAIT,
97106866Sdeischen	PJT_COND_WAIT,
98156319Sdeischen	PJT_DETACH,
99156319Sdeischen	PJT_EQUAL,
100156319Sdeischen	PJT_EXIT,
101106866Sdeischen	PJT_GETSPECIFIC,
102156319Sdeischen	PJT_JOIN,
103106866Sdeischen	PJT_KEY_CREATE,
104106866Sdeischen	PJT_KEY_DELETE,
105156319Sdeischen	PJT_KILL,
106106866Sdeischen	PJT_MAIN_NP,
107156319Sdeischen	PJT_MUTEXATTR_DESTROY,
108156319Sdeischen	PJT_MUTEXATTR_INIT,
109156319Sdeischen	PJT_MUTEXATTR_SETTYPE,
110106866Sdeischen	PJT_MUTEX_DESTROY,
111106866Sdeischen	PJT_MUTEX_INIT,
112106866Sdeischen	PJT_MUTEX_LOCK,
113106866Sdeischen	PJT_MUTEX_TRYLOCK,
114106866Sdeischen	PJT_MUTEX_UNLOCK,
115106866Sdeischen	PJT_ONCE,
116106866Sdeischen	PJT_RWLOCK_DESTROY,
117106866Sdeischen	PJT_RWLOCK_INIT,
118106866Sdeischen	PJT_RWLOCK_RDLOCK,
119106866Sdeischen	PJT_RWLOCK_TRYRDLOCK,
120106866Sdeischen	PJT_RWLOCK_TRYWRLOCK,
121106866Sdeischen	PJT_RWLOCK_UNLOCK,
122106866Sdeischen	PJT_RWLOCK_WRLOCK,
123106866Sdeischen	PJT_SELF,
124156319Sdeischen	PJT_SETCANCELSTATE,
125156319Sdeischen	PJT_SETCANCELTYPE,
126106866Sdeischen	PJT_SETSPECIFIC,
127106866Sdeischen	PJT_SIGMASK,
128156319Sdeischen	PJT_TESTCANCEL,
129106866Sdeischen	PJT_MAX
130106866Sdeischen} pjt_index_t;
131106866Sdeischen
132106870Sdeischentypedef int (*pthread_func_t)(void);
133106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2];
134106866Sdeischen
135106880Sdeischenextern pthread_func_entry_t __thr_jtable[];
136106866Sdeischen
137106866Sdeischen/*
138111618Snectar * yplib internal interfaces
139111618Snectar */
140111618Snectar#ifdef YP
141111618Snectarint _yp_check(char **);
142111618Snectar#endif
143111618Snectar
144133754Sdfr/*
145133754Sdfr * Initialise TLS for static programs
146133754Sdfr */
147133754Sdfrvoid _init_tls(void);
148111618Snectar
149111618Snectar/*
150133754Sdfr * Set the TLS thread pointer
151133754Sdfr */
152133754Sdfrvoid _set_tp(void *tp);
153133754Sdfr
154133754Sdfr/*
15593399Smarkm * This is a pointer in the C run-time startup code. It is used
15693399Smarkm * by getprogname() and setprogname().
15793399Smarkm */
15893399Smarkmextern const char *__progname;
15993399Smarkm
160122069Sdeischen/*
161154248Sjasone * These functions are used by the threading libraries in order to protect
162154248Sjasone * malloc across fork().
163122069Sdeischen */
164154248Sjasonevoid _malloc_prefork(void);
165154248Sjasonevoid _malloc_postfork(void);
166122069Sdeischen
167150040Sstefanf/*
168150040Sstefanf * Function to clean up streams, called from abort() and exit().
169150040Sstefanf */
170150040Sstefanfextern void (*__cleanup)(void);
171150040Sstefanf
17235124Sjb#endif /* _LIBC_PRIVATE_H_ */
173