1003ebb0eSIngo Weinhold /*
2b6455c08SAxel Dörfler * Copyright 2003-2011, Axel Dörfler, axeld@pinc-software.de.
3003ebb0eSIngo Weinhold * Distributed under the terms of the MIT License.
4003ebb0eSIngo Weinhold *
5003ebb0eSIngo Weinhold * Copyright 2002, Manuel J. Petit. All rights reserved.
6003ebb0eSIngo Weinhold * Distributed under the terms of the NewOS License.
7003ebb0eSIngo Weinhold */
8003ebb0eSIngo Weinhold
9003ebb0eSIngo Weinhold
10003ebb0eSIngo Weinhold #include "runtime_loader_private.h"
1144c0c4d3SPawel Dziepak #include "elf_tls.h"
12003ebb0eSIngo Weinhold
13003ebb0eSIngo Weinhold
14003ebb0eSIngo Weinhold // exported via the rld_export structure in user space program arguments
15003ebb0eSIngo Weinhold
16003ebb0eSIngo Weinhold
17003ebb0eSIngo Weinhold static image_id
export_load_add_on(char const * name,uint32 flags)18003ebb0eSIngo Weinhold export_load_add_on(char const *name, uint32 flags)
19003ebb0eSIngo Weinhold {
20003ebb0eSIngo Weinhold void* handle;
21*b2b83ad1SJérôme Duval return load_library(name, flags, true, NULL, &handle);
22003ebb0eSIngo Weinhold }
23003ebb0eSIngo Weinhold
24003ebb0eSIngo Weinhold
25003ebb0eSIngo Weinhold static status_t
export_unload_add_on(image_id id)26003ebb0eSIngo Weinhold export_unload_add_on(image_id id)
27003ebb0eSIngo Weinhold {
28003ebb0eSIngo Weinhold return unload_library(NULL, id, true);
29003ebb0eSIngo Weinhold }
30003ebb0eSIngo Weinhold
31003ebb0eSIngo Weinhold
32003ebb0eSIngo Weinhold static image_id
export_load_library(char const * name,uint32 flags,void * caller,void ** _handle)33*b2b83ad1SJérôme Duval export_load_library(char const *name, uint32 flags, void* caller,
34*b2b83ad1SJérôme Duval void **_handle)
35003ebb0eSIngo Weinhold {
36*b2b83ad1SJérôme Duval return load_library(name, flags, false, caller, _handle);
37003ebb0eSIngo Weinhold }
38003ebb0eSIngo Weinhold
39003ebb0eSIngo Weinhold
40003ebb0eSIngo Weinhold static status_t
export_unload_library(void * handle)41003ebb0eSIngo Weinhold export_unload_library(void* handle)
42003ebb0eSIngo Weinhold {
43003ebb0eSIngo Weinhold return unload_library(handle, -1, false);
44003ebb0eSIngo Weinhold }
45003ebb0eSIngo Weinhold
46003ebb0eSIngo Weinhold
4732560010SAugustin Cavalier status_t
reinit_after_fork()4832560010SAugustin Cavalier reinit_after_fork()
4932560010SAugustin Cavalier {
5032560010SAugustin Cavalier status_t returnstatus = B_OK;
5132560010SAugustin Cavalier if (status_t status = elf_reinit_after_fork())
5232560010SAugustin Cavalier returnstatus = status;
5332560010SAugustin Cavalier if (status_t status = heap_reinit_after_fork())
5432560010SAugustin Cavalier returnstatus = status;
5532560010SAugustin Cavalier return returnstatus;
5632560010SAugustin Cavalier }
5732560010SAugustin Cavalier
5832560010SAugustin Cavalier
59003ebb0eSIngo Weinhold struct rld_export gRuntimeLoader = {
60003ebb0eSIngo Weinhold // dynamic loading support API
61003ebb0eSIngo Weinhold export_load_add_on,
62003ebb0eSIngo Weinhold export_unload_add_on,
63003ebb0eSIngo Weinhold export_load_library,
64003ebb0eSIngo Weinhold export_unload_library,
65003ebb0eSIngo Weinhold get_symbol,
66003ebb0eSIngo Weinhold get_library_symbol,
67003ebb0eSIngo Weinhold get_nth_symbol,
6843e7b1c2SHamish Morrison get_nearest_symbol_at_address,
69003ebb0eSIngo Weinhold test_executable,
70cf7e2ad8SIngo Weinhold get_executable_architecture,
71003ebb0eSIngo Weinhold get_next_image_dependency,
7244c0c4d3SPawel Dziepak get_tls_address,
7344c0c4d3SPawel Dziepak destroy_thread_tls,
74003ebb0eSIngo Weinhold
75a62458c7SAugustin Cavalier reinit_after_fork,
76003ebb0eSIngo Weinhold NULL, // call_atexit_hooks_for_range
775d0a1da8SPawel Dziepak terminate_program,
785d0a1da8SPawel Dziepak
795d0a1da8SPawel Dziepak // the following values will be set later
805d0a1da8SPawel Dziepak NULL, // program_args
815d0a1da8SPawel Dziepak NULL, // commpage_address
825d0a1da8SPawel Dziepak 0 // ABI version
83003ebb0eSIngo Weinhold };
84003ebb0eSIngo Weinhold
8544c0c4d3SPawel Dziepak rld_export* __gRuntimeLoader = &gRuntimeLoader;
8644c0c4d3SPawel Dziepak
87003ebb0eSIngo Weinhold
88003ebb0eSIngo Weinhold void
rldexport_init(void)89003ebb0eSIngo Weinhold rldexport_init(void)
90003ebb0eSIngo Weinhold {
91003ebb0eSIngo Weinhold gRuntimeLoader.program_args = gProgramArgs;
92e85e399fSPawel Dziepak gRuntimeLoader.commpage_address = __gCommPageAddress;
93003ebb0eSIngo Weinhold }
945d0a1da8SPawel Dziepak
955d0a1da8SPawel Dziepak
9607e1875eSPawel Dziepak /*! Is called for all images, and sets the minimum ABI version found to the
97be06cb25SJérôme Duval gRuntimeLoader.abi_version field and the minimum API version found to the
98be06cb25SJérôme Duval gRuntimeLoader.api_version field.
9907e1875eSPawel Dziepak */
1005d0a1da8SPawel Dziepak void
set_abi_api_version(int abi_version,int api_version)101be06cb25SJérôme Duval set_abi_api_version(int abi_version, int api_version)
1025d0a1da8SPawel Dziepak {
1035d0a1da8SPawel Dziepak if (gRuntimeLoader.abi_version == 0
1045d0a1da8SPawel Dziepak || gRuntimeLoader.abi_version > abi_version) {
1055d0a1da8SPawel Dziepak gRuntimeLoader.abi_version = abi_version;
1065d0a1da8SPawel Dziepak }
107be06cb25SJérôme Duval if (gRuntimeLoader.api_version == 0
108be06cb25SJérôme Duval || gRuntimeLoader.api_version > api_version) {
109be06cb25SJérôme Duval gRuntimeLoader.api_version = api_version;
110be06cb25SJérôme Duval }
1115d0a1da8SPawel Dziepak }
112