xref: /haiku/src/system/runtime_loader/runtime_loader_private.h (revision 2510baa4685f8f570c607ceedfd73473d69342c4)
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 #ifndef RUNTIME_LOADER_PRIVATE_H
9 #define RUNTIME_LOADER_PRIVATE_H
10 
11 #include <user_runtime.h>
12 #include <runtime_loader.h>
13 
14 #include "tracing_config.h"
15 
16 #include "utility.h"
17 
18 
19 //#define TRACE_RLD
20 #ifdef TRACE_RLD
21 #	define TRACE(x) dprintf x
22 #else
23 #	define TRACE(x) ;
24 #endif
25 
26 
27 #if RUNTIME_LOADER_TRACING
28 #	define KTRACE(x...)	ktrace_printf(x)
29 #else
30 #	define KTRACE(x...)
31 #endif	// RUNTIME_LOADER_TRACING
32 
33 
34 #define FATAL(x...)							\
35 	do {									\
36 		dprintf("runtime_loader: " x);		\
37 		if (!gProgramLoaded)				\
38 			printf("runtime_loader: " x);	\
39 	} while (false)
40 
41 
42 struct SymbolLookupCache;
43 
44 
45 extern struct user_space_program_args* gProgramArgs;
46 extern struct rld_export gRuntimeLoader;
47 extern char* (*gGetEnv)(const char* name);
48 extern bool gProgramLoaded;
49 extern image_t* gProgramImage;
50 
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 int runtime_loader(void* arg);
57 int open_executable(char* name, image_type type, const char* rpath,
58 	const char* programPath, const char* compatibilitySubDir);
59 status_t test_executable(const char* path, char* interpreter);
60 
61 void terminate_program(void);
62 image_id load_program(char const* path, void** entry);
63 image_id load_library(char const* path, uint32 flags, bool addOn,
64 	void** _handle);
65 status_t unload_library(void* handle, image_id imageID, bool addOn);
66 status_t get_nth_symbol(image_id imageID, int32 num, char* nameBuffer,
67 	int32* _nameLength, int32* _type, void** _location);
68 status_t get_nearest_symbol_at_address(void* address, image_id* _imageID,
69 	char** _imagePath, char** _symbolName, int32* _type, void** _location);
70 status_t get_symbol(image_id imageID, char const* symbolName, int32 symbolType,
71 	bool recursive, image_id* _inImage, void** _location);
72 status_t get_library_symbol(void* handle, void* caller, const char* symbolName,
73 	void** _location);
74 status_t get_next_image_dependency(image_id id, uint32* cookie,
75 	const char** _name);
76 int resolve_symbol(image_t* rootImage, image_t* image, elf_sym* sym,
77 	SymbolLookupCache* cache, addr_t* sym_addr);
78 
79 
80 status_t elf_verify_header(void* header, size_t length);
81 void rldelf_init(void);
82 void rldexport_init(void);
83 status_t elf_reinit_after_fork(void);
84 
85 status_t heap_init(void);
86 
87 // arch dependent prototypes
88 status_t arch_relocate_image(image_t* rootImage, image_t* image,
89 	SymbolLookupCache* cache);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif	/* RUNTIME_LOADER_PRIVATE_H */
96