libc_private.h revision 156319
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.
1335124Sjb * 3. All advertising materials mentioning features or use of this software
1435124Sjb *    must display the following acknowledgement:
1535124Sjb *	This product includes software developed by John Birrell.
1635124Sjb * 4. Neither the name of the author nor the names of any co-contributors
1735124Sjb *    may be used to endorse or promote products derived from this software
1835124Sjb *    without specific prior written permission.
1935124Sjb *
2035124Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
2135124Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2235124Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2335124Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2435124Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2535124Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2635124Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2735124Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2835124Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2935124Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3035124Sjb * SUCH DAMAGE.
3135124Sjb *
3250476Speter * $FreeBSD: head/lib/libc/include/libc_private.h 156319 2006-03-05 18:10:28Z deischen $
3335124Sjb *
3435124Sjb * Private definitions for libc, libc_r and libpthread.
3535124Sjb *
3635124Sjb */
3735124Sjb
3835124Sjb#ifndef _LIBC_PRIVATE_H_
3935124Sjb#define _LIBC_PRIVATE_H_
4035124Sjb
4135124Sjb/*
4235124Sjb * This global flag is non-zero when a process has created one
4335124Sjb * or more threads. It is used to avoid calling locking functions
4435124Sjb * when they are not required.
4535124Sjb */
4635124Sjbextern int	__isthreaded;
4735124Sjb
4835124Sjb/*
4935124Sjb * File lock contention is difficult to diagnose without knowing
5035124Sjb * where locks were set. Allow a debug library to be built which
5135124Sjb * records the source file and line number of each lock call.
5235124Sjb */
5335124Sjb#ifdef	_FLOCK_DEBUG
5435124Sjb#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
5535124Sjb#else
5671579Sdeischen#define _FLOCKFILE(x)	_flockfile(x)
5735124Sjb#endif
5835124Sjb
5935124Sjb/*
6035124Sjb * Macros for locking and unlocking FILEs. These test if the
6135124Sjb * process is threaded to avoid locking when not required.
6235124Sjb */
6335124Sjb#define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
6471579Sdeischen#define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
6535124Sjb
6693399Smarkm/*
67106866Sdeischen * Indexes into the pthread jump table.
68106866Sdeischen *
69106866Sdeischen * Warning! If you change this type, you must also change the threads
70106866Sdeischen * libraries that reference it (libc_r, libpthread).
71106866Sdeischen */
72106866Sdeischentypedef enum {
73156319Sdeischen	PJT_ATFORK,
74156319Sdeischen	PJT_ATTR_DESTROY,
75156319Sdeischen	PJT_ATTR_GETDETACHSTATE,
76156319Sdeischen	PJT_ATTR_GETGUARDSIZE,
77156319Sdeischen	PJT_ATTR_GETINHERITSCHED,
78156319Sdeischen	PJT_ATTR_GETSCHEDPARAM,
79156319Sdeischen	PJT_ATTR_GETSCHEDPOLICY,
80156319Sdeischen	PJT_ATTR_GETSCOPE,
81156319Sdeischen	PJT_ATTR_GETSTACKADDR,
82156319Sdeischen	PJT_ATTR_GETSTACKSIZE,
83156319Sdeischen	PJT_ATTR_INIT,
84156319Sdeischen	PJT_ATTR_SETDETACHSTATE,
85156319Sdeischen	PJT_ATTR_SETGUARDSIZE,
86156319Sdeischen	PJT_ATTR_SETINHERITSCHED,
87156319Sdeischen	PJT_ATTR_SETSCHEDPARAM,
88156319Sdeischen	PJT_ATTR_SETSCHEDPOLICY,
89156319Sdeischen	PJT_ATTR_SETSCOPE,
90156319Sdeischen	PJT_ATTR_SETSTACKADDR,
91156319Sdeischen	PJT_ATTR_SETSTACKSIZE,
92156319Sdeischen	PJT_CANCEL,
93156319Sdeischen	PJT_CLEANUP_POP,
94156319Sdeischen	PJT_CLEANUP_PUSH,
95106866Sdeischen	PJT_COND_BROADCAST,
96106866Sdeischen	PJT_COND_DESTROY,
97106866Sdeischen	PJT_COND_INIT,
98106866Sdeischen	PJT_COND_SIGNAL,
99156319Sdeischen	PJT_COND_TIMEDWAIT,
100106866Sdeischen	PJT_COND_WAIT,
101156319Sdeischen	PJT_DETACH,
102156319Sdeischen	PJT_EQUAL,
103156319Sdeischen	PJT_EXIT,
104106866Sdeischen	PJT_GETSPECIFIC,
105156319Sdeischen	PJT_JOIN,
106106866Sdeischen	PJT_KEY_CREATE,
107106866Sdeischen	PJT_KEY_DELETE,
108156319Sdeischen	PJT_KILL,
109106866Sdeischen	PJT_MAIN_NP,
110156319Sdeischen	PJT_MUTEXATTR_DESTROY,
111156319Sdeischen	PJT_MUTEXATTR_INIT,
112156319Sdeischen	PJT_MUTEXATTR_SETTYPE,
113106866Sdeischen	PJT_MUTEX_DESTROY,
114106866Sdeischen	PJT_MUTEX_INIT,
115106866Sdeischen	PJT_MUTEX_LOCK,
116106866Sdeischen	PJT_MUTEX_TRYLOCK,
117106866Sdeischen	PJT_MUTEX_UNLOCK,
118106866Sdeischen	PJT_ONCE,
119106866Sdeischen	PJT_RWLOCK_DESTROY,
120106866Sdeischen	PJT_RWLOCK_INIT,
121106866Sdeischen	PJT_RWLOCK_RDLOCK,
122106866Sdeischen	PJT_RWLOCK_TRYRDLOCK,
123106866Sdeischen	PJT_RWLOCK_TRYWRLOCK,
124106866Sdeischen	PJT_RWLOCK_UNLOCK,
125106866Sdeischen	PJT_RWLOCK_WRLOCK,
126106866Sdeischen	PJT_SELF,
127156319Sdeischen	PJT_SETCANCELSTATE,
128156319Sdeischen	PJT_SETCANCELTYPE,
129106866Sdeischen	PJT_SETSPECIFIC,
130106866Sdeischen	PJT_SIGMASK,
131156319Sdeischen	PJT_TESTCANCEL,
132106866Sdeischen	PJT_MAX
133106866Sdeischen} pjt_index_t;
134106866Sdeischen
135106870Sdeischentypedef int (*pthread_func_t)(void);
136106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2];
137106866Sdeischen
138106880Sdeischenextern pthread_func_entry_t __thr_jtable[];
139106866Sdeischen
140106866Sdeischen/*
141111618Snectar * yplib internal interfaces
142111618Snectar */
143111618Snectar#ifdef YP
144111618Snectarint _yp_check(char **);
145111618Snectar#endif
146111618Snectar
147133754Sdfr/*
148133754Sdfr * Initialise TLS for static programs
149133754Sdfr */
150133754Sdfrvoid _init_tls(void);
151111618Snectar
152111618Snectar/*
153133754Sdfr * Set the TLS thread pointer
154133754Sdfr */
155133754Sdfrvoid _set_tp(void *tp);
156133754Sdfr
157133754Sdfr/*
15893399Smarkm * This is a pointer in the C run-time startup code. It is used
15993399Smarkm * by getprogname() and setprogname().
16093399Smarkm */
16193399Smarkmextern const char *__progname;
16293399Smarkm
163122069Sdeischen/*
164154248Sjasone * These functions are used by the threading libraries in order to protect
165154248Sjasone * malloc across fork().
166122069Sdeischen */
167154248Sjasonevoid _malloc_prefork(void);
168154248Sjasonevoid _malloc_postfork(void);
169122069Sdeischen
170150040Sstefanf/*
171150040Sstefanf * Function to clean up streams, called from abort() and exit().
172150040Sstefanf */
173150040Sstefanfextern void (*__cleanup)(void);
174150040Sstefanf
17535124Sjb#endif /* _LIBC_PRIVATE_H_ */
176