libc_private.h revision 231868
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 231868 2012-02-17 10:49:29Z 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 8493399Smarkm/* 85106866Sdeischen * Indexes into the pthread jump table. 86106866Sdeischen * 87106866Sdeischen * Warning! If you change this type, you must also change the threads 88106866Sdeischen * libraries that reference it (libc_r, libpthread). 89106866Sdeischen */ 90106866Sdeischentypedef enum { 91156319Sdeischen PJT_ATFORK, 92156319Sdeischen PJT_ATTR_DESTROY, 93156319Sdeischen PJT_ATTR_GETDETACHSTATE, 94156319Sdeischen PJT_ATTR_GETGUARDSIZE, 95156319Sdeischen PJT_ATTR_GETINHERITSCHED, 96156319Sdeischen PJT_ATTR_GETSCHEDPARAM, 97156319Sdeischen PJT_ATTR_GETSCHEDPOLICY, 98156319Sdeischen PJT_ATTR_GETSCOPE, 99156319Sdeischen PJT_ATTR_GETSTACKADDR, 100156319Sdeischen PJT_ATTR_GETSTACKSIZE, 101156319Sdeischen PJT_ATTR_INIT, 102156319Sdeischen PJT_ATTR_SETDETACHSTATE, 103156319Sdeischen PJT_ATTR_SETGUARDSIZE, 104156319Sdeischen PJT_ATTR_SETINHERITSCHED, 105156319Sdeischen PJT_ATTR_SETSCHEDPARAM, 106156319Sdeischen PJT_ATTR_SETSCHEDPOLICY, 107156319Sdeischen PJT_ATTR_SETSCOPE, 108156319Sdeischen PJT_ATTR_SETSTACKADDR, 109156319Sdeischen PJT_ATTR_SETSTACKSIZE, 110156319Sdeischen PJT_CANCEL, 111156319Sdeischen PJT_CLEANUP_POP, 112156319Sdeischen PJT_CLEANUP_PUSH, 113106866Sdeischen PJT_COND_BROADCAST, 114106866Sdeischen PJT_COND_DESTROY, 115106866Sdeischen PJT_COND_INIT, 116106866Sdeischen PJT_COND_SIGNAL, 117156319Sdeischen PJT_COND_TIMEDWAIT, 118106866Sdeischen PJT_COND_WAIT, 119156319Sdeischen PJT_DETACH, 120156319Sdeischen PJT_EQUAL, 121156319Sdeischen PJT_EXIT, 122106866Sdeischen PJT_GETSPECIFIC, 123156319Sdeischen PJT_JOIN, 124106866Sdeischen PJT_KEY_CREATE, 125106866Sdeischen PJT_KEY_DELETE, 126156319Sdeischen PJT_KILL, 127106866Sdeischen PJT_MAIN_NP, 128156319Sdeischen PJT_MUTEXATTR_DESTROY, 129156319Sdeischen PJT_MUTEXATTR_INIT, 130156319Sdeischen PJT_MUTEXATTR_SETTYPE, 131106866Sdeischen PJT_MUTEX_DESTROY, 132106866Sdeischen PJT_MUTEX_INIT, 133106866Sdeischen PJT_MUTEX_LOCK, 134106866Sdeischen PJT_MUTEX_TRYLOCK, 135106866Sdeischen PJT_MUTEX_UNLOCK, 136106866Sdeischen PJT_ONCE, 137106866Sdeischen PJT_RWLOCK_DESTROY, 138106866Sdeischen PJT_RWLOCK_INIT, 139106866Sdeischen PJT_RWLOCK_RDLOCK, 140106866Sdeischen PJT_RWLOCK_TRYRDLOCK, 141106866Sdeischen PJT_RWLOCK_TRYWRLOCK, 142106866Sdeischen PJT_RWLOCK_UNLOCK, 143106866Sdeischen PJT_RWLOCK_WRLOCK, 144106866Sdeischen PJT_SELF, 145156319Sdeischen PJT_SETCANCELSTATE, 146156319Sdeischen PJT_SETCANCELTYPE, 147106866Sdeischen PJT_SETSPECIFIC, 148106866Sdeischen PJT_SIGMASK, 149156319Sdeischen PJT_TESTCANCEL, 150201546Sdavidxu PJT_CLEANUP_POP_IMP, 151201546Sdavidxu PJT_CLEANUP_PUSH_IMP, 152213153Sdavidxu PJT_CANCEL_ENTER, 153213153Sdavidxu PJT_CANCEL_LEAVE, 154106866Sdeischen PJT_MAX 155106866Sdeischen} pjt_index_t; 156106866Sdeischen 157106870Sdeischentypedef int (*pthread_func_t)(void); 158106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2]; 159106866Sdeischen 160106880Sdeischenextern pthread_func_entry_t __thr_jtable[]; 161106866Sdeischen 162106866Sdeischen/* 163111618Snectar * yplib internal interfaces 164111618Snectar */ 165111618Snectar#ifdef YP 166111618Snectarint _yp_check(char **); 167111618Snectar#endif 168111618Snectar 169133754Sdfr/* 170133754Sdfr * Initialise TLS for static programs 171133754Sdfr */ 172133754Sdfrvoid _init_tls(void); 173111618Snectar 174111618Snectar/* 175199606Sjhb * Provides pthread_once()-like functionality for both single-threaded 176199606Sjhb * and multi-threaded applications. 177199606Sjhb */ 178199606Sjhbint _once(pthread_once_t *, void (*)(void)); 179199606Sjhb 180199606Sjhb/* 181133754Sdfr * Set the TLS thread pointer 182133754Sdfr */ 183133754Sdfrvoid _set_tp(void *tp); 184133754Sdfr 185133754Sdfr/* 18693399Smarkm * This is a pointer in the C run-time startup code. It is used 18793399Smarkm * by getprogname() and setprogname(). 18893399Smarkm */ 18993399Smarkmextern const char *__progname; 19093399Smarkm 191122069Sdeischen/* 192182225Sjasone * This function is used by the threading libraries to notify malloc that a 193182225Sjasone * thread is exiting. 194182225Sjasone */ 195182225Sjasonevoid _malloc_thread_cleanup(void); 196182225Sjasone 197182225Sjasone/* 198154248Sjasone * These functions are used by the threading libraries in order to protect 199154248Sjasone * malloc across fork(). 200122069Sdeischen */ 201154248Sjasonevoid _malloc_prefork(void); 202154248Sjasonevoid _malloc_postfork(void); 203122069Sdeischen 204150040Sstefanf/* 205150040Sstefanf * Function to clean up streams, called from abort() and exit(). 206150040Sstefanf */ 207150040Sstefanfextern void (*__cleanup)(void); 208150040Sstefanf 209171219Speter/* 210171219Speter * Get kern.osreldate to detect ABI revisions. Explicitly 211171219Speter * ignores value of $OSVERSION and caches result. Prototypes 212171219Speter * for the wrapped "new" pad-less syscalls are here for now. 213171219Speter */ 214171219Speterextern int __getosreldate(void); 215171219Speter#include <sys/_types.h> 216171219Speter/* Without pad */ 217171219Speterextern __off_t __sys_lseek(int, __off_t, int); 218171219Speterextern int __sys_ftruncate(int, __off_t); 219171219Speterextern int __sys_truncate(const char *, __off_t); 220171219Speterextern __ssize_t __sys_pread(int, void *, __size_t, __off_t); 221171219Speterextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); 222171219Speterextern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); 223171219Speter 224171219Speter/* With pad */ 225171219Speterextern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); 226171219Speterextern int __sys_freebsd6_ftruncate(int, int, __off_t); 227171219Speterextern int __sys_freebsd6_truncate(const char *, int, __off_t); 228171219Speterextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); 229171219Speterextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); 230171219Speterextern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); 231171219Speter 232177911Sdfr/* Without back-compat translation */ 233177911Sdfrextern int __sys_fcntl(int, int, ...); 234177911Sdfr 235179947Sed/* execve() with PATH processing to implement posix_spawnp() */ 236179947Sedint _execvpe(const char *, char * const *, char * const *); 237179947Sed 238211416Skibint _elf_aux_info(int aux, void *buf, int buflen); 239211706Skibstruct dl_phdr_info; 240211706Skibint __elf_phdr_match_addr(struct dl_phdr_info *, void *); 241231868Skibvoid __init_elf_aux_vector(void); 242211416Skib 243213153Sdavidxuvoid _pthread_cancel_enter(int); 244213153Sdavidxuvoid _pthread_cancel_leave(int); 245213153Sdavidxu 24635124Sjb#endif /* _LIBC_PRIVATE_H_ */ 247