xref: /illumos-gate/usr/src/head/dlfcn.h (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5959ee943SRod Evans  * Common Development and Distribution License (the "License").
6959ee943SRod Evans  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23f441771bSRod Evans  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  *	Copyright (c) 1989 AT&T
267c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _DLFCN_H
317c478bd9Sstevel@tonic-gate #define	_DLFCN_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
3580b8e1d8Srie #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
3641072f3cSrie #include <sys/auxv.h>
37959ee943SRod Evans #include <sys/mman.h>
3880b8e1d8Srie #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
4541072f3cSrie  * Information structures for various dlinfo() requests.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
487c478bd9Sstevel@tonic-gate typedef struct	dl_info {
497c478bd9Sstevel@tonic-gate 	const char	*dli_fname;	/* file containing address range */
507c478bd9Sstevel@tonic-gate 	void		*dli_fbase;	/* base address of file image */
517c478bd9Sstevel@tonic-gate 	const char	*dli_sname;	/* symbol name */
527c478bd9Sstevel@tonic-gate 	void		*dli_saddr;	/* symbol address */
537c478bd9Sstevel@tonic-gate } Dl_info;
54959ee943SRod Evans typedef	Dl_info		Dl_info_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate typedef struct	dl_serpath {
577c478bd9Sstevel@tonic-gate 	char		*dls_name;	/* library search path name */
587c478bd9Sstevel@tonic-gate 	uint_t		dls_flags;	/* path information */
597c478bd9Sstevel@tonic-gate } Dl_serpath;
60959ee943SRod Evans typedef	Dl_serpath	Dl_serpath_t;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct	dl_serinfo {
637c478bd9Sstevel@tonic-gate 	size_t		dls_size;	/* total buffer size */
647c478bd9Sstevel@tonic-gate 	uint_t		dls_cnt;	/* number of path entries */
657c478bd9Sstevel@tonic-gate 	Dl_serpath	dls_serpath[1];	/* there may be more than one */
667c478bd9Sstevel@tonic-gate } Dl_serinfo;
67959ee943SRod Evans typedef	Dl_serinfo	Dl_serinfo_t;
68959ee943SRod Evans 
69959ee943SRod Evans typedef struct	dl_argsinfo {
70959ee943SRod Evans 	long		dla_argc;	/* process argument count */
71959ee943SRod Evans 	char		**dla_argv;	/* process arguments */
72959ee943SRod Evans 	char		**dla_envp;	/* process environment variables */
73959ee943SRod Evans 	auxv_t		*dla_auxv;	/* process auxv vectors */
74959ee943SRod Evans } Dl_argsinfo;
75959ee943SRod Evans typedef	Dl_argsinfo	Dl_argsinfo_t;
76959ee943SRod Evans 
77959ee943SRod Evans typedef struct {
78959ee943SRod Evans 	mmapobj_result_t *dlm_maps;	/* mapping information */
79959ee943SRod Evans 	uint_t		dlm_acnt;	/* number of dlm_maps mappings */
80959ee943SRod Evans 	uint_t		dlm_rcnt;	/* number of returned mappings */
81959ee943SRod Evans } Dl_mapinfo_t;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate typedef struct {
847c478bd9Sstevel@tonic-gate 	uint_t		dlui_version;	/* version # */
857c478bd9Sstevel@tonic-gate 	uint_t		dlui_flags;	/* flags */
867c478bd9Sstevel@tonic-gate 	char		*dlui_objname;	/* path to object */
877c478bd9Sstevel@tonic-gate 	void		*dlui_unwindstart; /* star of unwind hdr */
887c478bd9Sstevel@tonic-gate 	void		*dlui_unwindend; /* end of unwind hdr */
897c478bd9Sstevel@tonic-gate 	void		*dlui_segstart;	/* start of segment described */
907c478bd9Sstevel@tonic-gate 					/*  by unwind block */
917c478bd9Sstevel@tonic-gate 	void		*dlui_segend;	/* end of segment described */
927c478bd9Sstevel@tonic-gate 					/*  by unwind block */
937c478bd9Sstevel@tonic-gate } Dl_amd64_unwindinfo;
94959ee943SRod Evans typedef	Dl_amd64_unwindinfo	Dl_amd64_unwindinfo_t;
9541072f3cSrie 
96f441771bSRod Evans typedef	struct {
97f441771bSRod Evans 	const char	*dld_refname;	/* reference name */
98f441771bSRod Evans 	const char	*dld_depname;	/* new dependency name */
99f441771bSRod Evans } Dl_definfo_t;
100f441771bSRod Evans 
1017c478bd9Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate typedef ulong_t		Lmid_t;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Declarations used for dynamic linking support routines.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate extern void	*dlopen(const char *, int);
1107c478bd9Sstevel@tonic-gate extern void	*dlsym(void *_RESTRICT_KYWD, const char *_RESTRICT_KYWD);
1117c478bd9Sstevel@tonic-gate extern int	dlclose(void *);
1127c478bd9Sstevel@tonic-gate extern char	*dlerror(void);
1137c478bd9Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
1147c478bd9Sstevel@tonic-gate extern void	*dlmopen(Lmid_t, const char *, int);
1157c478bd9Sstevel@tonic-gate extern int	dladdr(void *, Dl_info *);
1167c478bd9Sstevel@tonic-gate extern int	dladdr1(void *, Dl_info *, void **, int);
1177c478bd9Sstevel@tonic-gate extern int	dldump(const char *, const char *, int);
1187c478bd9Sstevel@tonic-gate extern int	dlinfo(void *, int, void *);
1197c478bd9Sstevel@tonic-gate extern Dl_amd64_unwindinfo  *dlamd64getunwind(void *, Dl_amd64_unwindinfo *);
1207c478bd9Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(dlopen, dlsym, dlclose, dlerror)
1237c478bd9Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
1247c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(dlmopen, dladdr, dladdr1, dldump, dlinfo)
1257c478bd9Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
128*bbf21555SRichard Lowe  * Valid values for handle argument to dlsym(3C).
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate #define	RTLD_NEXT		(void *)-1	/* look in `next' dependency */
1317c478bd9Sstevel@tonic-gate #define	RTLD_DEFAULT		(void *)-2	/* look up symbol from scope */
1327c478bd9Sstevel@tonic-gate 						/*	of current object */
1337c478bd9Sstevel@tonic-gate #define	RTLD_SELF		(void *)-3	/* look in `ourself' */
1347c478bd9Sstevel@tonic-gate #define	RTLD_PROBE		(void *)-4	/* look up symbol from scope */
1357c478bd9Sstevel@tonic-gate 						/*	of current object, */
1367c478bd9Sstevel@tonic-gate 						/*	using currently */
1377c478bd9Sstevel@tonic-gate 						/*	loaded objects only. */
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Valid values for mode argument to dlopen.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate #define	RTLD_LAZY		0x00001		/* deferred function binding */
1427c478bd9Sstevel@tonic-gate #define	RTLD_NOW		0x00002		/* immediate function binding */
1437c478bd9Sstevel@tonic-gate #define	RTLD_NOLOAD		0x00004		/* don't load object */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #define	RTLD_GLOBAL		0x00100		/* export symbols to others */
1467c478bd9Sstevel@tonic-gate #define	RTLD_LOCAL		0x00000		/* symbols are only available */
1477c478bd9Sstevel@tonic-gate 						/*	to group members */
1487c478bd9Sstevel@tonic-gate #define	RTLD_PARENT		0x00200		/* add parent (caller) to */
1497c478bd9Sstevel@tonic-gate 						/*	a group dependencies */
1507c478bd9Sstevel@tonic-gate #define	RTLD_GROUP		0x00400		/* resolve symbols within */
1517c478bd9Sstevel@tonic-gate 						/*	members of the group */
1527c478bd9Sstevel@tonic-gate #define	RTLD_WORLD		0x00800		/* resolve symbols within */
1537c478bd9Sstevel@tonic-gate 						/*	global objects */
1547c478bd9Sstevel@tonic-gate #define	RTLD_NODELETE		0x01000		/* do not remove members */
1557c478bd9Sstevel@tonic-gate #define	RTLD_FIRST		0x02000		/* only first object is */
1567c478bd9Sstevel@tonic-gate 						/*	available for dlsym */
1577c478bd9Sstevel@tonic-gate #define	RTLD_CONFGEN		0x10000		/* crle(1) config generation */
1587c478bd9Sstevel@tonic-gate 						/*	internal use only */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * Valid values for flag argument to dldump.
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate #define	RTLD_REL_RELATIVE	0x00001		/* apply relative relocs */
1647c478bd9Sstevel@tonic-gate #define	RTLD_REL_EXEC		0x00002		/* apply symbolic relocs that */
1657c478bd9Sstevel@tonic-gate 						/*	bind to main */
1667c478bd9Sstevel@tonic-gate #define	RTLD_REL_DEPENDS	0x00004		/* apply symbolic relocs that */
1677c478bd9Sstevel@tonic-gate 						/*	bind to dependencies */
1687c478bd9Sstevel@tonic-gate #define	RTLD_REL_PRELOAD	0x00008		/* apply symbolic relocs that */
1697c478bd9Sstevel@tonic-gate 						/*	bind to preload objs */
1707c478bd9Sstevel@tonic-gate #define	RTLD_REL_SELF		0x00010		/* apply symbolic relocs that */
1717c478bd9Sstevel@tonic-gate 						/*	bind to ourself */
1727c478bd9Sstevel@tonic-gate #define	RTLD_REL_WEAK		0x00020		/* apply symbolic weak relocs */
1737c478bd9Sstevel@tonic-gate 						/*	even if unresolved */
1747c478bd9Sstevel@tonic-gate #define	RTLD_REL_ALL		0x00fff		/* apply all relocs */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #define	RTLD_MEMORY		0x01000		/* use memory sections */
1777c478bd9Sstevel@tonic-gate #define	RTLD_STRIP		0x02000		/* retain allocable sections */
1787c478bd9Sstevel@tonic-gate 						/*	only */
1797c478bd9Sstevel@tonic-gate #define	RTLD_NOHEAP		0x04000		/* do no save any heap */
1807c478bd9Sstevel@tonic-gate #define	RTLD_CONFSET		0x10000		/* crle(1) config generation */
1817c478bd9Sstevel@tonic-gate 						/*	internal use only */
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * Valid values for dladdr1() flags.
1857c478bd9Sstevel@tonic-gate  */
1867c478bd9Sstevel@tonic-gate #define	RTLD_DL_SYMENT		1		/* return symbol table entry */
1877c478bd9Sstevel@tonic-gate #define	RTLD_DL_LINKMAP		2		/* return public link-map */
1887c478bd9Sstevel@tonic-gate #define	RTLD_DL_MASK		0xffff
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * Arguments for dlinfo()
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate #define	RTLD_DI_LMID		1		/* obtain link-map id */
1957c478bd9Sstevel@tonic-gate #define	RTLD_DI_LINKMAP		2		/* obtain link-map */
1967c478bd9Sstevel@tonic-gate #define	RTLD_DI_CONFIGADDR	3		/* obtain config addr */
1977c478bd9Sstevel@tonic-gate #define	RTLD_DI_SERINFO		4		/* obtain search path info or */
1987c478bd9Sstevel@tonic-gate #define	RTLD_DI_SERINFOSIZE	5		/*    associated info size */
1997c478bd9Sstevel@tonic-gate #define	RTLD_DI_ORIGIN		6		/* obtain objects origin */
2007c478bd9Sstevel@tonic-gate #define	RTLD_DI_PROFILENAME	7		/* obtain profile object name */
2017c478bd9Sstevel@tonic-gate 						/*    internal use only */
2027c478bd9Sstevel@tonic-gate #define	RTLD_DI_PROFILEOUT	8		/* obtain profile output name */
2037c478bd9Sstevel@tonic-gate 						/*    internal use only */
2047c478bd9Sstevel@tonic-gate #define	RTLD_DI_GETSIGNAL	9		/* get termination signal */
2057c478bd9Sstevel@tonic-gate #define	RTLD_DI_SETSIGNAL	10		/* set termination signal */
20641072f3cSrie #define	RTLD_DI_ARGSINFO	11		/* get process arguments */
20741072f3cSrie 						/*    environment and auxv */
208959ee943SRod Evans #define	RTLD_DI_MMAPS		12		/* obtain objects mappings or */
209959ee943SRod Evans #define	RTLD_DI_MMAPCNT		13		/*    mapping count */
210f441771bSRod Evans #define	RTLD_DI_DEFERRED	14		/* assign new dependency to a */
211f441771bSRod Evans 						/*    deferred dependency */
212f441771bSRod Evans #define	RTLD_DI_DEFERRED_SYM	15		/* assign new dependency to a */
213f441771bSRod Evans 						/*    deferred dependency */
214f441771bSRod Evans 						/*    using a symbol name */
215f441771bSRod Evans #define	RTLD_DI_MAX		15
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * Version information for Dl_amd64_unwindinfo.dlui_version
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate #define	DLUI_VERS_1		1
2227c478bd9Sstevel@tonic-gate #define	DLUI_VERS_CURRENT	DLUI_VERS_1
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Valid flags for Dl_amd64_unwindinfo.dlfi_flags
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate #define	DLUI_FLG_NOUNWIND	0x0001		/* object has no Unwind info */
2287c478bd9Sstevel@tonic-gate #define	DLUI_FLG_NOOBJ		0x0002		/* no object was found */
2297c478bd9Sstevel@tonic-gate 						/*  matching the pc provided */
2307c478bd9Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate #endif
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #endif	/* _DLFCN_H */
237