[BACK]Return to link.h CVS log [TXT][DIR] Up to [local] / src / include

Annotation of src/include/link.h, Revision 1.10

1.10    ! deraadt     1: /*     $OpenBSD: link.h,v 1.9 2002/02/16 21:27:17 millert Exp $        */
1.2       deraadt     2: /*     $NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $     */
1.1       deraadt     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
1.10    ! deraadt    20:  *    derived from this software without specific prior written permission
1.1       deraadt    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:  * RRS section definitions.
                     36:  *
                     37:  * The layout of some data structures defined in this header file is
                     38:  * such that we can provide compatibility with the SunOS 4.x shared
                     39:  * library scheme.
                     40:  */
                     41:
                     42: #ifndef _LINK_H_
                     43: #define _LINK_H_
1.6       art        44:
                     45: /* XXXART - ? */
                     46: #ifndef DT_PROCNUM
                     47: #define DT_PROCNUM 0
                     48: #endif
1.1       deraadt    49:
                     50: /*
1.4       espie      51:  * A `Shared Object Descriptor' describes a shared object that is needed
1.1       deraadt    52:  * to complete the link edit process of the object containing it.
                     53:  * A list of such objects (chained through `sod_next') is pointed at
                     54:  * by `sdt_sods' in the section_dispatch_table structure.
                     55:  */
                     56:
                     57: struct sod {   /* Shared Object Descriptor */
                     58:        long    sod_name;               /* name (relative to load address) */
                     59:        u_int   sod_library  : 1,       /* Searched for by library rules */
                     60:                sod_reserved : 31;
                     61:        short   sod_major;              /* major version number */
                     62:        short   sod_minor;              /* minor version number */
                     63:        long    sod_next;               /* next sod */
                     64: };
                     65:
                     66: /*
                     67:  * `Shared Object Map's are used by the run-time link editor (ld.so) to
                     68:  * keep track of all shared objects loaded into a process' address space.
                     69:  * These structures are only used at run-time and do not occur within
                     70:  * the text or data segment of an executable or shared library.
                     71:  */
                     72: struct so_map {                /* Shared Object Map */
                     73:        caddr_t         som_addr;       /* Address at which object mapped */
                     74:        char            *som_path;      /* Path to mmap'ed file */
                     75:        struct so_map   *som_next;      /* Next map in chain */
                     76:        struct sod      *som_sod;       /* Sod responsible for this map */
                     77:        caddr_t         som_sodbase;    /* Base address of this sod */
                     78:        u_int           som_write : 1;  /* Text is currently writable */
                     79:        struct _dynamic *som_dynamic;   /* _dynamic structure */
                     80:        caddr_t         som_spd;        /* Private data */
                     81: };
                     82:
                     83: /*
                     84:  * Symbol description with size. This is simply an `nlist' with
                     85:  * one field (nz_size) added.
                     86:  * Used to convey size information on items in the data segment
                     87:  * of shared objects. An array of these live in the shared object's
                     88:  * text segment and is addressed by the `sdt_nzlist' field.
                     89:  */
                     90: struct nzlist {
                     91:        struct nlist    nlist;
                     92:        u_long          nz_size;
                     93: #define nz_un          nlist.n_un
                     94: #define nz_strx                nlist.n_un.n_strx
                     95: #define nz_name                nlist.n_un.n_name
                     96: #define nz_type                nlist.n_type
                     97: #define nz_value       nlist.n_value
                     98: #define nz_desc                nlist.n_desc
                     99: #define nz_other       nlist.n_other
                    100: };
                    101:
                    102: #define N_AUX(p)       ((p)->n_other & 0xf)
                    103: #define N_BIND(p)      (((unsigned int)(p)->n_other >> 4) & 0xf)
                    104: #define N_OTHER(r, v)  (((unsigned int)(r) << 4) | ((v) & 0xf))
                    105:
                    106: #define AUX_OBJECT     1
                    107: #define AUX_FUNC       2
                    108: /*#define BIND_LOCAL   0       not used */
                    109: /*#define BIND_GLOBAL  1       not used */
                    110: #define BIND_WEAK      2
                    111:
                    112:
                    113: /*
                    114:  * The `section_dispatch_table' structure contains offsets to various data
                    115:  * structures needed to do run-time relocation.
                    116:  */
                    117: struct section_dispatch_table {
                    118:        struct so_map *sdt_loaded;      /* List of loaded objects */
                    119:        long    sdt_sods;               /* List of shared objects descriptors */
                    120:        long    sdt_paths;              /* Library search paths */
                    121:        long    sdt_got;                /* Global offset table */
                    122:        long    sdt_plt;                /* Procedure linkage table */
                    123:        long    sdt_rel;                /* Relocation table */
                    124:        long    sdt_hash;               /* Symbol hash table */
                    125:        long    sdt_nzlist;             /* Symbol table itself */
                    126:        long    sdt_filler2;            /* Unused (was: stab_hash) */
                    127:        long    sdt_buckets;            /* Number of hash buckets */
                    128:        long    sdt_strings;            /* Symbol strings */
                    129:        long    sdt_str_sz;             /* Size of symbol strings */
                    130:        long    sdt_text_sz;            /* Size of text area */
                    131:        long    sdt_plt_sz;             /* Size of procedure linkage table */
                    132: };
                    133:
                    134: /*
                    135:  * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
                    136:  * Used to quickly lookup symbols of the shared object by hashing
                    137:  * on the symbol's name. `rh_symbolnum' is the index of the symbol
                    138:  * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
                    139:  * the next symbol in the hash bucket (in case of collisions).
                    140:  */
                    141: struct rrs_hash {
                    142:        int     rh_symbolnum;           /* Symbol number */
                    143:        int     rh_next;                /* Next hash entry */
                    144: };
                    145:
                    146: /*
                    147:  * `rt_symbols' is used to keep track of run-time allocated commons
                    148:  * and data items copied from shared objects.
                    149:  */
                    150: struct rt_symbol {
                    151:        struct nzlist           *rt_sp;         /* The symbol */
                    152:        struct rt_symbol        *rt_next;       /* Next in linear list */
                    153:        struct rt_symbol        *rt_link;       /* Next in bucket */
                    154:        caddr_t                 rt_srcaddr;     /* Address of "master" copy */
                    155:        struct so_map           *rt_smp;        /* Originating map */
                    156: };
                    157:
                    158: /*
                    159:  * Debugger interface structure.
                    160:  */
                    161: struct so_debug {
                    162:        int     dd_version;             /* Version # of interface */
                    163:        int     dd_in_debugger;         /* Set when run by debugger */
                    164:        int     dd_sym_loaded;          /* Run-time linking brought more
                    165:                                           symbols into scope */
                    166:        char     *dd_bpt_addr;          /* Address of rtld-generated bpt */
                    167:        int     dd_bpt_shadow;          /* Original contents of bpt */
                    168:        struct rt_symbol *dd_cc;        /* Allocated commons/copied data */
                    169: };
1.7       art       170:
                    171: /*
                    172:  *     Debug rendezvous struct. Pointer to this is set up in the
1.8       art       173:  *     target code pointed by the DT_DEBUG tag. If it is
1.7       art       174:  *     defined.
                    175:  */
                    176: struct r_debug {
                    177:        int     r_version;              /* Protocol version. */
                    178:        struct link_map *r_map;         /* Head of list of loaded objects. */
                    179:
                    180:        /*
                    181:         * This is the address of a function internal to the run-time linker,
                    182:         * that will always be called when the linker begins to map in a
                    183:         * library or unmap it, and again when the mapping change is complete.
                    184:         * The debugger can set a breakpoint at this address if it wants to
                    185:         * notice shared object mapping changes.
                    186:         */
1.8       art       187:        unsigned long r_brk;
1.7       art       188:        enum {
                    189:                /*
                    190:                 * This state value describes the mapping change taking place
                    191:                 * when the `r_brk' address is called.
                    192:                 */
                    193:                RT_CONSISTENT,          /* Mapping change is complete.  */
                    194:                RT_ADD,                 /* Adding a new object.  */
                    195:                RT_DELETE,              /* Removing an object mapping.  */
                    196:        } r_state;
                    197:
1.8       art       198:        unsigned long r_ldbase;         /* Base address the linker is loaded at.  */
1.7       art       199: };
1.1       deraadt   200:
                    201: /*
                    202:  * Entry points into ld.so - user interface to the run-time linker.
                    203:  */
                    204: struct ld_entry {
1.9       millert   205:        void    *(*dlopen)(const char *, int);
                    206:        int     (*dlclose)(void *);
                    207:        void    *(*dlsym)(void *, const char *);
                    208:        int     (*dlctl)(void *, int, void *);
                    209:        void    (*dlexit)(void);
                    210:        void    (*dlrsrvd[3])(void);
1.1       deraadt   211: };
                    212:
                    213: /*
                    214:  * This is the structure pointed at by the __DYNAMIC symbol if an
                    215:  * executable requires the attention of the run-time link editor.
                    216:  * __DYNAMIC is given the value zero if no run-time linking needs to
                    217:  * be done (it is always present in shared objects).
                    218:  * The union `d_un' provides for different versions of the dynamic
                    219:  * linking mechanism (switched on by `d_version'). The last version
                    220:  * used by Sun is 3. We leave some room here and go to version number
                    221:  * 8 for NetBSD, the main difference lying in the support for the
                    222:  * `nz_list' type of symbols.
                    223:  */
                    224:
                    225: struct _dynamic {
                    226:        int             d_version;      /* version # of this interface */
                    227:        struct so_debug *d_debug;
                    228:        union {
                    229:                struct section_dispatch_table *d_sdt;
                    230:        } d_un;
                    231:        struct ld_entry *d_entry;       /* compat - now in crt_ldso */
                    232: };
                    233:
                    234: #define LD_VERSION_SUN         (3)
                    235: #define LD_VERSION_BSD         (8)
                    236: #define LD_VERSION_NZLIST_P(v) ((v) >= 8)
                    237:
                    238: #define LD_GOT(x)      ((x)->d_un.d_sdt->sdt_got)
                    239: #define LD_PLT(x)      ((x)->d_un.d_sdt->sdt_plt)
                    240: #define LD_REL(x)      ((x)->d_un.d_sdt->sdt_rel)
                    241: #define LD_SYMBOL(x)   ((x)->d_un.d_sdt->sdt_nzlist)
                    242: #define LD_HASH(x)     ((x)->d_un.d_sdt->sdt_hash)
                    243: #define LD_STRINGS(x)  ((x)->d_un.d_sdt->sdt_strings)
                    244: #define LD_NEED(x)     ((x)->d_un.d_sdt->sdt_sods)
                    245: #define LD_BUCKETS(x)  ((x)->d_un.d_sdt->sdt_buckets)
                    246: #define LD_PATHS(x)    ((x)->d_un.d_sdt->sdt_paths)
                    247:
                    248: #define LD_GOTSZ(x)    ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
                    249: #define LD_RELSZ(x)    ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
                    250: #define LD_HASHSZ(x)   ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
                    251: #define LD_STABSZ(x)   ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
                    252: #define LD_PLTSZ(x)    ((x)->d_un.d_sdt->sdt_plt_sz)
                    253: #define LD_STRSZ(x)    ((x)->d_un.d_sdt->sdt_str_sz)
                    254: #define LD_TEXTSZ(x)   ((x)->d_un.d_sdt->sdt_text_sz)
                    255:
                    256: /*
                    257:  * Interface to ld.so
                    258:  */
                    259: struct crt_ldso {
                    260:        int             crt_ba;         /* Base address of ld.so */
                    261:        int             crt_dzfd;       /* "/dev/zero" file decriptor (SunOS) */
                    262:        int             crt_ldfd;       /* ld.so file descriptor */
                    263:        struct _dynamic *crt_dp;        /* Main's __DYNAMIC */
                    264:        char            **crt_ep;       /* environment strings */
                    265:        caddr_t         crt_bp;         /* Breakpoint if run from debugger */
                    266:        char            *crt_prog;      /* Program name (v3) */
                    267:        char            *crt_ldso;      /* Link editor name (v4) */
                    268:        struct ld_entry *crt_ldentry;   /* dl*() access (v4) */
                    269: };
                    270:
                    271: /*
                    272:  * Version passed from crt0 to ld.so (1st argument to _rtld()).
                    273:  */
                    274: #define CRT_VERSION_SUN                1
                    275: #define CRT_VERSION_BSD_2      2
                    276: #define CRT_VERSION_BSD_3      3
                    277: #define CRT_VERSION_BSD_4      4
                    278:
                    279:
                    280: /*
                    281:  * Maximum number of recognized shared object version numbers.
                    282:  */
                    283: #define MAXDEWEY       8
                    284:
                    285: /*
                    286:  * Header of the hints file.
                    287:  */
                    288: struct hints_header {
                    289:        long            hh_magic;
                    290: #define HH_MAGIC       011421044151
                    291:        long            hh_version;     /* Interface version number */
                    292: #define LD_HINTS_VERSION_1     1
1.2       deraadt   293: #define LD_HINTS_VERSION_2     2
1.1       deraadt   294:        long            hh_hashtab;     /* Location of hash table */
                    295:        long            hh_nbucket;     /* Number of buckets in hashtab */
                    296:        long            hh_strtab;      /* Location of strings */
                    297:        long            hh_strtab_sz;   /* Size of strings */
                    298:        long            hh_ehints;      /* End of hints (max offset in file) */
1.2       deraadt   299:        long            hh_dirlist;     /* Colon-separated list of srch dirs */
1.1       deraadt   300: };
                    301:
                    302: #define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC)
                    303:
                    304: /*
                    305:  * Hash table element in hints file.
                    306:  */
                    307: struct hints_bucket {
                    308:        /* namex and pathx are indices into the string table */
                    309:        int             hi_namex;               /* Library name */
                    310:        int             hi_pathx;               /* Full path */
                    311:        int             hi_dewey[MAXDEWEY];     /* The versions */
                    312:        int             hi_ndewey;              /* Number of version numbers */
                    313: #define hi_major hi_dewey[0]
                    314: #define hi_minor hi_dewey[1]
                    315:        int             hi_next;                /* Next in this bucket */
                    316: };
                    317:
                    318: #define _PATH_LD_HINTS         "/var/run/ld.so.hints"
                    319:
                    320: #endif /* _LINK_H_ */
                    321: