1/*
2 * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2003-2011, Axel D��rfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
5 *
6 * Copyright 2002, Manuel J. Petit. All rights reserved.
7 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
8 * Distributed under the terms of the NewOS License.
9 */
10#ifndef IMAGES_H
11#define IMAGES_H
12
13#include <runtime_loader.h>
14
15
16enum {
17	// the lower two bits are reserved for RTLD_NOW and RTLD_GLOBAL
18
19	RFLAG_RW					= 0x0010,
20	RFLAG_ANON					= 0x0020,
21
22	RFLAG_TERMINATED			= 0x0200,
23	RFLAG_INITIALIZED			= 0x0400,
24	RFLAG_SYMBOLIC				= 0x0800,
25	RFLAG_RELOCATED				= 0x1000,
26	RFLAG_PROTECTED				= 0x2000,
27	RFLAG_DEPENDENCIES_LOADED	= 0x4000,
28	RFLAG_REMAPPED				= 0x8000,
29
30	RFLAG_VISITED				= 0x10000,
31	RFLAG_USE_FOR_RESOLVING		= 0x20000
32		// temporarily set in the symbol resolution code
33};
34
35
36#define IMAGE_TYPE_TO_MASK(type)	(1 << ((type) - 1))
37#define ALL_IMAGE_TYPES				(IMAGE_TYPE_TO_MASK(B_APP_IMAGE) \
38									| IMAGE_TYPE_TO_MASK(B_LIBRARY_IMAGE) \
39									| IMAGE_TYPE_TO_MASK(B_ADD_ON_IMAGE) \
40									| IMAGE_TYPE_TO_MASK(B_SYSTEM_IMAGE))
41#define APP_OR_LIBRARY_TYPE			(IMAGE_TYPE_TO_MASK(B_APP_IMAGE) \
42									| IMAGE_TYPE_TO_MASK(B_LIBRARY_IMAGE))
43
44
45extern bool gInvalidImageIDs;
46
47
48image_t*	create_image(const char* name, const char* path, int regionCount);
49void		delete_image_struct(image_t* image);
50void		delete_image(image_t* image);
51void		put_image(image_t* image);
52
53status_t	map_image(int fd, char const* path, image_t* image, bool fixed);
54void		unmap_image(image_t* image);
55void		remap_images();
56
57void		register_image(image_t* image, int fd, const char* path);
58status_t	update_image_ids();
59
60image_queue_t& get_loaded_images();
61image_queue_t& get_disposable_images();
62uint32		count_loaded_images();
63void		enqueue_loaded_image(image_t* image);
64void		dequeue_loaded_image(image_t* image);
65void		dequeue_disposable_image(image_t* image);
66
67image_t*	find_loaded_image_by_name(char const* name, uint32 typeMask);
68image_t*	find_loaded_image_by_id(image_id id, bool ignoreDisposable);
69image_t*	find_loaded_image_by_address(addr_t address);
70
71void		set_image_flags_recursively(image_t* image, uint32 flags);
72void		clear_image_flags_recursively(image_t* image, uint32 flags);
73ssize_t		get_sorted_image_list(image_t* image, image_t*** _list,
74				uint32 sortFlag);
75
76
77#endif	// IMAGES_H
78