libc_private.h revision 228843
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 228843 2011-12-23 15:00:37Z cperciva $ 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/* 47228843Scperciva * libc should use libc_dlopen internally, which respects a global 48228843Scperciva * flag where loading of new shared objects can be restricted. 49228843Scperciva */ 50228843Scpercivavoid *libc_dlopen(const char *, int); 51228843Scperciva 52228843Scperciva/* 53228843Scperciva * For dynamic linker. 54228843Scperciva */ 55228843Scpercivavoid _rtld_error(const char *fmt, ...); 56228843Scperciva 57228843Scperciva/* 5835124Sjb * File lock contention is difficult to diagnose without knowing 5935124Sjb * where locks were set. Allow a debug library to be built which 6035124Sjb * records the source file and line number of each lock call. 6135124Sjb */ 6235124Sjb#ifdef _FLOCK_DEBUG 6335124Sjb#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) 6435124Sjb#else 6571579Sdeischen#define _FLOCKFILE(x) _flockfile(x) 6635124Sjb#endif 6735124Sjb 6835124Sjb/* 6935124Sjb * Macros for locking and unlocking FILEs. These test if the 7035124Sjb * process is threaded to avoid locking when not required. 7135124Sjb */ 7235124Sjb#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) 7371579Sdeischen#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) 7435124Sjb 7593399Smarkm/* 76106866Sdeischen * Indexes into the pthread jump table. 77106866Sdeischen * 78106866Sdeischen * Warning! If you change this type, you must also change the threads 79106866Sdeischen * libraries that reference it (libc_r, libpthread). 80106866Sdeischen */ 81106866Sdeischentypedef enum { 82156319Sdeischen PJT_ATFORK, 83156319Sdeischen PJT_ATTR_DESTROY, 84156319Sdeischen PJT_ATTR_GETDETACHSTATE, 85156319Sdeischen PJT_ATTR_GETGUARDSIZE, 86156319Sdeischen PJT_ATTR_GETINHERITSCHED, 87156319Sdeischen PJT_ATTR_GETSCHEDPARAM, 88156319Sdeischen PJT_ATTR_GETSCHEDPOLICY, 89156319Sdeischen PJT_ATTR_GETSCOPE, 90156319Sdeischen PJT_ATTR_GETSTACKADDR, 91156319Sdeischen PJT_ATTR_GETSTACKSIZE, 92156319Sdeischen PJT_ATTR_INIT, 93156319Sdeischen PJT_ATTR_SETDETACHSTATE, 94156319Sdeischen PJT_ATTR_SETGUARDSIZE, 95156319Sdeischen PJT_ATTR_SETINHERITSCHED, 96156319Sdeischen PJT_ATTR_SETSCHEDPARAM, 97156319Sdeischen PJT_ATTR_SETSCHEDPOLICY, 98156319Sdeischen PJT_ATTR_SETSCOPE, 99156319Sdeischen PJT_ATTR_SETSTACKADDR, 100156319Sdeischen PJT_ATTR_SETSTACKSIZE, 101156319Sdeischen PJT_CANCEL, 102156319Sdeischen PJT_CLEANUP_POP, 103156319Sdeischen PJT_CLEANUP_PUSH, 104106866Sdeischen PJT_COND_BROADCAST, 105106866Sdeischen PJT_COND_DESTROY, 106106866Sdeischen PJT_COND_INIT, 107106866Sdeischen PJT_COND_SIGNAL, 108156319Sdeischen PJT_COND_TIMEDWAIT, 109106866Sdeischen PJT_COND_WAIT, 110156319Sdeischen PJT_DETACH, 111156319Sdeischen PJT_EQUAL, 112156319Sdeischen PJT_EXIT, 113106866Sdeischen PJT_GETSPECIFIC, 114156319Sdeischen PJT_JOIN, 115106866Sdeischen PJT_KEY_CREATE, 116106866Sdeischen PJT_KEY_DELETE, 117156319Sdeischen PJT_KILL, 118106866Sdeischen PJT_MAIN_NP, 119156319Sdeischen PJT_MUTEXATTR_DESTROY, 120156319Sdeischen PJT_MUTEXATTR_INIT, 121156319Sdeischen PJT_MUTEXATTR_SETTYPE, 122106866Sdeischen PJT_MUTEX_DESTROY, 123106866Sdeischen PJT_MUTEX_INIT, 124106866Sdeischen PJT_MUTEX_LOCK, 125106866Sdeischen PJT_MUTEX_TRYLOCK, 126106866Sdeischen PJT_MUTEX_UNLOCK, 127106866Sdeischen PJT_ONCE, 128106866Sdeischen PJT_RWLOCK_DESTROY, 129106866Sdeischen PJT_RWLOCK_INIT, 130106866Sdeischen PJT_RWLOCK_RDLOCK, 131106866Sdeischen PJT_RWLOCK_TRYRDLOCK, 132106866Sdeischen PJT_RWLOCK_TRYWRLOCK, 133106866Sdeischen PJT_RWLOCK_UNLOCK, 134106866Sdeischen PJT_RWLOCK_WRLOCK, 135106866Sdeischen PJT_SELF, 136156319Sdeischen PJT_SETCANCELSTATE, 137156319Sdeischen PJT_SETCANCELTYPE, 138106866Sdeischen PJT_SETSPECIFIC, 139106866Sdeischen PJT_SIGMASK, 140156319Sdeischen PJT_TESTCANCEL, 141201546Sdavidxu PJT_CLEANUP_POP_IMP, 142201546Sdavidxu PJT_CLEANUP_PUSH_IMP, 143213153Sdavidxu PJT_CANCEL_ENTER, 144213153Sdavidxu PJT_CANCEL_LEAVE, 145106866Sdeischen PJT_MAX 146106866Sdeischen} pjt_index_t; 147106866Sdeischen 148106870Sdeischentypedef int (*pthread_func_t)(void); 149106880Sdeischentypedef pthread_func_t pthread_func_entry_t[2]; 150106866Sdeischen 151106880Sdeischenextern pthread_func_entry_t __thr_jtable[]; 152106866Sdeischen 153106866Sdeischen/* 154111618Snectar * yplib internal interfaces 155111618Snectar */ 156111618Snectar#ifdef YP 157111618Snectarint _yp_check(char **); 158111618Snectar#endif 159111618Snectar 160133754Sdfr/* 161133754Sdfr * Initialise TLS for static programs 162133754Sdfr */ 163133754Sdfrvoid _init_tls(void); 164111618Snectar 165111618Snectar/* 166199606Sjhb * Provides pthread_once()-like functionality for both single-threaded 167199606Sjhb * and multi-threaded applications. 168199606Sjhb */ 169199606Sjhbint _once(pthread_once_t *, void (*)(void)); 170199606Sjhb 171199606Sjhb/* 172133754Sdfr * Set the TLS thread pointer 173133754Sdfr */ 174133754Sdfrvoid _set_tp(void *tp); 175133754Sdfr 176133754Sdfr/* 17793399Smarkm * This is a pointer in the C run-time startup code. It is used 17893399Smarkm * by getprogname() and setprogname(). 17993399Smarkm */ 18093399Smarkmextern const char *__progname; 18193399Smarkm 182122069Sdeischen/* 183182225Sjasone * This function is used by the threading libraries to notify malloc that a 184182225Sjasone * thread is exiting. 185182225Sjasone */ 186182225Sjasonevoid _malloc_thread_cleanup(void); 187182225Sjasone 188182225Sjasone/* 189154248Sjasone * These functions are used by the threading libraries in order to protect 190154248Sjasone * malloc across fork(). 191122069Sdeischen */ 192154248Sjasonevoid _malloc_prefork(void); 193154248Sjasonevoid _malloc_postfork(void); 194122069Sdeischen 195150040Sstefanf/* 196150040Sstefanf * Function to clean up streams, called from abort() and exit(). 197150040Sstefanf */ 198150040Sstefanfextern void (*__cleanup)(void); 199150040Sstefanf 200171219Speter/* 201171219Speter * Get kern.osreldate to detect ABI revisions. Explicitly 202171219Speter * ignores value of $OSVERSION and caches result. Prototypes 203171219Speter * for the wrapped "new" pad-less syscalls are here for now. 204171219Speter */ 205171219Speterextern int __getosreldate(void); 206171219Speter#include <sys/_types.h> 207171219Speter/* Without pad */ 208171219Speterextern __off_t __sys_lseek(int, __off_t, int); 209171219Speterextern int __sys_ftruncate(int, __off_t); 210171219Speterextern int __sys_truncate(const char *, __off_t); 211171219Speterextern __ssize_t __sys_pread(int, void *, __size_t, __off_t); 212171219Speterextern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); 213171219Speterextern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); 214171219Speter 215171219Speter/* With pad */ 216171219Speterextern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); 217171219Speterextern int __sys_freebsd6_ftruncate(int, int, __off_t); 218171219Speterextern int __sys_freebsd6_truncate(const char *, int, __off_t); 219171219Speterextern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); 220171219Speterextern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); 221171219Speterextern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); 222171219Speter 223177911Sdfr/* Without back-compat translation */ 224177911Sdfrextern int __sys_fcntl(int, int, ...); 225177911Sdfr 226179947Sed/* execve() with PATH processing to implement posix_spawnp() */ 227179947Sedint _execvpe(const char *, char * const *, char * const *); 228179947Sed 229211416Skibint _elf_aux_info(int aux, void *buf, int buflen); 230211706Skibstruct dl_phdr_info; 231211706Skibint __elf_phdr_match_addr(struct dl_phdr_info *, void *); 232211416Skib 233213153Sdavidxuvoid _pthread_cancel_enter(int); 234213153Sdavidxuvoid _pthread_cancel_leave(int); 235213153Sdavidxu 23635124Sjb#endif /* _LIBC_PRIVATE_H_ */ 237