xref: /haiku/src/system/runtime_loader/export.cpp (revision 07e1875ea21bd0a05e949cce0d4e4558b6684ee0)
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"
11003ebb0eSIngo Weinhold 
12003ebb0eSIngo Weinhold 
13003ebb0eSIngo Weinhold // exported via the rld_export structure in user space program arguments
14003ebb0eSIngo Weinhold 
15003ebb0eSIngo Weinhold 
16003ebb0eSIngo Weinhold static image_id
17003ebb0eSIngo Weinhold export_load_add_on(char const *name, uint32 flags)
18003ebb0eSIngo Weinhold {
19003ebb0eSIngo Weinhold 	void* handle;
20003ebb0eSIngo Weinhold 	return load_library(name, flags, true, &handle);
21003ebb0eSIngo Weinhold }
22003ebb0eSIngo Weinhold 
23003ebb0eSIngo Weinhold 
24003ebb0eSIngo Weinhold static status_t
25003ebb0eSIngo Weinhold export_unload_add_on(image_id id)
26003ebb0eSIngo Weinhold {
27003ebb0eSIngo Weinhold 	return unload_library(NULL, id, true);
28003ebb0eSIngo Weinhold }
29003ebb0eSIngo Weinhold 
30003ebb0eSIngo Weinhold 
31003ebb0eSIngo Weinhold static image_id
32003ebb0eSIngo Weinhold export_load_library(char const *name, uint32 flags, void **_handle)
33003ebb0eSIngo Weinhold {
34003ebb0eSIngo Weinhold 	return load_library(name, flags, false, _handle);
35003ebb0eSIngo Weinhold }
36003ebb0eSIngo Weinhold 
37003ebb0eSIngo Weinhold 
38003ebb0eSIngo Weinhold static status_t
39003ebb0eSIngo Weinhold export_unload_library(void* handle)
40003ebb0eSIngo Weinhold {
41003ebb0eSIngo Weinhold 	return unload_library(handle, -1, false);
42003ebb0eSIngo Weinhold }
43003ebb0eSIngo Weinhold 
44003ebb0eSIngo Weinhold 
45003ebb0eSIngo Weinhold struct rld_export gRuntimeLoader = {
46003ebb0eSIngo Weinhold 	// dynamic loading support API
47003ebb0eSIngo Weinhold 	export_load_add_on,
48003ebb0eSIngo Weinhold 	export_unload_add_on,
49003ebb0eSIngo Weinhold 	export_load_library,
50003ebb0eSIngo Weinhold 	export_unload_library,
51003ebb0eSIngo Weinhold 	get_symbol,
52003ebb0eSIngo Weinhold 	get_library_symbol,
53003ebb0eSIngo Weinhold 	get_nth_symbol,
5443e7b1c2SHamish Morrison 	get_nearest_symbol_at_address,
55003ebb0eSIngo Weinhold 	test_executable,
56003ebb0eSIngo Weinhold 	get_next_image_dependency,
57003ebb0eSIngo Weinhold 
58003ebb0eSIngo Weinhold 	elf_reinit_after_fork,
59003ebb0eSIngo Weinhold 	NULL, // call_atexit_hooks_for_range
605d0a1da8SPawel Dziepak 	terminate_program,
615d0a1da8SPawel Dziepak 
625d0a1da8SPawel Dziepak 	// the following values will be set later
635d0a1da8SPawel Dziepak 	NULL,	// program_args
645d0a1da8SPawel Dziepak 	NULL,	// commpage_address
655d0a1da8SPawel Dziepak 	0		// ABI version
66003ebb0eSIngo Weinhold };
67003ebb0eSIngo Weinhold 
68003ebb0eSIngo Weinhold 
69003ebb0eSIngo Weinhold void
70003ebb0eSIngo Weinhold rldexport_init(void)
71003ebb0eSIngo Weinhold {
72003ebb0eSIngo Weinhold 	gRuntimeLoader.program_args = gProgramArgs;
73e85e399fSPawel Dziepak 	gRuntimeLoader.commpage_address = __gCommPageAddress;
74003ebb0eSIngo Weinhold }
755d0a1da8SPawel Dziepak 
765d0a1da8SPawel Dziepak 
77*07e1875eSPawel Dziepak /*!	Is called for all images, and sets the minimum ABI version found to the
78*07e1875eSPawel Dziepak 	gRuntimeLoader.abi_version field.
79*07e1875eSPawel Dziepak */
805d0a1da8SPawel Dziepak void
815d0a1da8SPawel Dziepak set_abi_version(int abi_version)
825d0a1da8SPawel Dziepak {
835d0a1da8SPawel Dziepak 	if (gRuntimeLoader.abi_version == 0
845d0a1da8SPawel Dziepak 		|| gRuntimeLoader.abi_version > abi_version) {
855d0a1da8SPawel Dziepak 		gRuntimeLoader.abi_version = abi_version;
865d0a1da8SPawel Dziepak 	}
875d0a1da8SPawel Dziepak }
88