1 /* 2 * Copyright 2003-2011, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2002, Manuel J. Petit. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 #ifndef RUNTIME_LOADER_PRIVATE_H 9 #define RUNTIME_LOADER_PRIVATE_H 10 11 #include <user_runtime.h> 12 #include <runtime_loader.h> 13 14 #include "tracing_config.h" 15 16 #include "utility.h" 17 18 19 //#define TRACE_RLD 20 #ifdef TRACE_RLD 21 # define TRACE(x) dprintf x 22 #else 23 # define TRACE(x) ; 24 #endif 25 26 27 #if RUNTIME_LOADER_TRACING 28 # define KTRACE(x...) ktrace_printf(x) 29 #else 30 # define KTRACE(x...) 31 #endif // RUNTIME_LOADER_TRACING 32 33 #if defined(_COMPAT_MODE) && !defined(__x86_64__) 34 #define RLD_PREFIX "runtime_loader_compat: " 35 #endif 36 #ifndef RLD_PREFIX 37 #define RLD_PREFIX "runtime_loader: " 38 #endif 39 #define FATAL(x...) \ 40 do { \ 41 dprintf(RLD_PREFIX x); \ 42 if (!gProgramLoaded) \ 43 printf(RLD_PREFIX x); \ 44 } while (false) 45 46 47 struct SymbolLookupCache; 48 49 50 extern struct user_space_program_args* gProgramArgs; 51 extern void* __gCommPageAddress; 52 extern struct rld_export gRuntimeLoader; 53 extern char* (*gGetEnv)(const char* name); 54 extern bool gProgramLoaded; 55 extern image_t* gProgramImage; 56 57 58 extern "C" { 59 60 int runtime_loader(void* arg, void* commpage); 61 int open_executable(char* name, image_type type, const char* rpath, 62 const char* programPath, const char* requestingObjectPath, 63 const char* abiSpecificSubDir); 64 status_t test_executable(const char* path, char* interpreter); 65 status_t get_executable_architecture(const char* path, 66 const char** _architecture); 67 68 void terminate_program(void); 69 image_id load_program(char const* path, void** entry); 70 image_id load_library(char const* path, uint32 flags, bool addOn, 71 void** _handle); 72 status_t unload_library(void* handle, image_id imageID, bool addOn); 73 status_t get_nth_symbol(image_id imageID, int32 num, char* nameBuffer, 74 int32* _nameLength, int32* _type, void** _location); 75 status_t get_nearest_symbol_at_address(void* address, image_id* _imageID, 76 char** _imagePath, char** _imageName, char** _symbolName, int32* _type, 77 void** _location, bool* _exactMatch); 78 status_t get_symbol(image_id imageID, char const* symbolName, int32 symbolType, 79 bool recursive, image_id* _inImage, void** _location); 80 status_t get_library_symbol(void* handle, void* caller, const char* symbolName, 81 void** _location); 82 status_t get_next_image_dependency(image_id id, uint32* cookie, 83 const char** _name); 84 int resolve_symbol(image_t* rootImage, image_t* image, elf_sym* sym, 85 SymbolLookupCache* cache, addr_t* sym_addr, image_t** symbolImage = NULL); 86 87 88 status_t elf_verify_header(void* header, size_t length); 89 #ifdef _COMPAT_MODE 90 #ifdef __x86_64__ 91 status_t elf32_verify_header(void *header, size_t length); 92 #else 93 status_t elf64_verify_header(void *header, size_t length); 94 #endif // __x86_64__ 95 #endif // _COMPAT_MODE 96 void rldelf_init(void); 97 void rldexport_init(void); 98 void set_abi_version(int abi_version); 99 status_t elf_reinit_after_fork(void); 100 101 status_t heap_init(void); 102 103 // arch dependent prototypes 104 status_t arch_relocate_image(image_t* rootImage, image_t* image, 105 SymbolLookupCache* cache); 106 107 } 108 109 #endif /* RUNTIME_LOADER_PRIVATE_H */ 110