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 #if __GNUC__ == 2 35 #define RLD_PREFIX "runtime_loader_x86_gcc2: " 36 #else 37 #define RLD_PREFIX "runtime_loader_x86: " 38 #endif 39 #endif 40 #ifndef RLD_PREFIX 41 #define RLD_PREFIX "runtime_loader: " 42 #endif 43 #define FATAL(x...) \ 44 do { \ 45 dprintf(RLD_PREFIX x); \ 46 if (!gProgramLoaded) \ 47 printf(RLD_PREFIX x); \ 48 } while (false) 49 50 51 struct SymbolLookupCache; 52 53 54 extern struct user_space_program_args* gProgramArgs; 55 extern void* __gCommPageAddress; 56 extern struct rld_export gRuntimeLoader; 57 extern char* (*gGetEnv)(const char* name); 58 extern bool gProgramLoaded; 59 extern image_t* gProgramImage; 60 61 62 extern "C" { 63 64 int runtime_loader(void* arg, void* commpage); 65 int open_executable(char* name, image_type type, const char* rpath, 66 const char* programPath, const char* requestingObjectPath, 67 const char* abiSpecificSubDir); 68 status_t test_executable(const char* path, char* interpreter); 69 status_t get_executable_architecture(const char* path, 70 const char** _architecture); 71 72 void terminate_program(void); 73 image_id load_program(char const* path, void** entry); 74 image_id load_library(char const* path, uint32 flags, bool addOn, 75 void** _handle); 76 status_t unload_library(void* handle, image_id imageID, bool addOn); 77 status_t get_nth_symbol(image_id imageID, int32 num, char* nameBuffer, 78 int32* _nameLength, int32* _type, void** _location); 79 status_t get_nearest_symbol_at_address(void* address, image_id* _imageID, 80 char** _imagePath, char** _imageName, char** _symbolName, int32* _type, 81 void** _location, bool* _exactMatch); 82 status_t get_symbol(image_id imageID, char const* symbolName, int32 symbolType, 83 bool recursive, image_id* _inImage, void** _location); 84 status_t get_library_symbol(void* handle, void* caller, const char* symbolName, 85 void** _location); 86 status_t get_next_image_dependency(image_id id, uint32* cookie, 87 const char** _name); 88 int resolve_symbol(image_t* rootImage, image_t* image, elf_sym* sym, 89 SymbolLookupCache* cache, addr_t* sym_addr, image_t** symbolImage = NULL); 90 91 92 status_t elf_verify_header(void* header, size_t length); 93 #ifdef _COMPAT_MODE 94 #ifdef __x86_64__ 95 status_t elf32_verify_header(void *header, size_t length); 96 #else 97 status_t elf64_verify_header(void *header, size_t length); 98 #endif // __x86_64__ 99 #endif // _COMPAT_MODE 100 void rldelf_init(void); 101 void rldexport_init(void); 102 void set_abi_version(int abi_version); 103 status_t elf_reinit_after_fork(); 104 105 status_t heap_init(); 106 status_t heap_reinit_after_fork(); 107 108 // arch dependent prototypes 109 status_t arch_relocate_image(image_t* rootImage, image_t* image, 110 SymbolLookupCache* cache); 111 112 } 113 114 #endif /* RUNTIME_LOADER_PRIVATE_H */ 115