libc_private.h revision 234871
154359Sroberto/* 254359Sroberto * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. 354359Sroberto * All rights reserved. 475202Sphk * 575202Sphk * Redistribution and use in source and binary forms, with or without 675202Sphk * modification, are permitted provided that the following conditions 775202Sphk * are met: 875202Sphk * 1. Redistributions of source code must retain the above copyright 954359Sroberto * notice, this list of conditions and the following disclaimer. 1054359Sroberto * 2. Redistributions in binary form must reproduce the above copyright 1154359Sroberto * notice, this list of conditions and the following disclaimer in the 1254359Sroberto * documentation and/or other materials provided with the distribution. 1354359Sroberto * 3. Neither the name of the author nor the names of any co-contributors 1454359Sroberto * may be used to endorse or promote products derived from this software 1554359Sroberto * without specific prior written permission. 1654359Sroberto * 17182007Sroberto * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 1854359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1954359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2082502Sroberto * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2182502Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2282502Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2382502Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2482502Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2582502Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2682502Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27276158Sdes * SUCH DAMAGE. 28276158Sdes * 29276158Sdes * $FreeBSD: stable/9/lib/libc/include/libc_private.h 234871 2012-05-01 10:49:20Z kib $ 30276158Sdes * 3154359Sroberto * Private definitions for libc, libc_r and libpthread. 3254359Sroberto * 3354359Sroberto */ 3454359Sroberto 3554359Sroberto#ifndef _LIBC_PRIVATE_H_ 3654359Sroberto#define _LIBC_PRIVATE_H_ 3754359Sroberto#include <sys/_pthreadtypes.h> 3854359Sroberto 3954359Sroberto/* 4082502Sroberto * This global flag is non-zero when a process has created one 4182502Sroberto * or more threads. It is used to avoid calling locking functions 4282502Sroberto * when they are not required. 4354359Sroberto */ 4454359Srobertoextern int __isthreaded; 4554359Sroberto 4654359Sroberto/* 4754359Sroberto * Elf_Auxinfo *__elf_aux_vector, the pointer to the ELF aux vector 4854359Sroberto * provided by kernel. Either set for us by rtld, or found at runtime 4954359Sroberto * on stack for static binaries. 5054359Sroberto * 5154359Sroberto * Type is void to avoid polluting whole libc with ELF types. 5254359Sroberto */ 5354359Srobertoextern void *__elf_aux_vector; 5454359Sroberto 55132455Sroberto/* 5654359Sroberto * libc should use libc_dlopen internally, which respects a global 57132455Sroberto * flag where loading of new shared objects can be restricted. 5854359Sroberto */ 5954359Srobertovoid *libc_dlopen(const char *, int); 6082502Sroberto 6182502Sroberto/* 6254359Sroberto * For dynamic linker. 6382502Sroberto */ 6454359Srobertovoid _rtld_error(const char *fmt, ...); 6554359Sroberto 6654359Sroberto/* 67132455Sroberto * File lock contention is difficult to diagnose without knowing 6854359Sroberto * where locks were set. Allow a debug library to be built which 6954359Sroberto * records the source file and line number of each lock call. 7054359Sroberto */ 7182502Sroberto#ifdef _FLOCK_DEBUG 72182007Sroberto#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) 73182007Sroberto#else 74182007Sroberto#define _FLOCKFILE(x) _flockfile(x) 7554359Sroberto#endif 7654359Sroberto 7754359Sroberto/* 7854359Sroberto * Macros for locking and unlocking FILEs. These test if the 7982502Sroberto * process is threaded to avoid locking when not required. 8054359Sroberto */ 8182502Sroberto#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) 8254359Sroberto#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) 8354359Sroberto 8482502Srobertostruct _spinlock; 8582502Srobertoextern struct _spinlock __stdio_thread_lock; 8654359Sroberto#define STDIO_THREAD_LOCK() \ 8754359Srobertodo { \ 88132455Sroberto if (__isthreaded) \ 8982502Sroberto _SPINLOCK(&__stdio_thread_lock); \ 9054359Sroberto} while (0) 9154359Sroberto#define STDIO_THREAD_UNLOCK() \ 9254359Srobertodo { \ 9354359Sroberto if (__isthreaded) \ 9454359Sroberto _SPINUNLOCK(&__stdio_thread_lock); \ 9554359Sroberto} while (0) 9654359Sroberto 9754359Sroberto/* 9854359Sroberto * Indexes into the pthread jump table. 9954359Sroberto * 10054359Sroberto * Warning! If you change this type, you must also change the threads 10154359Sroberto * libraries that reference it (libc_r, libpthread). 10254359Sroberto */ 10354359Srobertotypedef enum { 10482502Sroberto PJT_ATFORK, 10582502Sroberto PJT_ATTR_DESTROY, 10654359Sroberto PJT_ATTR_GETDETACHSTATE, 10782502Sroberto PJT_ATTR_GETGUARDSIZE, 10854359Sroberto PJT_ATTR_GETINHERITSCHED, 10954359Sroberto PJT_ATTR_GETSCHEDPARAM, 11054359Sroberto PJT_ATTR_GETSCHEDPOLICY, 11154359Sroberto PJT_ATTR_GETSCOPE, 11254359Sroberto PJT_ATTR_GETSTACKADDR, 11354359Sroberto PJT_ATTR_GETSTACKSIZE, 11454359Sroberto PJT_ATTR_INIT, 11554359Sroberto PJT_ATTR_SETDETACHSTATE, 11654359Sroberto PJT_ATTR_SETGUARDSIZE, 11754359Sroberto PJT_ATTR_SETINHERITSCHED, 11854359Sroberto PJT_ATTR_SETSCHEDPARAM, 11982502Sroberto PJT_ATTR_SETSCHEDPOLICY, 12054359Sroberto PJT_ATTR_SETSCOPE, 12182502Sroberto PJT_ATTR_SETSTACKADDR, 122182007Sroberto PJT_ATTR_SETSTACKSIZE, 123182007Sroberto PJT_CANCEL, 124182007Sroberto PJT_CLEANUP_POP, 125182007Sroberto PJT_CLEANUP_PUSH, 126182007Sroberto PJT_COND_BROADCAST, 127182007Sroberto PJT_COND_DESTROY, 128182007Sroberto PJT_COND_INIT, 129132455Sroberto PJT_COND_SIGNAL, 130182007Sroberto PJT_COND_TIMEDWAIT, 131182007Sroberto PJT_COND_WAIT, 132182007Sroberto PJT_DETACH, 133182007Sroberto PJT_EQUAL, 134182007Sroberto PJT_EXIT, 135182007Sroberto PJT_GETSPECIFIC, 136182007Sroberto PJT_JOIN, 137182007Sroberto PJT_KEY_CREATE, 138182007Sroberto PJT_KEY_DELETE, 139182007Sroberto PJT_KILL, 140132455Sroberto PJT_MAIN_NP, 141182007Sroberto PJT_MUTEXATTR_DESTROY, 14254359Sroberto PJT_MUTEXATTR_INIT, 14354359Sroberto PJT_MUTEXATTR_SETTYPE, 14482502Sroberto PJT_MUTEX_DESTROY, 14554359Sroberto PJT_MUTEX_INIT, 14654359Sroberto PJT_MUTEX_LOCK, 14782502Sroberto PJT_MUTEX_TRYLOCK, 14882502Sroberto PJT_MUTEX_UNLOCK, 14954359Sroberto PJT_ONCE, 15054359Sroberto PJT_RWLOCK_DESTROY, 15182502Sroberto PJT_RWLOCK_INIT, 15254359Sroberto PJT_RWLOCK_RDLOCK, 15354359Sroberto PJT_RWLOCK_TRYRDLOCK, 15454359Sroberto PJT_RWLOCK_TRYWRLOCK, 15554359Sroberto PJT_RWLOCK_UNLOCK, 15654359Sroberto PJT_RWLOCK_WRLOCK, 15754359Sroberto PJT_SELF, 15854359Sroberto PJT_SETCANCELSTATE, 15954359Sroberto PJT_SETCANCELTYPE, 16054359Sroberto PJT_SETSPECIFIC, 16154359Sroberto PJT_SIGMASK, 16254359Sroberto PJT_TESTCANCEL, 16354359Sroberto PJT_CLEANUP_POP_IMP, 16454359Sroberto PJT_CLEANUP_PUSH_IMP, 16554359Sroberto PJT_CANCEL_ENTER, 16654359Sroberto PJT_CANCEL_LEAVE, 16782502Sroberto PJT_MAX 168182007Sroberto} pjt_index_t; 16954359Sroberto 170132455Srobertotypedef int (*pthread_func_t)(void); 171132455Srobertotypedef pthread_func_t pthread_func_entry_t[2]; 172132455Sroberto 17382502Srobertoextern pthread_func_entry_t __thr_jtable[]; 174132455Sroberto 175182007Sroberto/* 17682502Sroberto * yplib internal interfaces 177182007Sroberto */ 178132455Sroberto#ifdef YP 179132455Srobertoint _yp_check(char **); 18054359Sroberto#endif 18154359Sroberto 18254359Sroberto/* 18354359Sroberto * Initialise TLS for static programs 18454359Sroberto */ 18554359Srobertovoid _init_tls(void); 18654359Sroberto 18782502Sroberto/* 18882502Sroberto * Provides pthread_once()-like functionality for both single-threaded 18982502Sroberto * and multi-threaded applications. 19082502Sroberto */ 19182502Srobertoint _once(pthread_once_t *, void (*)(void)); 19282502Sroberto 19382502Sroberto/* 19482502Sroberto * Set the TLS thread pointer 19582502Sroberto */ 19682502Srobertovoid _set_tp(void *tp); 19782502Sroberto 19882502Sroberto/* 19982502Sroberto * This is a pointer in the C run-time startup code. It is used 20082502Sroberto * by getprogname() and setprogname(). 20182502Sroberto */ 20282502Srobertoextern const char *__progname; 20354359Sroberto 20482502Sroberto/* 20582502Sroberto * This function is used by the threading libraries to notify malloc that a 20682502Sroberto * thread is exiting. 20782502Sroberto */ 20882502Srobertovoid _malloc_thread_cleanup(void); 20982502Sroberto 210182007Sroberto/* 21182502Sroberto * These functions are used by the threading libraries in order to protect 21282502Sroberto * malloc across fork(). 21382502Sroberto */ 21482502Srobertovoid _malloc_prefork(void); 21582502Srobertovoid _malloc_postfork(void); 21682502Sroberto 21782502Sroberto/* 21882502Sroberto * Function to clean up streams, called from abort() and exit(). 21982502Sroberto */ 22082502Srobertoextern void (*__cleanup)(void); 22182502Sroberto 22282502Sroberto/* 22382502Sroberto * Get kern.osreldate to detect ABI revisions. Explicitly 22482502Sroberto * ignores value of $OSVERSION and caches result. Prototypes 225182007Sroberto * for the wrapped "new" pad-less syscalls are here for now. 226132455Sroberto */ 227182007Srobertoextern int __getosreldate(void); 228182007Sroberto#include <sys/_types.h> 229182007Sroberto/* Without pad */ 230132455Srobertoextern __off_t __sys_lseek(int, __off_t, int); 231132455Srobertoextern int __sys_ftruncate(int, __off_t); 232132455Srobertoextern int __sys_truncate(const char *, __off_t); 233132455Srobertoextern __ssize_t __sys_pread(int, void *, __size_t, __off_t); 234182007Srobertoextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); 235132455Srobertoextern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); 236182007Sroberto 23754359Sroberto/* With pad */ 23854359Srobertoextern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); 23954359Srobertoextern int __sys_freebsd6_ftruncate(int, int, __off_t); 24054359Srobertoextern int __sys_freebsd6_truncate(const char *, int, __off_t); 24154359Srobertoextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); 24254359Srobertoextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); 24382502Srobertoextern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); 24454359Sroberto 24554359Sroberto/* Without back-compat translation */ 24654359Srobertoextern int __sys_fcntl(int, int, ...); 24754359Sroberto 24882502Sroberto/* execve() with PATH processing to implement posix_spawnp() */ 24954359Srobertoint _execvpe(const char *, char * const *, char * const *); 25054359Sroberto 25154359Srobertoint _elf_aux_info(int aux, void *buf, int buflen); 25254359Srobertostruct dl_phdr_info; 25354359Srobertoint __elf_phdr_match_addr(struct dl_phdr_info *, void *); 25454359Srobertovoid __init_elf_aux_vector(void); 255182007Sroberto 25654359Srobertovoid _pthread_cancel_enter(int); 25754359Srobertovoid _pthread_cancel_leave(int); 25854359Sroberto 25954359Sroberto#endif /* _LIBC_PRIVATE_H_ */ 26054359Sroberto