| 1 | /*	$OpenBSD: link.h,v 1.15 2013/10/19 09:00:18 deraadt Exp $	*/ |
| 2 | /*	$NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $	*/ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1993 Paul Kranenburg |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. All advertising materials mentioning features or use of this software |
| 17 | * must display the following acknowledgement: |
| 18 | * This product includes software developed by Paul Kranenburg. |
| 19 | * 4. The name of the author may not be used to endorse or promote products |
| 20 | * derived from this software without specific prior written permission |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | |
| 35 | #ifndef _LINK_H_ |
| 36 | #define _LINK_H_ |
| 37 | |
| 38 | #ifdef __ELF__ |
| 39 | #include <link_elf.h> |
| 40 | #endif |
| 41 | |
| 42 | /* |
| 43 | * A `Shared Object Descriptor' describes a shared object that is needed |
| 44 | * to complete the link edit process of the object containing it. |
| 45 | * A list of such objects (chained through `sod_next') is pointed at |
| 46 | * by `sdt_sods' in the section_dispatch_table structure. |
| 47 | */ |
| 48 | |
| 49 | struct sod {	/* Shared Object Descriptor */ |
| 50 | 	long		sod_name;	/* name (relative to load address) */ |
| 51 | 	unsigned int 	sod_library : 1,/* Searched for by library rules */ |
| 52 | 			sod_reserved : 31; |
| 53 | 	short		sod_major;	/* major version number */ |
| 54 | 	short		sod_minor;	/* minor version number */ |
| 55 | 	long		sod_next;	/* next sod */ |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * `Shared Object Map's are used by the run-time link editor (ld.so) to |
| 60 | * keep track of all shared objects loaded into a process' address space. |
| 61 | * These structures are only used at run-time and do not occur within |
| 62 | * the text or data segment of an executable or shared library. |
| 63 | */ |
| 64 | struct so_map {		/* Shared Object Map */ |
| 65 | 	caddr_t		som_addr;	/* Address at which object mapped */ |
| 66 | 	char 		*som_path;	/* Path to mmap'ed file */ |
| 67 | 	struct so_map	*som_next;	/* Next map in chain */ |
| 68 | 	struct sod	*som_sod;	/* Sod responsible for this map */ |
| 69 | 	caddr_t		som_sodbase;	/* Base address of this sod */ |
| 70 | 	unsigned int	som_write : 1;	/* Text is currently writable */ |
| 71 | 	struct _dynamic	*som_dynamic;	/* _dynamic structure */ |
| 72 | 	caddr_t		som_spd;	/* Private data */ |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | *	Debug rendezvous struct. Pointer to this is set up in the |
| 78 | *	target code pointed by the DT_DEBUG tag. If it is |
| 79 | *	defined. |
| 80 | */ |
| 81 | struct r_debug { |
| 82 | 	int	r_version;		/* Protocol version. */ |
| 83 | 	struct link_map *r_map;		/* Head of list of loaded objects. */ |
| 84 | |
| 85 | 	/* |
| 86 | 	 * This is the address of a function internal to the run-time linker, |
| 87 | 	 * that will always be called when the linker begins to map in a |
| 88 | 	 * library or unmap it, and again when the mapping change is complete. |
| 89 | 	 * The debugger can set a breakpoint at this address if it wants to |
| 90 | 	 * notice shared object mapping changes. |
| 91 | 	 */ |
| 92 | 	unsigned long r_brk; |
| 93 | 	enum { |
| 94 | 		/* |
| 95 | 		 * This state value describes the mapping change taking place |
| 96 | 		 * when the `r_brk' address is called. |
| 97 | 		 */ |
| 98 | 		RT_CONSISTENT,		/* Mapping change is complete. */ |
| 99 | 		RT_ADD,			/* Adding a new object. */ |
| 100 | 		RT_DELETE		/* Removing an object mapping. */ |
| 101 | 	} r_state; |
| 102 | |
| 103 | 	unsigned long r_ldbase;		/* Base address the linker is loaded at. */ |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * Maximum number of recognized shared object version numbers. |
| 110 | */ |
| 111 | #define MAXDEWEY	8 |
| 112 | |
| 113 | /* |
| 114 | * Header of the hints file. |
| 115 | */ |
| 116 | struct hints_header { |
| 117 | 	long		hh_magic; |
| 118 | #define HH_MAGIC	011421044151 |
| 119 | 	long		hh_version;	/* Interface version number */ |
| 120 | #define LD_HINTS_VERSION_1	1 |
| 121 | #define LD_HINTS_VERSION_2	2 |
| 122 | 	long		hh_hashtab;	/* Location of hash table */ |
| 123 | 	long		hh_nbucket;	/* Number of buckets in hashtab */ |
| 124 | 	long		hh_strtab;	/* Location of strings */ |
| 125 | 	long		hh_strtab_sz;	/* Size of strings */ |
| 126 | 	long		hh_ehints;	/* End of hints (max offset in file) */ |
| 127 | 	long		hh_dirlist;	/* Colon-separated list of srch dirs */ |
| 128 | }; |
| 129 | |
| 130 | #define HH_BADMAG(hdr)	((hdr).hh_magic != HH_MAGIC) |
| 131 | |
| 132 | /* |
| 133 | * Hash table element in hints file. |
| 134 | */ |
| 135 | struct hints_bucket { |
| 136 | 	/* namex and pathx are indices into the string table */ |
| 137 | 	int		hi_namex;		/* Library name */ |
| 138 | 	int		hi_pathx;		/* Full path */ |
| 139 | 	int		hi_dewey[MAXDEWEY];	/* The versions */ |
| 140 | 	int		hi_ndewey;		/* Number of version numbers */ |
| 141 | #define hi_major hi_dewey[0] |
| 142 | #define hi_minor hi_dewey[1] |
| 143 | 	int		hi_next;		/* Next in this bucket */ |
| 144 | }; |
| 145 | |
| 146 | #define _PATH_LD_HINTS		"/var/run/ld.so.hints" |
| 147 | |
| 148 | #endif /* _LINK_H_ */ |