diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/gen/dlfcn.c | 14 | ||||
-rw-r--r-- | lib/libc/gen/dllockinit.3 | 109 |
3 files changed, 124 insertions, 1 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 9a23677..a193cc2 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -34,7 +34,7 @@ SRCS+= _rand48.c _spinlock_stub.c alarm.c arc4random.c assert.c \ .if ${LIB} == "c" MAN3+= alarm.3 arc4random.3 clock.3 \ confstr.3 crypt.3 ctermid.3 daemon.3 \ - devname.3 directory.3 dladdr.3 dlopen.3 \ + devname.3 directory.3 dladdr.3 dllockinit.3 dlopen.3 \ err.3 exec.3 fnmatch.3 frexp.3 ftok.3 fts.3 \ getbootfile.3 getbsize.3 getcap.3 getcwd.3 \ getdiskbyname.3 getdomainname.3 getfsent.3 \ diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c index ff77b79..fd0be34 100644 --- a/lib/libc/gen/dlfcn.c +++ b/lib/libc/gen/dlfcn.c @@ -78,6 +78,20 @@ dlerror(void) return sorry; } +#pragma weak dllockinit +void +dllockinit(void *context, + void *(*lock_create)(void *context), + void (*rlock_acquire)(void *lock), + void (*wlock_acquire)(void *lock), + void (*lock_release)(void *lock), + void (*lock_destroy)(void *lock), + void (*context_destroy)(void *context)) +{ + if (context_destroy != NULL) + context_destroy(context); +} + #pragma weak dlopen void * dlopen(const char *name, int mode) diff --git a/lib/libc/gen/dllockinit.3 b/lib/libc/gen/dllockinit.3 new file mode 100644 index 0000000..facb18b --- /dev/null +++ b/lib/libc/gen/dllockinit.3 @@ -0,0 +1,109 @@ +.\" +.\" Copyright (c) 1999 John D. Polstra +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd December 26, 1999 +.Os FreeBSD +.Dt DLLOCKINIT 3 +.Sh NAME +.Nm dllockinit +.Nd register thread locking methods with the dynamic linker +.Sh SYNOPSIS +.Fd #include <dlfcn.h> +.Ft void +.Fn dllockinit "const void *context" "void *(*lock_create)(void *context)" \ +"void (*rlock_acquire)(void *lock)" "void (*wlock_acquire)(void *lock)" \ +"void (*lock_release)(void *lock)" "void (*lock_destroy)(void *lock)" \ +"void (*context_destroy)(void *context)" +.Sh DESCRIPTION +Threads packages can call +.Nm +at initialization time to register locking functions for the dynamic +linker to use. This enables the dynamic linker to prevent multiple +threads from entering its critical sections simultaneously. +.Pp +The +.Fa context +parameter specifies an opaque context for creating locks. The +dynamic linker will pass it to the +.Fa lock_create +function when creating the locks it needs. When the dynamic linker +is permanently finished using the locking functions (e.g., if the +program makes a subsequent call to +.Nm +to register new locking functions) it will call +.Fa context_destroy +to destroy the context. +.Pp +The +.Fa lock_create +parameter specifies a function for creating a read/write lock. It +must return a pointer to the new lock. +.Pp +The +.Fa rlock_acquire +and +.Fa wlock_acquire +parameters specify functions which lock a lock for reading or +writing, respectively. The +.Fa lock_release +parameter specifies a function which unlocks a lock. Each of these +functions is passed a pointer to the lock. +.Pp +The +.Fa lock_destroy +parameter specifies a function to destroy a lock. It may be +.Dv NULL +if locks do not need to be destroyed. The +.Fa context_destroy +specifies a function to destroy the context. It may be +.Dv NULL +if the context does not need to be destroyed. +.Pp +Before +.Nm +is called, the dynamic linker protects its critical sections by +blocking the +.Dv SIGVTALRM , +.Dv SIGPROF , +and +.Dv SIGALRM +signals. This is sufficient for many application level threads +packages, which typically use one of these signals to implement +preemption. An application which has registered its own locking +methods with +.Nm +can restore the default locking by calling +.Nm +with all arguments +.Dv NULL . +.Sh SEE ALSO +.Xr rtld 1 , +.Xr signal 3 +.Sh HISTORY +The +.Nm +function first appeared in FreeBSD 4.0. |