dlfcn.h revision 195745
1275970Scy/*- 2275970Scy * Copyright (c) 1994 3275970Scy * The Regents of the University of California. All rights reserved. 4275970Scy * 5275970Scy * Redistribution and use in source and binary forms, with or without 6275970Scy * modification, are permitted provided that the following conditions 7275970Scy * are met: 8275970Scy * 1. Redistributions of source code must retain the above copyright 9275970Scy * notice, this list of conditions and the following disclaimer. 10275970Scy * 2. Redistributions in binary form must reproduce the above copyright 11275970Scy * notice, this list of conditions and the following disclaimer in the 12275970Scy * documentation and/or other materials provided with the distribution. 13275970Scy * 3. All advertising materials mentioning features or use of this software 14275970Scy * must display the following acknowledgement: 15275970Scy * This product includes software developed by the University of 16275970Scy * California, Berkeley and its contributors. 17275970Scy * 4. Neither the name of the University nor the names of its contributors 18275970Scy * may be used to endorse or promote products derived from this software 19275970Scy * without specific prior written permission. 20275970Scy * 21275970Scy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22275970Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23275970Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25275970Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26275970Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27275970Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28275970Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31275970Scy * SUCH DAMAGE. 32275970Scy * 33275970Scy * $FreeBSD: head/include/dlfcn.h 195745 2009-07-17 19:45:42Z kib $ 34275970Scy */ 35275970Scy 36275970Scy#ifndef _DLFCN_H_ 37275970Scy#define _DLFCN_H_ 38275970Scy 39275970Scy#include <sys/_types.h> 40275970Scy 41275970Scy/* 42275970Scy * Modes and flags for dlopen(). 43275970Scy */ 44275970Scy#define RTLD_LAZY 1 /* Bind function calls lazily. */ 45275970Scy#define RTLD_NOW 2 /* Bind function calls immediately. */ 46275970Scy#define RTLD_MODEMASK 0x3 47275970Scy#define RTLD_GLOBAL 0x100 /* Make symbols globally available. */ 48275970Scy#define RTLD_LOCAL 0 /* Opposite of RTLD_GLOBAL, and the default. */ 49275970Scy#define RTLD_TRACE 0x200 /* Trace loaded objects and exit. */ 50275970Scy#define RTLD_NODELETE 0x01000 /* Do not remove members. */ 51275970Scy#define RTLD_NOLOAD 0x02000 /* Do not load if not already loaded. */ 52275970Scy 53275970Scy/* 54275970Scy * Request arguments for dlinfo(). 55275970Scy */ 56275970Scy#define RTLD_DI_LINKMAP 2 /* Obtain link map. */ 57275970Scy#define RTLD_DI_SERINFO 4 /* Obtain search path info. */ 58275970Scy#define RTLD_DI_SERINFOSIZE 5 /* ... query for required space. */ 59275970Scy#define RTLD_DI_ORIGIN 6 /* Obtain object origin */ 60275970Scy#define RTLD_DI_MAX RTLD_DI_ORIGIN 61275970Scy 62275970Scy/* 63275970Scy * Special handle arguments for dlsym()/dlinfo(). 64275970Scy */ 65275970Scy#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ 66275970Scy#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ 67275970Scy#define RTLD_SELF ((void *) -3) /* Search the caller itself. */ 68275970Scy 69275970Scy#if __BSD_VISIBLE 70275970Scy 71275970Scy#ifndef _SIZE_T_DECLARED 72275970Scytypedef __size_t size_t; 73275970Scy#define _SIZE_T_DECLARED 74275970Scy#endif 75275970Scy 76275970Scy/* 77275970Scy * Structure filled in by dladdr(). 78275970Scy */ 79275970Scytypedef struct dl_info { 80275970Scy const char *dli_fname; /* Pathname of shared object. */ 81275970Scy void *dli_fbase; /* Base address of shared object. */ 82275970Scy const char *dli_sname; /* Name of nearest symbol. */ 83275970Scy void *dli_saddr; /* Address of nearest symbol. */ 84275970Scy} Dl_info; 85275970Scy 86275970Scy/*- 87275970Scy * The actual type declared by this typedef is immaterial, provided that 88275970Scy * it is a function pointer. Its purpose is to provide a return type for 89275970Scy * dlfunc() which can be cast to a function pointer type without depending 90275970Scy * on behavior undefined by the C standard, which might trigger a compiler 91275970Scy * diagnostic. We intentionally declare a unique type signature to force 92275970Scy * a diagnostic should the application not cast the return value of dlfunc() 93275970Scy * appropriately. 94275970Scy */ 95275970Scystruct __dlfunc_arg { 96275970Scy int __dlfunc_dummy; 97275970Scy}; 98275970Scy 99275970Scytypedef void (*dlfunc_t)(struct __dlfunc_arg); 100275970Scy 101275970Scy/* 102275970Scy * Structures, returned by the RTLD_DI_SERINFO dlinfo() request. 103275970Scy */ 104275970Scytypedef struct dl_serpath { 105275970Scy char * dls_name; /* single search path entry */ 106275970Scy unsigned int dls_flags; /* path information */ 107275970Scy} Dl_serpath; 108275970Scy 109275970Scytypedef struct dl_serinfo { 110275970Scy size_t dls_size; /* total buffer size */ 111275970Scy unsigned int dls_cnt; /* number of path entries */ 112275970Scy Dl_serpath dls_serpath[1]; /* there may be more than one */ 113275970Scy} Dl_serinfo; 114275970Scy 115275970Scy#endif /* __BSD_VISIBLE */ 116275970Scy 117275970Scy__BEGIN_DECLS 118275970Scy/* XSI functions first. */ 119275970Scyint dlclose(void *); 120275970Scyconst char * 121275970Scy dlerror(void); 122275970Scyvoid *dlopen(const char *, int); 123275970Scyvoid *dlsym(void * __restrict, const char * __restrict); 124275970Scy 125275970Scy#if __BSD_VISIBLE 126275970Scyint dladdr(const void * __restrict, Dl_info * __restrict); 127275970Scydlfunc_t dlfunc(void * __restrict, const char * __restrict); 128275970Scyint dlinfo(void * __restrict, int, void * __restrict); 129275970Scyvoid dllockinit(void *_context, 130275970Scy void *(*_lock_create)(void *_context), 131275970Scy void (*_rlock_acquire)(void *_lock), 132275970Scy void (*_wlock_acquire)(void *_lock), 133275970Scy void (*_lock_release)(void *_lock), 134275970Scy void (*_lock_destroy)(void *_lock), 135275970Scy void (*_context_destroy)(void *_context)); 136275970Scyvoid *dlvsym(void * __restrict, const char * __restrict, 137275970Scy const char * __restrict); 138275970Scy#endif /* __BSD_VISIBLE */ 139275970Scy__END_DECLS 140275970Scy 141275970Scy#endif /* !_DLFCN_H_ */ 142275970Scy