xref: /haiku/headers/private/runtime_loader/runtime_loader.h (revision 4b3b81da9e459443d75329cfd08bc9a57ad02653)
1 /*
2  * Copyright 2003-2006, 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  * Copyright 2001, Travis Geiselbrecht. All rights reserved.
7  * Distributed under the terms of the NewOS License.
8  */
9 
10 #ifndef _RUNTIME_LOADER_H
11 #define _RUNTIME_LOADER_H
12 
13 #include <image.h>
14 #include <OS.h>
15 
16 #include <elf32.h>
17 
18 typedef struct elf_region_t {
19 	area_id		id;
20 	addr_t		start;
21 	addr_t		size;
22 	addr_t		vmstart;
23 	addr_t		vmsize;
24 	addr_t		fdstart;
25 	addr_t		fdsize;
26 	long		delta;
27 	uint32		flags;
28 } elf_region_t;
29 
30 typedef struct image_t {
31 	// image identification
32 	char				path[B_PATH_NAME_LENGTH];
33 	char				name[B_OS_NAME_LENGTH];
34 	image_id			id;
35 	image_type			type;
36 
37 	struct image_t		*next;
38 	struct image_t		*prev;
39 	int32				ref_count;
40 	uint32				flags;
41 
42 	struct {
43 		int				major;
44 		int				middle;
45 		int				minor;
46 	} gcc_version;
47 
48 	addr_t 				entry_point;
49 	addr_t				init_routine;
50 	addr_t				term_routine;
51 	addr_t 				dynamic_ptr; 	// pointer to the dynamic section
52 
53 	// pointer to symbol participation data structures
54 	uint32				*symhash;
55 	struct Elf32_Sym	*syms;
56 	char				*strtab;
57 	struct Elf32_Rel	*rel;
58 	int					rel_len;
59 	struct Elf32_Rela	*rela;
60 	int					rela_len;
61 	struct Elf32_Rel	*pltrel;
62 	int					pltrel_len;
63 
64 	uint32				num_needed;
65 	struct image_t		**needed;
66 
67 	// describes the text and data regions
68 	uint32				num_regions;
69 	elf_region_t		regions[1];
70 } image_t;
71 
72 typedef struct image_queue_t {
73 	image_t *head;
74 	image_t *tail;
75 } image_queue_t;
76 
77 // image_t::flags
78 #define	IMAGE_FLAG_RTLD_MASK			0x03
79 			// RTLD_{LAZY,NOW} | RTLD_{LOCAL,GLOBAL}
80 #define	IMAGE_FLAG_R5_SYMBOL_RESOLUTION	0x04
81 
82 #define STRING(image, offset) ((char *)(&(image)->strtab[(offset)]))
83 #define SYMNAME(image, sym) STRING(image, (sym)->st_name)
84 #define SYMBOL(image, num) ((struct Elf32_Sym *)&(image)->syms[num])
85 #define HASHTABSIZE(image) ((image)->symhash[0])
86 #define HASHBUCKETS(image) ((unsigned int *)&(image)->symhash[2])
87 #define HASHCHAINS(image) ((unsigned int *)&(image)->symhash[2+HASHTABSIZE(image)])
88 
89 
90 // The name of the area the runtime loader creates for debugging purposes.
91 #define RUNTIME_LOADER_DEBUG_AREA_NAME	"_rld_debug_"
92 
93 // The contents of the runtime loader debug area.
94 typedef struct runtime_loader_debug_area {
95 	image_queue_t	*loaded_images;
96 } runtime_loader_debug_area;
97 
98 #endif	// _RUNTIME_LOADER_H
99