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.
13203964Simp * 3. Neither the name of the University nor the names of its contributors
1433236Sjdp *    may be used to endorse or promote products derived from this software
1533236Sjdp *    without specific prior written permission.
1633236Sjdp *
1733236Sjdp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1833236Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1933236Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2033236Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2133236Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2233236Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2333236Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2433236Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2533236Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2633236Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2733236Sjdp * SUCH DAMAGE.
2833236Sjdp *
2950473Speter * $FreeBSD$
3033236Sjdp */
3133236Sjdp
3233236Sjdp#ifndef _DLFCN_H_
3333236Sjdp#define	_DLFCN_H_
34103196Smike
35110804Skan#include <sys/_types.h>
3633236Sjdp
3733236Sjdp/*
3850603Sjdp * Modes and flags for dlopen().
3933236Sjdp */
40103196Smike#define	RTLD_LAZY	1	/* Bind function calls lazily. */
41103196Smike#define	RTLD_NOW	2	/* Bind function calls immediately. */
42103196Smike#define	RTLD_MODEMASK	0x3
43103196Smike#define	RTLD_GLOBAL	0x100	/* Make symbols globally available. */
44103196Smike#define	RTLD_LOCAL	0	/* Opposite of RTLD_GLOBAL, and the default. */
45103196Smike#define	RTLD_TRACE	0x200	/* Trace loaded objects and exit. */
46190543Skib#define	RTLD_NODELETE	0x01000	/* Do not remove members. */
47195745Skib#define	RTLD_NOLOAD	0x02000	/* Do not load if not already loaded. */
4833236Sjdp
4933236Sjdp/*
50110804Skan * Request arguments for dlinfo().
5133236Sjdp */
52110804Skan#define	RTLD_DI_LINKMAP		2	/* Obtain link map. */
53110804Skan#define	RTLD_DI_SERINFO		4	/* Obtain search path info. */
54110804Skan#define	RTLD_DI_SERINFOSIZE	5	/*  ... query for required space. */
55110804Skan#define	RTLD_DI_ORIGIN		6	/* Obtain object origin */
56110804Skan#define	RTLD_DI_MAX		RTLD_DI_ORIGIN
57110804Skan
58110804Skan/*
59110804Skan * Special handle arguments for dlsym()/dlinfo().
60110804Skan */
61103196Smike#define	RTLD_NEXT	((void *) -1)	/* Search subsequent objects. */
62103196Smike#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
63110804Skan#define	RTLD_SELF	((void *) -3)	/* Search the caller itself. */
6433236Sjdp
65103212Smike#if __BSD_VISIBLE
66110804Skan
67110804Skan#ifndef	_SIZE_T_DECLARED
68110804Skantypedef __size_t        size_t;
69110804Skan#define	_SIZE_T_DECLARED
70110804Skan#endif
71110804Skan
7233236Sjdp/*
7333236Sjdp * Structure filled in by dladdr().
7433236Sjdp */
75103196Smiketypedef	struct dl_info {
76103196Smike	const char	*dli_fname;	/* Pathname of shared object. */
77103196Smike	void		*dli_fbase;	/* Base address of shared object. */
78103196Smike	const char	*dli_sname;	/* Name of nearest symbol. */
79103196Smike	void		*dli_saddr;	/* Address of nearest symbol. */
8033236Sjdp} Dl_info;
8133236Sjdp
82103196Smike/*-
8397475Swollman * The actual type declared by this typedef is immaterial, provided that
8497475Swollman * it is a function pointer.  Its purpose is to provide a return type for
8597475Swollman * dlfunc() which can be cast to a function pointer type without depending
8697475Swollman * on behavior undefined by the C standard, which might trigger a compiler
8797475Swollman * diagnostic.  We intentionally declare a unique type signature to force
8897475Swollman * a diagnostic should the application not cast the return value of dlfunc()
8997475Swollman * appropriately.
9097475Swollman */
9197475Swollmanstruct __dlfunc_arg {
92103196Smike	int	__dlfunc_dummy;
9397475Swollman};
9497475Swollman
95103196Smiketypedef	void (*dlfunc_t)(struct __dlfunc_arg);
9697475Swollman
97110804Skan/*
98110804Skan * Structures, returned by the RTLD_DI_SERINFO dlinfo() request.
99110804Skan */
100110804Skantypedef struct dl_serpath {
101110804Skan	char *		dls_name;	/* single search path entry */
102110804Skan	unsigned int	dls_flags;	/* path information */
103110804Skan} Dl_serpath;
104110804Skan
105110804Skantypedef struct  dl_serinfo {
106110804Skan        size_t		dls_size;       /* total buffer size */
107110804Skan        unsigned int	dls_cnt;        /* number of path entries */
108110804Skan        Dl_serpath	dls_serpath[1]; /* there may be more than one */
109110804Skan} Dl_serinfo;
110110804Skan
111103212Smike#endif /* __BSD_VISIBLE */
112103212Smike
11333236Sjdp__BEGIN_DECLS
114103196Smike/* XSI functions first. */
115103196Smikeint	 dlclose(void *);
116205606Sgahrchar	*dlerror(void);
117103196Smikevoid	*dlopen(const char *, int);
118103212Smikevoid	*dlsym(void * __restrict, const char * __restrict);
11997475Swollman
12097475Swollman#if __BSD_VISIBLE
121229768Skibvoid	*fdlopen(int, int);
122110804Skanint	 dladdr(const void * __restrict, Dl_info * __restrict);
123103212Smikedlfunc_t dlfunc(void * __restrict, const char * __restrict);
124110804Skanint	 dlinfo(void * __restrict, int, void * __restrict);
125103196Smikevoid	 dllockinit(void *_context,
126103196Smike	    void *(*_lock_create)(void *_context),
127103196Smike	    void (*_rlock_acquire)(void *_lock),
128103196Smike	    void (*_wlock_acquire)(void *_lock),
129103196Smike	    void (*_lock_release)(void *_lock),
130103196Smike	    void (*_lock_destroy)(void *_lock),
131103196Smike	    void (*_context_destroy)(void *_context));
132153515Skanvoid	*dlvsym(void * __restrict, const char * __restrict,
133153515Skan	    const char * __restrict);
13497475Swollman#endif /* __BSD_VISIBLE */
13533236Sjdp__END_DECLS
13633236Sjdp
13733236Sjdp#endif /* !_DLFCN_H_ */
138