xref: /haiku/headers/os/kernel/image.h (revision f75a7bf508f3156d63a14f8fd77c5e0ca4d08c42)
1 /*
2  * Copyright 2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT license.
4  */
5 #ifndef _IMAGE_H
6 #define	_IMAGE_H
7 
8 
9 #include <OS.h>
10 #include <sys/param.h>
11 
12 
13 typedef	int32 image_id;
14 
15 typedef enum {
16 	B_APP_IMAGE			= 1,
17 	B_LIBRARY_IMAGE,
18 	B_ADD_ON_IMAGE,
19 	B_SYSTEM_IMAGE
20 } image_type;
21 
22 typedef struct {
23 	image_id	id;
24 	image_type	type;
25 	int32		sequence;
26 	int32		init_order;
27 	void		(*init_routine)();
28 	void		(*term_routine)();
29 	dev_t		device;
30 	ino_t		node;
31 	char		name[MAXPATHLEN];
32 	void		*text;
33 	void		*data;
34 	int32		text_size;
35 	int32		data_size;
36 } image_info;
37 
38 // flags for clear_caches()
39 #define B_FLUSH_DCACHE				0x0001	/* data cache */
40 #define B_FLUSH_ICACHE				0x0004	/* instruction cache */
41 #define B_INVALIDATE_DCACHE			0x0002
42 #define B_INVALIDATE_ICACHE			0x0008
43 
44 // symbol types
45 #define	B_SYMBOL_TYPE_DATA			0x1
46 #define	B_SYMBOL_TYPE_TEXT			0x2
47 #define B_SYMBOL_TYPE_ANY			0x5
48 
49 // initialization/termination functions of shared objects
50 #define	B_INIT_BEFORE_FUNCTION_NAME	"initialize_before"
51 #define B_INIT_AFTER_FUNCTION_NAME	"initialize_after"
52 #define	B_TERM_BEFORE_FUNCTION_NAME	"terminate_before"
53 #define B_TERM_AFTER_FUNCTION_NAME	"terminate_after"
54 
55 // flags for _kern_load_image() (private API)
56 enum {
57 	B_WAIT_TILL_LOADED	= 0x01,
58 		// Wait till the loader has loaded and relocated
59 		// (but not yet initialized) the application
60 		// image and all dependencies. If not supplied,
61 		// the function returns before the loader
62 		// started to do anything at all, i.e. it
63 		// returns success, even if the executable
64 		// doesn't exist.
65 };
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 thread_id load_image(int32 argc, const char **argv, const char **environ);
72 image_id load_add_on(const char *path);
73 status_t unload_add_on(image_id image);
74 status_t get_image_symbol(image_id image, const char *name, int32 symbolType,
75 				void **_symbolLocation);
76 status_t get_nth_image_symbol(image_id image, int32 n, char *nameBuffer,
77 				int32 *_nameLength, int32 *_symbolType, void **_symbolLocation);
78 void clear_caches(void *address, size_t length, uint32 flags);
79 
80 #define get_image_info(image, info) \
81 				_get_image_info((image), (info), sizeof(*(info)))
82 #define get_next_image_info(team, cookie, info) \
83 				_get_next_image_info((team), (cookie), (info), sizeof(*(info)))
84 
85 /* private, use the macros above */
86 status_t _get_image_info (image_id image, image_info *info, size_t size);
87 status_t _get_next_image_info (team_id team, int32 *cookie, image_info *info,
88 				size_t size);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif	/* _IMAGE_H */
95