dlfcn.h revision 153515
1103196Smike/*-
233236Sjdp * Copyright (c) 1994
333236Sjdp *	The Regents of the University of California.  All rights reserved.
433236Sjdp *
533236Sjdp * Redistribution and use in source and binary forms, with or without
633236Sjdp * modification, are permitted provided that the following conditions
733236Sjdp * are met:
833236Sjdp * 1. Redistributions of source code must retain the above copyright
933236Sjdp *    notice, this list of conditions and the following disclaimer.
1033236Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1133236Sjdp *    notice, this list of conditions and the following disclaimer in the
1233236Sjdp *    documentation and/or other materials provided with the distribution.
1333236Sjdp * 3. All advertising materials mentioning features or use of this software
1433236Sjdp *    must display the following acknowledgement:
1533236Sjdp *	This product includes software developed by the University of
1633236Sjdp *	California, Berkeley and its contributors.
1733236Sjdp * 4. Neither the name of the University nor the names of its contributors
1833236Sjdp *    may be used to endorse or promote products derived from this software
1933236Sjdp *    without specific prior written permission.
2033236Sjdp *
2133236Sjdp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2233236Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2333236Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2433236Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2533236Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2633236Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2733236Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2833236Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2933236Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3033236Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3133236Sjdp * SUCH DAMAGE.
3233236Sjdp *
3350473Speter * $FreeBSD: head/include/dlfcn.h 153515 2005-12-18 19:43:33Z kan $
3433236Sjdp */
3533236Sjdp
3633236Sjdp#ifndef _DLFCN_H_
3733236Sjdp#define	_DLFCN_H_
38103196Smike
39110804Skan#include <sys/_types.h>
4033236Sjdp
4133236Sjdp/*
4250603Sjdp * Modes and flags for dlopen().
4333236Sjdp */
44103196Smike#define	RTLD_LAZY	1	/* Bind function calls lazily. */
45103196Smike#define	RTLD_NOW	2	/* Bind function calls immediately. */
46103196Smike#define	RTLD_MODEMASK	0x3
47103196Smike#define	RTLD_GLOBAL	0x100	/* Make symbols globally available. */
48103196Smike#define	RTLD_LOCAL	0	/* Opposite of RTLD_GLOBAL, and the default. */
49103196Smike#define	RTLD_TRACE	0x200	/* Trace loaded objects and exit. */
5033236Sjdp
5133236Sjdp/*
52110804Skan * Request arguments for dlinfo().
5333236Sjdp */
54110804Skan#define	RTLD_DI_LINKMAP		2	/* Obtain link map. */
55110804Skan#define	RTLD_DI_SERINFO		4	/* Obtain search path info. */
56110804Skan#define	RTLD_DI_SERINFOSIZE	5	/*  ... query for required space. */
57110804Skan#define	RTLD_DI_ORIGIN		6	/* Obtain object origin */
58110804Skan#define	RTLD_DI_MAX		RTLD_DI_ORIGIN
59110804Skan
60110804Skan/*
61110804Skan * Special handle arguments for dlsym()/dlinfo().
62110804Skan */
63103196Smike#define	RTLD_NEXT	((void *) -1)	/* Search subsequent objects. */
64103196Smike#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
65110804Skan#define	RTLD_SELF	((void *) -3)	/* Search the caller itself. */
6633236Sjdp
67103212Smike#if __BSD_VISIBLE
68110804Skan
69110804Skan#ifndef	_SIZE_T_DECLARED
70110804Skantypedef __size_t        size_t;
71110804Skan#define	_SIZE_T_DECLARED
72110804Skan#endif
73110804Skan
7433236Sjdp/*
7533236Sjdp * Structure filled in by dladdr().
7633236Sjdp */
77103196Smiketypedef	struct dl_info {
78103196Smike	const char	*dli_fname;	/* Pathname of shared object. */
79103196Smike	void		*dli_fbase;	/* Base address of shared object. */
80103196Smike	const char	*dli_sname;	/* Name of nearest symbol. */
81103196Smike	void		*dli_saddr;	/* Address of nearest symbol. */
8233236Sjdp} Dl_info;
8333236Sjdp
84103196Smike/*-
8597475Swollman * The actual type declared by this typedef is immaterial, provided that
8697475Swollman * it is a function pointer.  Its purpose is to provide a return type for
8797475Swollman * dlfunc() which can be cast to a function pointer type without depending
8897475Swollman * on behavior undefined by the C standard, which might trigger a compiler
8997475Swollman * diagnostic.  We intentionally declare a unique type signature to force
9097475Swollman * a diagnostic should the application not cast the return value of dlfunc()
9197475Swollman * appropriately.
9297475Swollman */
9397475Swollmanstruct __dlfunc_arg {
94103196Smike	int	__dlfunc_dummy;
9597475Swollman};
9697475Swollman
97103196Smiketypedef	void (*dlfunc_t)(struct __dlfunc_arg);
9897475Swollman
99110804Skan/*
100110804Skan * Structures, returned by the RTLD_DI_SERINFO dlinfo() request.
101110804Skan */
102110804Skantypedef struct dl_serpath {
103110804Skan	char *		dls_name;	/* single search path entry */
104110804Skan	unsigned int	dls_flags;	/* path information */
105110804Skan} Dl_serpath;
106110804Skan
107110804Skantypedef struct  dl_serinfo {
108110804Skan        size_t		dls_size;       /* total buffer size */
109110804Skan        unsigned int	dls_cnt;        /* number of path entries */
110110804Skan        Dl_serpath	dls_serpath[1]; /* there may be more than one */
111110804Skan} Dl_serinfo;
112110804Skan
113103212Smike#endif /* __BSD_VISIBLE */
114103212Smike
11533236Sjdp__BEGIN_DECLS
116103196Smike/* XSI functions first. */
117103196Smikeint	 dlclose(void *);
118103196Smikeconst char *
119103196Smike	 dlerror(void);
120103196Smikevoid	*dlopen(const char *, int);
121103212Smikevoid	*dlsym(void * __restrict, const char * __restrict);
12297475Swollman
12397475Swollman#if __BSD_VISIBLE
124110804Skanint	 dladdr(const void * __restrict, Dl_info * __restrict);
125103212Smikedlfunc_t dlfunc(void * __restrict, const char * __restrict);
126110804Skanint	 dlinfo(void * __restrict, int, void * __restrict);
127103196Smikevoid	 dllockinit(void *_context,
128103196Smike	    void *(*_lock_create)(void *_context),
129103196Smike	    void (*_rlock_acquire)(void *_lock),
130103196Smike	    void (*_wlock_acquire)(void *_lock),
131103196Smike	    void (*_lock_release)(void *_lock),
132103196Smike	    void (*_lock_destroy)(void *_lock),
133103196Smike	    void (*_context_destroy)(void *_context));
134153515Skanvoid	*dlvsym(void * __restrict, const char * __restrict,
135153515Skan	    const char * __restrict);
13697475Swollman#endif /* __BSD_VISIBLE */
13733236Sjdp__END_DECLS
13833236Sjdp
13933236Sjdp#endif /* !_DLFCN_H_ */
140