1/* 2 * Copyright 2007-2019, 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 13typedef int32 image_id; 14 15typedef enum { 16 B_APP_IMAGE = 1, 17 B_LIBRARY_IMAGE, 18 B_ADD_ON_IMAGE, 19 B_SYSTEM_IMAGE 20} image_type; 21 22typedef 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 37 /* Haiku R1 extensions */ 38 int32 api_version; /* the Haiku API version used by the image */ 39 int32 abi; /* the Haiku ABI used by the image */ 40} image_info; 41 42 43#ifdef __cplusplus 44extern "C" { 45#endif 46 47 48/* flags for clear_caches() */ 49#define B_FLUSH_DCACHE 0x0001 /* data cache */ 50#define B_FLUSH_ICACHE 0x0004 /* instruction cache */ 51#define B_INVALIDATE_DCACHE 0x0002 52#define B_INVALIDATE_ICACHE 0x0008 53 54 55/* symbol types */ 56#define B_SYMBOL_TYPE_DATA 0x1 57#define B_SYMBOL_TYPE_TEXT 0x2 58#define B_SYMBOL_TYPE_ANY 0x5 59 60 61/* initialization/termination functions of shared objects */ 62#define B_INIT_BEFORE_FUNCTION_NAME "initialize_before" 63#define B_INIT_AFTER_FUNCTION_NAME "initialize_after" 64#define B_TERM_BEFORE_FUNCTION_NAME "terminate_before" 65#define B_TERM_AFTER_FUNCTION_NAME "terminate_after" 66 67void initialize_before(image_id self); 68void initialize_after(image_id self); 69void terminate_before(image_id self); 70void terminate_after(image_id self); 71 72 73#define B_APP_IMAGE_SYMBOL ((void*)(addr_t)0) 74 /* value that can be used instead of a pointer to a symbol in the program 75 image. */ 76#define B_CURRENT_IMAGE_SYMBOL ((void*)__func__) 77 /* pointer to a symbol in the callers image */ 78 79 80thread_id load_image(int32 argc, const char **argv, const char **environ); 81image_id load_add_on(const char *path); 82status_t unload_add_on(image_id image); 83status_t get_image_symbol(image_id image, const char *name, int32 symbolType, 84 void **_symbolLocation); 85status_t get_nth_image_symbol(image_id image, int32 n, char *nameBuffer, 86 int32 *_nameLength, int32 *_symbolType, void **_symbolLocation); 87void clear_caches(void *address, size_t length, uint32 flags); 88 89#define get_image_info(image, info) \ 90 _get_image_info((image), (info), sizeof(*(info))) 91#define get_next_image_info(team, cookie, info) \ 92 _get_next_image_info((team), (cookie), (info), sizeof(*(info))) 93 94/* private, use the macros above */ 95status_t _get_image_info(image_id image, image_info *info, size_t size); 96status_t _get_next_image_info(team_id team, int32 *cookie, image_info *info, 97 size_t size); 98 99 100#ifdef __cplusplus 101} 102#endif 103 104 105#endif /* _IMAGE_H */ 106