/branches/dynload/uspace/lib/libc/rtld/include/rtld.h |
---|
0,0 → 1,74 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef RTLD_H_ |
#define RTLD_H_ |
#include <sys/types.h> |
#include <libadt/list.h> |
#include <dynamic.h> |
#include <module.h> |
/* Define to enable debugging mode. */ |
#undef RTLD_DEBUG |
#ifdef RTLD_DEBUG |
#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__); |
#else |
#define DPRINTF(format, ...) |
#endif |
typedef struct { |
elf_dyn_t *rtld_dynamic; |
module_t rtld; |
module_t *program; |
module_t *libc; |
/** List of all loaded modules including rtld and the program */ |
link_t modules_head; |
/** Temporary hack to place each module at different address. */ |
uintptr_t next_bias; |
} runtime_env_t; |
extern runtime_env_t *runtime_env; |
extern void rtld_init_static(void); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/rtld/include/dynamic.h |
---|
0,0 → 1,107 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef DYNAMIC_H_ |
#define DYNAMIC_H_ |
#include <bool.h> |
#include <elf_dyn.h> |
#include <arch/dynamic.h> |
/** |
* Holds the data extracted from an ELF Dynamic section. |
* |
* The data is already pre-processed: Pointers are adjusted |
* to their final run-time values by adding the load bias |
* and indices into the symbol table are converted to pointers. |
*/ |
typedef struct dyn_info { |
/** Type of relocations used for the PLT, either DT_REL or DT_RELA */ |
int plt_rel; |
/** Relocation table without explicit addends */ |
void *rel; |
size_t rel_sz; |
size_t rel_ent; |
/** Relocation table with explicit addends */ |
void *rela; |
size_t rela_sz; |
size_t rela_ent; |
/** PLT relocation table */ |
void *jmp_rel; |
size_t plt_rel_sz; |
/** Pointer to PLT/GOT (processor-specific) */ |
void *plt_got; |
/** Hash table */ |
elf_word *hash; |
/** String table */ |
char *str_tab; |
size_t str_sz; |
/** Symbol table */ |
void *sym_tab; |
size_t sym_ent; |
void *init; /**< Module initialization code */ |
void *fini; /**< Module cleanup code */ |
char *soname; /**< Library identifier */ |
char *rpath; /**< Library search path list */ |
bool symbolic; |
bool text_rel; |
bool bind_now; |
/* Assume for now that there's at most one needed library */ |
char *needed; |
/** Pointer to the module's dynamic section */ |
elf_dyn_t *dynamic; |
/** Architecture-specific info. */ |
dyn_info_arch_t arch; |
} dyn_info_t; |
void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info); |
void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/rtld/include/module.h |
---|
0,0 → 1,74 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef MODULE_H_ |
#define MODULE_H_ |
#include <sys/types.h> |
#include <dynamic.h> |
#include <libadt/list.h> |
typedef struct module { |
dyn_info_t dyn; |
size_t bias; |
/** Array of pointers to directly dependent modules */ |
struct module **deps; |
/** Number of fields in deps */ |
size_t n_deps; |
/** True iff relocations have already been processed in this module. */ |
bool relocated; |
/** Link to list of all modules in runtime environment */ |
link_t modules_link; |
/** Link to BFS queue. Only used when doing a BFS of the module graph */ |
link_t queue_link; |
/** Tag for modules already processed during a BFS */ |
bool bfs_tag; |
} module_t; |
void module_process_relocs(module_t *m); |
module_t *module_find(char *name); |
module_t *module_load(char *name); |
void module_load_deps(module_t *m); |
void modules_process_relocs(module_t *start); |
void modules_untag(void); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/rtld/include/symbol.h |
---|
0,0 → 1,48 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef SYMBOL_H_ |
#define SYMBOL_H_ |
#include <rtld.h> |
#include <elf.h> |
elf_symbol_t *symbol_bfs_find(char *name, module_t *start, module_t **mod); |
elf_symbol_t *symbol_def_find(char *name, module_t *origin, module_t **mod); |
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/rtld/include/rtld_arch.h |
---|
0,0 → 1,51 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef RTLD_ARCH_H_ |
#define RTLD_ARCH_H_ |
#include <rtld.h> |
#include <loader/pcb.h> |
void module_process_pre_arch(module_t *m); |
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size); |
void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size); |
void program_run(void *entry, pcb_t *pcb); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/rtld/include/elf_dyn.h |
---|
0,0 → 1,122 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup generic |
* @{ |
*/ |
/** @file |
*/ |
#ifndef ELF_DYN_H_ |
#define ELF_DYN_H_ |
#include <arch/elf.h> |
#include <sys/types.h> |
#include <elf.h> |
#include <arch/elf_dyn.h> |
#define ELF32_R_SYM(i) ((i)>>8) |
#define ELF32_R_TYPE(i) ((unsigned char)(i)) |
struct elf32_dyn { |
elf_sword d_tag; |
union { |
elf_word d_val; |
elf32_addr d_ptr; |
} d_un; |
}; |
struct elf32_rel { |
elf32_addr r_offset; |
elf_word r_info; |
}; |
struct elf32_rela { |
elf32_addr r_offset; |
elf_word r_info; |
elf_sword r_addend; |
}; |
#ifdef __32_BITS__ |
typedef struct elf32_dyn elf_dyn_t; |
typedef struct elf32_rel elf_rel_t; |
typedef struct elf32_rela elf_rela_t; |
#endif |
/* |
* Dynamic array tags |
*/ |
#define DT_NULL 0 |
#define DT_NEEDED 1 |
#define DT_PLTRELSZ 2 |
#define DT_PLTGOT 3 |
#define DT_HASH 4 |
#define DT_STRTAB 5 |
#define DT_SYMTAB 6 |
#define DT_RELA 7 |
#define DT_RELASZ 8 |
#define DT_RELAENT 9 |
#define DT_STRSZ 10 |
#define DT_SYMENT 11 |
#define DT_INIT 12 |
#define DT_FINI 13 |
#define DT_SONAME 14 |
#define DT_RPATH 15 |
#define DT_SYMBOLIC 16 |
#define DT_REL 17 |
#define DT_RELSZ 18 |
#define DT_RELENT 19 |
#define DT_PLTREL 20 |
#define DT_DEBUG 21 |
#define DT_TEXTREL 22 |
#define DT_JMPREL 23 |
#define DT_BIND_NOW 24 |
#define DT_LOPROC 0x70000000 |
#define DT_HIPROC 0x7fffffff |
/* |
* Special section indexes |
*/ |
#define SHN_UNDEF 0 |
#define SHN_LORESERVE 0xff00 |
#define SHN_LOPROC 0xff00 |
#define SHN_HIPROC 0xff1f |
#define SHN_ABS 0xfff1 |
#define SHN_COMMON 0xfff2 |
#define SHN_HIRESERVE 0xffff |
/* |
* Special symbol table index |
*/ |
#define STN_UNDEF 0 |
#endif |
/** @} |
*/ |