xref: /freebsd/sys/sys/link_elf.h (revision c56df6ce71ae96f00b088790d3ad2e0ebebdd59a)
160727d8bSWarner Losh /*-
2c4e20cadSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3c4e20cadSPedro F. Giffuni  *
4a70c9659SJordan K. Hubbard  * Copyright (c) 1993 Paul Kranenburg
5a70c9659SJordan K. Hubbard  * All rights reserved.
690f2ed3aSPaul Richards  *
7a70c9659SJordan K. Hubbard  * Redistribution and use in source and binary forms, with or without
8a70c9659SJordan K. Hubbard  * modification, are permitted provided that the following conditions
9a70c9659SJordan K. Hubbard  * are met:
10a70c9659SJordan K. Hubbard  * 1. Redistributions of source code must retain the above copyright
11a70c9659SJordan K. Hubbard  *    notice, this list of conditions and the following disclaimer.
12a70c9659SJordan K. Hubbard  * 2. Redistributions in binary form must reproduce the above copyright
13a70c9659SJordan K. Hubbard  *    notice, this list of conditions and the following disclaimer in the
14a70c9659SJordan K. Hubbard  *    documentation and/or other materials provided with the distribution.
15a70c9659SJordan K. Hubbard  * 3. All advertising materials mentioning features or use of this software
16a70c9659SJordan K. Hubbard  *    must display the following acknowledgement:
17a70c9659SJordan K. Hubbard  *      This product includes software developed by Paul Kranenburg.
18a70c9659SJordan K. Hubbard  * 4. The name of the author may not be used to endorse or promote products
1971d9c781SMike Pritchard  *    derived from this software without specific prior written permission
20a70c9659SJordan K. Hubbard  *
21a70c9659SJordan K. Hubbard  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22a70c9659SJordan K. Hubbard  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23a70c9659SJordan K. Hubbard  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24a70c9659SJordan K. Hubbard  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25a70c9659SJordan K. Hubbard  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26a70c9659SJordan K. Hubbard  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27a70c9659SJordan K. Hubbard  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28a70c9659SJordan K. Hubbard  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29a70c9659SJordan K. Hubbard  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30a70c9659SJordan K. Hubbard  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31a70c9659SJordan K. Hubbard  */
32a70c9659SJordan K. Hubbard 
33a70c9659SJordan K. Hubbard /*
34a70c9659SJordan K. Hubbard  * RRS section definitions.
35a70c9659SJordan K. Hubbard  *
36a70c9659SJordan K. Hubbard  * The layout of some data structures defined in this header file is
37a70c9659SJordan K. Hubbard  * such that we can provide compatibility with the SunOS 4.x shared
38a70c9659SJordan K. Hubbard  * library scheme.
3990f2ed3aSPaul Richards  */
4090f2ed3aSPaul Richards 
41c7fb14c7SPeter Wemm #ifndef _SYS_LINK_ELF_H_
42c7fb14c7SPeter Wemm #define	_SYS_LINK_ELF_H_
4312d68e37SDoug Rabson 
44585b0906SAlexander Kabaev #include <sys/elf.h>
4512d68e37SDoug Rabson 
4642d206e9SAlexander Kabaev /*
4742d206e9SAlexander Kabaev  * Flags that describe the origin of the entries in Dl_serinfo.
4842d206e9SAlexander Kabaev  * SunOS has these in <sys/link.h>, we follow the suit.
4942d206e9SAlexander Kabaev  */
5042d206e9SAlexander Kabaev #define	LA_SER_ORIG	0x01	/* original (needed) name */
5142d206e9SAlexander Kabaev #define	LA_SER_LIBPATH	0x02	/* LD_LIBRARY_PATH entry prepended */
5242d206e9SAlexander Kabaev #define	LA_SER_RUNPATH	0x04	/* runpath entry prepended */
5342d206e9SAlexander Kabaev #define	LA_SER_CONFIG	0x08	/* configuration entry prepended */
5442d206e9SAlexander Kabaev #define	LA_SER_DEFAULT	0x40	/* default path prepended */
5542d206e9SAlexander Kabaev #define	LA_SER_SECURE	0x80	/* default (secure) path prepended */
5642d206e9SAlexander Kabaev 
5742d206e9SAlexander Kabaev typedef struct link_map {
58d0ca9a7fSKonstantin Belousov 	caddr_t		l_base;			/* Base Address of library */
5912d68e37SDoug Rabson 	const char	*l_name;		/* Absolute Path to Library */
6012d68e37SDoug Rabson 	const void	*l_ld;			/* Pointer to .dynamic in memory */
61cf5d9c41SGordon Bergling 	struct link_map	*l_next, *l_prev;	/* linked list of mapped libs */
62d0ca9a7fSKonstantin Belousov 	caddr_t		l_addr;			/* Load Offset of library */
63c8ad15b6SKonstantin Belousov 	const char	*l_refname;		/* object we are filtering for */
6442d206e9SAlexander Kabaev } Link_map;
6512d68e37SDoug Rabson 
6612d68e37SDoug Rabson struct r_debug {
6771df6a15SKonstantin Belousov 	int		r_version;		/* Currently '1' */
6812d68e37SDoug Rabson 	struct link_map *r_map;			/* list of loaded images */
690824e46aSJohn Polstra 	void		(*r_brk)(struct r_debug *, struct link_map *);
700824e46aSJohn Polstra 						/* pointer to break point */
7112d68e37SDoug Rabson 	enum {
7212d68e37SDoug Rabson 		RT_CONSISTENT,			/* things are stable */
7312d68e37SDoug Rabson 		RT_ADD,				/* adding a shared library */
7412d68e37SDoug Rabson 		RT_DELETE			/* removing a shared library */
7512d68e37SDoug Rabson 	}		r_state;
7671df6a15SKonstantin Belousov 	void		*r_ldbase;		/* Base address of rtld */
7712d68e37SDoug Rabson };
7812d68e37SDoug Rabson 
7971df6a15SKonstantin Belousov #define	R_DEBUG_VERSION		1
8071df6a15SKonstantin Belousov 
81585b0906SAlexander Kabaev struct dl_phdr_info
82585b0906SAlexander Kabaev {
83585b0906SAlexander Kabaev 	Elf_Addr dlpi_addr;			/* module relocation base */
84585b0906SAlexander Kabaev 	const char *dlpi_name;			/* module name */
85585b0906SAlexander Kabaev 	const Elf_Phdr *dlpi_phdr;		/* pointer to module's phdr */
86585b0906SAlexander Kabaev 	Elf_Half dlpi_phnum;			/* number of entries in phdr */
87585b0906SAlexander Kabaev 	unsigned long long int dlpi_adds;	/* total # of loads */
88585b0906SAlexander Kabaev 	unsigned long long int dlpi_subs;	/* total # of unloads */
89585b0906SAlexander Kabaev 	size_t dlpi_tls_modid;
90585b0906SAlexander Kabaev 	void *dlpi_tls_data;
91585b0906SAlexander Kabaev };
92585b0906SAlexander Kabaev 
93585b0906SAlexander Kabaev __BEGIN_DECLS
94585b0906SAlexander Kabaev 
957c9c0cb8SDavid E. O'Brien typedef int (*__dl_iterate_hdr_callback)(struct dl_phdr_info *, size_t, void *);
967cd3e269SKonstantin Belousov int dl_iterate_phdr(__dl_iterate_hdr_callback, void *);
97e048186aSKonstantin Belousov int _rtld_addr_phdr(const void *, struct dl_phdr_info *);
98212f264cSKonstantin Belousov int _rtld_get_stack_prot(void);
990e521992SKonstantin Belousov int _rtld_is_dlopened(void *);
100*c56df6ceSKonstantin Belousov const char *rtld_get_var(const char *name);
101*c56df6ceSKonstantin Belousov int rtld_set_var(const char *name, const char *val);
102585b0906SAlexander Kabaev 
103677a88ceSIan Lepore #ifdef __ARM_EABI__
104677a88ceSIan Lepore void * dl_unwind_find_exidx(const void *, int *);
105677a88ceSIan Lepore #endif
106677a88ceSIan Lepore 
107585b0906SAlexander Kabaev __END_DECLS
108585b0906SAlexander Kabaev 
109c7fb14c7SPeter Wemm #endif /* _SYS_LINK_ELF_H_ */
110