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 9 10 #include "runtime_loader_private.h" 11 #include "elf_tls.h" 12 13 14 // exported via the rld_export structure in user space program arguments 15 16 17 static image_id 18 export_load_add_on(char const *name, uint32 flags) 19 { 20 void* handle; 21 return load_library(name, flags, true, &handle); 22 } 23 24 25 static status_t 26 export_unload_add_on(image_id id) 27 { 28 return unload_library(NULL, id, true); 29 } 30 31 32 static image_id 33 export_load_library(char const *name, uint32 flags, void **_handle) 34 { 35 return load_library(name, flags, false, _handle); 36 } 37 38 39 static status_t 40 export_unload_library(void* handle) 41 { 42 return unload_library(handle, -1, false); 43 } 44 45 46 struct rld_export gRuntimeLoader = { 47 // dynamic loading support API 48 export_load_add_on, 49 export_unload_add_on, 50 export_load_library, 51 export_unload_library, 52 get_symbol, 53 get_library_symbol, 54 get_nth_symbol, 55 get_nearest_symbol_at_address, 56 test_executable, 57 get_executable_architecture, 58 get_next_image_dependency, 59 get_tls_address, 60 destroy_thread_tls, 61 62 elf_reinit_after_fork, 63 NULL, // call_atexit_hooks_for_range 64 terminate_program, 65 66 // the following values will be set later 67 NULL, // program_args 68 NULL, // commpage_address 69 0 // ABI version 70 }; 71 72 rld_export* __gRuntimeLoader = &gRuntimeLoader; 73 74 75 void 76 rldexport_init(void) 77 { 78 gRuntimeLoader.program_args = gProgramArgs; 79 gRuntimeLoader.commpage_address = __gCommPageAddress; 80 } 81 82 83 /*! Is called for all images, and sets the minimum ABI version found to the 84 gRuntimeLoader.abi_version field. 85 */ 86 void 87 set_abi_version(int abi_version) 88 { 89 if (gRuntimeLoader.abi_version == 0 90 || gRuntimeLoader.abi_version > abi_version) { 91 gRuntimeLoader.abi_version = abi_version; 92 } 93 } 94