libc_private.h revision 213153
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 213153 2010-09-25 01:57:47Z davidxu $
3035124Sjb *
3135124Sjb * Private definitions for libc, libc_r and libpthread.
3235124Sjb *
3335124Sjb */
3435124Sjb
3535124Sjb#ifndef _LIBC_PRIVATE_H_
3635124Sjb#define _LIBC_PRIVATE_H_
37199606Sjhb#include <sys/_pthreadtypes.h>
3835124Sjb
3935124Sjb/*
4035124Sjb * This global flag is non-zero when a process has created one
4135124Sjb * or more threads. It is used to avoid calling locking functions
4235124Sjb * when they are not required.
4335124Sjb */
4435124Sjbextern int	__isthreaded;
4535124Sjb
4635124Sjb/*
4735124Sjb * File lock contention is difficult to diagnose without knowing
4835124Sjb * where locks were set. Allow a debug library to be built which
4935124Sjb * records the source file and line number of each lock call.
5035124Sjb */
5135124Sjb#ifdef	_FLOCK_DEBUG
5235124Sjb#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
5335124Sjb#else
5471579Sdeischen#define _FLOCKFILE(x)	_flockfile(x)
5535124Sjb#endif
5635124Sjb
5735124Sjb/*
5835124Sjb * Macros for locking and unlocking FILEs. These test if the
5935124Sjb * process is threaded to avoid locking when not required.
6035124Sjb */
6135124Sjb#define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
6271579Sdeischen#define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
6335124Sjb
6493399Smarkm/*
65106866Sdeischen * Indexes into the pthread jump table.
66106866Sdeischen *
67106866Sdeischen * Warning! If you change this type, you must also change the threads
68106866Sdeischen * libraries that reference it (libc_r, libpthread).
69106866Sdeischen */
70106866Sdeischentypedef enum {
71156319Sdeischen	PJT_ATFORK,
72156319Sdeischen	PJT_ATTR_DESTROY,
73156319Sdeischen	PJT_ATTR_GETDETACHSTATE,
74156319Sdeischen	PJT_ATTR_GETGUARDSIZE,
75156319Sdeischen	PJT_ATTR_GETINHERITSCHED,
76156319Sdeischen	PJT_ATTR_GETSCHEDPARAM,
77156319Sdeischen	PJT_ATTR_GETSCHEDPOLICY,
78156319Sdeischen	PJT_ATTR_GETSCOPE,
79156319Sdeischen	PJT_ATTR_GETSTACKADDR,
80156319Sdeischen	PJT_ATTR_GETSTACKSIZE,
81156319Sdeischen	PJT_ATTR_INIT,
82156319Sdeischen	PJT_ATTR_SETDETACHSTATE,
83156319Sdeischen	PJT_ATTR_SETGUARDSIZE,
84156319Sdeischen	PJT_ATTR_SETINHERITSCHED,
85156319Sdeischen	PJT_ATTR_SETSCHEDPARAM,
86156319Sdeischen	PJT_ATTR_SETSCHEDPOLICY,
87156319Sdeischen	PJT_ATTR_SETSCOPE,
88156319Sdeischen	PJT_ATTR_SETSTACKADDR,
89156319Sdeischen	PJT_ATTR_SETSTACKSIZE,
90156319Sdeischen	PJT_CANCEL,
91156319Sdeischen	PJT_CLEANUP_POP,
92156319Sdeischen	PJT_CLEANUP_PUSH,
93106866Sdeischen	PJT_COND_BROADCAST,
94106866Sdeischen	PJT_COND_DESTROY,
95106866Sdeischen	PJT_COND_INIT,
96106866Sdeischen	PJT_COND_SIGNAL,
97156319Sdeischen	PJT_COND_TIMEDWAIT,
98106866Sdeischen	PJT_COND_WAIT,
99156319Sdeischen	PJT_DETACH,
100156319Sdeischen	PJT_EQUAL,
101156319Sdeischen	PJT_EXIT,
102106866Sdeischen	PJT_GETSPECIFIC,
103156319Sdeischen	PJT_JOIN,
104106866Sdeischen	PJT_KEY_CREATE,
105106866Sdeischen	PJT_KEY_DELETE,
106156319Sdeischen	PJT_KILL,
107106866Sdeischen	PJT_MAIN_NP,
108156319Sdeischen	PJT_MUTEXATTR_DESTROY,
109156319Sdeischen	PJT_MUTEXATTR_INIT,
110156319Sdeischen	PJT_MUTEXATTR_SETTYPE,
111106866Sdeischen	PJT_MUTEX_DESTROY,
112106866Sdeischen	PJT_MUTEX_INIT,
113106866Sdeischen	PJT_MUTEX_LOCK,
114106866Sdeischen	PJT_MUTEX_TRYLOCK,
115106866Sdeischen	PJT_MUTEX_UNLOCK,
116106866Sdeischen	PJT_ONCE,
117106866Sdeischen	PJT_RWLOCK_DESTROY,
118106866Sdeischen	PJT_RWLOCK_INIT,
119106866Sdeischen	PJT_RWLOCK_RDLOCK,
120106866Sdeischen	PJT_RWLOCK_TRYRDLOCK,
121106866Sdeischen	PJT_RWLOCK_TRYWRLOCK,
122106866Sdeischen	PJT_RWLOCK_UNLOCK,
123106866Sdeischen	PJT_RWLOCK_WRLOCK,
124106866Sdeischen	PJT_SELF,
125156319Sdeischen	PJT_SETCANCELSTATE,
126156319Sdeischen	PJT_SETCANCELTYPE,
127106866Sdeischen	PJT_SETSPECIFIC,
128106866Sdeischen	PJT_SIGMASK,
129156319Sdeischen	PJT_TESTCANCEL,
130201546Sdavidxu	PJT_CLEANUP_POP_IMP,
131201546Sdavidxu	PJT_CLEANUP_PUSH_IMP,
132213153Sdavidxu	PJT_CANCEL_ENTER,
133213153Sdavidxu	PJT_CANCEL_LEAVE,
134106866Sdeischen	PJT_MAX
135106866Sdeischen} pjt_index_t;
136106866Sdeischen
137106870Sdeischentypedef int (*pthread_func_t)(void);
138106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2];
139106866Sdeischen
140106880Sdeischenextern pthread_func_entry_t __thr_jtable[];
141106866Sdeischen
142106866Sdeischen/*
143111618Snectar * yplib internal interfaces
144111618Snectar */
145111618Snectar#ifdef YP
146111618Snectarint _yp_check(char **);
147111618Snectar#endif
148111618Snectar
149133754Sdfr/*
150133754Sdfr * Initialise TLS for static programs
151133754Sdfr */
152133754Sdfrvoid _init_tls(void);
153111618Snectar
154111618Snectar/*
155199606Sjhb * Provides pthread_once()-like functionality for both single-threaded
156199606Sjhb * and multi-threaded applications.
157199606Sjhb */
158199606Sjhbint _once(pthread_once_t *, void (*)(void));
159199606Sjhb
160199606Sjhb/*
161133754Sdfr * Set the TLS thread pointer
162133754Sdfr */
163133754Sdfrvoid _set_tp(void *tp);
164133754Sdfr
165133754Sdfr/*
16693399Smarkm * This is a pointer in the C run-time startup code. It is used
16793399Smarkm * by getprogname() and setprogname().
16893399Smarkm */
16993399Smarkmextern const char *__progname;
17093399Smarkm
171122069Sdeischen/*
172182225Sjasone * This function is used by the threading libraries to notify malloc that a
173182225Sjasone * thread is exiting.
174182225Sjasone */
175182225Sjasonevoid _malloc_thread_cleanup(void);
176182225Sjasone
177182225Sjasone/*
178154248Sjasone * These functions are used by the threading libraries in order to protect
179154248Sjasone * malloc across fork().
180122069Sdeischen */
181154248Sjasonevoid _malloc_prefork(void);
182154248Sjasonevoid _malloc_postfork(void);
183122069Sdeischen
184150040Sstefanf/*
185150040Sstefanf * Function to clean up streams, called from abort() and exit().
186150040Sstefanf */
187150040Sstefanfextern void (*__cleanup)(void);
188150040Sstefanf
189171219Speter/*
190171219Speter * Get kern.osreldate to detect ABI revisions.  Explicitly
191171219Speter * ignores value of $OSVERSION and caches result.  Prototypes
192171219Speter * for the wrapped "new" pad-less syscalls are here for now.
193171219Speter */
194171219Speterextern int __getosreldate(void);
195171219Speter#include <sys/_types.h>
196171219Speter/* Without pad */
197171219Speterextern __off_t	__sys_lseek(int, __off_t, int);
198171219Speterextern int	__sys_ftruncate(int, __off_t);
199171219Speterextern int	__sys_truncate(const char *, __off_t);
200171219Speterextern __ssize_t __sys_pread(int, void *, __size_t, __off_t);
201171219Speterextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
202171219Speterextern void *	__sys_mmap(void *, __size_t, int, int, int, __off_t);
203171219Speter
204171219Speter/* With pad */
205171219Speterextern __off_t	__sys_freebsd6_lseek(int, int, __off_t, int);
206171219Speterextern int	__sys_freebsd6_ftruncate(int, int, __off_t);
207171219Speterextern int	__sys_freebsd6_truncate(const char *, int, __off_t);
208171219Speterextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t);
209171219Speterextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t);
210171219Speterextern void *	__sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t);
211171219Speter
212177911Sdfr/* Without back-compat translation */
213177911Sdfrextern int	__sys_fcntl(int, int, ...);
214177911Sdfr
215179947Sed/* execve() with PATH processing to implement posix_spawnp() */
216179947Sedint _execvpe(const char *, char * const *, char * const *);
217179947Sed
218211416Skibint _elf_aux_info(int aux, void *buf, int buflen);
219211706Skibstruct dl_phdr_info;
220211706Skibint __elf_phdr_match_addr(struct dl_phdr_info *, void *);
221211416Skib
222213153Sdavidxuvoid	_pthread_cancel_enter(int);
223213153Sdavidxuvoid	_pthread_cancel_leave(int);
224213153Sdavidxu
22535124Sjb#endif /* _LIBC_PRIVATE_H_ */
226