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