10119ceebSAxel Dörfler/*
2b6455c08SAxel Dörfler * Copyright 2003-2011, Axel D��rfler, axeld@pinc-software.de.
3f4c3d28aSAxel Dörfler * Distributed under the terms of the MIT License.
4f4c3d28aSAxel Dörfler *
5f4c3d28aSAxel Dörfler * Copyright 2002, Manuel J. Petit. All rights reserved.
6f4c3d28aSAxel Dörfler * Distributed under the terms of the NewOS License.
7f4c3d28aSAxel Dörfler */
8f4c3d28aSAxel Dörfler
90119ceebSAxel Dörfler
1076cd9b19SAxel Dörfler#include "runtime_loader_private.h"
1144c0c4d3SPawel Dziepak#include "elf_tls.h"
120119ceebSAxel Dörfler
130119ceebSAxel Dörfler
140119ceebSAxel Dörfler// exported via the rld_export structure in user space program arguments
150119ceebSAxel Dörfler
160119ceebSAxel Dörfler
170119ceebSAxel Dörflerstatic image_id
180119ceebSAxel Dörflerexport_load_add_on(char const *name, uint32 flags)
190119ceebSAxel Dörfler{
200c85bd05SIngo Weinhold	void* handle;
210c85bd05SIngo Weinhold	return load_library(name, flags, true, &handle);
220119ceebSAxel Dörfler}
230119ceebSAxel Dörfler
240119ceebSAxel Dörfler
250119ceebSAxel Dörflerstatic status_t
260119ceebSAxel Dörflerexport_unload_add_on(image_id id)
270119ceebSAxel Dörfler{
280c85bd05SIngo Weinhold	return unload_library(NULL, id, true);
290c85bd05SIngo Weinhold}
300c85bd05SIngo Weinhold
310c85bd05SIngo Weinhold
320c85bd05SIngo Weinholdstatic image_id
330c85bd05SIngo Weinholdexport_load_library(char const *name, uint32 flags, void **_handle)
340c85bd05SIngo Weinhold{
350c85bd05SIngo Weinhold	return load_library(name, flags, false, _handle);
360c85bd05SIngo Weinhold}
370c85bd05SIngo Weinhold
380c85bd05SIngo Weinhold
390c85bd05SIngo Weinholdstatic status_t
400c85bd05SIngo Weinholdexport_unload_library(void* handle)
410c85bd05SIngo Weinhold{
420c85bd05SIngo Weinhold	return unload_library(handle, -1, false);
430119ceebSAxel Dörfler}
440119ceebSAxel Dörfler
450119ceebSAxel Dörfler
4632560010SAugustin Cavalierstatus_t
4732560010SAugustin Cavalierreinit_after_fork()
4832560010SAugustin Cavalier{
4932560010SAugustin Cavalier	status_t returnstatus = B_OK;
5032560010SAugustin Cavalier	if (status_t status = elf_reinit_after_fork())
5132560010SAugustin Cavalier		returnstatus = status;
5232560010SAugustin Cavalier	if (status_t status = heap_reinit_after_fork())
5332560010SAugustin Cavalier		returnstatus = status;
5432560010SAugustin Cavalier	return returnstatus;
5532560010SAugustin Cavalier}
5632560010SAugustin Cavalier
5732560010SAugustin Cavalier
5834a95562SStephan Aßmusstruct rld_export gRuntimeLoader = {
5934a95562SStephan Aßmus	// dynamic loading support API
6034a95562SStephan Aßmus	export_load_add_on,
6134a95562SStephan Aßmus	export_unload_add_on,
620c85bd05SIngo Weinhold	export_load_library,
630c85bd05SIngo Weinhold	export_unload_library,
640d7ec13aSAxel Dörfler	get_symbol,
650c85bd05SIngo Weinhold	get_library_symbol,
660d7ec13aSAxel Dörfler	get_nth_symbol,
6743e7b1c2SHamish Morrison	get_nearest_symbol_at_address,
680d7ec13aSAxel Dörfler	test_executable,
69cf7e2ad8SIngo Weinhold	get_executable_architecture,
701873b4b3SIngo Weinhold	get_next_image_dependency,
7144c0c4d3SPawel Dziepak	get_tls_address,
7244c0c4d3SPawel Dziepak	destroy_thread_tls,
731873b4b3SIngo Weinhold
74a62458c7SAugustin Cavalier	reinit_after_fork,
75c73aeac1SIngo Weinhold	NULL, // call_atexit_hooks_for_range
765d0a1da8SPawel Dziepak	terminate_program,
775d0a1da8SPawel Dziepak
785d0a1da8SPawel Dziepak	// the following values will be set later
795d0a1da8SPawel Dziepak	NULL,	// program_args
805d0a1da8SPawel Dziepak	NULL,	// commpage_address
815d0a1da8SPawel Dziepak	0		// ABI version
8234a95562SStephan Aßmus};
8334a95562SStephan Aßmus
8444c0c4d3SPawel Dziepakrld_export* __gRuntimeLoader = &gRuntimeLoader;
8544c0c4d3SPawel Dziepak
8634a95562SStephan Aßmus
8734a95562SStephan Aßmusvoid
88be22452fSAxel Dörflerrldexport_init(void)
890119ceebSAxel Dörfler{
9034a95562SStephan Aßmus	gRuntimeLoader.program_args = gProgramArgs;
91e85e399fSPawel Dziepak	gRuntimeLoader.commpage_address = __gCommPageAddress;
920119ceebSAxel Dörfler}
935d0a1da8SPawel Dziepak
945d0a1da8SPawel Dziepak
9507e1875eSPawel Dziepak/*!	Is called for all images, and sets the minimum ABI version found to the
96be06cb25SJérôme Duval	gRuntimeLoader.abi_version field and the minimum API version found to the
97be06cb25SJérôme Duval	gRuntimeLoader.api_version field.
9807e1875eSPawel Dziepak*/
995d0a1da8SPawel Dziepakvoid
100be06cb25SJérôme Duvalset_abi_api_version(int abi_version, int api_version)
1015d0a1da8SPawel Dziepak{
1025d0a1da8SPawel Dziepak	if (gRuntimeLoader.abi_version == 0
1035d0a1da8SPawel Dziepak		|| gRuntimeLoader.abi_version > abi_version) {
1045d0a1da8SPawel Dziepak		gRuntimeLoader.abi_version = abi_version;
1055d0a1da8SPawel Dziepak	}
106be06cb25SJérôme Duval	if (gRuntimeLoader.api_version == 0
107be06cb25SJérôme Duval		|| gRuntimeLoader.api_version > api_version) {
108be06cb25SJérôme Duval		gRuntimeLoader.api_version = api_version;
109be06cb25SJérôme Duval	}
1105d0a1da8SPawel Dziepak}
111