2007-10-16 03:21:01 +04:00
|
|
|
/*
|
2019-02-02 03:45:56 +03:00
|
|
|
* Copyright 2007-2019, Haiku, Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
2007-10-16 03:21:01 +04:00
|
|
|
*/
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifndef _IMAGE_H
|
|
|
|
#define _IMAGE_H
|
|
|
|
|
2007-10-16 03:21:01 +04:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#include <OS.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
|
|
|
|
typedef int32 image_id;
|
|
|
|
|
|
|
|
typedef enum {
|
2007-10-16 03:21:01 +04:00
|
|
|
B_APP_IMAGE = 1,
|
2002-09-20 02:33:58 +04:00
|
|
|
B_LIBRARY_IMAGE,
|
|
|
|
B_ADD_ON_IMAGE,
|
|
|
|
B_SYSTEM_IMAGE
|
|
|
|
} image_type;
|
|
|
|
|
|
|
|
typedef struct {
|
2002-10-05 05:19:31 +04:00
|
|
|
image_id id;
|
|
|
|
image_type type;
|
|
|
|
int32 sequence;
|
|
|
|
int32 init_order;
|
2002-09-20 02:33:58 +04:00
|
|
|
void (*init_routine)();
|
|
|
|
void (*term_routine)();
|
2002-10-05 05:19:31 +04:00
|
|
|
dev_t device;
|
2002-09-20 02:33:58 +04:00
|
|
|
ino_t node;
|
2002-10-05 05:19:31 +04:00
|
|
|
char name[MAXPATHLEN];
|
|
|
|
void *text;
|
2002-09-20 02:33:58 +04:00
|
|
|
void *data;
|
2002-10-05 05:19:31 +04:00
|
|
|
int32 text_size;
|
|
|
|
int32 data_size;
|
2009-05-13 01:08:56 +04:00
|
|
|
|
2016-03-27 17:58:38 +03:00
|
|
|
/* Haiku R1 extensions */
|
|
|
|
int32 api_version; /* the Haiku API version used by the image */
|
|
|
|
int32 abi; /* the Haiku ABI used by the image */
|
2002-09-20 02:33:58 +04:00
|
|
|
} image_info;
|
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
headers/kernel: Define B_CURRENT_IMAGE_SYMBOL via __func__.
Previously, __haiku_init_before was a symbol that was included in
each (shared) object, and so it could be used to determine what
one we were in. Now, there are no such universal symbols that
are declared private to only the object, so we have to use
a different approach.
__func__ is defined as a const char* at the very beginning of
every function it's used in, set to a string of the function name
only, i.e., the arguments and return type are left off. So while
including that is perhaps not quite optimal, in practice this
definition is used extremely rarely (it was introduced by Haiku,
and it is used in only 2 applications at all that I could find --
WebKit and Canna.)
There really isn't any other way to get a pointer that we know
for certain is within the current object besides this one
without inserting one, but that really isn't merited just for this.
(__builtin_return_address() has problematic semantics wrt. inlining,
including linker-inlining.) So this will have to do.
2019-02-02 03:50:29 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-03-27 17:58:38 +03:00
|
|
|
/* flags for clear_caches() */
|
2007-10-16 03:21:01 +04:00
|
|
|
#define B_FLUSH_DCACHE 0x0001 /* data cache */
|
|
|
|
#define B_FLUSH_ICACHE 0x0004 /* instruction cache */
|
|
|
|
#define B_INVALIDATE_DCACHE 0x0002
|
|
|
|
#define B_INVALIDATE_ICACHE 0x0008
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
2016-03-27 17:58:38 +03:00
|
|
|
/* symbol types */
|
2019-02-02 03:19:38 +03:00
|
|
|
#define B_SYMBOL_TYPE_DATA 0x1
|
|
|
|
#define B_SYMBOL_TYPE_TEXT 0x2
|
2007-10-16 03:21:01 +04:00
|
|
|
#define B_SYMBOL_TYPE_ANY 0x5
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
2016-03-27 17:58:38 +03:00
|
|
|
/* initialization/termination functions of shared objects */
|
2019-02-02 03:19:38 +03:00
|
|
|
#define B_INIT_BEFORE_FUNCTION_NAME "initialize_before"
|
2007-10-16 03:21:01 +04:00
|
|
|
#define B_INIT_AFTER_FUNCTION_NAME "initialize_after"
|
2019-02-02 03:19:38 +03:00
|
|
|
#define B_TERM_BEFORE_FUNCTION_NAME "terminate_before"
|
2007-10-16 03:21:01 +04:00
|
|
|
#define B_TERM_AFTER_FUNCTION_NAME "terminate_after"
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2019-02-03 02:10:54 +03:00
|
|
|
void initialize_before(image_id self);
|
|
|
|
void initialize_after(image_id self);
|
|
|
|
void terminate_before(image_id self);
|
|
|
|
void terminate_after(image_id self);
|
2019-02-02 04:30:39 +03:00
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
2013-11-06 00:27:42 +04:00
|
|
|
#define B_APP_IMAGE_SYMBOL ((void*)(addr_t)0)
|
2016-03-27 17:58:38 +03:00
|
|
|
/* value that can be used instead of a pointer to a symbol in the program
|
|
|
|
image. */
|
headers/kernel: Define B_CURRENT_IMAGE_SYMBOL via __func__.
Previously, __haiku_init_before was a symbol that was included in
each (shared) object, and so it could be used to determine what
one we were in. Now, there are no such universal symbols that
are declared private to only the object, so we have to use
a different approach.
__func__ is defined as a const char* at the very beginning of
every function it's used in, set to a string of the function name
only, i.e., the arguments and return type are left off. So while
including that is perhaps not quite optimal, in practice this
definition is used extremely rarely (it was introduced by Haiku,
and it is used in only 2 applications at all that I could find --
WebKit and Canna.)
There really isn't any other way to get a pointer that we know
for certain is within the current object besides this one
without inserting one, but that really isn't merited just for this.
(__builtin_return_address() has problematic semantics wrt. inlining,
including linker-inlining.) So this will have to do.
2019-02-02 03:50:29 +03:00
|
|
|
#define B_CURRENT_IMAGE_SYMBOL ((void*)&__func__)
|
2016-03-27 17:58:38 +03:00
|
|
|
/* pointer to a symbol in the callers image */
|
2013-11-06 00:27:42 +04:00
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
2007-10-16 03:21:01 +04:00
|
|
|
thread_id load_image(int32 argc, const char **argv, const char **environ);
|
|
|
|
image_id load_add_on(const char *path);
|
|
|
|
status_t unload_add_on(image_id image);
|
|
|
|
status_t get_image_symbol(image_id image, const char *name, int32 symbolType,
|
|
|
|
void **_symbolLocation);
|
|
|
|
status_t get_nth_image_symbol(image_id image, int32 n, char *nameBuffer,
|
|
|
|
int32 *_nameLength, int32 *_symbolType, void **_symbolLocation);
|
|
|
|
void clear_caches(void *address, size_t length, uint32 flags);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2007-10-16 03:21:01 +04:00
|
|
|
#define get_image_info(image, info) \
|
|
|
|
_get_image_info((image), (info), sizeof(*(info)))
|
|
|
|
#define get_next_image_info(team, cookie, info) \
|
|
|
|
_get_next_image_info((team), (cookie), (info), sizeof(*(info)))
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2007-10-16 03:21:01 +04:00
|
|
|
/* private, use the macros above */
|
2009-10-14 16:51:19 +04:00
|
|
|
status_t _get_image_info(image_id image, image_info *info, size_t size);
|
|
|
|
status_t _get_next_image_info(team_id team, int32 *cookie, image_info *info,
|
2007-10-16 03:21:01 +04:00
|
|
|
size_t size);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2013-11-06 00:27:42 +04:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-02 03:19:38 +03:00
|
|
|
|
2002-10-05 05:19:31 +04:00
|
|
|
#endif /* _IMAGE_H */
|