Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
10 KiB

25 years ago
  1. /* $OpenBSD: link.h,v 1.5 1999/12/09 18:10:23 espie Exp $ */
  2. /* $NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $ */
  3. /*
  4. * Copyright (c) 1993 Paul Kranenburg
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by Paul Kranenburg.
  18. * 4. The name of the author may not be used to endorse or promote products
  19. * derived from this software withough specific prior written permission
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * RRS section definitions.
  34. *
  35. * The layout of some data structures defined in this header file is
  36. * such that we can provide compatibility with the SunOS 4.x shared
  37. * library scheme.
  38. */
  39. #ifndef _LINK_H_
  40. #define _LINK_H_
  41. /*
  42. * A `Shared Object Descriptor' describes a shared object that is needed
  43. * to complete the link edit process of the object containing it.
  44. * A list of such objects (chained through `sod_next') is pointed at
  45. * by `sdt_sods' in the section_dispatch_table structure.
  46. */
  47. struct sod { /* Shared Object Descriptor */
  48. long sod_name; /* name (relative to load address) */
  49. u_int sod_library : 1, /* Searched for by library rules */
  50. sod_reserved : 31;
  51. short sod_major; /* major version number */
  52. short sod_minor; /* minor version number */
  53. long sod_next; /* next sod */
  54. };
  55. /*
  56. * `Shared Object Map's are used by the run-time link editor (ld.so) to
  57. * keep track of all shared objects loaded into a process' address space.
  58. * These structures are only used at run-time and do not occur within
  59. * the text or data segment of an executable or shared library.
  60. */
  61. struct so_map { /* Shared Object Map */
  62. caddr_t som_addr; /* Address at which object mapped */
  63. char *som_path; /* Path to mmap'ed file */
  64. struct so_map *som_next; /* Next map in chain */
  65. struct sod *som_sod; /* Sod responsible for this map */
  66. caddr_t som_sodbase; /* Base address of this sod */
  67. u_int som_write : 1; /* Text is currently writable */
  68. struct _dynamic *som_dynamic; /* _dynamic structure */
  69. caddr_t som_spd; /* Private data */
  70. };
  71. /*
  72. * Symbol description with size. This is simply an `nlist' with
  73. * one field (nz_size) added.
  74. * Used to convey size information on items in the data segment
  75. * of shared objects. An array of these live in the shared object's
  76. * text segment and is addressed by the `sdt_nzlist' field.
  77. */
  78. struct nzlist {
  79. struct nlist nlist;
  80. u_long nz_size;
  81. #define nz_un nlist.n_un
  82. #define nz_strx nlist.n_un.n_strx
  83. #define nz_name nlist.n_un.n_name
  84. #define nz_type nlist.n_type
  85. #define nz_value nlist.n_value
  86. #define nz_desc nlist.n_desc
  87. #define nz_other nlist.n_other
  88. };
  89. #define N_AUX(p) ((p)->n_other & 0xf)
  90. #define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf)
  91. #define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf))
  92. #define AUX_OBJECT 1
  93. #define AUX_FUNC 2
  94. /*#define BIND_LOCAL 0 not used */
  95. /*#define BIND_GLOBAL 1 not used */
  96. #define BIND_WEAK 2
  97. /*
  98. * The `section_dispatch_table' structure contains offsets to various data
  99. * structures needed to do run-time relocation.
  100. */
  101. struct section_dispatch_table {
  102. struct so_map *sdt_loaded; /* List of loaded objects */
  103. long sdt_sods; /* List of shared objects descriptors */
  104. long sdt_paths; /* Library search paths */
  105. long sdt_got; /* Global offset table */
  106. long sdt_plt; /* Procedure linkage table */
  107. long sdt_rel; /* Relocation table */
  108. long sdt_hash; /* Symbol hash table */
  109. long sdt_nzlist; /* Symbol table itself */
  110. long sdt_filler2; /* Unused (was: stab_hash) */
  111. long sdt_buckets; /* Number of hash buckets */
  112. long sdt_strings; /* Symbol strings */
  113. long sdt_str_sz; /* Size of symbol strings */
  114. long sdt_text_sz; /* Size of text area */
  115. long sdt_plt_sz; /* Size of procedure linkage table */
  116. };
  117. /*
  118. * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
  119. * Used to quickly lookup symbols of the shared object by hashing
  120. * on the symbol's name. `rh_symbolnum' is the index of the symbol
  121. * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
  122. * the next symbol in the hash bucket (in case of collisions).
  123. */
  124. struct rrs_hash {
  125. int rh_symbolnum; /* Symbol number */
  126. int rh_next; /* Next hash entry */
  127. };
  128. /*
  129. * `rt_symbols' is used to keep track of run-time allocated commons
  130. * and data items copied from shared objects.
  131. */
  132. struct rt_symbol {
  133. struct nzlist *rt_sp; /* The symbol */
  134. struct rt_symbol *rt_next; /* Next in linear list */
  135. struct rt_symbol *rt_link; /* Next in bucket */
  136. caddr_t rt_srcaddr; /* Address of "master" copy */
  137. struct so_map *rt_smp; /* Originating map */
  138. };
  139. /*
  140. * Debugger interface structure.
  141. */
  142. struct so_debug {
  143. int dd_version; /* Version # of interface */
  144. int dd_in_debugger; /* Set when run by debugger */
  145. int dd_sym_loaded; /* Run-time linking brought more
  146. symbols into scope */
  147. char *dd_bpt_addr; /* Address of rtld-generated bpt */
  148. int dd_bpt_shadow; /* Original contents of bpt */
  149. struct rt_symbol *dd_cc; /* Allocated commons/copied data */
  150. };
  151. /*
  152. * Entry points into ld.so - user interface to the run-time linker.
  153. */
  154. struct ld_entry {
  155. void *(*dlopen) __P((const char *, int));
  156. int (*dlclose) __P((void *));
  157. void *(*dlsym) __P((void *, const char *));
  158. int (*dlctl) __P((void *, int, void *));
  159. void (*dlexit) __P((void));
  160. void (*dlrsrvd[3]) __P((void));
  161. };
  162. /*
  163. * This is the structure pointed at by the __DYNAMIC symbol if an
  164. * executable requires the attention of the run-time link editor.
  165. * __DYNAMIC is given the value zero if no run-time linking needs to
  166. * be done (it is always present in shared objects).
  167. * The union `d_un' provides for different versions of the dynamic
  168. * linking mechanism (switched on by `d_version'). The last version
  169. * used by Sun is 3. We leave some room here and go to version number
  170. * 8 for NetBSD, the main difference lying in the support for the
  171. * `nz_list' type of symbols.
  172. */
  173. struct _dynamic {
  174. int d_version; /* version # of this interface */
  175. struct so_debug *d_debug;
  176. union {
  177. struct section_dispatch_table *d_sdt;
  178. } d_un;
  179. struct ld_entry *d_entry; /* compat - now in crt_ldso */
  180. };
  181. #define LD_VERSION_SUN (3)
  182. #define LD_VERSION_BSD (8)
  183. #define LD_VERSION_NZLIST_P(v) ((v) >= 8)
  184. #define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got)
  185. #define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt)
  186. #define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel)
  187. #define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist)
  188. #define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash)
  189. #define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings)
  190. #define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods)
  191. #define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets)
  192. #define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths)
  193. #define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
  194. #define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
  195. #define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
  196. #define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
  197. #define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz)
  198. #define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz)
  199. #define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz)
  200. /*
  201. * Interface to ld.so
  202. */
  203. struct crt_ldso {
  204. int crt_ba; /* Base address of ld.so */
  205. int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */
  206. int crt_ldfd; /* ld.so file descriptor */
  207. struct _dynamic *crt_dp; /* Main's __DYNAMIC */
  208. char **crt_ep; /* environment strings */
  209. caddr_t crt_bp; /* Breakpoint if run from debugger */
  210. char *crt_prog; /* Program name (v3) */
  211. char *crt_ldso; /* Link editor name (v4) */
  212. struct ld_entry *crt_ldentry; /* dl*() access (v4) */
  213. };
  214. /*
  215. * Version passed from crt0 to ld.so (1st argument to _rtld()).
  216. */
  217. #define CRT_VERSION_SUN 1
  218. #define CRT_VERSION_BSD_2 2
  219. #define CRT_VERSION_BSD_3 3
  220. #define CRT_VERSION_BSD_4 4
  221. /*
  222. * Maximum number of recognized shared object version numbers.
  223. */
  224. #define MAXDEWEY 8
  225. /*
  226. * Header of the hints file.
  227. */
  228. struct hints_header {
  229. long hh_magic;
  230. #define HH_MAGIC 011421044151
  231. long hh_version; /* Interface version number */
  232. #define LD_HINTS_VERSION_1 1
  233. #define LD_HINTS_VERSION_2 2
  234. long hh_hashtab; /* Location of hash table */
  235. long hh_nbucket; /* Number of buckets in hashtab */
  236. long hh_strtab; /* Location of strings */
  237. long hh_strtab_sz; /* Size of strings */
  238. long hh_ehints; /* End of hints (max offset in file) */
  239. long hh_dirlist; /* Colon-separated list of srch dirs */
  240. };
  241. #define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC)
  242. /*
  243. * Hash table element in hints file.
  244. */
  245. struct hints_bucket {
  246. /* namex and pathx are indices into the string table */
  247. int hi_namex; /* Library name */
  248. int hi_pathx; /* Full path */
  249. int hi_dewey[MAXDEWEY]; /* The versions */
  250. int hi_ndewey; /* Number of version numbers */
  251. #define hi_major hi_dewey[0]
  252. #define hi_minor hi_dewey[1]
  253. int hi_next; /* Next in this bucket */
  254. };
  255. #define _PATH_LD_HINTS "/var/run/ld.so.hints"
  256. #endif /* _LINK_H_ */