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$ 3035124Sjb * 3135124Sjb * Private definitions for libc, libc_r and libpthread. 3235124Sjb * 3335124Sjb */ 3435124Sjb 3535124Sjb#ifndef _LIBC_PRIVATE_H_ 3635124Sjb#define _LIBC_PRIVATE_H_ 37240819Skib#include <sys/_types.h> 38199606Sjhb#include <sys/_pthreadtypes.h> 3935124Sjb 4035124Sjb/* 4135124Sjb * This global flag is non-zero when a process has created one 4235124Sjb * or more threads. It is used to avoid calling locking functions 4335124Sjb * when they are not required. 4435124Sjb */ 4535124Sjbextern int __isthreaded; 4635124Sjb 4735124Sjb/* 48232388Skib * Elf_Auxinfo *__elf_aux_vector, the pointer to the ELF aux vector 49232388Skib * provided by kernel. Either set for us by rtld, or found at runtime 50232388Skib * on stack for static binaries. 51232388Skib * 52232388Skib * Type is void to avoid polluting whole libc with ELF types. 53232388Skib */ 54232388Skibextern void *__elf_aux_vector; 55232388Skib 56232388Skib/* 57228843Scperciva * libc should use libc_dlopen internally, which respects a global 58228843Scperciva * flag where loading of new shared objects can be restricted. 59228843Scperciva */ 60228843Scpercivavoid *libc_dlopen(const char *, int); 61228843Scperciva 62228843Scperciva/* 63228843Scperciva * For dynamic linker. 64228843Scperciva */ 65228843Scpercivavoid _rtld_error(const char *fmt, ...); 66228843Scperciva 67228843Scperciva/* 6835124Sjb * File lock contention is difficult to diagnose without knowing 6935124Sjb * where locks were set. Allow a debug library to be built which 7035124Sjb * records the source file and line number of each lock call. 7135124Sjb */ 7235124Sjb#ifdef _FLOCK_DEBUG 7335124Sjb#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) 7435124Sjb#else 7571579Sdeischen#define _FLOCKFILE(x) _flockfile(x) 7635124Sjb#endif 7735124Sjb 7835124Sjb/* 7935124Sjb * Macros for locking and unlocking FILEs. These test if the 8035124Sjb * process is threaded to avoid locking when not required. 8135124Sjb */ 8235124Sjb#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) 8371579Sdeischen#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) 8435124Sjb 85234871Skibstruct _spinlock; 86234871Skibextern struct _spinlock __stdio_thread_lock; 87234871Skib#define STDIO_THREAD_LOCK() \ 88234871Skibdo { \ 89234871Skib if (__isthreaded) \ 90234871Skib _SPINLOCK(&__stdio_thread_lock); \ 91234871Skib} while (0) 92234871Skib#define STDIO_THREAD_UNLOCK() \ 93234871Skibdo { \ 94234871Skib if (__isthreaded) \ 95234871Skib _SPINUNLOCK(&__stdio_thread_lock); \ 96234871Skib} while (0) 97234871Skib 9893399Smarkm/* 99106866Sdeischen * Indexes into the pthread jump table. 100106866Sdeischen * 101106866Sdeischen * Warning! If you change this type, you must also change the threads 102106866Sdeischen * libraries that reference it (libc_r, libpthread). 103106866Sdeischen */ 104106866Sdeischentypedef enum { 105156319Sdeischen PJT_ATFORK, 106156319Sdeischen PJT_ATTR_DESTROY, 107156319Sdeischen PJT_ATTR_GETDETACHSTATE, 108156319Sdeischen PJT_ATTR_GETGUARDSIZE, 109156319Sdeischen PJT_ATTR_GETINHERITSCHED, 110156319Sdeischen PJT_ATTR_GETSCHEDPARAM, 111156319Sdeischen PJT_ATTR_GETSCHEDPOLICY, 112156319Sdeischen PJT_ATTR_GETSCOPE, 113156319Sdeischen PJT_ATTR_GETSTACKADDR, 114156319Sdeischen PJT_ATTR_GETSTACKSIZE, 115156319Sdeischen PJT_ATTR_INIT, 116156319Sdeischen PJT_ATTR_SETDETACHSTATE, 117156319Sdeischen PJT_ATTR_SETGUARDSIZE, 118156319Sdeischen PJT_ATTR_SETINHERITSCHED, 119156319Sdeischen PJT_ATTR_SETSCHEDPARAM, 120156319Sdeischen PJT_ATTR_SETSCHEDPOLICY, 121156319Sdeischen PJT_ATTR_SETSCOPE, 122156319Sdeischen PJT_ATTR_SETSTACKADDR, 123156319Sdeischen PJT_ATTR_SETSTACKSIZE, 124156319Sdeischen PJT_CANCEL, 125156319Sdeischen PJT_CLEANUP_POP, 126156319Sdeischen PJT_CLEANUP_PUSH, 127106866Sdeischen PJT_COND_BROADCAST, 128106866Sdeischen PJT_COND_DESTROY, 129106866Sdeischen PJT_COND_INIT, 130106866Sdeischen PJT_COND_SIGNAL, 131156319Sdeischen PJT_COND_TIMEDWAIT, 132106866Sdeischen PJT_COND_WAIT, 133156319Sdeischen PJT_DETACH, 134156319Sdeischen PJT_EQUAL, 135156319Sdeischen PJT_EXIT, 136106866Sdeischen PJT_GETSPECIFIC, 137156319Sdeischen PJT_JOIN, 138106866Sdeischen PJT_KEY_CREATE, 139106866Sdeischen PJT_KEY_DELETE, 140156319Sdeischen PJT_KILL, 141106866Sdeischen PJT_MAIN_NP, 142156319Sdeischen PJT_MUTEXATTR_DESTROY, 143156319Sdeischen PJT_MUTEXATTR_INIT, 144156319Sdeischen PJT_MUTEXATTR_SETTYPE, 145106866Sdeischen PJT_MUTEX_DESTROY, 146106866Sdeischen PJT_MUTEX_INIT, 147106866Sdeischen PJT_MUTEX_LOCK, 148106866Sdeischen PJT_MUTEX_TRYLOCK, 149106866Sdeischen PJT_MUTEX_UNLOCK, 150106866Sdeischen PJT_ONCE, 151106866Sdeischen PJT_RWLOCK_DESTROY, 152106866Sdeischen PJT_RWLOCK_INIT, 153106866Sdeischen PJT_RWLOCK_RDLOCK, 154106866Sdeischen PJT_RWLOCK_TRYRDLOCK, 155106866Sdeischen PJT_RWLOCK_TRYWRLOCK, 156106866Sdeischen PJT_RWLOCK_UNLOCK, 157106866Sdeischen PJT_RWLOCK_WRLOCK, 158106866Sdeischen PJT_SELF, 159156319Sdeischen PJT_SETCANCELSTATE, 160156319Sdeischen PJT_SETCANCELTYPE, 161106866Sdeischen PJT_SETSPECIFIC, 162106866Sdeischen PJT_SIGMASK, 163156319Sdeischen PJT_TESTCANCEL, 164201546Sdavidxu PJT_CLEANUP_POP_IMP, 165201546Sdavidxu PJT_CLEANUP_PUSH_IMP, 166213153Sdavidxu PJT_CANCEL_ENTER, 167213153Sdavidxu PJT_CANCEL_LEAVE, 168106866Sdeischen PJT_MAX 169106866Sdeischen} pjt_index_t; 170106866Sdeischen 171106870Sdeischentypedef int (*pthread_func_t)(void); 172106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2]; 173106866Sdeischen 174106880Sdeischenextern pthread_func_entry_t __thr_jtable[]; 175106866Sdeischen 176106866Sdeischen/* 177111618Snectar * yplib internal interfaces 178111618Snectar */ 179111618Snectar#ifdef YP 180111618Snectarint _yp_check(char **); 181111618Snectar#endif 182111618Snectar 183133754Sdfr/* 184133754Sdfr * Initialise TLS for static programs 185133754Sdfr */ 186133754Sdfrvoid _init_tls(void); 187111618Snectar 188111618Snectar/* 189199606Sjhb * Provides pthread_once()-like functionality for both single-threaded 190199606Sjhb * and multi-threaded applications. 191199606Sjhb */ 192199606Sjhbint _once(pthread_once_t *, void (*)(void)); 193199606Sjhb 194199606Sjhb/* 195133754Sdfr * Set the TLS thread pointer 196133754Sdfr */ 197133754Sdfrvoid _set_tp(void *tp); 198133754Sdfr 199133754Sdfr/* 20093399Smarkm * This is a pointer in the C run-time startup code. It is used 20193399Smarkm * by getprogname() and setprogname(). 20293399Smarkm */ 20393399Smarkmextern const char *__progname; 20493399Smarkm 205122069Sdeischen/* 206182225Sjasone * This function is used by the threading libraries to notify malloc that a 207182225Sjasone * thread is exiting. 208182225Sjasone */ 209182225Sjasonevoid _malloc_thread_cleanup(void); 210182225Sjasone 211182225Sjasone/* 212154248Sjasone * These functions are used by the threading libraries in order to protect 213154248Sjasone * malloc across fork(). 214122069Sdeischen */ 215154248Sjasonevoid _malloc_prefork(void); 216154248Sjasonevoid _malloc_postfork(void); 217122069Sdeischen 218150040Sstefanf/* 219150040Sstefanf * Function to clean up streams, called from abort() and exit(). 220150040Sstefanf */ 221150040Sstefanfextern void (*__cleanup)(void); 222150040Sstefanf 223171219Speter/* 224171219Speter * Get kern.osreldate to detect ABI revisions. Explicitly 225171219Speter * ignores value of $OSVERSION and caches result. Prototypes 226171219Speter * for the wrapped "new" pad-less syscalls are here for now. 227171219Speter */ 228171219Speterextern int __getosreldate(void); 229171219Speter#include <sys/_types.h> 230171219Speter/* Without pad */ 231171219Speterextern __off_t __sys_lseek(int, __off_t, int); 232171219Speterextern int __sys_ftruncate(int, __off_t); 233171219Speterextern int __sys_truncate(const char *, __off_t); 234171219Speterextern __ssize_t __sys_pread(int, void *, __size_t, __off_t); 235171219Speterextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); 236171219Speterextern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); 237171219Speter 238171219Speter/* With pad */ 239171219Speterextern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); 240171219Speterextern int __sys_freebsd6_ftruncate(int, int, __off_t); 241171219Speterextern int __sys_freebsd6_truncate(const char *, int, __off_t); 242171219Speterextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); 243171219Speterextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); 244171219Speterextern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); 245171219Speter 246177911Sdfr/* Without back-compat translation */ 247177911Sdfrextern int __sys_fcntl(int, int, ...); 248177911Sdfr 249240819Skibstruct timespec; 250240819Skibstruct timeval; 251240819Skibstruct timezone; 252240819Skibint __sys_gettimeofday(struct timeval *, struct timezone *); 253240819Skibint __sys_clock_gettime(__clockid_t, struct timespec *ts); 254240819Skib 255179947Sed/* execve() with PATH processing to implement posix_spawnp() */ 256179947Sedint _execvpe(const char *, char * const *, char * const *); 257179947Sed 258211416Skibint _elf_aux_info(int aux, void *buf, int buflen); 259211706Skibstruct dl_phdr_info; 260211706Skibint __elf_phdr_match_addr(struct dl_phdr_info *, void *); 261232388Skibvoid __init_elf_aux_vector(void); 262211416Skib 263213153Sdavidxuvoid _pthread_cancel_enter(int); 264213153Sdavidxuvoid _pthread_cancel_leave(int); 265213153Sdavidxu 26635124Sjb#endif /* _LIBC_PRIVATE_H_ */ 267