rtld.h revision 38467
134192Sjdp/*- 234192Sjdp * Copyright 1996-1998 John D. Polstra. 334192Sjdp * All rights reserved. 434192Sjdp * 534192Sjdp * Redistribution and use in source and binary forms, with or without 634192Sjdp * modification, are permitted provided that the following conditions 734192Sjdp * are met: 834192Sjdp * 1. Redistributions of source code must retain the above copyright 934192Sjdp * notice, this list of conditions and the following disclaimer. 1034192Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1134192Sjdp * notice, this list of conditions and the following disclaimer in the 1234192Sjdp * documentation and/or other materials provided with the distribution. 1334192Sjdp * 1434192Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1534192Sjdp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1634192Sjdp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1734192Sjdp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1834192Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1934192Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2034192Sjdp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2134192Sjdp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2234192Sjdp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2334192Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2434192Sjdp * 2538467Sjb * $Id: rtld.h,v 1.2 1998/04/30 07:48:02 dfr Exp $ 2634192Sjdp */ 2734192Sjdp 2834192Sjdp#ifndef RTLD_H /* { */ 2934192Sjdp#define RTLD_H 1 3034192Sjdp 3134192Sjdp#include <sys/types.h> 3234192Sjdp 3335529Sdfr#include <link.h> 3434192Sjdp#include <elf.h> 3534192Sjdp#include <stddef.h> 3634192Sjdp 3734192Sjdp#ifndef STANDARD_LIBRARY_PATH 3834192Sjdp#define STANDARD_LIBRARY_PATH "/usr/lib/elf:/usr/lib" 3934192Sjdp#endif 4034192Sjdp 4134192Sjdp#define NEW(type) ((type *) xmalloc(sizeof(type))) 4234192Sjdp#define CNEW(type) ((type *) xcalloc(sizeof(type))) 4334192Sjdp 4434192Sjdp/* We might as well do booleans like C++. */ 4534192Sjdptypedef unsigned char bool; 4634192Sjdp#define false 0 4734192Sjdp#define true 1 4834192Sjdp 4934192Sjdpstruct Struct_Obj_Entry; 5034192Sjdp 5134192Sjdptypedef struct Struct_Needed_Entry { 5234192Sjdp struct Struct_Needed_Entry *next; 5334192Sjdp struct Struct_Obj_Entry *obj; 5434192Sjdp unsigned long name; /* Offset of name in string table */ 5534192Sjdp} Needed_Entry; 5634192Sjdp 5734192Sjdp/* 5834192Sjdp * Shared object descriptor. 5934192Sjdp * 6034192Sjdp * Items marked with "(%)" are dynamically allocated, and must be freed 6134192Sjdp * when the structure is destroyed. 6234192Sjdp */ 6334192Sjdptypedef struct Struct_Obj_Entry { 6434192Sjdp /* 6534192Sjdp * These two items have to be set right for compatibility with the 6634192Sjdp * original ElfKit crt1.o. 6734192Sjdp */ 6838467Sjb Elf_Word magic; /* Magic number (sanity check) */ 6938467Sjb Elf_Word version; /* Version number of struct format */ 7034192Sjdp 7134192Sjdp struct Struct_Obj_Entry *next; 7234192Sjdp char *path; /* Pathname of underlying file (%) */ 7334192Sjdp int refcount; 7434192Sjdp int dl_refcount; /* Number of times loaded by dlopen */ 7534192Sjdp 7634192Sjdp /* These items are computed by map_object() or by digest_phdr(). */ 7734192Sjdp caddr_t mapbase; /* Base address of mapped region */ 7834192Sjdp size_t mapsize; /* Size of mapped region in bytes */ 7934192Sjdp size_t textsize; /* Size of text segment in bytes */ 8038467Sjb Elf_Addr vaddrbase; /* Base address in shared object file */ 8134192Sjdp caddr_t relocbase; /* Relocation constant = mapbase - vaddrbase */ 8238467Sjb const Elf_Dyn *dynamic; /* Dynamic section */ 8334192Sjdp caddr_t entry; /* Entry point */ 8438467Sjb const Elf_Phdr *phdr; /* Program header if it is mapped, else NULL */ 8534192Sjdp size_t phsize; /* Size of program header in bytes */ 8634192Sjdp 8734192Sjdp /* Items from the dynamic section. */ 8838467Sjb Elf_Addr *got; /* GOT table */ 8938467Sjb const Elf_Rel *rel; /* Relocation entries */ 9034192Sjdp unsigned long relsize; /* Size in bytes of relocation info */ 9138467Sjb const Elf_Rel *pltrel; /* PLT relocation entries */ 9234192Sjdp unsigned long pltrelsize; /* Size in bytes of PLT relocation info */ 9338467Sjb const Elf_Sym *symtab; /* Symbol table */ 9434192Sjdp const char *strtab; /* String table */ 9534192Sjdp unsigned long strsize; /* Size in bytes of string table */ 9634192Sjdp 9738467Sjb const Elf_Word *buckets; /* Hash table buckets array */ 9834192Sjdp unsigned long nbuckets; /* Number of buckets */ 9938467Sjb const Elf_Word *chains; /* Hash table chain array */ 10034192Sjdp unsigned long nchains; /* Number of chains */ 10134192Sjdp 10234192Sjdp const char *rpath; /* Search path specified in object */ 10334192Sjdp Needed_Entry *needed; /* Shared objects needed by this one (%) */ 10434192Sjdp 10534192Sjdp void (*init)(void); /* Initialization function to call */ 10634192Sjdp void (*fini)(void); /* Termination function to call */ 10734192Sjdp 10834192Sjdp bool mainprog; /* True if this is the main program */ 10934192Sjdp bool rtld; /* True if this is the dynamic linker */ 11034192Sjdp bool textrel; /* True if there are relocations to text seg */ 11134192Sjdp bool symbolic; /* True if generated with "-Bsymbolic" */ 11235529Sdfr 11335529Sdfr struct link_map linkmap; /* for GDB */ 11434192Sjdp} Obj_Entry; 11534192Sjdp 11634192Sjdp#define RTLD_MAGIC 0xd550b87a 11734192Sjdp#define RTLD_VERSION 1 11834192Sjdp 11934192Sjdpextern void _rtld_error(const char *, ...); 12034192Sjdpextern Obj_Entry *map_object(int); 12134192Sjdpextern void *xcalloc(size_t); 12234192Sjdpextern void *xmalloc(size_t); 12334192Sjdpextern char *xstrdup(const char *); 12434192Sjdp 12534192Sjdp#endif /* } */ 126