dlfcn.h revision 190543
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 190543 2009-03-30 08:47:28Z kib $
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. */
50190543Skib#define	RTLD_NODELETE	0x01000	/* Do not remove members. */
5133236Sjdp
5233236Sjdp/*
53110804Skan * Request arguments for dlinfo().
5433236Sjdp */
55110804Skan#define	RTLD_DI_LINKMAP		2	/* Obtain link map. */
56110804Skan#define	RTLD_DI_SERINFO		4	/* Obtain search path info. */
57110804Skan#define	RTLD_DI_SERINFOSIZE	5	/*  ... query for required space. */
58110804Skan#define	RTLD_DI_ORIGIN		6	/* Obtain object origin */
59110804Skan#define	RTLD_DI_MAX		RTLD_DI_ORIGIN
60110804Skan
61110804Skan/*
62110804Skan * Special handle arguments for dlsym()/dlinfo().
63110804Skan */
64103196Smike#define	RTLD_NEXT	((void *) -1)	/* Search subsequent objects. */
65103196Smike#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
66110804Skan#define	RTLD_SELF	((void *) -3)	/* Search the caller itself. */
6733236Sjdp
68103212Smike#if __BSD_VISIBLE
69110804Skan
70110804Skan#ifndef	_SIZE_T_DECLARED
71110804Skantypedef __size_t        size_t;
72110804Skan#define	_SIZE_T_DECLARED
73110804Skan#endif
74110804Skan
7533236Sjdp/*
7633236Sjdp * Structure filled in by dladdr().
7733236Sjdp */
78103196Smiketypedef	struct dl_info {
79103196Smike	const char	*dli_fname;	/* Pathname of shared object. */
80103196Smike	void		*dli_fbase;	/* Base address of shared object. */
81103196Smike	const char	*dli_sname;	/* Name of nearest symbol. */
82103196Smike	void		*dli_saddr;	/* Address of nearest symbol. */
8333236Sjdp} Dl_info;
8433236Sjdp
85103196Smike/*-
8697475Swollman * The actual type declared by this typedef is immaterial, provided that
8797475Swollman * it is a function pointer.  Its purpose is to provide a return type for
8897475Swollman * dlfunc() which can be cast to a function pointer type without depending
8997475Swollman * on behavior undefined by the C standard, which might trigger a compiler
9097475Swollman * diagnostic.  We intentionally declare a unique type signature to force
9197475Swollman * a diagnostic should the application not cast the return value of dlfunc()
9297475Swollman * appropriately.
9397475Swollman */
9497475Swollmanstruct __dlfunc_arg {
95103196Smike	int	__dlfunc_dummy;
9697475Swollman};
9797475Swollman
98103196Smiketypedef	void (*dlfunc_t)(struct __dlfunc_arg);
9997475Swollman
100110804Skan/*
101110804Skan * Structures, returned by the RTLD_DI_SERINFO dlinfo() request.
102110804Skan */
103110804Skantypedef struct dl_serpath {
104110804Skan	char *		dls_name;	/* single search path entry */
105110804Skan	unsigned int	dls_flags;	/* path information */
106110804Skan} Dl_serpath;
107110804Skan
108110804Skantypedef struct  dl_serinfo {
109110804Skan        size_t		dls_size;       /* total buffer size */
110110804Skan        unsigned int	dls_cnt;        /* number of path entries */
111110804Skan        Dl_serpath	dls_serpath[1]; /* there may be more than one */
112110804Skan} Dl_serinfo;
113110804Skan
114103212Smike#endif /* __BSD_VISIBLE */
115103212Smike
11633236Sjdp__BEGIN_DECLS
117103196Smike/* XSI functions first. */
118103196Smikeint	 dlclose(void *);
119103196Smikeconst char *
120103196Smike	 dlerror(void);
121103196Smikevoid	*dlopen(const char *, int);
122103212Smikevoid	*dlsym(void * __restrict, const char * __restrict);
12397475Swollman
12497475Swollman#if __BSD_VISIBLE
125110804Skanint	 dladdr(const void * __restrict, Dl_info * __restrict);
126103212Smikedlfunc_t dlfunc(void * __restrict, const char * __restrict);
127110804Skanint	 dlinfo(void * __restrict, int, void * __restrict);
128103196Smikevoid	 dllockinit(void *_context,
129103196Smike	    void *(*_lock_create)(void *_context),
130103196Smike	    void (*_rlock_acquire)(void *_lock),
131103196Smike	    void (*_wlock_acquire)(void *_lock),
132103196Smike	    void (*_lock_release)(void *_lock),
133103196Smike	    void (*_lock_destroy)(void *_lock),
134103196Smike	    void (*_context_destroy)(void *_context));
135153515Skanvoid	*dlvsym(void * __restrict, const char * __restrict,
136153515Skan	    const char * __restrict);
13797475Swollman#endif /* __BSD_VISIBLE */
13833236Sjdp__END_DECLS
13933236Sjdp
14033236Sjdp#endif /* !_DLFCN_H_ */
141