libc_private.h revision 234657
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 234657 2012-04-24 17:51:36Z kib $
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/*
47231868Skib * Elf_Auxinfo *__elf_aux_vector, the pointer to the ELF aux vector
48231868Skib * provided by kernel. Either set for us by rtld, or found at runtime
49231868Skib * on stack for static binaries.
50231868Skib *
51231868Skib * Type is void to avoid polluting whole libc with ELF types.
52231868Skib */
53231868Skibextern void	*__elf_aux_vector;
54231868Skib
55231868Skib/*
56228843Scperciva * libc should use libc_dlopen internally, which respects a global
57228843Scperciva * flag where loading of new shared objects can be restricted.
58228843Scperciva */
59228843Scpercivavoid *libc_dlopen(const char *, int);
60228843Scperciva
61228843Scperciva/*
62228843Scperciva * For dynamic linker.
63228843Scperciva */
64228843Scpercivavoid _rtld_error(const char *fmt, ...);
65228843Scperciva
66228843Scperciva/*
6735124Sjb * File lock contention is difficult to diagnose without knowing
6835124Sjb * where locks were set. Allow a debug library to be built which
6935124Sjb * records the source file and line number of each lock call.
7035124Sjb */
7135124Sjb#ifdef	_FLOCK_DEBUG
7235124Sjb#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
7335124Sjb#else
7471579Sdeischen#define _FLOCKFILE(x)	_flockfile(x)
7535124Sjb#endif
7635124Sjb
7735124Sjb/*
7835124Sjb * Macros for locking and unlocking FILEs. These test if the
7935124Sjb * process is threaded to avoid locking when not required.
8035124Sjb */
8135124Sjb#define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
8271579Sdeischen#define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
8335124Sjb
84234657Skibstruct _spinlock;
85234657Skibextern struct _spinlock __stdio_thread_lock;
86234657Skib#define STDIO_THREAD_LOCK()				\
87234657Skibdo {							\
88234657Skib	if (__isthreaded)				\
89234657Skib		_SPINLOCK(&__stdio_thread_lock);	\
90234657Skib} while (0)
91234657Skib#define STDIO_THREAD_UNLOCK()				\
92234657Skibdo {							\
93234657Skib	if (__isthreaded)				\
94234657Skib		_SPINUNLOCK(&__stdio_thread_lock);	\
95234657Skib} while (0)
96234657Skib
9793399Smarkm/*
98106866Sdeischen * Indexes into the pthread jump table.
99106866Sdeischen *
100106866Sdeischen * Warning! If you change this type, you must also change the threads
101106866Sdeischen * libraries that reference it (libc_r, libpthread).
102106866Sdeischen */
103106866Sdeischentypedef enum {
104156319Sdeischen	PJT_ATFORK,
105156319Sdeischen	PJT_ATTR_DESTROY,
106156319Sdeischen	PJT_ATTR_GETDETACHSTATE,
107156319Sdeischen	PJT_ATTR_GETGUARDSIZE,
108156319Sdeischen	PJT_ATTR_GETINHERITSCHED,
109156319Sdeischen	PJT_ATTR_GETSCHEDPARAM,
110156319Sdeischen	PJT_ATTR_GETSCHEDPOLICY,
111156319Sdeischen	PJT_ATTR_GETSCOPE,
112156319Sdeischen	PJT_ATTR_GETSTACKADDR,
113156319Sdeischen	PJT_ATTR_GETSTACKSIZE,
114156319Sdeischen	PJT_ATTR_INIT,
115156319Sdeischen	PJT_ATTR_SETDETACHSTATE,
116156319Sdeischen	PJT_ATTR_SETGUARDSIZE,
117156319Sdeischen	PJT_ATTR_SETINHERITSCHED,
118156319Sdeischen	PJT_ATTR_SETSCHEDPARAM,
119156319Sdeischen	PJT_ATTR_SETSCHEDPOLICY,
120156319Sdeischen	PJT_ATTR_SETSCOPE,
121156319Sdeischen	PJT_ATTR_SETSTACKADDR,
122156319Sdeischen	PJT_ATTR_SETSTACKSIZE,
123156319Sdeischen	PJT_CANCEL,
124156319Sdeischen	PJT_CLEANUP_POP,
125156319Sdeischen	PJT_CLEANUP_PUSH,
126106866Sdeischen	PJT_COND_BROADCAST,
127106866Sdeischen	PJT_COND_DESTROY,
128106866Sdeischen	PJT_COND_INIT,
129106866Sdeischen	PJT_COND_SIGNAL,
130156319Sdeischen	PJT_COND_TIMEDWAIT,
131106866Sdeischen	PJT_COND_WAIT,
132156319Sdeischen	PJT_DETACH,
133156319Sdeischen	PJT_EQUAL,
134156319Sdeischen	PJT_EXIT,
135106866Sdeischen	PJT_GETSPECIFIC,
136156319Sdeischen	PJT_JOIN,
137106866Sdeischen	PJT_KEY_CREATE,
138106866Sdeischen	PJT_KEY_DELETE,
139156319Sdeischen	PJT_KILL,
140106866Sdeischen	PJT_MAIN_NP,
141156319Sdeischen	PJT_MUTEXATTR_DESTROY,
142156319Sdeischen	PJT_MUTEXATTR_INIT,
143156319Sdeischen	PJT_MUTEXATTR_SETTYPE,
144106866Sdeischen	PJT_MUTEX_DESTROY,
145106866Sdeischen	PJT_MUTEX_INIT,
146106866Sdeischen	PJT_MUTEX_LOCK,
147106866Sdeischen	PJT_MUTEX_TRYLOCK,
148106866Sdeischen	PJT_MUTEX_UNLOCK,
149106866Sdeischen	PJT_ONCE,
150106866Sdeischen	PJT_RWLOCK_DESTROY,
151106866Sdeischen	PJT_RWLOCK_INIT,
152106866Sdeischen	PJT_RWLOCK_RDLOCK,
153106866Sdeischen	PJT_RWLOCK_TRYRDLOCK,
154106866Sdeischen	PJT_RWLOCK_TRYWRLOCK,
155106866Sdeischen	PJT_RWLOCK_UNLOCK,
156106866Sdeischen	PJT_RWLOCK_WRLOCK,
157106866Sdeischen	PJT_SELF,
158156319Sdeischen	PJT_SETCANCELSTATE,
159156319Sdeischen	PJT_SETCANCELTYPE,
160106866Sdeischen	PJT_SETSPECIFIC,
161106866Sdeischen	PJT_SIGMASK,
162156319Sdeischen	PJT_TESTCANCEL,
163201546Sdavidxu	PJT_CLEANUP_POP_IMP,
164201546Sdavidxu	PJT_CLEANUP_PUSH_IMP,
165213153Sdavidxu	PJT_CANCEL_ENTER,
166213153Sdavidxu	PJT_CANCEL_LEAVE,
167106866Sdeischen	PJT_MAX
168106866Sdeischen} pjt_index_t;
169106866Sdeischen
170106870Sdeischentypedef int (*pthread_func_t)(void);
171106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2];
172106866Sdeischen
173106880Sdeischenextern pthread_func_entry_t __thr_jtable[];
174106866Sdeischen
175106866Sdeischen/*
176111618Snectar * yplib internal interfaces
177111618Snectar */
178111618Snectar#ifdef YP
179111618Snectarint _yp_check(char **);
180111618Snectar#endif
181111618Snectar
182133754Sdfr/*
183133754Sdfr * Initialise TLS for static programs
184133754Sdfr */
185133754Sdfrvoid _init_tls(void);
186111618Snectar
187111618Snectar/*
188199606Sjhb * Provides pthread_once()-like functionality for both single-threaded
189199606Sjhb * and multi-threaded applications.
190199606Sjhb */
191199606Sjhbint _once(pthread_once_t *, void (*)(void));
192199606Sjhb
193199606Sjhb/*
194133754Sdfr * Set the TLS thread pointer
195133754Sdfr */
196133754Sdfrvoid _set_tp(void *tp);
197133754Sdfr
198133754Sdfr/*
19993399Smarkm * This is a pointer in the C run-time startup code. It is used
20093399Smarkm * by getprogname() and setprogname().
20193399Smarkm */
20293399Smarkmextern const char *__progname;
20393399Smarkm
204122069Sdeischen/*
205182225Sjasone * This function is used by the threading libraries to notify malloc that a
206182225Sjasone * thread is exiting.
207182225Sjasone */
208182225Sjasonevoid _malloc_thread_cleanup(void);
209182225Sjasone
210182225Sjasone/*
211154248Sjasone * These functions are used by the threading libraries in order to protect
212154248Sjasone * malloc across fork().
213122069Sdeischen */
214154248Sjasonevoid _malloc_prefork(void);
215154248Sjasonevoid _malloc_postfork(void);
216122069Sdeischen
217150040Sstefanf/*
218150040Sstefanf * Function to clean up streams, called from abort() and exit().
219150040Sstefanf */
220150040Sstefanfextern void (*__cleanup)(void);
221150040Sstefanf
222171219Speter/*
223171219Speter * Get kern.osreldate to detect ABI revisions.  Explicitly
224171219Speter * ignores value of $OSVERSION and caches result.  Prototypes
225171219Speter * for the wrapped "new" pad-less syscalls are here for now.
226171219Speter */
227171219Speterextern int __getosreldate(void);
228171219Speter#include <sys/_types.h>
229171219Speter/* Without pad */
230171219Speterextern __off_t	__sys_lseek(int, __off_t, int);
231171219Speterextern int	__sys_ftruncate(int, __off_t);
232171219Speterextern int	__sys_truncate(const char *, __off_t);
233171219Speterextern __ssize_t __sys_pread(int, void *, __size_t, __off_t);
234171219Speterextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
235171219Speterextern void *	__sys_mmap(void *, __size_t, int, int, int, __off_t);
236171219Speter
237171219Speter/* With pad */
238171219Speterextern __off_t	__sys_freebsd6_lseek(int, int, __off_t, int);
239171219Speterextern int	__sys_freebsd6_ftruncate(int, int, __off_t);
240171219Speterextern int	__sys_freebsd6_truncate(const char *, int, __off_t);
241171219Speterextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t);
242171219Speterextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t);
243171219Speterextern void *	__sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t);
244171219Speter
245177911Sdfr/* Without back-compat translation */
246177911Sdfrextern int	__sys_fcntl(int, int, ...);
247177911Sdfr
248179947Sed/* execve() with PATH processing to implement posix_spawnp() */
249179947Sedint _execvpe(const char *, char * const *, char * const *);
250179947Sed
251211416Skibint _elf_aux_info(int aux, void *buf, int buflen);
252211706Skibstruct dl_phdr_info;
253211706Skibint __elf_phdr_match_addr(struct dl_phdr_info *, void *);
254231868Skibvoid __init_elf_aux_vector(void);
255211416Skib
256213153Sdavidxuvoid	_pthread_cancel_enter(int);
257213153Sdavidxuvoid	_pthread_cancel_leave(int);
258213153Sdavidxu
25935124Sjb#endif /* _LIBC_PRIVATE_H_ */
260