1998-04-11 06:57:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2007-01-12 07:31:30 +00:00
|
|
|
* 3. Neither the name of the author nor the names of any co-contributors
|
1998-04-11 06:57:33 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1998-04-11 06:57:33 +00:00
|
|
|
*
|
|
|
|
* Private definitions for libc, libc_r and libpthread.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBC_PRIVATE_H_
|
|
|
|
#define _LIBC_PRIVATE_H_
|
2009-11-20 19:19:51 +00:00
|
|
|
#include <sys/_pthreadtypes.h>
|
1998-04-11 06:57:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This global flag is non-zero when a process has created one
|
|
|
|
* or more threads. It is used to avoid calling locking functions
|
|
|
|
* when they are not required.
|
|
|
|
*/
|
|
|
|
extern int __isthreaded;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File lock contention is difficult to diagnose without knowing
|
|
|
|
* where locks were set. Allow a debug library to be built which
|
|
|
|
* records the source file and line number of each lock call.
|
|
|
|
*/
|
|
|
|
#ifdef _FLOCK_DEBUG
|
|
|
|
#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__)
|
|
|
|
#else
|
2001-01-24 13:01:12 +00:00
|
|
|
#define _FLOCKFILE(x) _flockfile(x)
|
1998-04-11 06:57:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for locking and unlocking FILEs. These test if the
|
|
|
|
* process is threaded to avoid locking when not required.
|
|
|
|
*/
|
|
|
|
#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp)
|
2001-01-24 13:01:12 +00:00
|
|
|
#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp)
|
1998-04-11 06:57:33 +00:00
|
|
|
|
2002-11-13 18:12:09 +00:00
|
|
|
/*
|
|
|
|
* Indexes into the pthread jump table.
|
|
|
|
*
|
|
|
|
* Warning! If you change this type, you must also change the threads
|
|
|
|
* libraries that reference it (libc_r, libpthread).
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_ATFORK,
|
|
|
|
PJT_ATTR_DESTROY,
|
|
|
|
PJT_ATTR_GETDETACHSTATE,
|
|
|
|
PJT_ATTR_GETGUARDSIZE,
|
|
|
|
PJT_ATTR_GETINHERITSCHED,
|
|
|
|
PJT_ATTR_GETSCHEDPARAM,
|
|
|
|
PJT_ATTR_GETSCHEDPOLICY,
|
|
|
|
PJT_ATTR_GETSCOPE,
|
|
|
|
PJT_ATTR_GETSTACKADDR,
|
|
|
|
PJT_ATTR_GETSTACKSIZE,
|
|
|
|
PJT_ATTR_INIT,
|
|
|
|
PJT_ATTR_SETDETACHSTATE,
|
|
|
|
PJT_ATTR_SETGUARDSIZE,
|
|
|
|
PJT_ATTR_SETINHERITSCHED,
|
|
|
|
PJT_ATTR_SETSCHEDPARAM,
|
|
|
|
PJT_ATTR_SETSCHEDPOLICY,
|
|
|
|
PJT_ATTR_SETSCOPE,
|
|
|
|
PJT_ATTR_SETSTACKADDR,
|
|
|
|
PJT_ATTR_SETSTACKSIZE,
|
|
|
|
PJT_CANCEL,
|
|
|
|
PJT_CLEANUP_POP,
|
|
|
|
PJT_CLEANUP_PUSH,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_COND_BROADCAST,
|
|
|
|
PJT_COND_DESTROY,
|
|
|
|
PJT_COND_INIT,
|
|
|
|
PJT_COND_SIGNAL,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_COND_TIMEDWAIT,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_COND_WAIT,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_DETACH,
|
|
|
|
PJT_EQUAL,
|
|
|
|
PJT_EXIT,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_GETSPECIFIC,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_JOIN,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_KEY_CREATE,
|
|
|
|
PJT_KEY_DELETE,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_KILL,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_MAIN_NP,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_MUTEXATTR_DESTROY,
|
|
|
|
PJT_MUTEXATTR_INIT,
|
|
|
|
PJT_MUTEXATTR_SETTYPE,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_MUTEX_DESTROY,
|
|
|
|
PJT_MUTEX_INIT,
|
|
|
|
PJT_MUTEX_LOCK,
|
|
|
|
PJT_MUTEX_TRYLOCK,
|
|
|
|
PJT_MUTEX_UNLOCK,
|
|
|
|
PJT_ONCE,
|
|
|
|
PJT_RWLOCK_DESTROY,
|
|
|
|
PJT_RWLOCK_INIT,
|
|
|
|
PJT_RWLOCK_RDLOCK,
|
|
|
|
PJT_RWLOCK_TRYRDLOCK,
|
|
|
|
PJT_RWLOCK_TRYWRLOCK,
|
|
|
|
PJT_RWLOCK_UNLOCK,
|
|
|
|
PJT_RWLOCK_WRLOCK,
|
|
|
|
PJT_SELF,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_SETCANCELSTATE,
|
|
|
|
PJT_SETCANCELTYPE,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_SETSPECIFIC,
|
|
|
|
PJT_SIGMASK,
|
2006-03-05 18:10:28 +00:00
|
|
|
PJT_TESTCANCEL,
|
Use umtx to implement process sharable semaphore, to make this work,
now type sema_t is a structure which can be put in a shared memory area,
and multiple processes can operate it concurrently.
User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open()
to initialize a shared semaphore.
Named semaphore uses file system and is located in /tmp directory, and its
file name is prefixed with 'SEMD', so now it is chroot or jail friendly.
In simplist cases, both for named and un-named semaphore, userland code
does not have to enter kernel to reduce/increase semaphore's count.
The semaphore is designed to be crash-safe, it means even if an application
is crashed in the middle of operating semaphore, the semaphore state is
still safely recovered by later use, there is no waiter counter maintained
by userland code.
The main semaphore code is in libc and libthr only has some necessary stubs,
this makes it possible that a non-threaded application can use semaphore
without linking to thread library.
Old semaphore implementation is kept libc to maintain binary compatibility.
The kernel ksem API is no longer used in the new implemenation.
Discussed on: threads@
2010-01-05 02:37:59 +00:00
|
|
|
PJT_CLEANUP_POP_IMP,
|
|
|
|
PJT_CLEANUP_PUSH_IMP,
|
2002-11-13 18:12:09 +00:00
|
|
|
PJT_MAX
|
|
|
|
} pjt_index_t;
|
|
|
|
|
2002-11-13 19:35:40 +00:00
|
|
|
typedef int (*pthread_func_t)(void);
|
2002-11-13 21:55:22 +00:00
|
|
|
typedef pthread_func_t pthread_func_entry_t[2];
|
2002-11-13 18:12:09 +00:00
|
|
|
|
2002-11-13 21:55:22 +00:00
|
|
|
extern pthread_func_entry_t __thr_jtable[];
|
2002-11-13 18:12:09 +00:00
|
|
|
|
2003-02-27 13:40:01 +00:00
|
|
|
/*
|
|
|
|
* yplib internal interfaces
|
|
|
|
*/
|
|
|
|
#ifdef YP
|
|
|
|
int _yp_check(char **);
|
|
|
|
#endif
|
|
|
|
|
2004-08-15 16:18:52 +00:00
|
|
|
/*
|
|
|
|
* Initialise TLS for static programs
|
|
|
|
*/
|
|
|
|
void _init_tls(void);
|
|
|
|
|
2009-11-20 19:19:51 +00:00
|
|
|
/*
|
|
|
|
* Provides pthread_once()-like functionality for both single-threaded
|
|
|
|
* and multi-threaded applications.
|
|
|
|
*/
|
|
|
|
int _once(pthread_once_t *, void (*)(void));
|
|
|
|
|
2004-08-15 16:18:52 +00:00
|
|
|
/*
|
|
|
|
* Set the TLS thread pointer
|
|
|
|
*/
|
|
|
|
void _set_tp(void *tp);
|
2003-02-27 13:40:01 +00:00
|
|
|
|
2002-03-29 22:43:43 +00:00
|
|
|
/*
|
|
|
|
* This is a pointer in the C run-time startup code. It is used
|
|
|
|
* by getprogname() and setprogname().
|
|
|
|
*/
|
|
|
|
extern const char *__progname;
|
|
|
|
|
Add thread-specific caching for small size classes, based on magazines.
This caching allows for completely lock-free allocation/deallocation in the
steady state, at the expense of likely increased memory use and
fragmentation.
Reduce the default number of arenas to 2*ncpus, since thread-specific
caching typically reduces arena contention.
Modify size class spacing to include ranges of 2^n-spaced, quantum-spaced,
cacheline-spaced, and subpage-spaced size classes. The advantages are:
fewer size classes, reduced false cacheline sharing, and reduced internal
fragmentation for allocations that are slightly over 512, 1024, etc.
Increase RUN_MAX_SMALL, in order to limit fragmentation for the
subpage-spaced size classes.
Add a size-->bin lookup table for small sizes to simplify translating sizes
to size classes. Include a hard-coded constant table that is used unless
custom size class spacing is specified at run time.
Add the ability to disable tiny size classes at compile time via
MALLOC_TINY.
2008-08-27 02:00:53 +00:00
|
|
|
/*
|
|
|
|
* This function is used by the threading libraries to notify malloc that a
|
|
|
|
* thread is exiting.
|
|
|
|
*/
|
|
|
|
void _malloc_thread_cleanup(void);
|
|
|
|
|
2003-11-04 19:49:56 +00:00
|
|
|
/*
|
2006-01-12 07:28:21 +00:00
|
|
|
* These functions are used by the threading libraries in order to protect
|
|
|
|
* malloc across fork().
|
2003-11-04 19:49:56 +00:00
|
|
|
*/
|
2006-01-12 07:28:21 +00:00
|
|
|
void _malloc_prefork(void);
|
|
|
|
void _malloc_postfork(void);
|
2003-11-04 19:49:56 +00:00
|
|
|
|
2005-09-12 13:46:32 +00:00
|
|
|
/*
|
|
|
|
* Function to clean up streams, called from abort() and exit().
|
|
|
|
*/
|
|
|
|
extern void (*__cleanup)(void);
|
|
|
|
|
2007-07-04 23:27:38 +00:00
|
|
|
/*
|
|
|
|
* Get kern.osreldate to detect ABI revisions. Explicitly
|
|
|
|
* ignores value of $OSVERSION and caches result. Prototypes
|
|
|
|
* for the wrapped "new" pad-less syscalls are here for now.
|
|
|
|
*/
|
|
|
|
extern int __getosreldate(void);
|
|
|
|
#include <sys/_types.h>
|
|
|
|
/* Without pad */
|
|
|
|
extern __off_t __sys_lseek(int, __off_t, int);
|
|
|
|
extern int __sys_ftruncate(int, __off_t);
|
|
|
|
extern int __sys_truncate(const char *, __off_t);
|
|
|
|
extern __ssize_t __sys_pread(int, void *, __size_t, __off_t);
|
|
|
|
extern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
|
|
|
|
extern void * __sys_mmap(void *, __size_t, int, int, int, __off_t);
|
|
|
|
|
|
|
|
/* With pad */
|
|
|
|
extern __off_t __sys_freebsd6_lseek(int, int, __off_t, int);
|
|
|
|
extern int __sys_freebsd6_ftruncate(int, int, __off_t);
|
|
|
|
extern int __sys_freebsd6_truncate(const char *, int, __off_t);
|
|
|
|
extern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t);
|
|
|
|
extern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t);
|
|
|
|
extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t);
|
|
|
|
|
2008-04-04 09:43:03 +00:00
|
|
|
/* Without back-compat translation */
|
|
|
|
extern int __sys_fcntl(int, int, ...);
|
|
|
|
|
2008-06-23 05:22:06 +00:00
|
|
|
/* execve() with PATH processing to implement posix_spawnp() */
|
|
|
|
int _execvpe(const char *, char * const *, char * const *);
|
|
|
|
|
1998-04-11 06:57:33 +00:00
|
|
|
#endif /* _LIBC_PRIVATE_H_ */
|